Class layer¶
The object-oriented authoring layer over the device core: a
Function is one class instance grouping one or
more interfaces, and an Interface is one
bInterfaceNumber. Single-interface classes need no explicit Function -
add() wraps a bare Interface in one.
Components → USBDevice explains the model; a new
device class is just an Interface subclass
(Components → Device classes).
function
¶
The class layer - author reusable USB device classes as objects.
An :class:Interface subclass declares endpoints (:func:~usbip.device.In /
:func:~usbip.device.Out), emits class-specific descriptors
(extra_descriptors) and handles class/vendor control requests
(on_control); a :class:Function groups one or more interfaces into the
unit Windows binds a driver to, optionally with an Interface Association
Descriptor. Both compose themselves onto a :class:~usbip.device.USBDevice
through its public primitives alone (add_group / claim_interface /
route_endpoint / on_control / ...) - the device core knows nothing
about them. Mirrors the C class layer (classes/usb_class.c) over the class-free
device core.
Function
¶
A function: one class instance grouping one or more USB :class:Interface\ s,
bound as a unit (the USB-IF Interface Association Descriptor model). Owns the child
interfaces; a composite function optionally emits an IAD (iad = True) and sets the
device-descriptor class triple (device_triple). Most classes are a single interface
and need no explicit Function - :meth:USBDevice.add wraps a bare :class:Interface in
an anonymous one. Mirrors the C usbip_function.
A subclass either sets self.interfaces = (...) before super().__init__() or
passes the list to Function.__init__. Set iad = True plus iad_class /
iad_subclass / iad_protocol (and usually device_triple = (0xEF, 0x02, 0x01))
only for a true composite function; CDC/Bluetooth/audio group their interfaces by
class-specific means and must NOT emit an IAD.
Source code in usbip/function.py
primary
property
¶
The handle :meth:USBDevice.add gives back: this class's data-plane object.
Default is the function itself; a multi-interface class points at the child
that carries the data-plane API (CDCACM -> the Data port, UVC -> the streaming
interface, ...), so one line both adds the class and names what you talk to.
Mirrors the C <class>_add() return type.
enable_msos
¶
Advertise Microsoft OS descriptors for THIS function (see
:meth:USBDevice.enable_msos). On a composite this is what scopes the
Compatible ID to this function's interfaces instead of the whole device.
Call it after the function has been added to a device.
Source code in usbip/function.py
enable_winusb
¶
association_descriptor
¶
The 8-byte Interface Association Descriptor, or b"" when this function
emits none - see iad / iad_on_composite.
Source code in usbip/function.py
Interface
¶
Source code in usbip/function.py
extra_descriptors
¶
on_control
¶
Handle a class/vendor control request. data is the OUT payload (for
host->device requests). Return bytes (IN) or b'' (OUT ack); raise Stall to
reject. Default rejects everything.
Source code in usbip/function.py
adjust_for_speed
¶
Resize speed-dependent endpoints for the device's reported speed. Called by USBDevice.add() (and USBDevice.set_speed()). Default: no change. Speed-aware classes override this to size bulk endpoints (512 B at HS) or iso endpoints (per-microframe at HS) - both the descriptor and the runtime mps follow from the endpoint's .mps.
Source code in usbip/function.py
on_iso
¶
Isochronous data: one call handles one transfer's packets. On an OUT
endpoint the host sent data - packets is a list of bytes objects, one
per packet; read them (the return value is ignored). On an IN endpoint
the host wants data - packets is a list of ints, the size it asked for
per packet; return a list of bytes objects, each up to its requested
size. An endpoint's direction never changes, so an override only ever
sees one of the two cases. Default: no data (IN) / discard (OUT).
Source code in usbip/function.py
on_out
¶
Bulk/interrupt OUT data from the host. Override to consume it as it
arrives; the default queues it on the endpoint for :meth:Endpoint.read.
on_reset
¶
Called when a host attaches (bus reset): endpoint queues are already flushed - override to reset class-level state. Default: nothing.