USBIP C library 0.7.0
Virtual USB devices & host drivers over USB/IP
Loading...
Searching...
No Matches
usbip_device_class Struct Reference

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().
 

Detailed Description

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).

Field Documentation

◆ name

const char* usbip_device_class::name

The class's name, e.g.

"hid" - used in diagnostics.

◆ bInterfaceClass

uint8_t usbip_device_class::bInterfaceClass

Default bInterfaceClass for the interface.

◆ bInterfaceSubClass

uint8_t usbip_device_class::bInterfaceSubClass

Default bInterfaceSubClass.

◆ bInterfaceProtocol

uint8_t usbip_device_class::bInterfaceProtocol

Default bInterfaceProtocol.

◆ build

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.

Parameters
functhe function being created.
paramsthe class-specific parameters (a *_add() helper passes its opts struct through).
Returns
USB_SUCCESS on success, or a negative USB_ERROR code to abort instantiation.

◆ control

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.

Parameters
functhe function.
setupthe 8-byte SETUP packet.
bufdata buffer - IN: fill with up to len bytes; OUT: holds len bytes.
lenIN: capacity of buf; OUT: number of bytes received.
Returns
bytes produced (IN) or consumed-OK (OUT, >= 0), or < 0 to STALL.

◆ on_out

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).

Parameters
functhe function.
epthe OUT endpoint it arrived on.
datathe received bytes.
lennumber of bytes in data.

◆ set_alt

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.

Parameters
functhe function.
ifnumthe interface whose alternate setting changed.
altthe newly selected alternate setting.
Returns
ignored.

◆ on_iso

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).

Parameters
functhe function.
epthe isochronous endpoint.
npktsnumber of packets.
lensthe per-packet sizes.
bufthe packet bytes, back-to-back.
Returns
USB_SUCCESS (0) on success.

◆ destroy

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.

Parameters
functhe function being destroyed.

◆ state_size

size_t usbip_device_class::state_size

Bytes of per-instance state - zero-initialised and reachable from any callback via usbip_function_state().


The documentation for this struct was generated from the following file: