Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
61 | f9daq | 1 | #ifndef __USB_H__ |
2 | #define __USB_H__ |
||
3 | |||
4 | #include <stdlib.h> |
||
5 | #include <windows.h> |
||
6 | |||
7 | /* |
||
8 | * 'interface' is defined somewhere in the Windows header files. This macro |
||
9 | * is deleted here to avoid conflicts and compile errors. |
||
10 | */ |
||
11 | |||
12 | #ifdef interface |
||
13 | #undef interface |
||
14 | #endif |
||
15 | |||
16 | /* |
||
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 |
||
19 | */ |
||
20 | |||
21 | #define LIBUSB_PATH_MAX 512 |
||
22 | |||
23 | |||
24 | /* |
||
25 | * USB spec information |
||
26 | * |
||
27 | * This is all stuff grabbed from various USB specs and is pretty much |
||
28 | * not subject to change |
||
29 | */ |
||
30 | |||
31 | /* |
||
32 | * Device and/or Interface Class codes |
||
33 | */ |
||
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 |
||
43 | |||
44 | /* |
||
45 | * Descriptor types |
||
46 | */ |
||
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 |
||
52 | |||
53 | #define USB_DT_HID 0x21 |
||
54 | #define USB_DT_REPORT 0x22 |
||
55 | #define USB_DT_PHYSICAL 0x23 |
||
56 | #define USB_DT_HUB 0x29 |
||
57 | |||
58 | /* |
||
59 | * Descriptor sizes per descriptor type |
||
60 | */ |
||
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 |
||
67 | |||
68 | |||
69 | /* ensure byte-packed structures */ |
||
70 | #include <pshpack1.h> |
||
71 | |||
72 | |||
73 | /* All standard descriptors have these 2 fields in common */ |
||
74 | struct usb_descriptor_header { |
||
75 | unsigned char bLength; |
||
76 | unsigned char bDescriptorType; |
||
77 | }; |
||
78 | |||
79 | /* String descriptor */ |
||
80 | struct usb_string_descriptor { |
||
81 | unsigned char bLength; |
||
82 | unsigned char bDescriptorType; |
||
83 | unsigned short wData[1]; |
||
84 | }; |
||
85 | |||
86 | /* HID descriptor */ |
||
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; |
||
93 | }; |
||
94 | |||
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; |
||
106 | |||
107 | unsigned char *extra; /* Extra descriptors */ |
||
108 | int extralen; |
||
109 | }; |
||
110 | |||
111 | #define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ |
||
112 | #define USB_ENDPOINT_DIR_MASK 0x80 |
||
113 | |||
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 |
||
119 | |||
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; |
||
132 | |||
133 | struct usb_endpoint_descriptor *endpoint; |
||
134 | |||
135 | unsigned char *extra; /* Extra descriptors */ |
||
136 | int extralen; |
||
137 | }; |
||
138 | |||
139 | #define USB_MAXALTSETTING 128 /* Hard limit */ |
||
140 | |||
141 | struct usb_interface { |
||
142 | struct usb_interface_descriptor *altsetting; |
||
143 | |||
144 | int num_altsetting; |
||
145 | }; |
||
146 | |||
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; |
||
158 | |||
159 | struct usb_interface *interface; |
||
160 | |||
161 | unsigned char *extra; /* Extra descriptors */ |
||
162 | int extralen; |
||
163 | }; |
||
164 | |||
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; |
||
181 | }; |
||
182 | |||
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; |
||
189 | }; |
||
190 | |||
191 | /* |
||
192 | * Standard requests |
||
193 | */ |
||
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 |
||
207 | |||
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) |
||
212 | |||
213 | #define USB_RECIP_DEVICE 0x00 |
||
214 | #define USB_RECIP_INTERFACE 0x01 |
||
215 | #define USB_RECIP_ENDPOINT 0x02 |
||
216 | #define USB_RECIP_OTHER 0x03 |
||
217 | |||
218 | /* |
||
219 | * Various libusb API related stuff |
||
220 | */ |
||
221 | |||
222 | #define USB_ENDPOINT_IN 0x80 |
||
223 | #define USB_ENDPOINT_OUT 0x00 |
||
224 | |||
225 | /* Error codes */ |
||
226 | #define USB_ERROR_BEGIN 500000 |
||
227 | |||
228 | /* |
||
229 | * This is supposed to look weird. This file is generated from autoconf |
||
230 | * and I didn't want to make this too complicated. |
||
231 | */ |
||
232 | #define USB_LE16_TO_CPU(x) |
||
233 | |||
234 | /* Data types */ |
||
235 | /* struct usb_device; */ |
||
236 | /* struct usb_bus; */ |
||
237 | |||
238 | struct usb_device { |
||
239 | struct usb_device *next, *prev; |
||
240 | |||
241 | char filename[LIBUSB_PATH_MAX]; |
||
242 | |||
243 | struct usb_bus *bus; |
||
244 | |||
245 | struct usb_device_descriptor descriptor; |
||
246 | struct usb_config_descriptor *config; |
||
247 | |||
248 | void *dev; /* Darwin support */ |
||
249 | |||
250 | unsigned char devnum; |
||
251 | |||
252 | unsigned char num_children; |
||
253 | struct usb_device **children; |
||
254 | }; |
||
255 | |||
256 | struct usb_bus { |
||
257 | struct usb_bus *next, *prev; |
||
258 | |||
259 | char dirname[LIBUSB_PATH_MAX]; |
||
260 | |||
261 | struct usb_device *devices; |
||
262 | unsigned long location; |
||
263 | |||
264 | struct usb_device *root_dev; |
||
265 | }; |
||
266 | |||
267 | /* Version information, Windows specific */ |
||
268 | struct usb_version { |
||
269 | struct { |
||
270 | int major; |
||
271 | int minor; |
||
272 | int micro; |
||
273 | int nano; |
||
274 | } dll; |
||
275 | struct { |
||
276 | int major; |
||
277 | int minor; |
||
278 | int micro; |
||
279 | int nano; |
||
280 | } driver; |
||
281 | }; |
||
282 | |||
283 | |||
284 | struct usb_dev_handle; |
||
285 | typedef struct usb_dev_handle usb_dev_handle; |
||
286 | |||
287 | /* Variables */ |
||
288 | //#ifndef __USB_C__ |
||
289 | //#define usb_busses usb_get_busses() |
||
290 | //#endif |
||
291 | |||
292 | |||
293 | |||
294 | #include <poppack.h> |
||
295 | |||
296 | |||
297 | #ifdef __cplusplus |
||
298 | extern "C" { |
||
299 | #endif |
||
300 | |||
301 | /* Function prototypes */ |
||
302 | |||
303 | /* usb.c */ |
||
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, |
||
307 | size_t buflen); |
||
308 | int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf, |
||
309 | size_t buflen); |
||
310 | |||
311 | /* descriptors.c */ |
||
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); |
||
317 | |||
318 | /* <arch>.c */ |
||
319 | int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size, |
||
320 | int timeout); |
||
321 | int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size, |
||
322 | int timeout); |
||
323 | int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size, |
||
324 | int timeout); |
||
325 | int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, |
||
326 | int timeout); |
||
327 | int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, |
||
328 | int value, int index, char *bytes, int size, |
||
329 | int timeout); |
||
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); |
||
337 | |||
338 | char *usb_strerror(void); |
||
339 | |||
340 | void usb_init(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); |
||
346 | |||
347 | |||
348 | /* Windows specific functions */ |
||
349 | |||
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); |
||
354 | |||
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); |
||
359 | |||
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); |
||
364 | |||
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); |
||
369 | |||
370 | #define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1 |
||
371 | int usb_install_needs_restart_np(void); |
||
372 | |||
373 | const struct usb_version *usb_get_version(void); |
||
374 | |||
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, |
||
378 | unsigned char ep); |
||
379 | int usb_interrupt_setup_async(usb_dev_handle *dev, void **context, |
||
380 | unsigned char ep); |
||
381 | |||
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); |
||
387 | |||
388 | |||
389 | #ifdef __cplusplus |
||
390 | } |
||
391 | #endif |
||
392 | |||
393 | #endif /* __USB_H__ */ |
||
394 |