USBIP C library 0.7.0
Virtual USB devices & host drivers over USB/IP
Loading...
Searching...
No Matches
usb_class.h File Reference

Class layer - functions, interfaces, and the usbip_device_class vtable. More...

#include <stdarg.h>
#include "usbip-device.h"

Data Structures

struct  usbip_device_class
 A reusable device class: the descriptors it declares, the callbacks that drive it, and the size of its per-instance state. More...
 

Macros

#define USB_DT_CS_INTERFACE
 Class-specific descriptor type codes - CDC, UAC and UVC all use these two values.
 
#define USB_DT_CS_ENDPOINT
 class-specific endpoint descriptor
 

Typedefs

typedef struct usbip_function usbip_function
 A function: one class instance (>=1 iface)
 
typedef struct usbip_interface usbip_interface
 One USB interface (one bInterfaceNumber)

 
typedef int(* usbip_function_control_fn) (usbip_function *func, const usb_setup *setup, uint8_t *buf, uint16_t len)
 Class/vendor control handler.
 

Functions

usbip_functionusbip_device_add_function (usbip_device *dev)
 Low-level: add a bare function you configure yourself, descriptor by descriptor.
 
int usbip_function_add_descriptor (usbip_function *func, const void *descriptor)
 Append a typed descriptor (interface / endpoint / HID / class-specific) to a function, in wire order.
 
usbip_epusbip_function_add_endpoint (usbip_function *func, const void *ep_descriptor)
 Append an endpoint descriptor and return the pipe it created.
 
uint8_t usbip_function_reserve_endpoint (usbip_function *func, uint8_t want_addr)
 Claim an endpoint address now, for an endpoint declared later.
 
usbip_epusbip_function_endpoint (usbip_function *func, uint8_t addr)
 Fetch one of this function's endpoint pipes by address.
 
void usbip_function_on_control (usbip_function *func, usbip_function_control_fn cb)
 Install the class/vendor control handler for an interface.
 
int usbip_function_enable_msos (usbip_function *func, const char *compatible, const char *guid)
 Advertise Microsoft OS descriptors for one function of a composite device.
 
int usbip_function_enable_winusb (usbip_function *func, const char *guid)
 usbip_function_enable_msos() with the "WINUSB" Compatible ID.
 
usbip_functionusbip_device_add_class (usbip_device *dev, const usbip_device_class *cls, const void *params)
 Instantiate a reusable device class onto a device, adding one function.
 
void * usbip_function_state (usbip_function *func)
 The function's per-instance state block (sized by usbip_device_class::state_size).
 
usbip_deviceusbip_function_device (usbip_function *func)
 The device a function belongs to - for device-level setup from a class build (e.g.
 
int usbip_function_base_ifnum (usbip_function *func)
 The bInterfaceNumber of this function's first interface.
 
int usbip_function_instance (usbip_function *func)
 Which instance of its own class this function is, counting from 0 in add order.
 
usbip_interfaceusbip_function_add_interface (usbip_function *func, uint8_t cls, uint8_t sub, uint8_t proto)
 Add a USB interface (a fresh bInterfaceNumber, alternate setting 0) to a function.
 
int usbip_interface_add_altsetting (usbip_interface *iface, uint8_t alt)
 Add an alternate setting to an interface (same bInterfaceNumber, new bAlternateSetting).
 
int usbip_interface_add_descriptor (usbip_interface *iface, const void *descriptor)
 Append a class-specific descriptor to an interface's current alternate setting.
 
usbip_epusbip_interface_add_endpoint (usbip_interface *iface, const void *ep_descriptor)
 Append an endpoint to an interface's current alternate setting.
 
int usbip_interface_number (usbip_interface *iface)
 An interface's bInterfaceNumber.
 
void usbip_interface_set_string (usbip_interface *iface, uint8_t istr)
 Set the iInterface string index on the interface's current alternate setting.
 
void usbip_function_associate (usbip_function *func, uint8_t count, uint8_t cls, uint8_t sub, uint8_t proto, uint8_t iFunction)
 Emit an Interface Association Descriptor grouping this function's interfaces (opt-in).
 
void usbip_class_vlog (void(*emit)(void *user, const char *text), void *user, const char *prefix, const char *fmt, va_list ap)
 Format a log line and hand it to a class module's on_event-style callback.
 

Detailed Description

Class layer - functions, interfaces, and the usbip_device_class vtable.

Composes a device out of functions (one class instance each, owning one or more interfaces), mirroring the Linux gadget composite framework. Built entirely on the public device-core API (usbip_device.h): descriptor groups, per-interface control/set-alt registration, and per-endpoint data callbacks. The core never references this layer, so a device can also be authored against the core alone.

Conventions: functions return USB_SUCCESS (0) on success and a negative USB_ERROR code on failure; constructors return a pointer or NULL. The prefix names the receiver of the first parameter (usbip_function_*, usbip_interface_*).