|
USBIP C library 0.7.0
Virtual USB devices & host drivers over USB/IP
|
A reusable device class: the descriptors it declares, the callbacks that drive it, and the size of its per-instance state. More...
#include <classes/usb_class.h>
Data Fields | |
| const char * | name |
| The class's name, e.g. | |
| uint8_t | bInterfaceClass |
| Default bInterfaceClass for the interface. | |
| uint8_t | bInterfaceSubClass |
| Default bInterfaceSubClass. | |
| uint8_t | bInterfaceProtocol |
| Default bInterfaceProtocol. | |
| int(* | build )(usbip_function *func, const void *params) |
| Build the function (required). | |
| int(* | control )(usbip_function *func, const usb_setup *setup, uint8_t *buf, uint16_t len) |
| Handle a class/vendor control request on endpoint 0 (optional). | |
| void(* | on_out )(usbip_function *func, usbip_ep *ep, const void *data, int len) |
| A bulk/interrupt OUT packet arrived from the host (optional). | |
| int(* | set_alt )(usbip_function *func, int ifnum, int alt) |
| The host issued SET_INTERFACE (optional). | |
| int(* | on_iso )(usbip_function *func, usbip_ep *ep, int npkts, uint32_t *lens, uint8_t *buf) |
| Isochronous data (optional). | |
| void(* | destroy )(usbip_function *func) |
| Release per-instance state on teardown (optional). | |
| size_t | state_size |
| Bytes of per-instance state - zero-initialised and reachable from any callback via usbip_function_state(). | |
A reusable device class: the descriptors it declares, the callbacks that drive it, and the size of its per-instance state.
Declare one statically, then instantiate it on a device with usbip_device_add_class() (the built-in classes also expose a convenience *_add() helper).
Every callback receives the usbip_function being served - reach its per-instance state with usbip_function_state() and its device with usbip_function_device(). Only build is required; any other callback may be NULL (that event is then simply not handled).
| const char* usbip_device_class::name |
The class's name, e.g.
"hid" - used in diagnostics.
| uint8_t usbip_device_class::bInterfaceClass |
Default bInterfaceClass for the interface.
| uint8_t usbip_device_class::bInterfaceSubClass |
Default bInterfaceSubClass.
| uint8_t usbip_device_class::bInterfaceProtocol |
Default bInterfaceProtocol.
| int(* usbip_device_class::build) (usbip_function *func, const void *params) |
Build the function (required).
Called once when the function is instantiated - via usbip_device_add_class() or a class's *_add() helper: declare the interface/endpoint/class descriptors with usbip_function_add_descriptor() and keep the endpoint pipes it returns.
| func | the function being created. |
| params | the class-specific parameters (a *_add() helper passes its opts struct through). |
| int(* usbip_device_class::control) (usbip_function *func, const usb_setup *setup, uint8_t *buf, uint16_t len) |
Handle a class/vendor control request on endpoint 0 (optional).
The core answers standard requests; only class/vendor ones reach here. Same contract as usbip_function_control_fn.
| func | the function. |
| setup | the 8-byte SETUP packet. |
| buf | data buffer - IN: fill with up to len bytes; OUT: holds len bytes. |
| len | IN: capacity of buf; OUT: number of bytes received. |
| void(* usbip_device_class::on_out) (usbip_function *func, usbip_ep *ep, const void *data, int len) |
A bulk/interrupt OUT packet arrived from the host (optional).
| func | the function. |
| ep | the OUT endpoint it arrived on. |
| data | the received bytes. |
| len | number of bytes in data. |
| int(* usbip_device_class::set_alt) (usbip_function *func, int ifnum, int alt) |
The host issued SET_INTERFACE (optional).
Lets an interface that spans several USB interfaces (e.g. audio's two streaming interfaces) tell them apart.
| func | the function. |
| ifnum | the interface whose alternate setting changed. |
| alt | the newly selected alternate setting. |
| int(* usbip_device_class::on_iso) (usbip_function *func, usbip_ep *ep, int npkts, uint32_t *lens, uint8_t *buf) |
Isochronous data (optional).
Same contract as usbip_ep_iso_fn: buf holds npkts packets back-to-back, packet i being lens[i] bytes. On an OUT endpoint the packets arrive filled in - read them. On an IN endpoint lens[i] arrives as the size the host asked for - fill buf and set each lens[i] to the bytes you wrote. A function serving both directions (e.g. audio) tells them apart with usbip_endpoint_address(ep) & 0x80 (set = IN).
| func | the function. |
| ep | the isochronous endpoint. |
| npkts | number of packets. |
| lens | the per-packet sizes. |
| buf | the packet bytes, back-to-back. |
| void(* usbip_device_class::destroy) (usbip_function *func) |
Release per-instance state on teardown (optional).
Called when a failed build unwinds; free anything build allocated.
| func | the function being destroyed. |
| size_t usbip_device_class::state_size |
Bytes of per-instance state - zero-initialised and reachable from any callback via usbip_function_state().