usb-debug.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
- /*
- * debug.c - USB debug helper routines.
- *
- * I just want these out of the way where they aren't in your
- * face, but so that you can still use them..
- */
- #include <linux/config.h>
- #include <linux/version.h>
- #include <linux/kernel.h>
- #include <linux/mm.h>
- #include <linux/slab.h>
- #ifdef CONFIG_USB_DEBUG
- #define DEBUG
- #else
- #undef DEBUG
- #endif
- #include <linux/usb.h>
- static void usb_show_endpoint(struct usb_endpoint_descriptor *endpoint)
- {
- usb_show_endpoint_descriptor(endpoint);
- }
- static void usb_show_interface(struct usb_interface_descriptor *altsetting)
- {
- int i;
- usb_show_interface_descriptor(altsetting);
- for (i = 0; i < altsetting->bNumEndpoints; i++)
- usb_show_endpoint(altsetting->endpoint + i);
- }
- static void usb_show_config(struct usb_config_descriptor *config)
- {
- int i, j;
- struct usb_interface *ifp;
- usb_show_config_descriptor(config);
- for (i = 0; i < config->bNumInterfaces; i++) {
- ifp = config->interface + i;
- if (!ifp)
- break;
- printk("n Interface: %dn", i);
- for (j = 0; j < ifp->num_altsetting; j++)
- usb_show_interface(ifp->altsetting + j);
- }
- }
- void usb_show_device(struct usb_device *dev)
- {
- int i;
- usb_show_device_descriptor(&dev->descriptor);
- for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
- usb_show_config(dev->config + i);
- }
- /*
- * Parse and show the different USB descriptors.
- */
- void usb_show_device_descriptor(struct usb_device_descriptor *desc)
- {
- if (!desc)
- {
- printk("Invalid USB device descriptor (NULL POINTER)n");
- return;
- }
- printk(" Length = %2d%sn", desc->bLength,
- desc->bLength == USB_DT_DEVICE_SIZE ? "" : " (!!!)");
- printk(" DescriptorType = %02xn", desc->bDescriptorType);
- printk(" USB version = %x.%02xn",
- desc->bcdUSB >> 8, desc->bcdUSB & 0xff);
- printk(" Vendor:Product = %04x:%04xn",
- desc->idVendor, desc->idProduct);
- printk(" MaxPacketSize0 = %dn", desc->bMaxPacketSize0);
- printk(" NumConfigurations = %dn", desc->bNumConfigurations);
- printk(" Device version = %x.%02xn",
- desc->bcdDevice >> 8, desc->bcdDevice & 0xff);
- printk(" Device Class:SubClass:Protocol = %02x:%02x:%02xn",
- desc->bDeviceClass, desc->bDeviceSubClass, desc->bDeviceProtocol);
- switch (desc->bDeviceClass) {
- case 0:
- printk(" Per-interface classesn");
- break;
- case USB_CLASS_AUDIO:
- printk(" Audio device classn");
- break;
- case USB_CLASS_COMM:
- printk(" Communications classn");
- break;
- case USB_CLASS_HID:
- printk(" Human Interface Devices classn");
- break;
- case USB_CLASS_PRINTER:
- printk(" Printer device classn");
- break;
- case USB_CLASS_MASS_STORAGE:
- printk(" Mass Storage device classn");
- break;
- case USB_CLASS_HUB:
- printk(" Hub device classn");
- break;
- case USB_CLASS_VENDOR_SPEC:
- printk(" Vendor classn");
- break;
- default:
- printk(" Unknown classn");
- }
- }
- void usb_show_config_descriptor(struct usb_config_descriptor *desc)
- {
- printk("Configuration:n");
- printk(" bLength = %4d%sn", desc->bLength,
- desc->bLength == USB_DT_CONFIG_SIZE ? "" : " (!!!)");
- printk(" bDescriptorType = %02xn", desc->bDescriptorType);
- printk(" wTotalLength = %04xn", desc->wTotalLength);
- printk(" bNumInterfaces = %02xn", desc->bNumInterfaces);
- printk(" bConfigurationValue = %02xn", desc->bConfigurationValue);
- printk(" iConfiguration = %02xn", desc->iConfiguration);
- printk(" bmAttributes = %02xn", desc->bmAttributes);
- printk(" MaxPower = %4dmAn", desc->MaxPower * 2);
- }
- void usb_show_interface_descriptor(struct usb_interface_descriptor *desc)
- {
- printk(" Alternate Setting: %2dn", desc->bAlternateSetting);
- printk(" bLength = %4d%sn", desc->bLength,
- desc->bLength == USB_DT_INTERFACE_SIZE ? "" : " (!!!)");
- printk(" bDescriptorType = %02xn", desc->bDescriptorType);
- printk(" bInterfaceNumber = %02xn", desc->bInterfaceNumber);
- printk(" bAlternateSetting = %02xn", desc->bAlternateSetting);
- printk(" bNumEndpoints = %02xn", desc->bNumEndpoints);
- printk(" bInterface Class:SubClass:Protocol = %02x:%02x:%02xn",
- desc->bInterfaceClass, desc->bInterfaceSubClass, desc->bInterfaceProtocol);
- printk(" iInterface = %02xn", desc->iInterface);
- }
- void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *desc)
- {
- char *LengthCommentString = (desc->bLength ==
- USB_DT_ENDPOINT_AUDIO_SIZE) ? " (Audio)" : (desc->bLength ==
- USB_DT_ENDPOINT_SIZE) ? "" : " (!!!)";
- char *EndpointType[4] = { "Control", "Isochronous", "Bulk", "Interrupt" };
- printk(" Endpoint:n");
- printk(" bLength = %4d%sn",
- desc->bLength, LengthCommentString);
- printk(" bDescriptorType = %02xn", desc->bDescriptorType);
- printk(" bEndpointAddress = %02x (%s)n", desc->bEndpointAddress,
- (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_CONTROL ? "i/o" :
- (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? "in" : "out");
- printk(" bmAttributes = %02x (%s)n", desc->bmAttributes,
- EndpointType[USB_ENDPOINT_XFERTYPE_MASK & desc->bmAttributes]);
- printk(" wMaxPacketSize = %04xn", desc->wMaxPacketSize);
- printk(" bInterval = %02xn", desc->bInterval);
- /* Audio extensions to the endpoint descriptor */
- if (desc->bLength == USB_DT_ENDPOINT_AUDIO_SIZE) {
- printk(" bRefresh = %02xn", desc->bRefresh);
- printk(" bSynchAddress = %02xn", desc->bSynchAddress);
- }
- }
- void usb_show_string(struct usb_device *dev, char *id, int index)
- {
- char *buf;
- if (!index)
- return;
- if (!(buf = kmalloc(256, GFP_KERNEL)))
- return;
- if (usb_string(dev, index, buf, 256) > 0)
- printk(KERN_INFO "%s: %sn", id, buf);
- kfree(buf);
- }
- void usb_dump_urb (struct urb *urb)
- {
- printk ("urb :%pn", urb);
- printk ("next :%pn", urb->next);
- printk ("dev :%pn", urb->dev);
- printk ("pipe :%08Xn", urb->pipe);
- printk ("status :%dn", urb->status);
- printk ("transfer_flags :%08Xn", urb->transfer_flags);
- printk ("transfer_buffer :%pn", urb->transfer_buffer);
- printk ("transfer_buffer_length:%dn", urb->transfer_buffer_length);
- printk ("actual_length :%dn", urb->actual_length);
- printk ("setup_packet :%pn", urb->setup_packet);
- printk ("start_frame :%dn", urb->start_frame);
- printk ("number_of_packets :%dn", urb->number_of_packets);
- printk ("interval :%dn", urb->interval);
- printk ("error_count :%dn", urb->error_count);
- printk ("context :%pn", urb->context);
- printk ("complete :%pn", urb->complete);
- }