/* This was pulled from data at https://www.kernel.org/doc/html/latest/usb/usbip_protocol.html * and translated to stdint types * * The values that are to be placed into the fields, or read out of the fields * are in network byte order. * * Except... the setup block which appears to be literal. */ #include #ifndef _USBIP_H_ #define _USBIP_H_ /* Advertise version 1.11 * * There was no obvious place that indicated what features each * version has. */ #define USBIP_VERSION 0x0111 #define USBIP_OP_REQ_DEVLIST 0x8005 #define USBIP_OP_REP_DEVLIST 0x0005 #define USBIP_OP_REQ_IMPORT 0x8003 #define USBIP_OP_REP_IMPORT 0x0003 #define USBIP_STATUS_OK 0x0 #define USBIP_SIZE_PATH 256 #define USBIP_SIZE_BUSID 32 struct usbip_op_req_devlist { uint16_t version; uint16_t command; uint32_t status; }; struct usbip_op_rep_devlist { uint16_t version; uint16_t replycode; uint32_t status; uint32_t numdevices; }; struct usbip_exported_devices { uint8_t path[USBIP_SIZE_PATH]; uint8_t busid[USBIP_SIZE_BUSID]; uint32_t busnum; uint32_t devnum; uint32_t speed; uint16_t idVendor; uint16_t idProduct; uint16_t bcdDevice; uint8_t bDeviceClass; uint8_t bDeviceSubClass; uint8_t bDeviceProtocol; uint8_t bConfigurationValue; uint8_t bNumConfigurations; uint8_t bNumInterfaces; }; struct usbip_interface { uint8_t bInterfaceClass; uint8_t bInterfaceSubClass; uint8_t bInterfaceProtocol; uint8_t padding; }; struct usbip_op_req_import { uint16_t version; uint16_t command; uint32_t status; uint8_t busid[USBIP_SIZE_BUSID]; }; struct usbip_op_rep_import { uint16_t version; uint16_t replycode; uint32_t status; struct usbip_exported_devices device; }; #define USBIP_DIR_OUT 0 #define USBIP_DIR_IN 1 #define USBIP_CMD_SUBMIT 0x00000001 #define USBIP_RET_SUBMIT 0x00000003 #define USBIP_CMD_UNLINK 0x00000002 #define USBIP_RET_UNLINK 0x00000004 #define USBIP_TF_DIR_IN 0x00000200 struct usbip_header_basic { uint32_t command; uint32_t seqnum; uint32_t devid; uint32_t direction; uint32_t ep; }; struct usbip_cmd_submit { struct usbip_header_basic command; uint32_t transfer_flags; uint32_t transfer_buffer_length; uint32_t start_frame; uint32_t number_of_packets; uint32_t interval; #define USBIP_SETUP_SIZE 8 uint8_t setup[USBIP_SETUP_SIZE]; }; /* The iso_packet_descriptor was taken from Wireshark packet dumps */ struct usbip_iso_packet_descriptor { uint32_t offset; uint32_t length; uint32_t actual_length; uint32_t status; }; struct usbip_ret_submit { struct usbip_header_basic command; uint32_t status; uint32_t actual_length; uint32_t start_frame; uint32_t number_of_packets; uint32_t error_count; uint8_t padding[8]; }; struct usbip_cmd_unlink { struct usbip_header_basic command; uint32_t unlink_seqnum; uint8_t padding[24]; }; struct usbip_ret_unlink { struct usbip_header_basic command; uint32_t status; uint8_t padding[24]; }; /* These are Linux errno values that are used in the USBIP * protocol. Others may exist, but these were observed * in protocol dumps. */ #define USBIP_ERROR_EXDEV -18 #define USBIP_ERROR_EPIPE -32 #define USBIP_ERROR_ETIME -62 #endif