7 * 'interface' is defined somewhere in the Windows header files. This macro
8 * is deleted here to avoid conflicts and compile errors.
16 * PATH_MAX from limits.h can't be used on Windows if the dll and
17 * import libraries are build/used by different compilers
20 #define LIBUSB_PATH_MAX 512
24 * USB spec information
26 * This is all stuff grabbed from various USB specs and is pretty much
27 * not subject to change
31 * Device and/or Interface Class codes
33 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
34 #define USB_CLASS_AUDIO 1
35 #define USB_CLASS_COMM 2
36 #define USB_CLASS_HID 3
37 #define USB_CLASS_PRINTER 7
38 #define USB_CLASS_MASS_STORAGE 8
39 #define USB_CLASS_HUB 9
40 #define USB_CLASS_DATA 10
41 #define USB_CLASS_VENDOR_SPEC 0xff
46 #define USB_DT_DEVICE 0x01
47 #define USB_DT_CONFIG 0x02
48 #define USB_DT_STRING 0x03
49 #define USB_DT_INTERFACE 0x04
50 #define USB_DT_ENDPOINT 0x05
52 #define USB_DT_HID 0x21
53 #define USB_DT_REPORT 0x22
54 #define USB_DT_PHYSICAL 0x23
55 #define USB_DT_HUB 0x29
58 * Descriptor sizes per descriptor type
60 #define USB_DT_DEVICE_SIZE 18
61 #define USB_DT_CONFIG_SIZE 9
62 #define USB_DT_INTERFACE_SIZE 9
63 #define USB_DT_ENDPOINT_SIZE 7
64 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
65 #define USB_DT_HUB_NONVAR_SIZE 7
68 /* ensure byte-packed structures */
72 /* All standard descriptors have these 2 fields in common */
73 struct usb_descriptor_header
{
74 unsigned char bLength
;
75 unsigned char bDescriptorType
;
78 /* String descriptor */
79 struct usb_string_descriptor
{
80 unsigned char bLength
;
81 unsigned char bDescriptorType
;
82 unsigned short wData
[1];
86 struct usb_hid_descriptor
{
87 unsigned char bLength
;
88 unsigned char bDescriptorType
;
89 unsigned short bcdHID
;
90 unsigned char bCountryCode
;
91 unsigned char bNumDescriptors
;
94 /* Endpoint descriptor */
95 #define USB_MAXENDPOINTS 32
96 struct usb_endpoint_descriptor
{
97 unsigned char bLength
;
98 unsigned char bDescriptorType
;
99 unsigned char bEndpointAddress
;
100 unsigned char bmAttributes
;
101 unsigned short wMaxPacketSize
;
102 unsigned char bInterval
;
103 unsigned char bRefresh
;
104 unsigned char bSynchAddress
;
106 unsigned char *extra
; /* Extra descriptors */
110 #define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
111 #define USB_ENDPOINT_DIR_MASK 0x80
113 #define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
114 #define USB_ENDPOINT_TYPE_CONTROL 0
115 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
116 #define USB_ENDPOINT_TYPE_BULK 2
117 #define USB_ENDPOINT_TYPE_INTERRUPT 3
119 /* Interface descriptor */
120 #define USB_MAXINTERFACES 32
121 struct usb_interface_descriptor
{
122 unsigned char bLength
;
123 unsigned char bDescriptorType
;
124 unsigned char bInterfaceNumber
;
125 unsigned char bAlternateSetting
;
126 unsigned char bNumEndpoints
;
127 unsigned char bInterfaceClass
;
128 unsigned char bInterfaceSubClass
;
129 unsigned char bInterfaceProtocol
;
130 unsigned char iInterface
;
132 struct usb_endpoint_descriptor
*endpoint
;
134 unsigned char *extra
; /* Extra descriptors */
138 #define USB_MAXALTSETTING 128 /* Hard limit */
140 struct usb_interface
{
141 struct usb_interface_descriptor
*altsetting
;
146 /* Configuration descriptor information.. */
147 #define USB_MAXCONFIG 8
148 struct usb_config_descriptor
{
149 unsigned char bLength
;
150 unsigned char bDescriptorType
;
151 unsigned short wTotalLength
;
152 unsigned char bNumInterfaces
;
153 unsigned char bConfigurationValue
;
154 unsigned char iConfiguration
;
155 unsigned char bmAttributes
;
156 unsigned char MaxPower
;
158 struct usb_interface
*interface
;
160 unsigned char *extra
; /* Extra descriptors */
164 /* Device descriptor */
165 struct usb_device_descriptor
{
166 unsigned char bLength
;
167 unsigned char bDescriptorType
;
168 unsigned short bcdUSB
;
169 unsigned char bDeviceClass
;
170 unsigned char bDeviceSubClass
;
171 unsigned char bDeviceProtocol
;
172 unsigned char bMaxPacketSize0
;
173 unsigned short idVendor
;
174 unsigned short idProduct
;
175 unsigned short bcdDevice
;
176 unsigned char iManufacturer
;
177 unsigned char iProduct
;
178 unsigned char iSerialNumber
;
179 unsigned char bNumConfigurations
;
182 struct usb_ctrl_setup
{
183 unsigned char bRequestType
;
184 unsigned char bRequest
;
185 unsigned short wValue
;
186 unsigned short wIndex
;
187 unsigned short wLength
;
193 #define USB_REQ_GET_STATUS 0x00
194 #define USB_REQ_CLEAR_FEATURE 0x01
195 /* 0x02 is reserved */
196 #define USB_REQ_SET_FEATURE 0x03
197 /* 0x04 is reserved */
198 #define USB_REQ_SET_ADDRESS 0x05
199 #define USB_REQ_GET_DESCRIPTOR 0x06
200 #define USB_REQ_SET_DESCRIPTOR 0x07
201 #define USB_REQ_GET_CONFIGURATION 0x08
202 #define USB_REQ_SET_CONFIGURATION 0x09
203 #define USB_REQ_GET_INTERFACE 0x0A
204 #define USB_REQ_SET_INTERFACE 0x0B
205 #define USB_REQ_SYNCH_FRAME 0x0C
207 #define USB_TYPE_STANDARD (0x00 << 5)
208 #define USB_TYPE_CLASS (0x01 << 5)
209 #define USB_TYPE_VENDOR (0x02 << 5)
210 #define USB_TYPE_RESERVED (0x03 << 5)
212 #define USB_RECIP_DEVICE 0x00
213 #define USB_RECIP_INTERFACE 0x01
214 #define USB_RECIP_ENDPOINT 0x02
215 #define USB_RECIP_OTHER 0x03
218 * Various libusb API related stuff
221 #define USB_ENDPOINT_IN 0x80
222 #define USB_ENDPOINT_OUT 0x00
225 #define USB_ERROR_BEGIN 500000
228 * This is supposed to look weird. This file is generated from autoconf
229 * and I didn't want to make this too complicated.
231 #define USB_LE16_TO_CPU(x)
234 /* struct usb_device; */
235 /* struct usb_bus; */
238 struct usb_device
*next
, *prev
;
240 char filename
[LIBUSB_PATH_MAX
];
244 struct usb_device_descriptor descriptor
;
245 struct usb_config_descriptor
*config
;
247 void *dev
; /* Darwin support */
249 unsigned char devnum
;
251 unsigned char num_children
;
252 struct usb_device
**children
;
256 struct usb_bus
*next
, *prev
;
258 char dirname
[LIBUSB_PATH_MAX
];
260 struct usb_device
*devices
;
261 unsigned long location
;
263 struct usb_device
*root_dev
;
266 /* Version information, Windows specific */
283 struct usb_dev_handle
;
284 typedef struct usb_dev_handle usb_dev_handle
;
287 extern struct usb_bus
*usb_busses
;
297 /* Function prototypes */
300 usb_dev_handle
*usb_open(struct usb_device
*dev
);
301 int usb_close(usb_dev_handle
*dev
);
302 int usb_get_string(usb_dev_handle
*dev
, int index
, int langid
, char *buf
,
304 int usb_get_string_simple(usb_dev_handle
*dev
, int index
, char *buf
,
308 int usb_get_descriptor_by_endpoint(usb_dev_handle
*udev
, int ep
,
309 unsigned char type
, unsigned char index
,
310 void *buf
, int size
);
311 int usb_get_descriptor(usb_dev_handle
*udev
, unsigned char type
,
312 unsigned char index
, void *buf
, int size
);
315 int usb_bulk_write(usb_dev_handle
*dev
, int ep
, char *bytes
, int size
,
317 int usb_bulk_read(usb_dev_handle
*dev
, int ep
, char *bytes
, int size
,
319 int usb_interrupt_write(usb_dev_handle
*dev
, int ep
, char *bytes
, int size
,
321 int usb_interrupt_read(usb_dev_handle
*dev
, int ep
, char *bytes
, int size
,
323 int usb_control_msg(usb_dev_handle
*dev
, int requesttype
, int request
,
324 int value
, int index
, char *bytes
, int size
,
326 int usb_set_configuration(usb_dev_handle
*dev
, int configuration
);
327 int usb_claim_interface(usb_dev_handle
*dev
, int interface
);
328 int usb_release_interface(usb_dev_handle
*dev
, int interface
);
329 int usb_set_altinterface(usb_dev_handle
*dev
, int alternate
);
330 int usb_resetep(usb_dev_handle
*dev
, unsigned int ep
);
331 int usb_clear_halt(usb_dev_handle
*dev
, unsigned int ep
);
332 int usb_reset(usb_dev_handle
*dev
);
334 char *usb_strerror(void);
337 void usb_set_debug(int level
);
338 int usb_find_busses(void);
339 int usb_find_devices(void);
340 struct usb_device
*usb_device(usb_dev_handle
*dev
);
341 struct usb_bus
*usb_get_busses(void);
344 /* Windows specific functions */
346 #define LIBUSB_HAS_INSTALL_SERVICE_NP 1
347 int usb_install_service_np(void);
349 #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
350 int usb_uninstall_service_np(void);
352 #define LIBUSB_HAS_INSTALL_DRIVER_NP 1
353 int usb_install_driver_np(const char *inf_file
);
355 const struct usb_version
*usb_get_version(void);
357 int usb_isochronous_setup_async(usb_dev_handle
*dev
, void **context
,
358 unsigned char ep
, int pktsize
);
359 int usb_bulk_setup_async(usb_dev_handle
*dev
, void **context
,
361 int usb_interrupt_setup_async(usb_dev_handle
*dev
, void **context
,
364 int usb_submit_async(void *context
, char *bytes
, int size
);
365 int usb_reap_async(void *context
, int timeout
);
366 int usb_free_async(void **context
);
373 #endif /* __USB_H__ */