class UsbPeripheral
Defined at line 98 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
This is the main class for the USB peripheral role driver.
It binds against the USB DCI driver device and manages a list of UsbFunction devices,
one for each USB function in the peripheral role configuration.
Public Members
static basic_string_view kDriverName
static basic_string_view kChildNodeName
static const uint8_t kMaxInterfaces
static const uint8_t kMaxStrings
static const uint8_t kMaxStringLength
static const uint8_t kOutEpStart
static const uint8_t kOutEpEnd
static const uint8_t kInEpStart
static const uint8_t kInEpEnd
Public Methods
zx::result<> Start (fdf::DriverContext context)
fdf::DriverBase2 implementation.
Defined at line 167 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t UsbDciEndpointSetStall (uint8_t ep_address)
Defined at line 119 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t UsbDciEndpointClearStall (uint8_t ep_address)
Defined at line 136 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
bool IsPeripheralStopping ()
Defined at line 96 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t ConnectToEndpoint (uint8_t ep_address, fidl::ServerEnd<fuchsia_hardware_usb_endpoint::Endpoint> ep)
Defined at line 153 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void UsbPeripheral ()
Defined at line 179 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void ~UsbPeripheral ()
Defined at line 180 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
DeviceState SnapshotState ()
Defined at line 228 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
size_t active_functions_count ()
Defined at line 233 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void IncrementActiveFunctionsLocked ()
Defined at line 238 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void DecrementActiveFunctions (uint64_t config_generation)
Defined at line 240 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetState (DeviceState state)
Defined at line 258 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
bool HasPendingSetConfiguration ()
Defined at line 263 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
fdescriptor::UsbMode SnapshotUsbMode ()
Defined at line 268 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetUsbMode (fdescriptor::UsbMode mode)
Defined at line 273 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const fidl::WireSyncClient<fuchsia_hardware_usb_dci::UsbDci> & dci ()
Defined at line 305 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const usb_device_descriptor_t & device_desc ()
Defined at line 310 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetBcdUsbForTesting (uint16_t bcd_usb)
Defined at line 311 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
bool HasActiveFunctionsForTesting ()
Defined at line 312 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
size_t functions_count_for_testing ()
Defined at line 316 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
inspect::Node & inspect_node ()
Defined at line 329 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const inspect::Inspector & inspector ()
Defined at line 330 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
usb_inspect::DciInspect & dci_inspect ()
Defined at line 332 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void Stop (fdf::StopCompleter completer)
Defined at line 2766 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t UsbDciCancelAll (uint8_t ep_address)
Defined at line 101 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetConfiguration (SetConfigurationRequestView request, SetConfigurationCompleter::Sync & completer)
fuchsia_hardware_usb_peripheral::Device protocol implementation.
Defined at line 2582 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ClearFunctions (ClearFunctionsCompleter::Sync & completer)
Defined at line 2682 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void GetConfiguration (GetConfigurationCompleter::Sync & completer)
Defined at line 2690 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetStateChangeListener (SetStateChangeListenerRequestView request, SetStateChangeListenerCompleter::Sync & completer)
Defined at line 2753 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void handle_unknown_method (fidl::UnknownMethodMetadata<fuchsia_hardware_usb_peripheral::Device> metadata, fidl::UnknownMethodCompleter::Sync & completer)
Defined at line 2761 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t SetDeviceDescriptor (DeviceDescriptor desc)
Defined at line 2644 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx::result<uint8_t> ValidateFunction (size_tfunction_index,void *descriptors,size_tlength)
Validates a function and returns the number of interfaces it uses on
success.
Defined at line 357 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t FunctionRegistered ()
Defined at line 514 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t CheckAndStartController ()
Defined at line 536 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t StartController ()
Defined at line 817 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t StopController ()
Defined at line 848 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t FunctionUnregistered (fit::callback<void ()> on_complete)
Handles unregistration of a single USB function (`Deconfigure` or channel closure).
Callback Semantics (`on_complete`, optional):
- Invocation: If non-null, invoked on `dispatcher()` exactly once after remaining functions
have finished unconfiguring and the DCI controller has stopped (or synchronously if the
controller was not active).
Defined at line 754 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void FunctionCleared (size_t function_index, uint64_t config_generation)
Defined at line 2070 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetStateLocked (DeviceState state)
Defined at line 880 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx::result<ResourceAllocations> AllocResources (size_tfunction_index,uint8_tinterface_count,std::span<fuchsia_hardware_usb_function::EndpointResource>endpoints,std::span<std::string>strings)
Defined at line 1134 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
bool ValidateEndpoint (size_t function_index, uint8_t ep_address)
Defined at line 1432 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ReleaseResources (size_t function_index)
Defined at line 2843 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ReleaseResourcesLocked (size_t function_index)
Defined at line 2848 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
ResourceAllocations GetResourceAllocations (size_t function_index)
Returns currently allocated resources for the given function.
For testing purposes only.
Defined at line 2883 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void OnHostConnectionChanged (bool connected, fit::callback<void ()> on_complete)
Updates host connection status and, on disconnect, drains `UsbFunction::Unconfigure()` across
all functions before transitioning back to `kPeripheralReady`.
Callback Semantics (`on_complete`, optional):
- Invocation: If non-null, invoked on `dispatcher()` exactly once: synchronously on connect
(or if no functions need unconfiguring), or asynchronously after all functions finish
unconfiguring (or clearing) on disconnect.
Defined at line 2460 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
Enumerations
enum class DeviceState : uint8_t
| Name | Value |
|---|---|
| kNoConfiguration | 0 |
| kWaitForFunctionBind | 1 |
| kStarting | 2 |
| kPeripheralReady | 3 |
| kHostConnected | 4 |
| kUnregisteringFunction | 5 |
| kClearingFunctions | 6 |
| kStoppingDriver | 7 |
The driver uses a formal state machine to manage the lifecycle of configurations
and host connections. This ensures that resources (child nodes, DCI mode) are
handled safely during asynchronous events like host (dis)connects or driver
teardown.
State Machine:
kNoConfiguration:
Initial state. No active configuration. Functions can be added to the staging area.
Transitions:
-> kWaitForFunctionBind: Occurs when a configuration is committed (SetConfiguration()
or SetDefaultConfig()). Child nodes are published.
-> kClearingFunctions: Occurs on ClearFunctions().
-> kStoppingDriver: Occurs on Stop().
kWaitForFunctionBind:
Configuration committed. Child nodes are published. Waiting for function drivers to bind.
Transitions:
-> kStarting: Occurs when all functions have registered.
-> kClearingFunctions: Occurs on ClearFunctions().
-> kStoppingDriver: Occurs on Stop().
kStarting:
All functions have registered. Starting the DCI controller.
Transitions:
-> kPeripheralReady: Occurs when StartController() succeeds.
-> kWaitForFunctionBind: Occurs if StartController() fails.
-> kClearingFunctions: Occurs on ClearFunctions().
-> kStoppingDriver: Occurs on Stop().
kPeripheralReady:
All functions have registered. DCI is active. Ready for a USB host to connect.
Transitions:
-> kHostConnected: Occurs when a USB host connects.
-> kUnregisteringFunction: Occurs if a function is unregistered (`Deconfigure` / unbind).
-> kClearingFunctions: Occurs on ClearFunctions().
-> kStoppingDriver: Occurs on Stop().
kHostConnected:
USB host has performed enumeration and selected a configuration. Data paths are active.
Transitions:
-> kPeripheralReady: Occurs when the host disconnects and all functions finish
unconfiguring.
-> kUnregisteringFunction: Occurs if a function is unregistered (`Deconfigure` / unbind).
-> kClearingFunctions: Occurs on ClearFunctions().
-> kStoppingDriver: Occurs on Stop().
kUnregisteringFunction:
A single function unregistered while the controller was active. Unconfiguring remaining
functions and stopping the controller before returning to `kWaitForFunctionBind`.
Transitions:
-> kWaitForFunctionBind: Once remaining functions finish unconfiguring and DCI stops.
-> kClearingFunctions: Occurs if ClearFunctions() is called during unregistration.
-> kStoppingDriver: Occurs if Stop() is called during unregistration.
kClearingFunctions:
Configuration clear in progress (`ClearFunctions()`). Unconfiguring all functions, stopping
the controller, and removing child nodes.
Transitions:
-> kNoConfiguration: When all functions are cleared.
-> kStoppingDriver: Occurs if Stop() is called while clearing functions.
kStoppingDriver:
Terminal driver shutdown in progress (`Stop()`).
Defined at line 165 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
Records
Friends
class UsbDciInterfaceServer