Index: head/lib/libusb/libusb.h =================================================================== --- head/lib/libusb/libusb.h (revision 277244) +++ head/lib/libusb/libusb.h (revision 277245) @@ -1,492 +1,494 @@ /* $FreeBSD$ */ /*- * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef __LIBUSB_H__ #define __LIBUSB_H__ #ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include #include #include #endif #define LIBUSB_CALL #ifdef __cplusplus extern "C" { #endif #if 0 } /* indent fix */ #endif /* libusb enums */ enum libusb_class_code { LIBUSB_CLASS_PER_INTERFACE = 0, LIBUSB_CLASS_AUDIO = 1, LIBUSB_CLASS_COMM = 2, LIBUSB_CLASS_HID = 3, LIBUSB_CLASS_PTP = 6, LIBUSB_CLASS_IMAGE = 6, LIBUSB_CLASS_PRINTER = 7, LIBUSB_CLASS_MASS_STORAGE = 8, LIBUSB_CLASS_HUB = 9, LIBUSB_CLASS_DATA = 10, LIBUSB_CLASS_SMART_CARD = 11, LIBUSB_CLASS_CONTENT_SECURITY = 13, LIBUSB_CLASS_VIDEO = 14, LIBUSB_CLASS_PERSONAL_HEALTHCARE = 15, LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc, LIBUSB_CLASS_WIRELESS = 0xe0, LIBUSB_CLASS_APPLICATION = 0xfe, LIBUSB_CLASS_VENDOR_SPEC = 0xff, }; enum libusb_descriptor_type { LIBUSB_DT_DEVICE = 0x01, LIBUSB_DT_CONFIG = 0x02, LIBUSB_DT_STRING = 0x03, LIBUSB_DT_INTERFACE = 0x04, LIBUSB_DT_ENDPOINT = 0x05, LIBUSB_DT_HID = 0x21, LIBUSB_DT_REPORT = 0x22, LIBUSB_DT_PHYSICAL = 0x23, LIBUSB_DT_HUB = 0x29, LIBUSB_DT_BOS = 0x0f, LIBUSB_DT_DEVICE_CAPABILITY = 0x10, LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30, }; enum libusb_device_capability_type { LIBUSB_WIRELESS_USB_DEVICE_CAPABILITY = 0x1, LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY = 0x2, LIBUSB_SS_USB_DEVICE_CAPABILITY = 0x3, LIBUSB_CONTAINER_ID_DEVICE_CAPABILITY = 0x4, }; #define LIBUSB_DT_DEVICE_SIZE 18 #define LIBUSB_DT_CONFIG_SIZE 9 #define LIBUSB_DT_INTERFACE_SIZE 9 #define LIBUSB_DT_ENDPOINT_SIZE 7 #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 #define LIBUSB_DT_HUB_NONVAR_SIZE 7 #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6 #define LIBUSB_DT_BOS_SIZE 5 #define LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE 7 #define LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE 10 #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f #define LIBUSB_ENDPOINT_DIR_MASK 0x80 enum libusb_endpoint_direction { LIBUSB_ENDPOINT_IN = 0x80, LIBUSB_ENDPOINT_OUT = 0x00, }; #define LIBUSB_TRANSFER_TYPE_MASK 0x03 enum libusb_transfer_type { LIBUSB_TRANSFER_TYPE_CONTROL = 0, LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, LIBUSB_TRANSFER_TYPE_BULK = 2, LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, }; enum libusb_standard_request { LIBUSB_REQUEST_GET_STATUS = 0x00, LIBUSB_REQUEST_CLEAR_FEATURE = 0x01, LIBUSB_REQUEST_SET_FEATURE = 0x03, LIBUSB_REQUEST_SET_ADDRESS = 0x05, LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06, LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07, LIBUSB_REQUEST_GET_CONFIGURATION = 0x08, LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, LIBUSB_REQUEST_GET_INTERFACE = 0x0A, LIBUSB_REQUEST_SET_INTERFACE = 0x0B, LIBUSB_REQUEST_SYNCH_FRAME = 0x0C, + LIBUSB_REQUEST_SET_SEL = 0x30, + LIBUSB_REQUEST_SET_ISOCH_DELAY = 0x31, }; enum libusb_request_type { LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5), LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5), LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5), LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5), }; enum libusb_request_recipient { LIBUSB_RECIPIENT_DEVICE = 0x00, LIBUSB_RECIPIENT_INTERFACE = 0x01, LIBUSB_RECIPIENT_ENDPOINT = 0x02, LIBUSB_RECIPIENT_OTHER = 0x03, }; #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C enum libusb_iso_sync_type { LIBUSB_ISO_SYNC_TYPE_NONE = 0, LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, LIBUSB_ISO_SYNC_TYPE_SYNC = 3, }; #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 enum libusb_iso_usage_type { LIBUSB_ISO_USAGE_TYPE_DATA = 0, LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2, }; enum libusb_error { LIBUSB_SUCCESS = 0, LIBUSB_ERROR_IO = -1, LIBUSB_ERROR_INVALID_PARAM = -2, LIBUSB_ERROR_ACCESS = -3, LIBUSB_ERROR_NO_DEVICE = -4, LIBUSB_ERROR_NOT_FOUND = -5, LIBUSB_ERROR_BUSY = -6, LIBUSB_ERROR_TIMEOUT = -7, LIBUSB_ERROR_OVERFLOW = -8, LIBUSB_ERROR_PIPE = -9, LIBUSB_ERROR_INTERRUPTED = -10, LIBUSB_ERROR_NO_MEM = -11, LIBUSB_ERROR_NOT_SUPPORTED = -12, LIBUSB_ERROR_OTHER = -99, }; enum libusb_speed { LIBUSB_SPEED_UNKNOWN = 0, LIBUSB_SPEED_LOW = 1, LIBUSB_SPEED_FULL = 2, LIBUSB_SPEED_HIGH = 3, LIBUSB_SPEED_SUPER = 4, }; enum libusb_transfer_status { LIBUSB_TRANSFER_COMPLETED, LIBUSB_TRANSFER_ERROR, LIBUSB_TRANSFER_TIMED_OUT, LIBUSB_TRANSFER_CANCELLED, LIBUSB_TRANSFER_STALL, LIBUSB_TRANSFER_NO_DEVICE, LIBUSB_TRANSFER_OVERFLOW, }; enum libusb_transfer_flags { LIBUSB_TRANSFER_SHORT_NOT_OK = 1 << 0, LIBUSB_TRANSFER_FREE_BUFFER = 1 << 1, LIBUSB_TRANSFER_FREE_TRANSFER = 1 << 2, }; enum libusb_log_level { LIBUSB_LOG_LEVEL_NONE = 0, LIBUSB_LOG_LEVEL_ERROR, LIBUSB_LOG_LEVEL_WARNING, LIBUSB_LOG_LEVEL_INFO, LIBUSB_LOG_LEVEL_DEBUG }; /* XXX */ /* libusb_set_debug should take parameters from libusb_log_level * above according to * http://libusb.sourceforge.net/api-1.0/group__lib.html */ enum libusb_debug_level { LIBUSB_DEBUG_NO=0, LIBUSB_DEBUG_FUNCTION=1, LIBUSB_DEBUG_TRANSFER=2, }; /* libusb structures */ struct libusb_context; struct libusb_device; struct libusb_transfer; struct libusb_device_handle; struct libusb_pollfd { int fd; short events; }; typedef struct libusb_context libusb_context; typedef struct libusb_device libusb_device; typedef struct libusb_device_handle libusb_device_handle; typedef struct libusb_pollfd libusb_pollfd; typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data); typedef void (*libusb_pollfd_removed_cb) (int fd, void *user_data); typedef struct libusb_device_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdUSB; uint8_t bDeviceClass; uint8_t bDeviceSubClass; uint8_t bDeviceProtocol; uint8_t bMaxPacketSize0; uint16_t idVendor; uint16_t idProduct; uint16_t bcdDevice; uint8_t iManufacturer; uint8_t iProduct; uint8_t iSerialNumber; uint8_t bNumConfigurations; } libusb_device_descriptor; typedef struct libusb_endpoint_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bEndpointAddress; uint8_t bmAttributes; uint16_t wMaxPacketSize; uint8_t bInterval; uint8_t bRefresh; uint8_t bSynchAddress; uint8_t *extra; int extra_length; } libusb_endpoint_descriptor __aligned(sizeof(void *)); typedef struct libusb_ss_endpoint_companion_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bMaxBurst; uint8_t bmAttributes; uint16_t wBytesPerInterval; } libusb_ss_endpoint_companion_descriptor __aligned(sizeof(void *)); typedef struct libusb_interface_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bInterfaceNumber; uint8_t bAlternateSetting; uint8_t bNumEndpoints; uint8_t bInterfaceClass; uint8_t bInterfaceSubClass; uint8_t bInterfaceProtocol; uint8_t iInterface; struct libusb_endpoint_descriptor *endpoint; uint8_t *extra; int extra_length; } libusb_interface_descriptor __aligned(sizeof(void *)); typedef struct libusb_interface { struct libusb_interface_descriptor *altsetting; int num_altsetting; } libusb_interface __aligned(sizeof(void *)); typedef struct libusb_config_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t wTotalLength; uint8_t bNumInterfaces; uint8_t bConfigurationValue; uint8_t iConfiguration; uint8_t bmAttributes; uint8_t MaxPower; struct libusb_interface *interface; uint8_t *extra; int extra_length; } libusb_config_descriptor __aligned(sizeof(void *)); typedef struct libusb_usb_2_0_device_capability_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDevCapabilityType; uint32_t bmAttributes; #define LIBUSB_USB_2_0_CAPABILITY_LPM_SUPPORT (1 << 1) } libusb_usb_2_0_device_capability_descriptor __aligned(sizeof(void *)); typedef struct libusb_ss_usb_device_capability_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDevCapabilityType; uint8_t bmAttributes; #define LIBUSB_SS_USB_CAPABILITY_LPM_SUPPORT (1 << 1) uint16_t wSpeedSupported; #define LIBUSB_CAPABILITY_LOW_SPEED_OPERATION (1) #define LIBUSB_CAPABILITY_FULL_SPEED_OPERATION (1 << 1) #define LIBUSB_CAPABILITY_HIGH_SPEED_OPERATION (1 << 2) #define LIBUSB_CAPABILITY_5GBPS_OPERATION (1 << 3) uint8_t bFunctionalitySupport; uint8_t bU1DevExitLat; uint16_t wU2DevExitLat; } libusb_ss_usb_device_capability_descriptor __aligned(sizeof(void *)); typedef struct libusb_bos_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t wTotalLength; uint8_t bNumDeviceCapabilities; struct libusb_usb_2_0_device_capability_descriptor *usb_2_0_ext_cap; struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap; } libusb_bos_descriptor __aligned(sizeof(void *)); typedef struct libusb_control_setup { uint8_t bmRequestType; uint8_t bRequest; uint16_t wValue; uint16_t wIndex; uint16_t wLength; } libusb_control_setup; #define LIBUSB_CONTROL_SETUP_SIZE 8 /* bytes */ typedef struct libusb_iso_packet_descriptor { uint32_t length; uint32_t actual_length; enum libusb_transfer_status status; } libusb_iso_packet_descriptor __aligned(sizeof(void *)); typedef void (*libusb_transfer_cb_fn) (struct libusb_transfer *transfer); typedef struct libusb_transfer { libusb_device_handle *dev_handle; uint8_t flags; uint8_t endpoint; uint8_t type; uint32_t timeout; enum libusb_transfer_status status; int length; int actual_length; libusb_transfer_cb_fn callback; void *user_data; uint8_t *buffer; int num_iso_packets; struct libusb_iso_packet_descriptor iso_packet_desc[0]; } libusb_transfer __aligned(sizeof(void *)); /* Library initialisation */ void libusb_set_debug(libusb_context * ctx, int level); const char *libusb_strerror(int code); const char *libusb_error_name(int code); int libusb_init(libusb_context ** context); void libusb_exit(struct libusb_context *ctx); /* Device handling and enumeration */ ssize_t libusb_get_device_list(libusb_context * ctx, libusb_device *** list); void libusb_free_device_list(libusb_device ** list, int unref_devices); uint8_t libusb_get_bus_number(libusb_device * dev); int libusb_get_port_numbers(libusb_device *dev, uint8_t *buf, uint8_t bufsize); int libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *buf, uint8_t bufsize); uint8_t libusb_get_device_address(libusb_device * dev); enum libusb_speed libusb_get_device_speed(libusb_device * dev); int libusb_clear_halt(libusb_device_handle *devh, uint8_t endpoint); int libusb_get_max_packet_size(libusb_device * dev, uint8_t endpoint); int libusb_get_max_iso_packet_size(libusb_device * dev, uint8_t endpoint); libusb_device *libusb_ref_device(libusb_device * dev); void libusb_unref_device(libusb_device * dev); int libusb_open(libusb_device * dev, libusb_device_handle ** devh); libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context * ctx, uint16_t vendor_id, uint16_t product_id); void libusb_close(libusb_device_handle * devh); libusb_device *libusb_get_device(libusb_device_handle * devh); int libusb_get_configuration(libusb_device_handle * devh, int *config); int libusb_set_configuration(libusb_device_handle * devh, int configuration); int libusb_claim_interface(libusb_device_handle * devh, int interface_number); int libusb_release_interface(libusb_device_handle * devh, int interface_number); int libusb_reset_device(libusb_device_handle * devh); int libusb_check_connected(libusb_device_handle * devh); int libusb_kernel_driver_active(libusb_device_handle * devh, int interface); int libusb_get_driver_np(libusb_device_handle * devh, int interface, char *name, int namelen); int libusb_get_driver(libusb_device_handle * devh, int interface, char *name, int namelen); int libusb_detach_kernel_driver_np(libusb_device_handle * devh, int interface); int libusb_detach_kernel_driver(libusb_device_handle * devh, int interface); int libusb_attach_kernel_driver(libusb_device_handle * devh, int interface); int libusb_set_interface_alt_setting(libusb_device_handle * devh, int interface_number, int alternate_setting); /* USB Descriptors */ int libusb_get_device_descriptor(libusb_device * dev, struct libusb_device_descriptor *desc); int libusb_get_active_config_descriptor(libusb_device * dev, struct libusb_config_descriptor **config); int libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config); int libusb_get_config_descriptor_by_value(libusb_device * dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config); void libusb_free_config_descriptor(struct libusb_config_descriptor *config); int libusb_get_string_descriptor(libusb_device_handle * devh, uint8_t desc_index, uint16_t langid, unsigned char *data, int length); int libusb_get_string_descriptor_ascii(libusb_device_handle * devh, uint8_t desc_index, uint8_t *data, int length); int libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, uint8_t desc_index, uint8_t *data, int length); int libusb_parse_ss_endpoint_comp(const void *buf, int len, struct libusb_ss_endpoint_companion_descriptor **ep_comp); void libusb_free_ss_endpoint_comp(struct libusb_ss_endpoint_companion_descriptor *ep_comp); int libusb_parse_bos_descriptor(const void *buf, int len, struct libusb_bos_descriptor **bos); void libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos); /* Asynchronous device I/O */ struct libusb_transfer *libusb_alloc_transfer(int iso_packets); void libusb_free_transfer(struct libusb_transfer *transfer); int libusb_submit_transfer(struct libusb_transfer *transfer); int libusb_cancel_transfer(struct libusb_transfer *transfer); uint8_t *libusb_get_iso_packet_buffer(struct libusb_transfer *transfer, uint32_t index); uint8_t *libusb_get_iso_packet_buffer_simple(struct libusb_transfer *transfer, uint32_t index); void libusb_set_iso_packet_lengths(struct libusb_transfer *transfer, uint32_t length); uint8_t *libusb_control_transfer_get_data(struct libusb_transfer *transfer); struct libusb_control_setup *libusb_control_transfer_get_setup(struct libusb_transfer *transfer); void libusb_fill_control_setup(uint8_t *buf, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength); void libusb_fill_control_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t *buf, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout); void libusb_fill_bulk_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout); void libusb_fill_interrupt_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout); void libusb_fill_iso_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, int npacket, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout); /* Polling and timing */ int libusb_try_lock_events(libusb_context * ctx); void libusb_lock_events(libusb_context * ctx); void libusb_unlock_events(libusb_context * ctx); int libusb_event_handling_ok(libusb_context * ctx); int libusb_event_handler_active(libusb_context * ctx); void libusb_lock_event_waiters(libusb_context * ctx); void libusb_unlock_event_waiters(libusb_context * ctx); int libusb_wait_for_event(libusb_context * ctx, struct timeval *tv); int libusb_handle_events_timeout_completed(libusb_context * ctx, struct timeval *tv, int *completed); int libusb_handle_events_completed(libusb_context * ctx, int *completed); int libusb_handle_events_timeout(libusb_context * ctx, struct timeval *tv); int libusb_handle_events(libusb_context * ctx); int libusb_handle_events_locked(libusb_context * ctx, struct timeval *tv); int libusb_get_next_timeout(libusb_context * ctx, struct timeval *tv); void libusb_set_pollfd_notifiers(libusb_context * ctx, libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, void *user_data); const struct libusb_pollfd **libusb_get_pollfds(libusb_context * ctx); /* Synchronous device I/O */ int libusb_control_transfer(libusb_device_handle * devh, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength, uint32_t timeout); int libusb_bulk_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout); int libusb_interrupt_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout); /* Byte-order */ uint16_t libusb_cpu_to_le16(uint16_t x); uint16_t libusb_le16_to_cpu(uint16_t x); #if 0 { /* indent fix */ #endif #ifdef __cplusplus } #endif #endif /* __LIBUSB_H__ */ Index: head/lib/libusb/libusb20_desc.h =================================================================== --- head/lib/libusb/libusb20_desc.h (revision 277244) +++ head/lib/libusb/libusb20_desc.h (revision 277245) @@ -1,597 +1,603 @@ /* $FreeBSD$ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * Copyright (c) 2007-2008 Daniel Drake. All rights reserved. * Copyright (c) 2001 Johannes Erdfelt. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * NOTE: This file contains the definition of some standard USB * structures. All structures which name ends by *DECODED use host byte * order. */ /* * NOTE: This file uses a lot of macros. If you want to see what the * macros become when they are expanded then run the following * commands from your shell: * * cpp libusb20_desc.h > temp.h * indent temp.h * less temp.h */ #ifndef _LIBUSB20_DESC_H_ #define _LIBUSB20_DESC_H_ #ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include #endif #ifdef __cplusplus extern "C" { #endif #if 0 }; /* style */ #endif /* basic macros */ #define LIBUSB20__NOT(...) __VA_ARGS__ #define LIBUSB20_NOT(arg) LIBUSB20__NOT(LIBUSB20_YES arg(() LIBUSB20_NO)) #define LIBUSB20_YES(...) __VA_ARGS__ #define LIBUSB20_NO(...) #define LIBUSB20_END(...) __VA_ARGS__ #define LIBUSB20_MAX(a,b) (((a) > (b)) ? (a) : (b)) #define LIBUSB20_MIN(a,b) (((a) < (b)) ? (a) : (b)) #define LIBUSB20_ADD_BYTES(ptr,off) \ ((void *)(((const uint8_t *)(ptr)) + (off) - ((const uint8_t *)0))) /* basic message elements */ enum { LIBUSB20_ME_INT8, LIBUSB20_ME_INT16, LIBUSB20_ME_INT32, LIBUSB20_ME_INT64, LIBUSB20_ME_STRUCT, LIBUSB20_ME_MAX, /* used to indicate end */ }; /* basic message element modifiers */ enum { LIBUSB20_ME_IS_UNSIGNED = 0x00, LIBUSB20_ME_IS_SIGNED = 0x80, LIBUSB20_ME_MASK = 0x7F, }; enum { LIBUSB20_ME_IS_RAW, /* structure excludes length field * (hardcoded value) */ LIBUSB20_ME_IS_ENCODED, /* structure includes length field */ LIBUSB20_ME_IS_EMPTY, /* no structure */ LIBUSB20_ME_IS_DECODED, /* structure is recursive */ }; /* basic helper structures and macros */ #define LIBUSB20_ME_STRUCT_ALIGN sizeof(void *) struct libusb20_me_struct { void *ptr; /* data pointer */ uint16_t len; /* defaults to zero */ uint16_t type; /* defaults to LIBUSB20_ME_IS_EMPTY */ } __aligned(LIBUSB20_ME_STRUCT_ALIGN); struct libusb20_me_format { const uint8_t *format; /* always set */ const char *desc; /* optionally set */ const char *fields; /* optionally set */ }; #define LIBUSB20_ME_STRUCT(n, field, arg, ismeta) \ ismeta ( LIBUSB20_ME_STRUCT, 1, 0, ) \ LIBUSB20_NOT(ismeta) ( struct libusb20_me_struct field; ) #define LIBUSB20_ME_STRUCT_ARRAY(n, field, arg, ismeta) \ ismeta ( LIBUSB20_ME_STRUCT , (arg) & 0xFF, \ ((arg) / 0x100) & 0xFF, ) \ LIBUSB20_NOT(ismeta) ( struct libusb20_me_struct field [arg]; ) #define LIBUSB20_ME_INTEGER(n, field, ismeta, un, u, bits, a, size) \ ismeta ( LIBUSB20_ME_INT##bits | \ LIBUSB20_ME_IS_##un##SIGNED , \ (size) & 0xFF, ((size) / 0x100) & 0xFF, ) \ LIBUSB20_NOT(ismeta) ( u##int##bits##_t \ __aligned((bits) / 8) field a; ) #define LIBUSB20_ME_UINT8_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 8, , 1) #define LIBUSB20_ME_UINT8_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 8, [arg], arg) #define LIBUSB20_ME_SINT8_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 8, , 1) #define LIBUSB20_ME_SINT8_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 8, [arg], arg) #define LIBUSB20_ME_UINT16_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 16, , 1) #define LIBUSB20_ME_UINT16_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 16, [arg], arg) #define LIBUSB20_ME_SINT16_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 16, , 1) #define LIBUSB20_ME_SINT16_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 16, [arg], arg) #define LIBUSB20_ME_UINT32_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 32, , 1) #define LIBUSB20_ME_UINT32_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 32, [arg], arg) #define LIBUSB20_ME_SINT32_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 32, , 1) #define LIBUSB20_ME_SINT32_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 32, [arg], arg) #define LIBUSB20_ME_UINT64_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 64, , 1) #define LIBUSB20_ME_UINT64_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 64, [arg], arg) #define LIBUSB20_ME_SINT64_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 64, , 1) #define LIBUSB20_ME_SINT64_ARRAY_T(n, field, arg, ismeta) \ LIBUSB20_ME_INTEGER(n, field, ismeta,,, 64, [arg], arg) #define LIBUSB20_MAKE_DECODED_FIELD(n, type, field, arg) \ LIBUSB20_ME_##type (n, field, arg, LIBUSB20_NO) #define LIBUSB20_MAKE_STRUCT(name) \ extern const struct libusb20_me_format \ name##_FORMAT[1]; \ struct name##_DECODED { \ const struct libusb20_me_format *name##_FORMAT; \ name (LIBUSB20_MAKE_DECODED_FIELD,) \ } #define LIBUSB20_MAKE_STRUCT_FORMAT(name) \ const struct libusb20_me_format \ name##_FORMAT[1] = {{ \ .format = LIBUSB20_MAKE_FORMAT(name), \ .desc = #name, \ .fields = NULL, \ }} #define LIBUSB20_MAKE_FORMAT_SUB(n, type, field, arg) \ LIBUSB20_ME_##type (n, field, arg, LIBUSB20_YES) #define LIBUSB20_MAKE_FORMAT(what) (const uint8_t []) \ { what (LIBUSB20_MAKE_FORMAT_SUB, ) LIBUSB20_ME_MAX, 0, 0 } #define LIBUSB20_INIT(what, ptr) do { \ memset(ptr, 0, sizeof(*(ptr))); \ (ptr)->what##_FORMAT = what##_FORMAT; \ } while (0) #define LIBUSB20_DEVICE_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT16_T, bcdUSB, ) \ m(n, UINT8_T, bDeviceClass, ) \ m(n, UINT8_T, bDeviceSubClass, ) \ m(n, UINT8_T, bDeviceProtocol, ) \ m(n, UINT8_T, bMaxPacketSize0, ) \ m(n, UINT16_T, idVendor, ) \ m(n, UINT16_T, idProduct, ) \ m(n, UINT16_T, bcdDevice, ) \ m(n, UINT8_T, iManufacturer, ) \ m(n, UINT8_T, iProduct, ) \ m(n, UINT8_T, iSerialNumber, ) \ m(n, UINT8_T, bNumConfigurations, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_DEVICE_DESC); #define LIBUSB20_ENDPOINT_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT8_T, bEndpointAddress, ) \ m(n, UINT8_T, bmAttributes, ) \ m(n, UINT16_T, wMaxPacketSize, ) \ m(n, UINT8_T, bInterval, ) \ m(n, UINT8_T, bRefresh, ) \ m(n, UINT8_T, bSynchAddress, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_ENDPOINT_DESC); #define LIBUSB20_INTERFACE_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT8_T, bInterfaceNumber, ) \ m(n, UINT8_T, bAlternateSetting, ) \ m(n, UINT8_T, bNumEndpoints, ) \ m(n, UINT8_T, bInterfaceClass, ) \ m(n, UINT8_T, bInterfaceSubClass, ) \ m(n, UINT8_T, bInterfaceProtocol, ) \ m(n, UINT8_T, iInterface, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_INTERFACE_DESC); #define LIBUSB20_CONFIG_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT16_T, wTotalLength, ) \ m(n, UINT8_T, bNumInterfaces, ) \ m(n, UINT8_T, bConfigurationValue, ) \ m(n, UINT8_T, iConfiguration, ) \ m(n, UINT8_T, bmAttributes, ) \ m(n, UINT8_T, bMaxPower, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_CONFIG_DESC); #define LIBUSB20_CONTROL_SETUP(m,n) \ m(n, UINT8_T, bmRequestType, ) \ m(n, UINT8_T, bRequest, ) \ m(n, UINT16_T, wValue, ) \ m(n, UINT16_T, wIndex, ) \ m(n, UINT16_T, wLength, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_CONTROL_SETUP); #define LIBUSB20_SS_ENDPT_COMP_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT8_T, bMaxBurst, ) \ m(n, UINT8_T, bmAttributes, ) \ m(n, UINT16_T, wBytesPerInterval, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_ENDPT_COMP_DESC); #define LIBUSB20_USB_20_DEVCAP_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT8_T, bDevCapabilityType, ) \ m(n, UINT32_T, bmAttributes, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_USB_20_DEVCAP_DESC); #define LIBUSB20_SS_USB_DEVCAP_DESC(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT8_T, bDevCapabilityType, ) \ m(n, UINT8_T, bmAttributes, ) \ m(n, UINT16_T, wSpeedSupported, ) \ m(n, UINT8_T, bFunctionalitySupport, ) \ m(n, UINT8_T, bU1DevExitLat, ) \ m(n, UINT16_T, wU2DevExitLat, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC); #define LIBUSB20_BOS_DESCRIPTOR(m,n) \ m(n, UINT8_T, bLength, ) \ m(n, UINT8_T, bDescriptorType, ) \ m(n, UINT16_T, wTotalLength, ) \ m(n, UINT8_T, bNumDeviceCapabilities, ) \ LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR); /* standard USB stuff */ /** \ingroup desc * Device and/or Interface Class codes */ enum libusb20_class_code { /** In the context of a \ref LIBUSB20_DEVICE_DESC "device * descriptor", this bDeviceClass value indicates that each * interface specifies its own class information and all * interfaces operate independently. */ LIBUSB20_CLASS_PER_INTERFACE = 0, /** Audio class */ LIBUSB20_CLASS_AUDIO = 1, /** Communications class */ LIBUSB20_CLASS_COMM = 2, /** Human Interface Device class */ LIBUSB20_CLASS_HID = 3, /** Printer dclass */ LIBUSB20_CLASS_PRINTER = 7, /** Picture transfer protocol class */ LIBUSB20_CLASS_PTP = 6, /** Mass storage class */ LIBUSB20_CLASS_MASS_STORAGE = 8, /** Hub class */ LIBUSB20_CLASS_HUB = 9, /** Data class */ LIBUSB20_CLASS_DATA = 10, /** Class is vendor-specific */ LIBUSB20_CLASS_VENDOR_SPEC = 0xff, }; /** \ingroup desc * Descriptor types as defined by the USB specification. */ enum libusb20_descriptor_type { /** Device descriptor. See LIBUSB20_DEVICE_DESC. */ LIBUSB20_DT_DEVICE = 0x01, /** Configuration descriptor. See LIBUSB20_CONFIG_DESC. */ LIBUSB20_DT_CONFIG = 0x02, /** String descriptor */ LIBUSB20_DT_STRING = 0x03, /** Interface descriptor. See LIBUSB20_INTERFACE_DESC. */ LIBUSB20_DT_INTERFACE = 0x04, /** Endpoint descriptor. See LIBUSB20_ENDPOINT_DESC. */ LIBUSB20_DT_ENDPOINT = 0x05, /** HID descriptor */ LIBUSB20_DT_HID = 0x21, /** HID report descriptor */ LIBUSB20_DT_REPORT = 0x22, /** Physical descriptor */ LIBUSB20_DT_PHYSICAL = 0x23, /** Hub descriptor */ LIBUSB20_DT_HUB = 0x29, /** Binary Object Store, BOS */ LIBUSB20_DT_BOS = 0x0f, /** Device Capability */ LIBUSB20_DT_DEVICE_CAPABILITY = 0x10, /** SuperSpeed endpoint companion */ LIBUSB20_DT_SS_ENDPOINT_COMPANION = 0x30, }; /** \ingroup desc * Device capability types as defined by the USB specification. */ enum libusb20_device_capability_type { LIBUSB20_WIRELESS_USB_DEVICE_CAPABILITY = 0x1, LIBUSB20_USB_2_0_EXTENSION_DEVICE_CAPABILITY = 0x2, LIBUSB20_SS_USB_DEVICE_CAPABILITY = 0x3, LIBUSB20_CONTAINER_ID_DEVICE_CAPABILITY = 0x4, }; /* Descriptor sizes per descriptor type */ #define LIBUSB20_DT_DEVICE_SIZE 18 #define LIBUSB20_DT_CONFIG_SIZE 9 #define LIBUSB20_DT_INTERFACE_SIZE 9 #define LIBUSB20_DT_ENDPOINT_SIZE 7 #define LIBUSB20_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ #define LIBUSB20_DT_HUB_NONVAR_SIZE 7 #define LIBUSB20_DT_SS_ENDPOINT_COMPANION_SIZE 6 #define LIBUSB20_DT_BOS_SIZE 5 #define LIBUSB20_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE 7 #define LIBUSB20_SS_USB_DEVICE_CAPABILITY_SIZE 10 #define LIBUSB20_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ #define LIBUSB20_ENDPOINT_DIR_MASK 0x80 /** \ingroup desc * Endpoint direction. Values for bit 7 of the * \ref LIBUSB20_ENDPOINT_DESC::bEndpointAddress "endpoint address" scheme. */ enum libusb20_endpoint_direction { /** In: device-to-host */ LIBUSB20_ENDPOINT_IN = 0x80, /** Out: host-to-device */ LIBUSB20_ENDPOINT_OUT = 0x00, }; #define LIBUSB20_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ /** \ingroup desc * Endpoint transfer type. Values for bits 0:1 of the * \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "endpoint attributes" field. */ enum libusb20_transfer_type { /** Control endpoint */ LIBUSB20_TRANSFER_TYPE_CONTROL = 0, /** Isochronous endpoint */ LIBUSB20_TRANSFER_TYPE_ISOCHRONOUS = 1, /** Bulk endpoint */ LIBUSB20_TRANSFER_TYPE_BULK = 2, /** Interrupt endpoint */ LIBUSB20_TRANSFER_TYPE_INTERRUPT = 3, }; /** \ingroup misc * Standard requests, as defined in table 9-3 of the USB2 specifications */ enum libusb20_standard_request { /** Request status of the specific recipient */ LIBUSB20_REQUEST_GET_STATUS = 0x00, /** Clear or disable a specific feature */ LIBUSB20_REQUEST_CLEAR_FEATURE = 0x01, /* 0x02 is reserved */ /** Set or enable a specific feature */ LIBUSB20_REQUEST_SET_FEATURE = 0x03, /* 0x04 is reserved */ /** Set device address for all future accesses */ LIBUSB20_REQUEST_SET_ADDRESS = 0x05, /** Get the specified descriptor */ LIBUSB20_REQUEST_GET_DESCRIPTOR = 0x06, /** Used to update existing descriptors or add new descriptors */ LIBUSB20_REQUEST_SET_DESCRIPTOR = 0x07, /** Get the current device configuration value */ LIBUSB20_REQUEST_GET_CONFIGURATION = 0x08, /** Set device configuration */ LIBUSB20_REQUEST_SET_CONFIGURATION = 0x09, /** Return the selected alternate setting for the specified * interface */ LIBUSB20_REQUEST_GET_INTERFACE = 0x0A, /** Select an alternate interface for the specified interface */ LIBUSB20_REQUEST_SET_INTERFACE = 0x0B, /** Set then report an endpoint's synchronization frame */ LIBUSB20_REQUEST_SYNCH_FRAME = 0x0C, + + /** Set U1 and U2 system exit latency */ + LIBUSB20_REQUEST_SET_SEL = 0x30, + + /** Set isochronous delay */ + LIBUSB20_REQUEST_SET_ISOCH_DELAY = 0x31, }; /** \ingroup misc * Request type bits of the * \ref libusb20_control_setup::bmRequestType "bmRequestType" field in * control transfers. */ enum libusb20_request_type { /** Standard */ LIBUSB20_REQUEST_TYPE_STANDARD = (0x00 << 5), /** Class */ LIBUSB20_REQUEST_TYPE_CLASS = (0x01 << 5), /** Vendor */ LIBUSB20_REQUEST_TYPE_VENDOR = (0x02 << 5), /** Reserved */ LIBUSB20_REQUEST_TYPE_RESERVED = (0x03 << 5), }; /** \ingroup misc * Recipient bits of the * \ref libusb20_control_setup::bmRequestType "bmRequestType" field in * control transfers. Values 4 through 31 are reserved. */ enum libusb20_request_recipient { /** Device */ LIBUSB20_RECIPIENT_DEVICE = 0x00, /** Interface */ LIBUSB20_RECIPIENT_INTERFACE = 0x01, /** Endpoint */ LIBUSB20_RECIPIENT_ENDPOINT = 0x02, /** Other */ LIBUSB20_RECIPIENT_OTHER = 0x03, }; #define LIBUSB20_ISO_SYNC_TYPE_MASK 0x0C /** \ingroup desc * Synchronization type for isochronous endpoints. Values for bits 2:3 * of the \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "bmAttributes" * field in LIBUSB20_ENDPOINT_DESC. */ enum libusb20_iso_sync_type { /** No synchronization */ LIBUSB20_ISO_SYNC_TYPE_NONE = 0, /** Asynchronous */ LIBUSB20_ISO_SYNC_TYPE_ASYNC = 1, /** Adaptive */ LIBUSB20_ISO_SYNC_TYPE_ADAPTIVE = 2, /** Synchronous */ LIBUSB20_ISO_SYNC_TYPE_SYNC = 3, }; #define LIBUSB20_ISO_USAGE_TYPE_MASK 0x30 /** \ingroup desc * Usage type for isochronous endpoints. Values for bits 4:5 of the * \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "bmAttributes" field in * LIBUSB20_ENDPOINT_DESC. */ enum libusb20_iso_usage_type { /** Data endpoint */ LIBUSB20_ISO_USAGE_TYPE_DATA = 0, /** Feedback endpoint */ LIBUSB20_ISO_USAGE_TYPE_FEEDBACK = 1, /** Implicit feedback Data endpoint */ LIBUSB20_ISO_USAGE_TYPE_IMPLICIT = 2, }; struct libusb20_endpoint { struct LIBUSB20_ENDPOINT_DESC_DECODED desc; struct libusb20_me_struct extra; } __aligned(sizeof(void *)); struct libusb20_interface { struct LIBUSB20_INTERFACE_DESC_DECODED desc; struct libusb20_me_struct extra; struct libusb20_interface *altsetting; struct libusb20_endpoint *endpoints; uint8_t num_altsetting; uint8_t num_endpoints; } __aligned(sizeof(void *)); struct libusb20_config { struct LIBUSB20_CONFIG_DESC_DECODED desc; struct libusb20_me_struct extra; struct libusb20_interface *interface; uint8_t num_interface; } __aligned(sizeof(void *)); uint8_t libusb20_me_get_1(const struct libusb20_me_struct *ie, uint16_t offset); uint16_t libusb20_me_get_2(const struct libusb20_me_struct *ie, uint16_t offset); uint16_t libusb20_me_encode(void *ptr, uint16_t len, const void *pd); uint16_t libusb20_me_decode(const void *ptr, uint16_t len, void *pd); const uint8_t *libusb20_desc_foreach(const struct libusb20_me_struct *pdesc, const uint8_t *psubdesc); struct libusb20_config *libusb20_parse_config_desc(const void *config_desc); #if 0 { /* style */ #endif #ifdef __cplusplus } #endif #endif /* _LIBUSB20_DESC_H_ */