class UsbPeripheral
Defined at line 102 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::DriverBase implementation.
Defined at line 130 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t UsbDciCancelAll (uint8_t ep_address)
Defined at line 42 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
DeviceState SnapshotState ()
Defined at line 202 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetState (DeviceState state)
Defined at line 208 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
usb_mode_t SnapshotUsbMode ()
Defined at line 213 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetUsbMode (usb_mode_t mode)
Defined at line 218 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const ddk::UsbDciProtocolClient & dci ()
Defined at line 249 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const fidl::WireSyncClient<fuchsia_hardware_usb_dci::UsbDci> & dci_new ()
Defined at line 250 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
size_t ParentRequestSize ()
Defined at line 254 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
zx_status_t ConnectToEndpoint (uint8_t ep_address, fidl::ServerEnd<fuchsia_hardware_usb_endpoint::Endpoint> ep)
Defined at line 258 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const usb_device_descriptor_t & device_desc ()
Defined at line 272 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void UsbPeripheral (fdf::DriverStartArgs start_args, fdf::UnownedSynchronizedDispatcher driver_dispatcher)
Defined at line 430 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void PrepareStop (fdf::PrepareStopCompleter completer)
Defined at line 1470 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetConfiguration (SetConfigurationRequestView request, SetConfigurationCompleter::Sync & completer)
This is called by management components (e.g. usbctl) to define the initial configuration of the
USB peripheral device.
Defined at line 1357 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ClearFunctions (ClearFunctionsCompleter::Sync & completer)
Defined at line 1450 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetStateChangeListener (SetStateChangeListenerRequestView request, SetStateChangeListenerCompleter::Sync & completer)
Defined at line 1462 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t SetDeviceDescriptor (DeviceDescriptor desc)
Defined at line 1412 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 350 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t FunctionRegistered ()
Defined at line 454 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t CheckAndStartController ()
Defined at line 470 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t StartController ()
Defined at line 579 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t StopController ()
Defined at line 613 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t FunctionUnregistered ()
Defined at line 551 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void FunctionCleared (size_t function_index)
Defined at line 1100 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetStateLocked (DeviceState state)
Defined at line 646 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 698 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
bool ValidateEndpoint (size_t function_index, uint8_t ep_address)
Defined at line 776 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ReleaseResources (size_t function_index)
Defined at line 1578 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ReleaseResourcesLocked (size_t function_index)
Defined at line 1583 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 1617 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void UsbPeripheralRequestQueue (usb_request_t * usb_request, const usb_request_complete_callback_t * complete_cb)
Defined at line 87 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void OnHostConnectionChanged (bool connected)
Defined at line 1315 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 |
| kStopping | 5 |
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.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kWaitForFunctionBind:
Configuration committed. Child nodes are published. Waiting for function drivers to bind.
Transitions:
-> kStarting: Occurs when all functions have registered.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
-> kWaitForFunctionBind: Occurs when a function is unregistered (node unbound).
kStarting:
All functions have registered. Starting the DCI controller.
Transitions:
-> kPeripheralReady: Occurs when StartController() succeeds.
-> kWaitForFunctionBind: Occurs if StartController() fails.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kPeripheralReady:
All functions have registered. DCI is active. Ready for a USB host to connect.
Transitions:
-> kHostConnected: Occurs when a USB host connects.
-> kWaitForFunctionBind: Occurs if a function is unregistered.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kHostConnected:
USB host has performed enumeration and selected a configuration. Data paths are active.
Transitions:
-> kPeripheralReady: Occurs when the host disconnects.
-> kWaitForFunctionBind: Occurs if a function is unregistered.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kStopping:
Teardown in progress (either a configuration clear or a full driver shutdown).
Transitions:
-> Terminates: When all functions are cleared and the driver is stopping.
-> kNoConfiguration: When all functions are cleared and we are just clearing functions
(not stopping the driver).
Defined at line 153 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
Records
Friends
class UsbDciInterfaceServer