The `usb` class contains several subclasses providing access to the interfaces, descriptors,
and endpoints of the usb device. The subclasses included are:

- [`InterfaceList`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/src/devices/usb/lib/usb/include/usb/usb.h#523)
- [`Interface`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/src/devices/usb/lib/usb/include/usb/usb.h#405)
- [`DescriptorList`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/src/devices/usb/lib/usb/include/usb/usb.h#203)
- [`EndpointList`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/src/devices/usb/lib/usb/include/usb/usb.h#311)

USB descriptor report all of the device's attributes. An endpoint is a specific type of descriptor
that describes the terminus of a communication flow between the host and the device.

The `InterfaceList` class iterates over each `Interface` within the usb device.
Each `Interface` then contains:

- `DescriptorList` through `GetDescriptorList()`
- `EndpointList` through `GetEndpointList()`

These methods allow access to all the descriptors and endpoints of the interface.

> [!NOTE]
> **Note:** Endpoints are still considered descriptors and therefore can also be accessible through the `GetDescriptorList()` method.

The hierarchy of these subclasses can be seen in **Figure 1.**

![Diagram of USB class hierarchy](https://fuchsia.dev/static/fuchsia-src/development/drivers/driver_guides/usb/images/usbstructure.jpg)

**Figure 1**

## Examples

### Receiving Descriptors from USB

These examples iterate through all the descriptors in a USB device. The example iterates through all
of the USB Interfaces and then iterates through all the descriptors in each interface.

> [!NOTE]
> **Note:** To iterate through the endpoints instead, replace `interface.GetDescriptorList()` with `interface.GetEndpointList()`.

#### Range-based for loop

    std::optional<InterfaceList> interface_list;

    status = InterfaceList::Create(my_client, true, &interface_list);

    if (status != ZX_OK) {
        ...
    }

    for (auto& interface : *interface_list) {

        for (auto& descriptor : interface.GetDescriptorList()) {
            ...
        }
    }

#### Manual for loop

    std::optional<InterfaceList> interface_list;

    status = InterfaceList::Create(my_client, true, &interface_list);

    if (status != ZX_OK) {
        ...
    }

    for (auto& interface : *interface_list) {

        auto dList_itr = interface.GetDescriptorList().begin(); // or cbegin().

        do {
            ...
        } while (++dList_itr != interface.GetDescriptorList().end());
    }

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/drivers/driver_guides/usb/getting_descriptors_and_endpoints.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/drivers/driver_guides/usb/getting_descriptors_and_endpoints.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/drivers/driver_guides/usb/getting_descriptors_and_endpoints.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/drivers/driver_guides/usb/getting_descriptors_and_endpoints.md "Edit the source code of this page")