8 * 'interface' is defined somewhere in the Windows header files. This macro
9 * is deleted here to avoid conflicts and compile errors.
17 * PATH_MAX from limits.h can't be used on Windows if the dll and
18 * import libraries are build/used by different compilers
21 #define LIBUSB_PATH_MAX 512
25 * USB spec information
27 * This is all stuff grabbed from various USB specs and is pretty much
28 * not subject to change
32 * Device and/or Interface Class codes
34 #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
35 #define USB_CLASS_AUDIO 1
36 #define USB_CLASS_COMM 2
37 #define USB_CLASS_HID 3
38 #define USB_CLASS_PRINTER 7
39 #define USB_CLASS_MASS_STORAGE 8
40 #define USB_CLASS_HUB 9
41 #define USB_CLASS_DATA 10
42 #define USB_CLASS_VENDOR_SPEC 0xff
47 #define USB_DT_DEVICE 0x01
48 #define USB_DT_CONFIG 0x02
49 #define USB_DT_STRING 0x03
50 #define USB_DT_INTERFACE 0x04
51 #define USB_DT_ENDPOINT 0x05
53 #define USB_DT_HID 0x21
54 #define USB_DT_REPORT 0x22
55 #define USB_DT_PHYSICAL 0x23
56 #define USB_DT_HUB 0x29
59 * Descriptor sizes per descriptor type
61 #define USB_DT_DEVICE_SIZE 18
62 #define USB_DT_CONFIG_SIZE 9
63 #define USB_DT_INTERFACE_SIZE 9
64 #define USB_DT_ENDPOINT_SIZE 7
65 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
66 #define USB_DT_HUB_NONVAR_SIZE 7
69 /* ensure byte-packed structures */
73 /* All standard descriptors have these 2 fields in common */
74 struct usb_descriptor_header {
75 unsigned char bLength;
76 unsigned char bDescriptorType;
79 /* String descriptor */
80 struct usb_string_descriptor {
81 unsigned char bLength;
82 unsigned char bDescriptorType;
83 unsigned short wData[1];
87 struct usb_hid_descriptor {
88 unsigned char bLength;
89 unsigned char bDescriptorType;
90 unsigned short bcdHID;
91 unsigned char bCountryCode;
92 unsigned char bNumDescriptors;
95 /* Endpoint descriptor */
96 #define USB_MAXENDPOINTS 32
97 struct usb_endpoint_descriptor {
98 unsigned char bLength;
99 unsigned char bDescriptorType;
100 unsigned char bEndpointAddress;
101 unsigned char bmAttributes;
102 unsigned short wMaxPacketSize;
103 unsigned char bInterval;
104 unsigned char bRefresh;
105 unsigned char bSynchAddress;
107 unsigned char *extra; /* Extra descriptors */
111 #define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
112 #define USB_ENDPOINT_DIR_MASK 0x80
114 #define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
115 #define USB_ENDPOINT_TYPE_CONTROL 0
116 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
117 #define USB_ENDPOINT_TYPE_BULK 2
118 #define USB_ENDPOINT_TYPE_INTERRUPT 3
120 /* Interface descriptor */
121 #define USB_MAXINTERFACES 32
122 struct usb_interface_descriptor {
123 unsigned char bLength;
124 unsigned char bDescriptorType;
125 unsigned char bInterfaceNumber;
126 unsigned char bAlternateSetting;
127 unsigned char bNumEndpoints;
128 unsigned char bInterfaceClass;
129 unsigned char bInterfaceSubClass;
130 unsigned char bInterfaceProtocol;
131 unsigned char iInterface;
133 struct usb_endpoint_descriptor *endpoint;
135 unsigned char *extra; /* Extra descriptors */
139 #define USB_MAXALTSETTING 128 /* Hard limit */
141 struct usb_interface {
142 struct usb_interface_descriptor *altsetting;
147 /* Configuration descriptor information.. */
148 #define USB_MAXCONFIG 8
149 struct usb_config_descriptor {
150 unsigned char bLength;
151 unsigned char bDescriptorType;
152 unsigned short wTotalLength;
153 unsigned char bNumInterfaces;
154 unsigned char bConfigurationValue;
155 unsigned char iConfiguration;
156 unsigned char bmAttributes;
157 unsigned char MaxPower;
159 struct usb_interface *interface;
161 unsigned char *extra; /* Extra descriptors */
165 /* Device descriptor */
166 struct usb_device_descriptor {
167 unsigned char bLength;
168 unsigned char bDescriptorType;
169 unsigned short bcdUSB;
170 unsigned char bDeviceClass;
171 unsigned char bDeviceSubClass;
172 unsigned char bDeviceProtocol;
173 unsigned char bMaxPacketSize0;
174 unsigned short idVendor;
175 unsigned short idProduct;
176 unsigned short bcdDevice;
177 unsigned char iManufacturer;
178 unsigned char iProduct;
179 unsigned char iSerialNumber;
180 unsigned char bNumConfigurations;
183 struct usb_ctrl_setup {
184 unsigned char bRequestType;
185 unsigned char bRequest;
186 unsigned short wValue;
187 unsigned short wIndex;
188 unsigned short wLength;
194 #define USB_REQ_GET_STATUS 0x00
195 #define USB_REQ_CLEAR_FEATURE 0x01
196 /* 0x02 is reserved */
197 #define USB_REQ_SET_FEATURE 0x03
198 /* 0x04 is reserved */
199 #define USB_REQ_SET_ADDRESS 0x05
200 #define USB_REQ_GET_DESCRIPTOR 0x06
201 #define USB_REQ_SET_DESCRIPTOR 0x07
202 #define USB_REQ_GET_CONFIGURATION 0x08
203 #define USB_REQ_SET_CONFIGURATION 0x09
204 #define USB_REQ_GET_INTERFACE 0x0A
205 #define USB_REQ_SET_INTERFACE 0x0B
206 #define USB_REQ_SYNCH_FRAME 0x0C
208 #define USB_TYPE_STANDARD (0x00 << 5)
209 #define USB_TYPE_CLASS (0x01 << 5)
210 #define USB_TYPE_VENDOR (0x02 << 5)
211 #define USB_TYPE_RESERVED (0x03 << 5)
213 #define USB_RECIP_DEVICE 0x00
214 #define USB_RECIP_INTERFACE 0x01
215 #define USB_RECIP_ENDPOINT 0x02
216 #define USB_RECIP_OTHER 0x03
219 * Various libusb API related stuff
222 #define USB_ENDPOINT_IN 0x80
223 #define USB_ENDPOINT_OUT 0x00
226 #define USB_ERROR_BEGIN 500000
229 * This is supposed to look weird. This file is generated from autoconf
230 * and I didn't want to make this too complicated.
232 #define USB_LE16_TO_CPU(x)
235 /* struct usb_device; */
236 /* struct usb_bus; */
239 struct usb_device *next, *prev;
241 char filename[LIBUSB_PATH_MAX];
245 struct usb_device_descriptor descriptor;
246 struct usb_config_descriptor *config;
248 void *dev; /* Darwin support */
250 unsigned char devnum;
252 unsigned char num_children;
253 struct usb_device **children;
257 struct usb_bus *next, *prev;
259 char dirname[LIBUSB_PATH_MAX];
261 struct usb_device *devices;
262 unsigned long location;
264 struct usb_device *root_dev;
267 /* Version information, Windows specific */
284 struct usb_dev_handle;
285 typedef struct usb_dev_handle usb_dev_handle;
289 #define usb_busses usb_get_busses()
301 /* Function prototypes */
304 usb_dev_handle *usb_open(struct usb_device *dev);
305 int usb_close(usb_dev_handle *dev);
306 int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
308 int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
312 int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
313 unsigned char type, unsigned char index,
314 void *buf, int size);
315 int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
316 unsigned char index, void *buf, int size);
319 int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
321 int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
323 int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
325 int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
327 int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
328 int value, int index, char *bytes, int size,
330 int usb_set_configuration(usb_dev_handle *dev, int configuration);
331 int usb_claim_interface(usb_dev_handle *dev, int interface);
332 int usb_release_interface(usb_dev_handle *dev, int interface);
333 int usb_set_altinterface(usb_dev_handle *dev, int alternate);
334 int usb_resetep(usb_dev_handle *dev, unsigned int ep);
335 int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
336 int usb_reset(usb_dev_handle *dev);
338 char *usb_strerror(void);
341 void usb_set_debug(int level);
342 int usb_find_busses(void);
343 int usb_find_devices(void);
344 struct usb_device *usb_device(usb_dev_handle *dev);
345 struct usb_bus *usb_get_busses(void);
348 /* Windows specific functions */
350 #define LIBUSB_HAS_INSTALL_SERVICE_NP 1
351 int usb_install_service_np(void);
352 void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
353 LPSTR cmd_line, int cmd_show);
355 #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
356 int usb_uninstall_service_np(void);
357 void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
358 LPSTR cmd_line, int cmd_show);
360 #define LIBUSB_HAS_INSTALL_DRIVER_NP 1
361 int usb_install_driver_np(const char *inf_file);
362 void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
363 LPSTR cmd_line, int cmd_show);
365 #define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
366 int usb_touch_inf_file_np(const char *inf_file);
367 void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
368 LPSTR cmd_line, int cmd_show);
370 #define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
371 int usb_install_needs_restart_np(void);
373 const struct usb_version *usb_get_version(void);
375 int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,
376 unsigned char ep, int pktsize);
377 int usb_bulk_setup_async(usb_dev_handle *dev, void **context,
379 int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,
382 int usb_submit_async(void *context, char *bytes, int size);
383 int usb_reap_async(void *context, int timeout);
384 int usb_reap_async_nocancel(void *context, int timeout);
385 int usb_cancel_async(void *context);
386 int usb_free_async(void **context);
393 #endif /* __USB_H__ */