Skip to main content

UsbRequest

Enum UsbRequest 

Source
pub enum UsbRequest {
    ConnectToEndpoint {
        ep_addr: u8,
        ep: ServerEnd<EndpointMarker>,
        responder: UsbConnectToEndpointResponder,
    },
    GetDeviceSpeed {
        responder: UsbGetDeviceSpeedResponder,
    },
    GetDeviceId {
        responder: UsbGetDeviceIdResponder,
    },
    GetDeviceDescriptor {
        responder: UsbGetDeviceDescriptorResponder,
    },
    GetConfigurationDescriptor {
        config: u8,
        responder: UsbGetConfigurationDescriptorResponder,
    },
    GetConfiguration {
        responder: UsbGetConfigurationResponder,
    },
    SetConfiguration {
        configuration: u8,
        responder: UsbSetConfigurationResponder,
    },
    SetInterface {
        interface_number: u8,
        alt_setting: u8,
        responder: UsbSetInterfaceResponder,
    },
    ControlTransfer {
        setup: UsbSetup,
        timeout_ns: i64,
        write_data: Vec<u8>,
        responder: UsbControlTransferResponder,
    },
    EnableEndpoint {
        ep_desc: UsbEndpointDescriptor,
        ss_com_desc: UsbSsEpCompDescriptor,
        enable: bool,
        responder: UsbEnableEndpointResponder,
    },
    ResetEndpoint {
        ep_address: u8,
        responder: UsbResetEndpointResponder,
    },
#[non_exhaustive]
_UnknownMethod { ordinal: u64, control_handle: UsbControlHandle, method_type: MethodType, }, }
Expand description

Protocol for managing and communicating with an attached USB device on the host bus.

Unless otherwise noted, methods on this protocol reply only after the corresponding USB bus transaction (if any) and host controller state update have completed.

Variants§

§

ConnectToEndpoint

Connects a channel to the specified USB endpoint (ep_addr).

Endpoint 0 (the default control pipe) cannot be connected via this method; use [ControlTransfer] instead.

Closing the [Usb] channel does not automatically close open [Endpoint] channels, which remain bound to the underlying host controller until explicitly closed by the client or disconnected when the physical USB device is unplugged.

  • error:
    • ZX_ERR_INVALID_ARGS if ep_addr refers to endpoint 0 or an endpoint number > 15.
    • ZX_ERR_NOT_FOUND if the device or endpoint address does not exist.
    • ZX_ERR_ALREADY_BOUND if the endpoint is already bound to an active channel.
    • ZX_ERR_IO_NOT_PRESENT if the device has been disconnected.
§

GetDeviceSpeed

Returns the negotiated bus speed of the USB device.

§

GetDeviceId

Returns the internal device ID assigned by the USB host controller / bus driver.

Fields

§

GetDeviceDescriptor

Returns the USB device descriptor.

§

GetConfigurationDescriptor

Returns the full raw configuration descriptor hierarchy (in standard USB wire format) for the configuration with bConfigurationValue == config.

  • error:
    • ZX_ERR_INVALID_ARGS if config does not match any configuration descriptor on the device.
§

GetConfiguration

Returns the bConfigurationValue of the currently active USB configuration.

§

SetConfiguration

Selects the active USB configuration (SET_CONFIGURATION) and updates the host controller state.

Replies after the SET_CONFIGURATION control transfer and controller state update complete.

  • error:
    • ZX_ERR_INVALID_ARGS if configuration does not match any configuration on the device.
    • ZX_ERR_TIMED_OUT if the control transfer times out.
    • ZX_ERR_IO_REFUSED if the device stalls the request.
    • ZX_ERR_IO_NOT_PRESENT if the device has been disconnected.
    • ZX_ERR_NOT_SUPPORTED if invoked on an interface-scoped connection that prohibits device-wide configuration changes.

Fields

§configuration: u8
§

SetInterface

Selects an alternate setting for the specified USB interface (SET_INTERFACE) and updates the host controller state.

Replies after the SET_INTERFACE control transfer and controller state update complete.

  • error:
    • ZX_ERR_INVALID_ARGS if interface_number or alt_setting is invalid.
    • ZX_ERR_TIMED_OUT if the control transfer times out.
    • ZX_ERR_IO_REFUSED if the device stalls the request.
    • ZX_ERR_IO_NOT_PRESENT if the device has been disconnected.

Fields

§interface_number: u8
§alt_setting: u8
§

ControlTransfer

Performs a synchronous USB control transfer (IN or OUT) over endpoint 0.

Replies after the control transaction completes on the bus (and any associated host controller state updates for standard SET_CONFIGURATION or SET_INTERFACE requests finish).

While this method can be used to read descriptors, prefer [GetDeviceDescriptor] and [GetConfigurationDescriptor] when reading descriptors.

If timeout_ns is 0 or negative, a default 5-second timeout is used (per USB 2.0 Section 9.2.6.4).

  • error:
    • ZX_ERR_INVALID_ARGS if the setup packet length or write_data size is invalid.
    • ZX_ERR_TIMED_OUT if the control transfer does not complete within the timeout.
    • ZX_ERR_IO_REFUSED if the device returns a STALL handshake.
    • ZX_ERR_IO_NOT_PRESENT if the device has been disconnected.
    • ZX_ERR_NOT_SUPPORTED if the server does not support raw control transfers.

Fields

§setup: UsbSetup
§timeout_ns: i64
§write_data: Vec<u8>
§

EnableEndpoint

Enables or disables a USB endpoint on the host controller, configuring it as specified by the provided descriptors.

Replies after the host controller has updated its endpoint context and transfer ring state.

  • error:
    • ZX_ERR_INVALID_ARGS if the endpoint descriptor is invalid.
    • ZX_ERR_NO_RESOURCES if the host controller lacks bandwidth or resources.
    • ZX_ERR_IO_NOT_PRESENT if the device has been disconnected.
    • ZX_ERR_NOT_SUPPORTED if the server does not support direct endpoint configuration.

Fields

§ep_desc: UsbEndpointDescriptor
§ss_com_desc: UsbSsEpCompDescriptor
§enable: bool
§

ResetEndpoint

Resets an endpoint on the host controller that is in a halted or error state, returning the host controller’s endpoint ring and data toggle to a normal running state.

Note: To clear a halt condition on a non-control endpoint, clients should also issue a standard CLEAR_FEATURE(ENDPOINT_HALT) control request to the device to reset the device’s data toggle to DATA0.

  • error:
    • ZX_ERR_INVALID_ARGS if the endpoint is not halted or the address is invalid.
    • ZX_ERR_IO_NOT_PRESENT if the device has been disconnected.

Fields

§ep_address: u8
§

#[non_exhaustive]
_UnknownMethod

An interaction was received which does not match any known method.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§ordinal: u64

Ordinal of the method that was called.

§control_handle: UsbControlHandle
§method_type: MethodType

Implementations§

Trait Implementations§

Source§

impl Debug for UsbRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.