godspeed_sdk/usbfn.rs
1// SPDX-License-Identifier: Apache-2.0
2//! The USB FUNCTION PROTOCOL's numbers: what a USB host service (`xhci`, `dwc2`, `ehci`) answers for the one device it
3//! binds for a driver of its own, and what that driver asks. A driver package speaks it through
4//! `gs::driver::bus`; the WiFi dongle's driver through `godspeed_wifi::usbfn`, which re-exports these and says
5//! what each one means in full (`sdk/wifi/src/usbfn.rs`). Every request starts with its op, and every reply with
6//! `[op, status]`.
7
8/// `[op]` -> `[op, status, vid (2 LE), pid (2 LE), gen (4 LE), ...]`: which device is bound, and which binding of it.
9pub const OP_INFO: u8 = 0x20;
10/// Where an `OP_INFO` answer's binding generation starts.
11pub const INFO_GEN_AT: usize = 6;
12/// Where the optional part of an `OP_INFO` answer starts (where the device is, from a host that says).
13pub const INFO_WHERE_AT: usize = 10;
14/// `[op, setup (8), data out...]` -> `[op, status, data in...]`: one control transfer on the default endpoint.
15pub const OP_CONTROL: u8 = 0x21;
16/// `OP_CONTROL`, attempted exactly once: the host does not retry it.
17pub const OP_CONTROL_ONCE: u8 = 0x22;
18/// `[op]` -> `[op, status, transfer...]`: the bulk IN transfer the host holds, if any; the IN armed again (`ehci`
19/// holds none: it waits briefly for the device and answers what came).
20pub const OP_BULK_IN: u8 = 0x23;
21/// `[op, out, transfer...]` -> `[op, status]`: one bulk OUT transfer to the device's `out`th bulk OUT endpoint.
22pub const OP_BULK_OUT: u8 = 0x24;
23/// `[op, notice]`, never answered: names a notice that arrived in place of an answer.
24pub const OP_SYNC: u8 = 0x25;
25/// Sent by the host, unanswered: a bulk IN transfer is held - ask `OP_BULK_IN`.
26pub const NOTE_BULK_IN: u8 = 0x2E;
27/// `[op]` -> `[op, status]`: reset the device's port and bind it afresh (`dwc2` takes it; `xhci` and `ehci` answer `ST_BAD_REQUEST`).
28pub const OP_REPLUG: u8 = 0x27;
29/// Sent by the host, unanswered: the binding changed - ask `OP_INFO`.
30pub const NOTE_RADIO: u8 = 0x2F;
31/// The transfer was done (or, for `OP_INFO`, a device is bound).
32pub const ST_OK: u8 = 0;
33/// No device is bound on this host.
34pub const ST_NO_DEVICE: u8 = 1;
35/// The host tried, and the device or the bus did not complete it.
36pub const ST_FAILED: u8 = 2;
37/// The request was malformed.
38pub const ST_BAD_REQUEST: u8 = 3;
39/// The most data one control transfer carries, either way.
40pub const CONTROL_MAX: usize = 256;
41/// The most one bulk IN transfer carries: seven 512-byte high-speed packets, beside the reply's two bytes.
42pub const BULK_IN_MAX: usize = 3584;
43/// The most one bulk OUT transfer carries: the rest of a message after the op and the endpoint byte.
44pub const BULK_OUT_MAX: usize = crate::ipc::MAX_PAYLOAD - 2;
45const _: () = assert!(BULK_IN_MAX + 2 <= crate::ipc::MAX_PAYLOAD);
46const _: () = assert!(BULK_IN_MAX % 512 == 0);