Enumerations

enum class State : uint8_t
Name Value Comments
kAwaitingUsbConnection 0

In kAwaitingUsbConnection, we have called function_.Configure(), and
are waiting for usb-peripheral to call SetConfigured(true). Calls to
SetConfigured(false) complete immediately with ZX_OK.

Once SetConfigured(true) has been called, we:
- Configure and enable the bulk endpoints,
- Queue USB receive requests to the bulk OUT endpoint,
- Tell any connected UsbAdbImpl clients that the device is online, and
- Move to kOnline.

If Stop is called, we move to kStoppingForUnbind.

kOnline 1

In kOnline, the USB connection is live, and we respond to any
QueueTx/Receive requests from UsbAdbImpl clients.

If any of the following happen:
- A fadb::Device client calls StopAdb().
- A UsbAdbImpl client closes their channel.
- usb-peripheral calls SetConfigured(false).
- The host sends an adb CNXN after the device has already sent data in this
session, meaning the host started a new adb session without a USB
disconnect (e.g. its adb server was restarted mid-transfer).
- Stop gets called.

... we disable endpoints, cancel in-flight requests, and move to
kStoppingForReconnect or kStoppingForUnbind.

kStoppingForUnbind 2

In kStoppingForUnbind, we wait for all outstanding USB requests to be completed.
Once they have been, we close any UsbAdbImpl connection, reply to any pending
StopAdb()/SetConfigured(false) completers, deconfigure the USB function, and
complete the driver Stop callback.

kStoppingForReconnect 3

In kStoppingForReconnect, we wait for all outstanding USB requests to be completed.
Once they have been:
- If the stop was initiated by ADB while online (reset_usb_on_stop_ is true),
we call function_.Deconfigure() and StartUsb() (function_.Configure()) to
bounce the USB connection for adbd re-enumeration, then move to
kAwaitingUsbConnection.
- If the stop was initiated by SetConfigured(false) (host reset or physical unplug),
we keep usb_function_binding_ and adb_binding_ bound, notify adb_binding_
that the device is offline, reply to set_configured_completers_, and move
back to kAwaitingUsbConnection.

The driver's internal state machine. Begins in kAwaitingUsbConnection.

Defined at line 53 of file ../../src/developer/adb/drivers/usb-adb-function/adb-function.h

Records

Functions

  • std::vector<uint8_t> AdbHeader (uint32_t command)

    Returns an adb packet header (struct amessage) for |command| with a valid magic.

    Defined at line 812 of file ../../src/developer/adb/drivers/usb-adb-function/adb-function-test.cc

  • std::vector<uint8_t> AfterStaleData (size_t stale_bytes, const std::vector<uint8_t> & tail)

    Returns |stale_bytes| of filler followed by |tail|, as the device receives it when the host's

    previous transfer was interrupted partway through a request.

    Defined at line 871 of file ../../src/developer/adb/drivers/usb-adb-function/adb-function-test.cc