1#ifndef __LINUX_USB_H
2#define __LINUX_USB_H
3
4
5
6
7
8
9#define USB_CLASS_PER_INTERFACE 0
10#define USB_CLASS_AUDIO 1
11#define USB_CLASS_COMM 2
12#define USB_CLASS_HID 3
13#define USB_CLASS_PHYSICAL 5
14#define USB_CLASS_STILL_IMAGE 6
15#define USB_CLASS_PRINTER 7
16#define USB_CLASS_MASS_STORAGE 8
17#define USB_CLASS_HUB 9
18#define USB_CLASS_CDC_DATA 0x0a
19#define USB_CLASS_CSCID 0x0b
20#define USB_CLASS_CONTENT_SEC 0x0d
21#define USB_CLASS_APP_SPEC 0xfe
22#define USB_CLASS_VENDOR_SPEC 0xff
23
24
25
26
27#define USB_TYPE_MASK (0x03 << 5)
28#define USB_TYPE_STANDARD (0x00 << 5)
29#define USB_TYPE_CLASS (0x01 << 5)
30#define USB_TYPE_VENDOR (0x02 << 5)
31#define USB_TYPE_RESERVED (0x03 << 5)
32
33
34
35
36#define USB_RECIP_MASK 0x1f
37#define USB_RECIP_DEVICE 0x00
38#define USB_RECIP_INTERFACE 0x01
39#define USB_RECIP_ENDPOINT 0x02
40#define USB_RECIP_OTHER 0x03
41
42
43
44
45#define USB_DIR_OUT 0
46#define USB_DIR_IN 0x80
47
48
49
50
51#define USB_DT_DEVICE 0x01
52#define USB_DT_CONFIG 0x02
53#define USB_DT_STRING 0x03
54#define USB_DT_INTERFACE 0x04
55#define USB_DT_ENDPOINT 0x05
56
57#define USB_DT_HID (USB_TYPE_CLASS | 0x01)
58#define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
59#define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
60#define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
61
62
63
64
65#define USB_DT_DEVICE_SIZE 18
66#define USB_DT_CONFIG_SIZE 9
67#define USB_DT_INTERFACE_SIZE 9
68#define USB_DT_ENDPOINT_SIZE 7
69#define USB_DT_ENDPOINT_AUDIO_SIZE 9
70#define USB_DT_HUB_NONVAR_SIZE 7
71#define USB_DT_HID_SIZE 9
72
73
74
75
76#define USB_ENDPOINT_NUMBER_MASK 0x0f
77#define USB_ENDPOINT_DIR_MASK 0x80
78
79#define USB_ENDPOINT_XFERTYPE_MASK 0x03
80#define USB_ENDPOINT_XFER_CONTROL 0
81#define USB_ENDPOINT_XFER_ISOC 1
82#define USB_ENDPOINT_XFER_BULK 2
83#define USB_ENDPOINT_XFER_INT 3
84
85
86
87
88#define USB_PID_UNDEF_0 0xf0
89#define USB_PID_OUT 0xe1
90#define USB_PID_ACK 0xd2
91#define USB_PID_DATA0 0xc3
92#define USB_PID_PING 0xb4
93#define USB_PID_SOF 0xa5
94#define USB_PID_NYET 0x96
95#define USB_PID_DATA2 0x87
96#define USB_PID_SPLIT 0x78
97#define USB_PID_IN 0x69
98#define USB_PID_NAK 0x5a
99#define USB_PID_DATA1 0x4b
100#define USB_PID_PREAMBLE 0x3c
101#define USB_PID_ERR 0x3c
102#define USB_PID_SETUP 0x2d
103#define USB_PID_STALL 0x1e
104#define USB_PID_MDATA 0x0f
105
106
107
108
109#define USB_REQ_GET_STATUS 0x00
110#define USB_REQ_CLEAR_FEATURE 0x01
111#define USB_REQ_SET_FEATURE 0x03
112#define USB_REQ_SET_ADDRESS 0x05
113#define USB_REQ_GET_DESCRIPTOR 0x06
114#define USB_REQ_SET_DESCRIPTOR 0x07
115#define USB_REQ_GET_CONFIGURATION 0x08
116#define USB_REQ_SET_CONFIGURATION 0x09
117#define USB_REQ_GET_INTERFACE 0x0A
118#define USB_REQ_SET_INTERFACE 0x0B
119#define USB_REQ_SYNCH_FRAME 0x0C
120
121
122
123
124#define USB_REQ_GET_REPORT 0x01
125#define USB_REQ_GET_IDLE 0x02
126#define USB_REQ_GET_PROTOCOL 0x03
127#define USB_REQ_SET_REPORT 0x09
128#define USB_REQ_SET_IDLE 0x0A
129#define USB_REQ_SET_PROTOCOL 0x0B
130
131
132#ifdef __KERNEL__
133
134#include <linux/types.h>
135#include <linux/ioctl.h>
136#include <linux/version.h>
137#include <linux/sched.h>
138#include <linux/delay.h>
139#include <linux/interrupt.h>
140#include <linux/config.h>
141#include <linux/list.h>
142
143#define USB_MAJOR 180
144
145static __inline__ void wait_ms(unsigned int ms)
146{
147 if(!in_interrupt()) {
148 current->state = TASK_UNINTERRUPTIBLE;
149 schedule_timeout(1 + ms * HZ / 1000);
150 }
151 else
152 mdelay(ms);
153}
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168struct usb_ctrlrequest {
169 __u8 bRequestType;
170 __u8 bRequest;
171 __u16 wValue;
172 __u16 wIndex;
173 __u16 wLength;
174} __attribute__ ((packed));
175
176
177
178
179
180
181#define USB_ST_NOERROR 0
182#define USB_ST_CRC (-EILSEQ)
183#define USB_ST_BITSTUFF (-EPROTO)
184#define USB_ST_NORESPONSE (-ETIMEDOUT)
185#define USB_ST_DATAOVERRUN (-EOVERFLOW)
186#define USB_ST_DATAUNDERRUN (-EREMOTEIO)
187#define USB_ST_BUFFEROVERRUN (-ECOMM)
188#define USB_ST_BUFFERUNDERRUN (-ENOSR)
189#define USB_ST_INTERNALERROR (-EPROTO)
190#define USB_ST_SHORT_PACKET (-EREMOTEIO)
191#define USB_ST_PARTIAL_ERROR (-EXDEV)
192#define USB_ST_URB_KILLED (-ENOENT)
193#define USB_ST_URB_PENDING (-EINPROGRESS)
194#define USB_ST_REMOVED (-ENODEV)
195#define USB_ST_TIMEOUT (-ETIMEDOUT)
196#define USB_ST_NOTSUPPORTED (-ENOSYS)
197#define USB_ST_BANDWIDTH_ERROR (-ENOSPC)
198#define USB_ST_URB_INVALID_ERROR (-EINVAL)
199#define USB_ST_URB_REQUEST_ERROR (-ENXIO)
200#define USB_ST_STALL (-EPIPE)
201
202
203
204
205
206struct usb_devmap {
207 unsigned long devicemap[128 / (8*sizeof(unsigned long))];
208};
209
210#define USB_MAXBUS 64
211
212struct usb_busmap {
213 unsigned long busmap[USB_MAXBUS / (8*sizeof(unsigned long))];
214};
215
216
217
218
219
220
221
222
223#define USB_MAXCONFIG 8
224#define USB_ALTSETTINGALLOC 4
225#define USB_MAXALTSETTING 128
226#define USB_MAXINTERFACES 32
227#define USB_MAXENDPOINTS 32
228
229
230struct usb_descriptor_header {
231 __u8 bLength;
232 __u8 bDescriptorType;
233} __attribute__ ((packed));
234
235
236struct usb_device_descriptor {
237 __u8 bLength;
238 __u8 bDescriptorType;
239 __u16 bcdUSB;
240 __u8 bDeviceClass;
241 __u8 bDeviceSubClass;
242 __u8 bDeviceProtocol;
243 __u8 bMaxPacketSize0;
244 __u16 idVendor;
245 __u16 idProduct;
246 __u16 bcdDevice;
247 __u8 iManufacturer;
248 __u8 iProduct;
249 __u8 iSerialNumber;
250 __u8 bNumConfigurations;
251} __attribute__ ((packed));
252
253
254struct usb_endpoint_descriptor {
255 __u8 bLength __attribute__ ((packed));
256 __u8 bDescriptorType __attribute__ ((packed));
257 __u8 bEndpointAddress __attribute__ ((packed));
258 __u8 bmAttributes __attribute__ ((packed));
259 __u16 wMaxPacketSize __attribute__ ((packed));
260 __u8 bInterval __attribute__ ((packed));
261 __u8 bRefresh __attribute__ ((packed));
262 __u8 bSynchAddress __attribute__ ((packed));
263
264 unsigned char *extra;
265 int extralen;
266};
267
268
269struct usb_interface_descriptor {
270 __u8 bLength __attribute__ ((packed));
271 __u8 bDescriptorType __attribute__ ((packed));
272 __u8 bInterfaceNumber __attribute__ ((packed));
273 __u8 bAlternateSetting __attribute__ ((packed));
274 __u8 bNumEndpoints __attribute__ ((packed));
275 __u8 bInterfaceClass __attribute__ ((packed));
276 __u8 bInterfaceSubClass __attribute__ ((packed));
277 __u8 bInterfaceProtocol __attribute__ ((packed));
278 __u8 iInterface __attribute__ ((packed));
279
280 struct usb_endpoint_descriptor *endpoint;
281
282 unsigned char *extra;
283 int extralen;
284};
285
286struct usb_interface {
287 struct usb_interface_descriptor *altsetting;
288
289 int act_altsetting;
290 int num_altsetting;
291 int max_altsetting;
292
293 struct usb_driver *driver;
294 void *private_data;
295};
296
297
298struct usb_config_descriptor {
299 __u8 bLength __attribute__ ((packed));
300 __u8 bDescriptorType __attribute__ ((packed));
301 __u16 wTotalLength __attribute__ ((packed));
302 __u8 bNumInterfaces __attribute__ ((packed));
303 __u8 bConfigurationValue __attribute__ ((packed));
304 __u8 iConfiguration __attribute__ ((packed));
305 __u8 bmAttributes __attribute__ ((packed));
306 __u8 MaxPower __attribute__ ((packed));
307
308 struct usb_interface *interface;
309
310 unsigned char *extra;
311 int extralen;
312};
313
314
315struct usb_string_descriptor {
316 __u8 bLength;
317 __u8 bDescriptorType;
318 __u16 wData[1];
319} __attribute__ ((packed));
320
321struct usb_device;
322
323
324
325
326
327
328
329
330
331
332
333
334
335#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
336#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
337#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
338#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
339#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
340#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
341#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
342#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
343#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
344#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
345
346#define USB_DEVICE_ID_MATCH_DEVICE (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
347#define USB_DEVICE_ID_MATCH_DEV_RANGE (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
348#define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
349#define USB_DEVICE_ID_MATCH_DEV_INFO \
350 (USB_DEVICE_ID_MATCH_DEV_CLASS | USB_DEVICE_ID_MATCH_DEV_SUBCLASS | USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
351#define USB_DEVICE_ID_MATCH_INT_INFO \
352 (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS | USB_DEVICE_ID_MATCH_INT_PROTOCOL)
353
354
355#define USB_DEVICE(vend,prod) \
356 match_flags: USB_DEVICE_ID_MATCH_DEVICE, idVendor: (vend), idProduct: (prod)
357#define USB_DEVICE_VER(vend,prod,lo,hi) \
358 match_flags: USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, idVendor: (vend), idProduct: (prod), bcdDevice_lo: (lo), bcdDevice_hi: (hi)
359#define USB_DEVICE_INFO(cl,sc,pr) \
360 match_flags: USB_DEVICE_ID_MATCH_DEV_INFO, bDeviceClass: (cl), bDeviceSubClass: (sc), bDeviceProtocol: (pr)
361#define USB_INTERFACE_INFO(cl,sc,pr) \
362 match_flags: USB_DEVICE_ID_MATCH_INT_INFO, bInterfaceClass: (cl), bInterfaceSubClass: (sc), bInterfaceProtocol: (pr)
363
364struct usb_device_id {
365
366
367
368 __u16 match_flags;
369
370
371
372
373
374
375 __u16 idVendor;
376 __u16 idProduct;
377 __u16 bcdDevice_lo, bcdDevice_hi;
378
379
380
381
382
383 __u8 bDeviceClass;
384 __u8 bDeviceSubClass;
385 __u8 bDeviceProtocol;
386
387
388
389
390
391 __u8 bInterfaceClass;
392 __u8 bInterfaceSubClass;
393 __u8 bInterfaceProtocol;
394
395
396
397
398 unsigned long driver_info;
399};
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445struct usb_driver {
446 struct module *owner;
447
448 const char *name;
449
450 void *(*probe)(
451 struct usb_device *dev,
452 unsigned intf,
453 const struct usb_device_id *id
454 );
455 void (*disconnect)(struct usb_device *, void *);
456
457 struct list_head driver_list;
458
459 struct file_operations *fops;
460 int minor;
461
462 struct semaphore serialize;
463
464 int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf);
465
466 const struct usb_device_id *id_table;
467};
468
469
470
471
472
473
474
475
476#define USB_DISABLE_SPD 0x0001
477#define URB_SHORT_NOT_OK USB_DISABLE_SPD
478#define USB_ISO_ASAP 0x0002
479#define USB_ASYNC_UNLINK 0x0008
480#define USB_QUEUE_BULK 0x0010
481#define USB_NO_FSBR 0x0020
482#define USB_ZERO_PACKET 0x0040
483#define URB_NO_INTERRUPT 0x0080
484
485#define USB_TIMEOUT_KILLED 0x1000
486
487struct iso_packet_descriptor
488{
489 unsigned int offset;
490 unsigned int length;
491 unsigned int actual_length;
492 unsigned int status;
493};
494
495#define usb_iso_packet_descriptor iso_packet_descriptor
496
497struct urb;
498typedef void (*usb_complete_t)(struct urb *);
499
500struct urb
501{
502 spinlock_t lock;
503 void *hcpriv;
504 struct list_head urb_list;
505 struct urb *next;
506 struct usb_device *dev;
507 unsigned int pipe;
508 int status;
509 unsigned int transfer_flags;
510 void *transfer_buffer;
511 dma_addr_t transfer_dma;
512 int transfer_buffer_length;
513 int actual_length;
514 int bandwidth;
515 unsigned char *setup_packet;
516 dma_addr_t setup_dma;
517
518 int start_frame;
519 int number_of_packets;
520 int interval;
521 int error_count;
522 int timeout;
523
524 void *context;
525 usb_complete_t complete;
526
527 struct iso_packet_descriptor iso_frame_desc[0];
528};
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545#define FILL_CONTROL_URB(URB,DEV,PIPE,SETUP_PACKET,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \
546 do {\
547 spin_lock_init(&(URB)->lock);\
548 (URB)->dev=DEV;\
549 (URB)->pipe=PIPE;\
550 (URB)->setup_packet=SETUP_PACKET;\
551 (URB)->transfer_buffer=TRANSFER_BUFFER;\
552 (URB)->transfer_buffer_length=BUFFER_LENGTH;\
553 (URB)->complete=COMPLETE;\
554 (URB)->context=CONTEXT;\
555 } while (0)
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571#define FILL_BULK_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \
572 do {\
573 spin_lock_init(&(URB)->lock);\
574 (URB)->dev=DEV;\
575 (URB)->pipe=PIPE;\
576 (URB)->transfer_buffer=TRANSFER_BUFFER;\
577 (URB)->transfer_buffer_length=BUFFER_LENGTH;\
578 (URB)->complete=COMPLETE;\
579 (URB)->context=CONTEXT;\
580 } while (0)
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597#define FILL_INT_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT,INTERVAL) \
598 do {\
599 spin_lock_init(&(URB)->lock);\
600 (URB)->dev=DEV;\
601 (URB)->pipe=PIPE;\
602 (URB)->transfer_buffer=TRANSFER_BUFFER;\
603 (URB)->transfer_buffer_length=BUFFER_LENGTH;\
604 (URB)->complete=COMPLETE;\
605 (URB)->context=CONTEXT;\
606 (URB)->interval=INTERVAL;\
607 (URB)->start_frame=-1;\
608 } while (0)
609
610#define FILL_CONTROL_URB_TO(a,aa,b,c,d,e,f,g,h) \
611 do {\
612 spin_lock_init(&(a)->lock);\
613 (a)->dev=aa;\
614 (a)->pipe=b;\
615 (a)->setup_packet=c;\
616 (a)->transfer_buffer=d;\
617 (a)->transfer_buffer_length=e;\
618 (a)->complete=f;\
619 (a)->context=g;\
620 (a)->timeout=h;\
621 } while (0)
622
623#define FILL_BULK_URB_TO(a,aa,b,c,d,e,f,g) \
624 do {\
625 spin_lock_init(&(a)->lock);\
626 (a)->dev=aa;\
627 (a)->pipe=b;\
628 (a)->transfer_buffer=c;\
629 (a)->transfer_buffer_length=d;\
630 (a)->complete=e;\
631 (a)->context=f;\
632 (a)->timeout=g;\
633 } while (0)
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649static inline void usb_fill_control_urb (struct urb *urb,
650 struct usb_device *dev,
651 unsigned int pipe,
652 unsigned char *setup_packet,
653 void *transfer_buffer,
654 int buffer_length,
655 usb_complete_t complete,
656 void *context)
657{
658 spin_lock_init(&urb->lock);
659 urb->dev = dev;
660 urb->pipe = pipe;
661 urb->setup_packet = setup_packet;
662 urb->transfer_buffer = transfer_buffer;
663 urb->transfer_buffer_length = buffer_length;
664 urb->complete = complete;
665 urb->context = context;
666}
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681static inline void usb_fill_bulk_urb (struct urb *urb,
682 struct usb_device *dev,
683 unsigned int pipe,
684 void *transfer_buffer,
685 int buffer_length,
686 usb_complete_t complete,
687 void *context)
688
689{
690 spin_lock_init(&urb->lock);
691 urb->dev = dev;
692 urb->pipe = pipe;
693 urb->transfer_buffer = transfer_buffer;
694 urb->transfer_buffer_length = buffer_length;
695 urb->complete = complete;
696 urb->context = context;
697}
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713static inline void usb_fill_int_urb (struct urb *urb,
714 struct usb_device *dev,
715 unsigned int pipe,
716 void *transfer_buffer,
717 int buffer_length,
718 usb_complete_t complete,
719 void *context,
720 int interval)
721{
722 spin_lock_init(&urb->lock);
723 urb->dev = dev;
724 urb->pipe = pipe;
725 urb->transfer_buffer = transfer_buffer;
726 urb->transfer_buffer_length = buffer_length;
727 urb->complete = complete;
728 urb->context = context;
729 urb->interval = interval;
730 urb->start_frame = -1;
731}
732
733struct urb *usb_alloc_urb(int iso_packets);
734void usb_free_urb (struct urb *urb);
735int usb_submit_urb(struct urb *urb);
736int usb_unlink_urb(struct urb *urb);
737int usb_internal_control_msg(struct usb_device *usb_dev, unsigned int pipe, struct usb_ctrlrequest *cmd, void *data, int len, int timeout);
738int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);
739
740
741
742
743
744struct usb_api_data
745{
746 wait_queue_head_t wqh;
747 int done;
748
749};
750
751
752
753struct usb_operations {
754 int (*allocate)(struct usb_device *);
755 int (*deallocate)(struct usb_device *);
756 int (*get_frame_number) (struct usb_device *usb_dev);
757 int (*submit_urb) (struct urb* purb);
758 int (*unlink_urb) (struct urb* purb);
759};
760
761#define DEVNUM_ROUND_ROBIN
762
763
764
765
766struct usb_bus {
767 int busnum;
768 char *bus_name;
769
770#ifdef DEVNUM_ROUND_ROBIN
771 int devnum_next;
772#endif
773
774 struct usb_devmap devmap;
775 struct usb_operations *op;
776 struct usb_device *root_hub;
777 struct list_head bus_list;
778 void *hcpriv;
779
780 int bandwidth_allocated;
781
782
783
784
785 int bandwidth_int_reqs;
786 int bandwidth_isoc_reqs;
787
788
789 struct list_head inodes;
790
791 atomic_t refcnt;
792};
793
794
795
796
797
798
799
800
801
802
803
804struct usb_tt {
805 struct usb_device *hub;
806 int multi;
807};
808
809
810
811
812
813
814#define USB_MAXCHILDREN (16)
815
816struct usb_device {
817 int devnum;
818 char devpath [16];
819
820 enum {
821 USB_SPEED_UNKNOWN = 0,
822 USB_SPEED_LOW, USB_SPEED_FULL,
823 USB_SPEED_HIGH
824 } speed;
825
826 struct usb_tt *tt;
827 int ttport;
828
829 atomic_t refcnt;
830 struct semaphore serialize;
831 struct semaphore exclusive_access;
832
833
834 unsigned int toggle[2];
835 unsigned int halted[2];
836
837 int epmaxpacketin[16];
838 int epmaxpacketout[16];
839
840 struct usb_device *parent;
841 struct usb_bus *bus;
842
843 struct usb_device_descriptor descriptor;
844 struct usb_config_descriptor *config;
845 struct usb_config_descriptor *actconfig;
846
847 char **rawdescriptors;
848
849 int have_langid;
850 int string_langid;
851
852 void *hcpriv;
853
854
855 struct list_head inodes;
856 struct list_head filelist;
857
858
859
860
861
862
863
864
865
866 int maxchild;
867 struct usb_device *children[USB_MAXCHILDREN];
868};
869
870extern int usb_ifnum_to_ifpos(struct usb_device *dev, unsigned ifnum);
871extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum);
872extern struct usb_endpoint_descriptor *usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum);
873
874extern int usb_register(struct usb_driver *);
875extern void usb_deregister(struct usb_driver *);
876extern void usb_scan_devices(void);
877
878
879extern int usb_find_interface_driver_for_ifnum(struct usb_device *dev, unsigned int ifnum);
880extern void usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void* priv);
881extern int usb_interface_claimed(struct usb_interface *iface);
882extern void usb_driver_release_interface(struct usb_driver *driver, struct usb_interface *iface);
883const struct usb_device_id *usb_match_id(struct usb_device *dev,
884 struct usb_interface *interface,
885 const struct usb_device_id *id);
886
887extern struct usb_bus *usb_alloc_bus(struct usb_operations *);
888extern void usb_free_bus(struct usb_bus *);
889extern void usb_register_bus(struct usb_bus *);
890extern void usb_deregister_bus(struct usb_bus *);
891
892extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);
893extern void usb_free_dev(struct usb_device *);
894extern void usb_inc_dev_use(struct usb_device *);
895#define usb_dec_dev_use usb_free_dev
896
897extern int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size, int timeout);
898
899extern int usb_root_hub_string(int id, int serial, char *type, __u8 *data, int len);
900extern void usb_connect(struct usb_device *dev);
901extern void usb_disconnect(struct usb_device **);
902
903extern void usb_destroy_configuration(struct usb_device *dev);
904
905int usb_get_current_frame_number (struct usb_device *usb_dev);
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934static inline int usb_make_path (struct usb_device *dev, char *buf, size_t size)
935{
936 int actual;
937 actual = snprintf (buf, size, "usb-%s-%s",
938 dev->bus->bus_name, dev->devpath);
939 return (actual >= size) ? -1 : actual;
940}
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979#define PIPE_ISOCHRONOUS 0
980#define PIPE_INTERRUPT 1
981#define PIPE_CONTROL 2
982#define PIPE_BULK 3
983
984#define usb_maxpacket(dev, pipe, out) (out \
985 ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
986 : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
987#define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)
988
989#define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
990#define usb_pipein(pipe) (((pipe) >> 7) & 1)
991#define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
992#define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
993#define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
994#define usb_pipedata(pipe) (((pipe) >> 19) & 1)
995#define usb_pipeslow(pipe) (((pipe) >> 26) & 1)
996#define usb_pipetype(pipe) (((pipe) >> 30) & 3)
997#define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
998#define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
999#define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
1000#define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
1001
1002#define PIPE_DEVEP_MASK 0x0007ff00
1003
1004
1005#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)
1006#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << (ep)))
1007static inline void usb_settoggle(struct usb_device *dev,
1008 unsigned int ep,
1009 unsigned int out,
1010 int bit)
1011{
1012 dev->toggle[out] &= ~(1 << ep);
1013 dev->toggle[out] |= bit << ep;
1014}
1015
1016
1017#define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
1018#define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
1019#define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
1020#define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
1021
1022static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint)
1023{
1024 return (dev->devnum << 8) | (endpoint << 15) |
1025 ((dev->speed == USB_SPEED_LOW) << 26);
1026}
1027
1028static inline unsigned int __default_pipe(struct usb_device *dev)
1029{
1030 return ((dev->speed == USB_SPEED_LOW) << 26);
1031}
1032
1033
1034#define usb_sndctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
1035#define usb_rcvctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1036#define usb_sndisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
1037#define usb_rcvisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1038#define usb_sndbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
1039#define usb_rcvbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1040#define usb_sndintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
1041#define usb_rcvintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1042#define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev))
1043#define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)
1044
1045
1046
1047
1048int usb_new_device(struct usb_device *dev);
1049int usb_reset_device(struct usb_device *dev);
1050int usb_set_address(struct usb_device *dev);
1051int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
1052 unsigned char descindex, void *buf, int size);
1053int usb_get_class_descriptor(struct usb_device *dev, int ifnum, unsigned char desctype,
1054 unsigned char descindex, void *buf, int size);
1055int usb_get_device_descriptor(struct usb_device *dev);
1056int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr);
1057int usb_get_status(struct usb_device *dev, int type, int target, void *data);
1058int usb_get_configuration(struct usb_device *dev);
1059int usb_get_protocol(struct usb_device *dev, int ifnum);
1060int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
1061int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
1062int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id);
1063int usb_set_configuration(struct usb_device *dev, int configuration);
1064int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
1065 unsigned char id, void *buf, int size);
1066int usb_set_report(struct usb_device *dev, int ifnum, unsigned char type,
1067 unsigned char id, void *buf, int size);
1068int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
1069int usb_clear_halt(struct usb_device *dev, int pipe);
1070void usb_set_maxpacket(struct usb_device *dev);
1071
1072#define usb_get_extra_descriptor(ifpoint,type,ptr)\
1073 __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,type,(void**)ptr)
1074
1075
1076
1077
1078void usb_show_device_descriptor(struct usb_device_descriptor *);
1079void usb_show_config_descriptor(struct usb_config_descriptor *);
1080void usb_show_interface_descriptor(struct usb_interface_descriptor *);
1081void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);
1082void usb_show_device(struct usb_device *);
1083void usb_show_string(struct usb_device *dev, char *id, int index);
1084
1085#ifdef DEBUG
1086#define dbg(format, arg...) printk(KERN_DEBUG __FILE__ ": " format "\n" , ## arg)
1087#else
1088#define dbg(format, arg...) do {} while (0)
1089#endif
1090#define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)
1091#define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ## arg)
1092#define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ## arg)
1093
1094
1095
1096
1097
1098
1099extern struct list_head usb_driver_list;
1100extern struct list_head usb_bus_list;
1101extern struct semaphore usb_bus_list_lock;
1102
1103
1104
1105
1106
1107#ifdef CONFIG_USB_DEVICEFS
1108
1109
1110
1111
1112
1113extern void usbdevfs_add_bus(struct usb_bus *bus);
1114extern void usbdevfs_remove_bus(struct usb_bus *bus);
1115extern void usbdevfs_add_device(struct usb_device *dev);
1116extern void usbdevfs_remove_device(struct usb_device *dev);
1117
1118extern int usbdevfs_init(void);
1119extern void usbdevfs_cleanup(void);
1120
1121#else
1122
1123static inline void usbdevfs_add_bus(struct usb_bus *bus) {}
1124static inline void usbdevfs_remove_bus(struct usb_bus *bus) {}
1125static inline void usbdevfs_add_device(struct usb_device *dev) {}
1126static inline void usbdevfs_remove_device(struct usb_device *dev) {}
1127
1128static inline int usbdevfs_init(void) { return 0; }
1129static inline void usbdevfs_cleanup(void) { }
1130
1131#endif
1132
1133#endif
1134
1135#endif
1136