设为首页 加入收藏

TOP

2.7 usb摄像头之usb摄像头描述符打印(一)
2019-09-01 23:08:45 】 浏览:63
Tags:2.7 usb 摄像头 描述 打印

学习目标:参考lsusb源码,打印USB摄像头的设备描述符、配置描述符、接口联合描述符、端点描述符;

一、lsusb命令和源码

使用命令lsusb可以看看设备的id,并执行 # lsusb -v -d 0x1b3b:2977 命令查看usb摄像头的描述符。

二、源码

打印以下描述符:

程序主要正在probe执行printk函数进行打印:

  1 static int myuvc_probe(struct usb_interface *intf,
  2              const struct usb_device_id *id)
  3 {
  4     static int cnt = 0;
  5     struct usb_device *dev = interface_to_usbdev(intf);
  6     struct usb_device_descriptor *descriptor = &dev->descriptor;
  7     struct usb_host_config *hostconfig;
  8     struct usb_config_descriptor *config;
  9     struct usb_interface_assoc_descriptor *assoc_desc;
 10     struct usb_interface_descriptor    *interface;
 11     struct usb_endpoint_descriptor  *endpoint;
 12     int i, j, k, l, m;
 13     unsigned char *buffer;
 14     int buflen;
 15     int desc_len;
 16     int desc_cnt;
 17 
 18     printk("myuvc_probe : cnt = %d\n", cnt++);
 19 
 20     /* 打印设备描述符 */
 21     printk("Device Descriptor:\n"
 22            "  bLength             %5u\n"
 23            "  bDescriptorType     %5u\n"
 24            "  bcdUSB              %2x.%02x\n"
 25            "  bDeviceClass        %5u \n"
 26            "  bDeviceSubClass     %5u \n"
 27            "  bDeviceProtocol     %5u \n"
 28            "  bMaxPacketSize0     %5u\n"
 29            "  idVendor           0x%04x \n"
 30            "  idProduct          0x%04x \n"
 31            "  bcdDevice           %2x.%02x\n"
 32            "  iManufacturer       %5u\n"
 33            "  iProduct            %5u\n"
 34            "  iSerial             %5u\n"
 35            "  bNumConfigurations  %5u\n",
 36            descriptor->bLength, descriptor->bDescriptorType,
 37            descriptor->bcdUSB >> 8, descriptor->bcdUSB & 0xff,
 38            descriptor->bDeviceClass, 
 39            descriptor->bDeviceSubClass,
 40            descriptor->bDeviceProtocol, 
 41            descriptor->bMaxPacketSize0,
 42            descriptor->idVendor,  descriptor->idProduct,
 43            descriptor->bcdDevice >> 8, descriptor->bcdDevice & 0xff,
 44            descriptor->iManufacturer, 
 45            descriptor->iProduct, 
 46            descriptor->iSerialNumber, 
 47            descriptor->bNumConfigurations);
 48 
 49     for (i = 0; i < descriptor->bNumConfigurations; i++)
 50     {
 51         hostconfig = &dev->config[i]; //第i个配置
 52         config     = &hostconfig->desc;
 53         printk("  Configuration Descriptor %d:\n"
 54                "    bLength             %5u\n"
 55                "    bDescriptorType     %5u\n"
 56                "    wTotalLength        %5u\n"
 57                "    bNumInterfaces      %5u\n"
 58                "    bConfigurationValue %5u\n"
 59                "    iConfiguration      %5u\n"
 60                "    bmAttributes         0x%02x\n",
 61                i, 
 62                config->bLength, config->bDescriptorType,
 63                le16_to_cpu(config->wTotalLength),
 64                config->bNumInterfaces, config->bConfigurationValue,
 65                config->iConfiguration,
 66                config->bmAttributes);
 67         
 68         assoc_desc = hostconfig->intf_assoc[0]; //IAD 
 69         printk("    Interface Association:\n"
 70                "      bLength             %5u\n"
 71                "      bDescriptorType     %5u\n"
 72                "      bFirstInterface     %5u\n"
 73                "      bInterfaceCount     %5u\n"
 74                "      bFunctionClass      %5u\n"
 75                "      bFunctionSubClass   %5u\n"
 76                "      bFunctionProtocol   %5u\n"
 77                "      iFunction           %5u\n",
 78             assoc_desc->bLength,
 79             assoc_desc->bDescriptorType,
 80             assoc_desc->bFirstInterface,
 81             assoc_desc->bInterfaceCount,
 82             assoc_desc->bFunctionClass,
 83             assoc_des
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇网络中的NAT模式 下一篇什么是TLB?

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目