2 * debug.c - USB debug helper routines.
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..
7 #include <linux/config.h>
8 #include <linux/version.h>
9 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #ifdef CONFIG_USB_DEBUG
17 #include <linux/usb.h>
19 static void usb_show_endpoint(struct usb_endpoint_descriptor *endpoint)
21 usb_show_endpoint_descriptor(endpoint);
24 static void usb_show_interface(struct usb_interface_descriptor *altsetting)
28 usb_show_interface_descriptor(altsetting);
30 for (i = 0; i < altsetting->bNumEndpoints; i++)
31 usb_show_endpoint(altsetting->endpoint + i);
34 static void usb_show_config(struct usb_config_descriptor *config)
37 struct usb_interface *ifp;
39 usb_show_config_descriptor(config);
40 for (i = 0; i < config->bNumInterfaces; i++) {
41 ifp = config->interface + i;
46 printk("\n Interface: %d\n", i);
47 for (j = 0; j < ifp->num_altsetting; j++)
48 usb_show_interface(ifp->altsetting + j);
52 void usb_show_device(struct usb_device *dev)
56 usb_show_device_descriptor(&dev->descriptor);
57 for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
58 usb_show_config(dev->config + i);
62 * Parse and show the different USB descriptors.
64 void usb_show_device_descriptor(struct usb_device_descriptor *desc)
68 printk("Invalid USB device descriptor (NULL POINTER)\n");
71 printk(" Length = %2d%s\n", desc->bLength,
72 desc->bLength == USB_DT_DEVICE_SIZE ? "" : " (!!!)");
73 printk(" DescriptorType = %02x\n", desc->bDescriptorType);
75 printk(" USB version = %x.%02x\n",
76 desc->bcdUSB >> 8, desc->bcdUSB & 0xff);
77 printk(" Vendor:Product = %04x:%04x\n",
78 desc->idVendor, desc->idProduct);
79 printk(" MaxPacketSize0 = %d\n", desc->bMaxPacketSize0);
80 printk(" NumConfigurations = %d\n", desc->bNumConfigurations);
81 printk(" Device version = %x.%02x\n",
82 desc->bcdDevice >> 8, desc->bcdDevice & 0xff);
84 printk(" Device Class:SubClass:Protocol = %02x:%02x:%02x\n",
85 desc->bDeviceClass, desc->bDeviceSubClass, desc->bDeviceProtocol);
86 switch (desc->bDeviceClass) {
88 printk(" Per-interface classes\n");
91 printk(" Audio device class\n");
94 printk(" Communications class\n");
97 printk(" Human Interface Devices class\n");
99 case USB_CLASS_PRINTER:
100 printk(" Printer device class\n");
102 case USB_CLASS_MASS_STORAGE:
103 printk(" Mass Storage device class\n");
106 printk(" Hub device class\n");
108 case USB_CLASS_VENDOR_SPEC:
109 printk(" Vendor class\n");
112 printk(" Unknown class\n");
116 void usb_show_config_descriptor(struct usb_config_descriptor *desc)
118 printk("Configuration:\n");
119 printk(" bLength = %4d%s\n", desc->bLength,
120 desc->bLength == USB_DT_CONFIG_SIZE ? "" : " (!!!)");
121 printk(" bDescriptorType = %02x\n", desc->bDescriptorType);
122 printk(" wTotalLength = %04x\n", desc->wTotalLength);
123 printk(" bNumInterfaces = %02x\n", desc->bNumInterfaces);
124 printk(" bConfigurationValue = %02x\n", desc->bConfigurationValue);
125 printk(" iConfiguration = %02x\n", desc->iConfiguration);
126 printk(" bmAttributes = %02x\n", desc->bmAttributes);
127 printk(" MaxPower = %4dmA\n", desc->MaxPower * 2);
130 void usb_show_interface_descriptor(struct usb_interface_descriptor *desc)
132 printk(" Alternate Setting: %2d\n", desc->bAlternateSetting);
133 printk(" bLength = %4d%s\n", desc->bLength,
134 desc->bLength == USB_DT_INTERFACE_SIZE ? "" : " (!!!)");
135 printk(" bDescriptorType = %02x\n", desc->bDescriptorType);
136 printk(" bInterfaceNumber = %02x\n", desc->bInterfaceNumber);
137 printk(" bAlternateSetting = %02x\n", desc->bAlternateSetting);
138 printk(" bNumEndpoints = %02x\n", desc->bNumEndpoints);
139 printk(" bInterface Class:SubClass:Protocol = %02x:%02x:%02x\n",
140 desc->bInterfaceClass, desc->bInterfaceSubClass, desc->bInterfaceProtocol);
141 printk(" iInterface = %02x\n", desc->iInterface);
144 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *desc)
146 char *LengthCommentString = (desc->bLength ==
147 USB_DT_ENDPOINT_AUDIO_SIZE) ? " (Audio)" : (desc->bLength ==
148 USB_DT_ENDPOINT_SIZE) ? "" : " (!!!)";
149 char *EndpointType[4] = { "Control", "Isochronous", "Bulk", "Interrupt" };
151 printk(" Endpoint:\n");
152 printk(" bLength = %4d%s\n",
153 desc->bLength, LengthCommentString);
154 printk(" bDescriptorType = %02x\n", desc->bDescriptorType);
155 printk(" bEndpointAddress = %02x (%s)\n", desc->bEndpointAddress,
156 (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
157 USB_ENDPOINT_XFER_CONTROL ? "i/o" :
158 (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? "in" : "out");
159 printk(" bmAttributes = %02x (%s)\n", desc->bmAttributes,
160 EndpointType[USB_ENDPOINT_XFERTYPE_MASK & desc->bmAttributes]);
161 printk(" wMaxPacketSize = %04x\n", desc->wMaxPacketSize);
162 printk(" bInterval = %02x\n", desc->bInterval);
164 /* Audio extensions to the endpoint descriptor */
165 if (desc->bLength == USB_DT_ENDPOINT_AUDIO_SIZE) {
166 printk(" bRefresh = %02x\n", desc->bRefresh);
167 printk(" bSynchAddress = %02x\n", desc->bSynchAddress);
171 void usb_show_string(struct usb_device *dev, char *id, int index)
177 if (!(buf = kmalloc(256, GFP_KERNEL)))
179 if (usb_string(dev, index, buf, 256) > 0)
180 printk(KERN_INFO "%s: %s\n", id, buf);
184 void usb_dump_urb (struct urb *urb)
186 printk ("urb :%p\n", urb);
187 printk ("next :%p\n", urb->next);
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);