Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
846 | giacomo | 1 | /* |
2 | * debug.c - USB debug helper routines. |
||
3 | * |
||
4 | * I just want these out of the way where they aren't in your |
||
5 | * face, but so that you can still use them.. |
||
6 | */ |
||
7 | #include <linuxcomp.h> |
||
8 | |||
9 | #include <linux/config.h> |
||
10 | #include <linux/kernel.h> |
||
11 | #include <linux/mm.h> |
||
12 | #include <linux/slab.h> |
||
13 | #ifdef CONFIG_USB_DEBUG |
||
14 | #define DEBUG |
||
15 | #else |
||
16 | #undef DEBUG |
||
17 | #endif |
||
18 | #include <linux/usb.h> |
||
19 | |||
20 | static void usb_show_endpoint(struct usb_host_endpoint *endpoint) |
||
21 | { |
||
22 | usb_show_endpoint_descriptor(&endpoint->desc); |
||
23 | } |
||
24 | |||
25 | static void usb_show_interface(struct usb_host_interface *altsetting) |
||
26 | { |
||
27 | int i; |
||
28 | |||
29 | usb_show_interface_descriptor(&altsetting->desc); |
||
30 | |||
31 | for (i = 0; i < altsetting->desc.bNumEndpoints; i++) |
||
32 | usb_show_endpoint(altsetting->endpoint + i); |
||
33 | } |
||
34 | |||
35 | static void usb_show_config(struct usb_host_config *config) |
||
36 | { |
||
37 | int i, j; |
||
38 | struct usb_interface *ifp; |
||
39 | |||
40 | usb_show_config_descriptor(&config->desc); |
||
41 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
||
42 | ifp = config->interface[i]; |
||
43 | |||
44 | if (!ifp) |
||
45 | break; |
||
46 | |||
47 | printk("\n Interface: %d\n", i); |
||
48 | for (j = 0; j < ifp->num_altsetting; j++) |
||
49 | usb_show_interface(ifp->altsetting + j); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | void usb_show_device(struct usb_device *dev) |
||
54 | { |
||
55 | int i; |
||
56 | |||
57 | usb_show_device_descriptor(&dev->descriptor); |
||
58 | for (i = 0; i < dev->descriptor.bNumConfigurations; i++) |
||
59 | usb_show_config(dev->config + i); |
||
60 | } |
||
61 | |||
62 | /* |
||
63 | * Parse and show the different USB descriptors. |
||
64 | */ |
||
65 | void usb_show_device_descriptor(struct usb_device_descriptor *desc) |
||
66 | { |
||
67 | if (!desc) |
||
68 | { |
||
69 | printk("Invalid USB device descriptor (NULL POINTER)\n"); |
||
70 | return; |
||
71 | } |
||
72 | printk(" Length = %2d%s\n", desc->bLength, |
||
73 | desc->bLength == USB_DT_DEVICE_SIZE ? "" : " (!!!)"); |
||
74 | printk(" DescriptorType = %02x\n", desc->bDescriptorType); |
||
75 | |||
76 | printk(" USB version = %x.%02x\n", |
||
77 | desc->bcdUSB >> 8, desc->bcdUSB & 0xff); |
||
78 | printk(" Vendor:Product = %04x:%04x\n", |
||
79 | desc->idVendor, desc->idProduct); |
||
80 | printk(" MaxPacketSize0 = %d\n", desc->bMaxPacketSize0); |
||
81 | printk(" NumConfigurations = %d\n", desc->bNumConfigurations); |
||
82 | printk(" Device version = %x.%02x\n", |
||
83 | desc->bcdDevice >> 8, desc->bcdDevice & 0xff); |
||
84 | |||
85 | printk(" Device Class:SubClass:Protocol = %02x:%02x:%02x\n", |
||
86 | desc->bDeviceClass, desc->bDeviceSubClass, desc->bDeviceProtocol); |
||
87 | switch (desc->bDeviceClass) { |
||
88 | case 0: |
||
89 | printk(" Per-interface classes\n"); |
||
90 | break; |
||
91 | case USB_CLASS_AUDIO: |
||
92 | printk(" Audio device class\n"); |
||
93 | break; |
||
94 | case USB_CLASS_COMM: |
||
95 | printk(" Communications class\n"); |
||
96 | break; |
||
97 | case USB_CLASS_HID: |
||
98 | printk(" Human Interface Devices class\n"); |
||
99 | break; |
||
100 | case USB_CLASS_PRINTER: |
||
101 | printk(" Printer device class\n"); |
||
102 | break; |
||
103 | case USB_CLASS_MASS_STORAGE: |
||
104 | printk(" Mass Storage device class\n"); |
||
105 | break; |
||
106 | case USB_CLASS_HUB: |
||
107 | printk(" Hub device class\n"); |
||
108 | break; |
||
109 | case USB_CLASS_VENDOR_SPEC: |
||
110 | printk(" Vendor class\n"); |
||
111 | break; |
||
112 | default: |
||
113 | printk(" Unknown class\n"); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | void usb_show_config_descriptor(struct usb_config_descriptor *desc) |
||
118 | { |
||
119 | printk("Configuration:\n"); |
||
120 | printk(" bLength = %4d%s\n", desc->bLength, |
||
121 | desc->bLength == USB_DT_CONFIG_SIZE ? "" : " (!!!)"); |
||
122 | printk(" bDescriptorType = %02x\n", desc->bDescriptorType); |
||
123 | printk(" wTotalLength = %04x\n", desc->wTotalLength); |
||
124 | printk(" bNumInterfaces = %02x\n", desc->bNumInterfaces); |
||
125 | printk(" bConfigurationValue = %02x\n", desc->bConfigurationValue); |
||
126 | printk(" iConfiguration = %02x\n", desc->iConfiguration); |
||
127 | printk(" bmAttributes = %02x\n", desc->bmAttributes); |
||
128 | printk(" bMaxPower = %4dmA\n", desc->bMaxPower * 2); |
||
129 | } |
||
130 | |||
131 | void usb_show_interface_descriptor(struct usb_interface_descriptor *desc) |
||
132 | { |
||
133 | printk(" Alternate Setting: %2d\n", desc->bAlternateSetting); |
||
134 | printk(" bLength = %4d%s\n", desc->bLength, |
||
135 | desc->bLength == USB_DT_INTERFACE_SIZE ? "" : " (!!!)"); |
||
136 | printk(" bDescriptorType = %02x\n", desc->bDescriptorType); |
||
137 | printk(" bInterfaceNumber = %02x\n", desc->bInterfaceNumber); |
||
138 | printk(" bAlternateSetting = %02x\n", desc->bAlternateSetting); |
||
139 | printk(" bNumEndpoints = %02x\n", desc->bNumEndpoints); |
||
140 | printk(" bInterface Class:SubClass:Protocol = %02x:%02x:%02x\n", |
||
141 | desc->bInterfaceClass, desc->bInterfaceSubClass, desc->bInterfaceProtocol); |
||
142 | printk(" iInterface = %02x\n", desc->iInterface); |
||
143 | } |
||
144 | |||
145 | void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *desc) |
||
146 | { |
||
147 | char *LengthCommentString = (desc->bLength == |
||
148 | USB_DT_ENDPOINT_AUDIO_SIZE) ? " (Audio)" : (desc->bLength == |
||
149 | USB_DT_ENDPOINT_SIZE) ? "" : " (!!!)"; |
||
150 | char *EndpointType[4] = { "Control", "Isochronous", "Bulk", "Interrupt" }; |
||
151 | |||
152 | printk(" Endpoint:\n"); |
||
153 | printk(" bLength = %4d%s\n", |
||
154 | desc->bLength, LengthCommentString); |
||
155 | printk(" bDescriptorType = %02x\n", desc->bDescriptorType); |
||
156 | printk(" bEndpointAddress = %02x (%s)\n", desc->bEndpointAddress, |
||
157 | (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
||
158 | USB_ENDPOINT_XFER_CONTROL ? "i/o" : |
||
159 | (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? "in" : "out"); |
||
160 | printk(" bmAttributes = %02x (%s)\n", desc->bmAttributes, |
||
161 | EndpointType[USB_ENDPOINT_XFERTYPE_MASK & desc->bmAttributes]); |
||
162 | printk(" wMaxPacketSize = %04x\n", desc->wMaxPacketSize); |
||
163 | printk(" bInterval = %02x\n", desc->bInterval); |
||
164 | |||
165 | /* Audio extensions to the endpoint descriptor */ |
||
166 | if (desc->bLength == USB_DT_ENDPOINT_AUDIO_SIZE) { |
||
167 | printk(" bRefresh = %02x\n", desc->bRefresh); |
||
168 | printk(" bSynchAddress = %02x\n", desc->bSynchAddress); |
||
169 | } |
||
170 | } |
||
171 | |||
172 | void usb_show_string(struct usb_device *dev, char *id, int index) |
||
173 | { |
||
174 | char *buf; |
||
175 | |||
176 | if (!index) |
||
177 | return; |
||
178 | if (!(buf = kmalloc(256, GFP_KERNEL))) |
||
179 | return; |
||
180 | if (usb_string(dev, index, buf, 256) > 0) |
||
181 | dev_printk(KERN_INFO, &dev->dev, "%s: %s\n", id, buf); |
||
182 | kfree(buf); |
||
183 | } |
||
184 | |||
185 | void usb_dump_urb (struct urb *urb) |
||
186 | { |
||
187 | printk ("urb :%p\n", urb); |
||
188 | printk ("dev :%p\n", urb->dev); |
||
189 | printk ("pipe :%08X\n", urb->pipe); |
||
190 | printk ("status :%d\n", urb->status); |
||
191 | printk ("transfer_flags :%08X\n", urb->transfer_flags); |
||
192 | printk ("transfer_buffer :%p\n", urb->transfer_buffer); |
||
193 | printk ("transfer_buffer_length:%d\n", urb->transfer_buffer_length); |
||
194 | printk ("actual_length :%d\n", urb->actual_length); |
||
195 | printk ("setup_packet :%p\n", urb->setup_packet); |
||
196 | printk ("start_frame :%d\n", urb->start_frame); |
||
197 | printk ("number_of_packets :%d\n", urb->number_of_packets); |
||
198 | printk ("interval :%d\n", urb->interval); |
||
199 | printk ("error_count :%d\n", urb->error_count); |
||
200 | printk ("context :%p\n", urb->context); |
||
201 | printk ("complete :%p\n", urb->complete); |
||
202 | } |
||
203 |