<br />

The fuchsia.usb.policy interfaces provide mechanisms for clients to query and monitor
the overall state of USB devices and the USB subsystem, independent of the underlying
hardware driver implementations.
Added: HEAD

## **PROTOCOLS**

## Configuration

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=107)*

Protocol for querying and dynamically reconfiguring USB peripheral functions.

Enables policy managers and system command-line tools to inspect active USB peripheral
configurations and reconfigure the peripheral device function stack at runtime.

<br />

### ConnectCable

Reconnects the Type-C port CC lines via the USB power debug service after
a previous `DisconnectCable` call, cancelling any pending automatic
reconnect alarm.

#### Request

\<EMPTY\>

#### Response

| Name | Type |
|---|---|
| `payload` | `Configuration_ConnectCable_Result` |

### DisconnectCable

Disconnects the Type-C port CC lines via the USB power debug service
to simulate a physical cable unplug.

If `duration` is positive, schedules an automatic Type-C cable reconnect
after `duration` using a hardware wake alarm in the persistent usb-policy
service so reconnect still completes even if the calling CLI session is
terminated when the USB link drops.

If `wait` is true, the reply is sent once the scheduled reconnect has
restored the CC lines instead of right after the disconnect. Closing the
channel while waiting doesn't cancel the reconnect.

# Errors

- `ZX_ERR_INVALID_ARGS`: `duration < 0`, or `wait` is true with `duration == 0`.
- `ZX_ERR_UNAVAILABLE`: USB power debug or wake alarm service is unavailable.
- `ZX_ERR_CANCELED`: The pending reconnect was cancelled by a concurrent `ConnectCable` or `DisconnectCable` while waiting.
- `ZX_ERR_INTERNAL`: Failed to arm the wake alarm or update the Type-C cable connection state.

#### Request

| Name | Type |
|---|---|
| `duration` | `zx/Duration` |
| `wait` | `bool` |

#### Response

| Name | Type |
|---|---|
| `payload` | `Configuration_DisconnectCable_Result` |

### GetConfiguration

Retrieves the current USB device descriptor and active configuration descriptors.

# Errors

- `ZX_ERR_NOT_SUPPORTED`: Peripheral function querying is not supported on the target hardware.

#### Request

\<EMPTY\>

#### Response

| Name | Type |
|---|---|
| `payload` | `Configuration_GetConfiguration_Result` |

### SetConfiguration

Sets and activates a new USB peripheral function configuration.

Teardown of the previous peripheral function stack occurs before initializing
and binding the newly specified functions. The call completes once the peripheral
controller and underlying function drivers are registered and ready.

# Errors

- `ZX_ERR_INVALID_ARGS`: Configuration parameters are invalid.
- `ZX_ERR_ALREADY_BOUND`: An existing peripheral configuration is locked or undergoing transition.
- `ZX_ERR_NOT_SUPPORTED`: The requested combination of functions cannot be supported simultaneously.

#### Request

| Name | Type |
|---|---|
| `device_desc` | `fuchsia.hardware.usb.peripheral/DeviceDescriptor` |
| `config_descriptors` | `vector<fuchsia.hardware.usb.peripheral/ConfigurationDescriptor>:5` |

#### Response

| Name | Type |
|---|---|
| `payload` | `Configuration_SetConfiguration_Result` |

## Health

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=91)*

Protocol for retrieving diagnostic and health information from the USB system.

<br />

### GetReport

Returns a snapshot of the current USB health and device state.

#### Request

\<EMPTY\>

#### Response

| Name | Type |
|---|---|
| `payload` | `Health_GetReport_Result` |

## PolicyProvider

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=98)*

An interface to monitor dynamic changes to the USB device state.

<br />

### WatchDeviceState

Notify a client of an updated device state value via a hanging get.
The first time this is called, it will return right away with the
current state. Subsequent calls will hang until there is a change
to report.
Returns a table containing the updated device state.

#### Request

\<EMPTY\>

#### Response

| Name | Type |
|---|---|
| `payload` | `fuchsia.hardware.usb.policy/DeviceStateWatcher_WatchDeviceState_Result` |

## **STRUCTS**

### Configuration_ConnectCable_Response

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=169)*

\<EMPTY\>

### Configuration_DisconnectCable_Response

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=164)*

\<EMPTY\>

### Configuration_GetConfiguration_Response

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=114)*

| Field | Type | Description | Default |
|---|---|---|---|
| `device_desc` | `fuchsia.hardware.usb.peripheral/DeviceDescriptor` |   | No default |
| `config_descriptors` | `vector<fuchsia.hardware.usb.peripheral/ConfigurationDescriptor>:5` |   | No default |

### Configuration_SetConfiguration_Response

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=137)*

\<EMPTY\>

## **ENUMS**

### CableStatus [flexible](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

Type: `uint32`

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=13)*

Status of the physical USB cable connection.

<br />

| Name | Value | Description |
|---|---|---|
| ### DISCONNECTED | `0` |   |
| ### CONNECTED | `1` |   |

### FunctionStatus [flexible](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

Type: `uint32`

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=19)*

Health status of a USB function driver or connection.

<br />

| Name | Value | Description |
|---|---|---|
| ### DISABLED | `0` |   |
| ### DISCONNECTED | `1` |   |
| ### CONNECTED | `2` |   |
| ### ERROR | `3` |   |

## **TABLES**

### AdbHealth

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=28)*

Health information for the USB ADB function subsystem.

<br />

| Ordinal | Field | Type | Description |
|---|---|---|---|
| ### 1 | `status` | `FunctionStatus` | Describes the high-level policy and configuration state of the ADB function. |
| ### 2 | `details` | `string:128` | Provides additional diagnostic details or state description. |
| ### 3 | `online` | `bool` | Indicates whether the underlying ADB daemon connection and transport are actively online and communicating with the host. In contrast to `status == CONNECTED` (which indicates the USB peripheral function descriptor is configured and bound), `online` indicates that end-to-end ADB transport is active. |
| ### 4 | `driver_state` | `string:32` | Describes the runtime execution state reported by the ADB function driver (e.g. "kAwaitingUsbConnection", "kOnline", "kStoppingForReconnect", "kStoppingForUnbind"). |

### CdcEthernetHealth

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=44)*

Health information for the USB CDC Ethernet function subsystem.

<br />

| Ordinal | Field | Type | Description |
|---|---|---|---|
| ### 1 | `status` | `FunctionStatus` | Describes the high-level policy and configuration state of the CDC Ethernet function. |
| ### 2 | `details` | `string:128` | Provides additional diagnostic details or state description. |
| ### 3 | `online` | `bool` | Indicates whether the underlying Ethernet network interface and link are actively online and ready for network traffic. In contrast to `status == CONNECTED` (which indicates the USB CDC interface is configured on the bus), `online` indicates that the link state is up. |

### HealthReport

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=74)*

A snapshot of the USB controller's current status and health.

<br />

| Ordinal | Field | Type | Description |
|---|---|---|---|
| ### 1 | `state` | `fuchsia.hardware.usb.policy/DeviceState` | Describes the current state of the device as defined by the USB 2.0 spec. |
| ### 2 | `address` | `uint8` | The address assigned to the USB device. |
| ### 3 | `cable_status` | `CableStatus` | Indicates whether the USB physical cable / `VBUS` is attached (\[CableStatus\]). |
| ### 4 | `adb` | `AdbHealth` | Describes the health status of the ADB function subsystem (\[AdbHealth\]). |
| ### 5 | `cdc_ethernet` | `CdcEthernetHealth` | Describes the health status of the CDC Ethernet function subsystem (\[CdcEthernetHealth\]). |
| ### 6 | `vsock` | `VsockHealth` | Describes the health status of the VSOCK function subsystem (\[VsockHealth\]). |

### VsockHealth

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=56)*

Health information for the USB VSOCK function subsystem.

<br />

| Ordinal | Field | Type | Description |
|---|---|---|---|
| ### 1 | `status` | `FunctionStatus` | Describes the high-level policy and configuration state of the VSOCK function. |
| ### 2 | `active_channels` | `uint32` | The number of currently active or open multiplexed VSOCK socket channels. If unknown or unsupported by the function driver, this field is absent (None). |
| ### 3 | `details` | `string:128` | Provides additional diagnostic details or state description. |
| ### 4 | `online` | `bool` | Indicates whether the underlying VSOCK transport driver is actively online and ready for traffic. In contrast to `status == CONNECTED` (which indicates the USB function is configured on the bus), `online` indicates that the VSOCK service is bound and ready to accept connections. |
| ### 5 | `driver_state` | `string:32` | Describes the runtime execution state reported by the VSOCK function driver (e.g. "Unconfigured", "Running"). |

## **UNIONS**

### Configuration_ConnectCable_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=169)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `Configuration_ConnectCable_Response` |   |
| ### 2 | `err` | `zx/Status` |   |
| ### 3 | `framework_err` | `internal` |   |

<br />

### Configuration_DisconnectCable_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=164)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `Configuration_DisconnectCable_Response` |   |
| ### 2 | `err` | `zx/Status` |   |
| ### 3 | `framework_err` | `internal` |   |

<br />

### Configuration_GetConfiguration_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=114)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `Configuration_GetConfiguration_Response` |   |
| ### 2 | `err` | `zx/Status` |   |
| ### 3 | `framework_err` | `internal` |   |

<br />

### Configuration_SetConfiguration_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=137)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `Configuration_SetConfiguration_Response` |   |
| ### 2 | `err` | `zx/Status` |   |
| ### 3 | `framework_err` | `internal` |   |

<br />

### Health_GetReport_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language.md.txt#strict-vs-flexible)

*Defined in [fuchsia.usb.policy/policy.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=93)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `HealthReport` |   |
| ### 2 | `err` | `zx/Status` |   |
| ### 3 | `framework_err` | `internal` |   |

<br />

## **CONSTANTS**

| Name | Value | Type | Description |
|---|---|---|---|
| [MAX_DETAILS_LENGTH](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.usb.policy/policy.fidl;l=10) | `128` | `uint32` |   |