设备描述符请求失败

人气:391 ℃/2023-03-05 02:32:34

在使用USB设备的时候,经常会出现设备描述符请求失败的状况,那么这个时候我们该怎么解决呢?一起来看看吧。

1、右键左下角Windows徽标键点击运行或者按Windows+R键打开运行窗口

2、弹出运行对话框之后,在输入框中输入services.msc按回车打开服务

3、里面项目的排序方式是首字母顺序倒叙,下滑找到Plug and Play,双击打开

4、先停止这个服务,点击确定退出,然后在双击进来重新启动这个服务

5、点击确定退出,然后重启电脑,重启完毕之后就修复成功了

设备描述符请求失败 usb无法使用

usb设备描述符

/* USB_DT_DEVICE: Device descriptor */struct usb_device_descriptor { __u8 bLength; // 0x12 __u8 bDescriptorType; __le16 bcdUSB; __u8 bDeviceClass; __u8 bDeviceSubClass; __u8 bDeviceProtocol; __u8 bMaxPacketSize0; __le16 idVendor; __le16 idProduct; __le16 bcdDevice; __u8 iManufacturer; __u8 iProduct; __u8 iSerialNumber; __u8 bNumConfigurations;} __attribute__ ((packed));#define USB_DT_DEVICE_SIZE 18

struct usb_composite_dev { struct usb_gadget *gadget; struct usb_request *req; struct usb_request *os_desc_req; struct usb_configuration *config; /* OS String is a custom (yet popular) extension to the USB standard. */ u8 qw_sign[OS_STRING_QW_SIGN_LEN]; u8 b_vendor_code; struct usb_configuration *os_desc_config; unsigned int use_os_string:1; /* private: */ /* internals */ unsigned int suspended:1; struct usb_device_descriptor desc; // usb 设备描述符 struct list_head configs; struct list_head gstrings; struct usb_composite_driver *driver; u8 next_string_id; char *def_manufacturer; /* the gadget driver won't enable the data pullup * while the deactivation count is nonzero. */ unsigned deactivations; /* the composite driver won't complete the control transfer's * data/status stages till delayed_status is zero. */ int delayed_status; /* protects deactivations and delayed_status counts*/ spinlock_t lock; unsigned setup_pending:1; unsigned os_desc_pending:1;};

#define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \{ \ return sprintf(page, "0xx\n", \ to_gadget_info(item)->cdev.desc.__name); \}#define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \{ \ return sprintf(page, "0xx\n", \ le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \}#define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ const char *page, size_t len) \{ \ u8 val; \ int ret; \ ret = kstrtou8(page, 0, &val); \ if (ret) \ return ret; \ to_gadget_info(item)->cdev.desc._name = val; \ return len; \}#define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ const char *page, size_t len) \{ \ u16 val; \ int ret; \ ret = kstrtou16(page, 0, &val); \ if (ret) \ return ret; \ to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \ return len; \}#define GI_DEVICE_DESC_SIMPLE_RW(_name, _type) \ GI_DEVICE_DESC_SIMPLE_R_##_type(_name) \ GI_DEVICE_DESC_SIMPLE_W_##_type(_name)GI_DEVICE_DESC_SIMPLE_R_u16(bcdUSB);GI_DEVICE_DESC_SIMPLE_RW(bDeviceClass, u8);GI_DEVICE_DESC_SIMPLE_RW(bDeviceSubClass, u8);GI_DEVICE_DESC_SIMPLE_RW(bDeviceProtocol, u8);GI_DEVICE_DESC_SIMPLE_RW(bMaxPacketSize0, u8);GI_DEVICE_DESC_SIMPLE_RW(idVendor, u16);GI_DEVICE_DESC_SIMPLE_RW(idProduct, u16);GI_DEVICE_DESC_SIMPLE_R_u16(bcdDevice);CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass);CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass);CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol);CONFIGFS_ATTR(gadget_dev_desc_, bMaxPacketSize0);CONFIGFS_ATTR(gadget_dev_desc_, idVendor);CONFIGFS_ATTR(gadget_dev_desc_, idProduct);CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice);CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB);CONFIGFS_ATTR(gadget_dev_desc_, UDC);static struct configfs_attribute *gadget_root_attrs[] = { &gadget_dev_desc_attr_bDeviceClass, &gadget_dev_desc_attr_bDeviceSubClass, &gadget_dev_desc_attr_bDeviceProtocol, &gadget_dev_desc_attr_bMaxPacketSize0, &gadget_dev_desc_attr_idVendor, &gadget_dev_desc_attr_idProduct, &gadget_dev_desc_attr_bcdDevice, &gadget_dev_desc_attr_bcdUSB, &gadget_dev_desc_attr_UDC, NULL,};static struct config_group *gadgets_make( struct config_group *group, const char *name){ struct gadget_info *gi; gi = kzalloc(sizeof(*gi), GFP_KERNEL); if (!gi) return ERR_PTR(-ENOMEM); gi->group.default_groups = gi->default_groups; gi->group.default_groups[0] = &gi->functions_group; gi->group.default_groups[1] = &gi->configs_group; gi->group.default_groups[2] = &gi->strings_group; gi->group.default_groups[3] = &gi->os_desc_group; config_group_init_type_name(&gi->functions_group, "functions", &functions_type); config_group_init_type_name(&gi->configs_group, "configs", &config_desc_type); config_group_init_type_name(&gi->strings_group, "strings", &gadget_strings_strings_type); config_group_init_type_name(&gi->os_desc_group, "os_desc", &os_desc_type); gi->composite.bind = configfs_do_nothing; gi->composite.unbind = configfs_do_nothing; gi->composite.suspend = NULL; gi->composite.resume = NULL; gi->composite.max_speed = USB_SPEED_SUPER; mutex_init(&gi->lock); INIT_LIST_HEAD(&gi->string_list); INIT_LIST_HEAD(&gi->available_func); composite_init_dev(&gi->cdev); gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE; // 设备描述符长度 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE; //类型是设备描述符 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice()); gi->composite.gadget_driver = configfs_driver_template; gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); gi->composite.name = gi->composite.gadget_driver.function; if (!gi->composite.gadget_driver.function) goto err; if (android_device_create(gi) < 0) goto err; config_group_init_type_name(&gi->group, name, &gadget_root_type); return &gi->group;err: kfree(gi); return ERR_PTR(-ENOMEM);}

枚举过程Host发送8个字节请求设备描述符:

80 06 00 01 00 00 12 00 // 12 就是0x12 18个字节 80 host从设备读取 06 得到描述符 01 设备

#define USB_DT_DEVICE 0x01 #define USB_DT_CONFIG 0x02 #define USB_DT_STRING 0x03 #define USB_DT_INTERFACE 0x04 #define USB_DT_ENDPOINT 0x05 #define USB_DT_DEVICE_QUALIFIER 0x06 #define USB_DT_OTHER_SPEED_CONFIG 0x7 #define USB_DT_INTERFACE_POWER 0x08/* these are from a minor usb 2.0 revision (ECN) */#define USB_DT_OTG 0x09#define USB_DT_DEBUG 0x0a#define USB_DT_INTERFACE_ASSOCIATION 0x0b/* these are from the Wireless USB spec */#define USB_DT_SECURITY 0x0c#define USB_DT_KEY 0x0d#define USB_DT_ENCRYPTION_TYPE 0x0e#define USB_DT_BOS 0x0f#define USB_DT_DEVICE_CAPABILITY 0x10#define USB_DT_WIRELESS_ENDPOINT_COMP 0x11#define USB_DT_WIRE_ADAPTER 0x21#define USB_DT_RPIPE 0x22#define USB_DT_CS_RADIO_CONTROL 0x23/* From the T10 UAS specification */#define USB_DT_PIPE_USAGE 0x24/* From the USB 3.0 spec */#define USB_DT_SS_ENDPOINT_COMP 0x30

设备回应:

12 01 00 02 ef 02 01 40 24 12 25 2a 00 01 01 02 00 01

/* USB_DT_DEVICE: Device descriptor */struct usb_device_descriptor { __u8 bLength; 12 __u8 bDescriptorType; 01 __le16 bcdUSB; 02 00 __u8 bDeviceClass; ef __u8 bDeviceSubClass; 02 __u8 bDeviceProtocol; 01 __u8 bMaxPacketSize0; 40 __le16 idVendor; 12 24 __le16 idProduct; 2a 25 __le16 bcdDevice; 01 00 __u8 iManufacturer; 01 __u8 iProduct; 02 __u8 iSerialNumber; 00 __u8 bNumConfigurations; 01 } __attribute__ ((packed));

---------------------- Device Descriptor ----------------------bLength : 0x12 (18 bytes)bDescriptorType : 0x01 (Device Descriptor)bcdUSB : 0x200 (USB Version 2.00)bDeviceClass : 0xEF (Miscellaneous)bDeviceSubClass : 0x02bDeviceProtocol : 0x01 (IAD - Interface Association Descriptor)bMaxPacketSize0 : 0x40 (64 bytes)idVendor : 0x1224idProduct : 0x2A25bcdDevice : 0x0100iManufacturer : 0x01 (String Descriptor 1) *!*ERROR String descriptor not foundiProduct : 0x02 (String Descriptor 2) *!*ERROR String descriptor not foundiSerialNumber : 0x00 (No String Descriptor)bNumConfigurations : 0x01 (1 Configuration)Data (HexDump) : 12 01 00 02 EF 02 01 40 24 12 25 2A 00 01 01 02 .......@$.%*.... 00 01 ..

* Don't let non-standard requests match any of the cases below * by accident. */ if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) goto unknown; switch (ctrl->bRequest) { /* we handle all standard USB descriptors */ case USB_REQ_GET_DESCRIPTOR: if (ctrl->bRequestType != USB_DIR_IN) goto unknown; switch (w_value >> 8) { case USB_DT_DEVICE: cdev->desc.bNumConfigurations = count_configs(cdev, USB_DT_DEVICE); cdev->desc.bMaxPacketSize0 = cdev->gadget->ep0->maxpacket; if (gadget_is_superspeed(gadget)) { if (gadget->speed >= USB_SPEED_SUPER) { cdev->desc.bcdUSB = cpu_to_le16(0x0310); cdev->desc.bMaxPacketSize0 = 9; } else { cdev->desc.bcdUSB = cpu_to_le16(0x0210); } } else { cdev->desc.bcdUSB = cpu_to_le16(0x0200); } value = min(w_length, (u16) sizeof cdev->desc); memcpy(req->buf, &cdev->desc, value); break;

/* respond with data transfer before status phase? */ if (value >= 0 && value != USB_GADGET_DELAYED_STATUS) { req->length = value; req->context = cdev; req->zero = value < w_length; value = composite_ep0_queue(cdev, req, GFP_ATOMIC); if (value < 0) { DBG(cdev, "ep_queue --> %d\n", value); req->status = 0; composite_setup_complete(gadget->ep0, req); } } else if (value == USB_GADGET_DELAYED_STATUS && w_length != 0) { WARN(cdev, "%s: Delayed status not supported for w_length != 0", __func__); }

static struct usb_device_descriptor webcam_device_descriptor = { .bLength = USB_DT_DEVICE_SIZE, .bDescriptorType = USB_DT_DEVICE, .bcdUSB = cpu_to_le16(0x0200), .bDeviceClass = USB_CLASS_MISC, .bDeviceSubClass = 0x02, .bDeviceProtocol = 0x01, .bMaxPacketSize0 = 0, /* dynamic */ .idVendor = cpu_to_le16(WEBCAM_VENDOR_ID), .idProduct = cpu_to_le16(WEBCAM_PRODUCT_ID), .bcdDevice = cpu_to_le16(WEBCAM_DEVICE_BCD), .iManufacturer = 0, /* dynamic */ .iProduct = 0, /* dynamic */ .iSerialNumber = 0, /* dynamic */ .bNumConfigurations = 0, /* dynamic */};

推荐

首页/电脑版/网名
© 2026 NiBaKu.Com All Rights Reserved.