class UsbFunction

Defined at line 31 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

This class represents a USB function in the peripheral role configurations.

USB function drivers bind to this.

Public Methods

void UsbFunction (size_t index, UsbPeripheral * peripheral, fuchsia_hardware_usb_peripheral::wire::FunctionDescriptor desc, uint8_t configuration, uint64_t config_generation, async_dispatcher_t * dispatcher)

Defined at line 34 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

uint64_t config_generation ()

Defined at line 45 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

size_t function_index ()

Defined at line 96 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

std::string name ()

Defined at line 97 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

uint8_t configuration ()

Defined at line 99 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

const usb_descriptor_header_t * GetDescriptors (size_t * out_length)

Defined at line 103 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

const fuchsia_hardware_usb_peripheral::wire::FunctionDescriptor & GetFunctionDescriptor ()

Defined at line 108 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

uint8_t GetNumInterfaces ()

Defined at line 113 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h

void ~UsbFunction ()

Defined at line 146 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void Configure (usb_speed_t speed, fit::callback<void (zx_status_t)> completer)

Configures the function for the given bus speed. If called from an already configured state

(`kConfiguring` or `kConfigured`), performs a deconfigure/reconfigure cycle per USB 2.0

ยง 9.1.1.5 to reset the function's endpoint state.

Callback Semantics:

- Invocation: Invoked on `dispatcher_` exactly once: asynchronously when the function driver

acknowledges the `UsbFunctionInterface.SetConfigured(true)` FIDL call (or an error/cancel

occurs), or synchronously with `ZX_ERR_BAD_STATE` if the function interface is unbound or in

`kWaitingForBind` / `kCleared`.

- Status codes:

* `ZX_OK`: Function driver successfully enabled its endpoints and is active.

* `ZX_ERR_BAD_STATE`: Function interface is unbound or in `kWaitingForBind` / `kCleared`.

* `ZX_ERR_CANCELED`: Request was superseded by a subsequent `Configure()`, `Unconfigure()`,

or disconnect before the configure RPC completed.

* Other error codes returned by the function driver or FIDL transport.

Defined at line 575 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void Unconfigure (fit::callback<void (zx_status_t)> completer)

Unconfigures the function (`UsbFunctionInterface::SetConfigured(false)`), coalescing

concurrent callers onto a single in-flight RPC and canceling any queued `Configure()` request.

Callback Semantics:

- Invocation: Invoked on `dispatcher_` exactly once when the function driver finishes

disabling its endpoints and canceling in-flight transfers. If the function is already

unconfigured, unbound, or in `kCleared`, the callback is invoked synchronously with `ZX_OK`.

- Status codes:

* `ZX_OK`: Function is deconfigured (or was already unconfigured/unbound/closed).

* Unexpected error codes returned by the function driver or FIDL transport.

Defined at line 630 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void SetInterface (uint8_t interface, uint8_t alt_setting, fit::callback<void (zx_status_t)> completer)

Selects an alternate setting for an interface on the function driver.

Callback Semantics:

- Invocation: Invoked on `dispatcher_` exactly once: asynchronously when the function driver

acknowledges `UsbFunctionInterface.SetInterface()`, or synchronously with `ZX_ERR_BAD_STATE`

if the function interface is invalid.

- Status codes:

* `ZX_OK`: Interface alternate setting applied successfully.

* `ZX_ERR_BAD_STATE`: Function interface is invalid.

* Errors propagated from the function driver or FIDL transport.

Defined at line 675 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void Control (const fdescriptor::wire::UsbSetup & setup, std::span<const uint8_t> write_buffer, fit::callback<void (zx::result<std::vector<uint8_t>>)> completer)

Forwards a setup control request to the function driver via `UsbFunctionInterface.Control()`.

Callback Semantics:

- Invocation: Invoked on `dispatcher_` exactly once with the read payload on success or an

error status on failure.

Defined at line 704 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void RequestRemoval ()

Defined at line 447 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void OnNodeControllerUnbound (fidl::UnbindInfo info)

Defined at line 469 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

std::optional<std::vector<uint8_t>> GetEndpointsForInterface (uint8_t interface_num, uint8_t alt_setting)

Returns all endpoint addresses associated with the given interface and alternate setting

by parsing the function's descriptors. Returns std::nullopt if the function has no descriptors

(e.g. mock test functions).

Defined at line 879 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

zx_status_t UsbFunctionCancelAll (uint8_t ep_address)
void ConnectToEndpoint (ConnectToEndpointRequest & request, ConnectToEndpointCompleter::Sync & completer)

fuchsia_hardware_usb_function.UsbFunction protocol implementation.

Defined at line 191 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void Configure (ConfigureRequest & request, ConfigureCompleter::Sync & completer)

Defined at line 295 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void AllocResources (AllocResourcesRequest & request, AllocResourcesCompleter::Sync & completer)

Defined at line 206 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void EndpointSetStall (EndpointSetStallRequest & request, EndpointSetStallCompleter::Sync & completer)

Defined at line 230 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void EndpointClearStall (EndpointClearStallRequest & request, EndpointClearStallCompleter::Sync & completer)

Defined at line 246 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void ConfigureEndpoint (ConfigureEndpointRequest & request, ConfigureEndpointCompleter::Sync & completer)

Defined at line 262 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void DisableEndpoint (DisableEndpointRequest & request, DisableEndpointCompleter::Sync & completer)

Defined at line 279 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

void Deconfigure (DeconfigureCompleter::Sync & completer)

Defined at line 349 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

zx::result<> AddChild (fidl::UnownedClientEnd<fuchsia_driver_framework::Node> parent, const std::shared_ptr<fdf::Namespace> & incoming, const std::shared_ptr<fdf::OutgoingDirectory> & outgoing)

Defined at line 25 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.cc

bool registered ()

Defined at line 142 of file ../../src/devices/usb/drivers/usb-peripheral/usb-function.h