📄 zc0301_descriptors.c
字号:
/* This file will give out the informations about device/config/interface/endpoint descriptor * * This device has one configurations, and one interface in configuration, then two endpoints * * in interface.So I havn't used for(;;) to enum them, because I know. * * It's created by WE.XCC at 2008.05.10
*
* Author's E-mail:84318391@163.com * */#include <linux/module.h>#include "zc0301_debug.h"#include "zc0301_struct.h"void zc0301_get_device_descriptor(struct zc0301_device *cam){ struct usb_device_descriptor *dev_des = NULL; struct usb_device *udev = NULL; if (cam == NULL) { debug_error("zc0301_get_device_descriptor:cam is null\n"); return; } udev = cam->usbdev; if (!(dev_des = kzalloc(sizeof(struct usb_device_descriptor), GFP_KERNEL))) { debug_error("device descriptor alloc failed\n"); return; } if ((usb_get_descriptor(udev, USB_DT_DEVICE, 0, dev_des, sizeof(struct usb_device_descriptor))) < 0) { debug_error("get usb device descriptor failed\n"); kfree(dev_des); return; } /*wanna know more details plz see /linux/usb/ch9.h*/ debug_info("**************USB DEVICE DESCRIPTOR LIST**********************\n"); debug_param("bLength: 0x%04x\n", dev_des->bLength); debug_param("bDescriptorType: 0x%04x\n", dev_des->bDescriptorType); debug_param("bcdUSB: 0x%04x\n", dev_des->bcdUSB); debug_param("bDeviceClass: 0x%04x\n", dev_des->bDeviceClass); debug_param("bDeviceSubClass: 0x%04x\n", dev_des->bDeviceSubClass); debug_param("bDeviceProtocol: 0x%04x\n", dev_des->bDeviceProtocol); debug_param("bMaxPacketSize0: 0x%04x\n", dev_des->bMaxPacketSize0); debug_param("idVendor: 0x%04x\n", dev_des->idVendor); debug_param("idProduct: 0x%04x\n", dev_des->idProduct); debug_param("bcdDevice: 0x%04x\n", dev_des->bcdDevice); debug_param("iManufacturer: 0x%04x\n", dev_des->iManufacturer); debug_param("iProduct: 0x%04x\n", dev_des->iProduct); debug_param("iSerialNumber: 0x%04x\n", dev_des->iSerialNumber); debug_param("bNumConfigurations:0x%04x\n", dev_des->bNumConfigurations); debug_info("**************************************************************\n\n"); /*to record the number of config descriptors*/ debug_param("This Device has %d configurations\n", dev_des->bNumConfigurations); kfree(dev_des);}void zc0301_get_config_descriptor(struct zc0301_device *cam){ struct usb_config_descriptor *config_des = NULL; struct usb_device *udev = NULL; s8 i = 0; if (cam == NULL) { debug_error("zc0301_get_config_descriptor:cam is null\n"); return; } udev = cam->usbdev; if (!(config_des = kzalloc(sizeof(struct usb_config_descriptor) , GFP_KERNEL))) { debug_error("config descriptor alloc failed\n"); return; } if ((usb_get_descriptor(udev, USB_DT_CONFIG, i, config_des, sizeof(struct usb_config_descriptor))) < 0) { debug_error("get usb config descriptor failed\n"); kfree(config_des); return; } debug_info("**************USB CONFIG DESCRIPTOR LIST*********************\n"); debug_param("bLength: 0x%04x\n", config_des->bLength); debug_param("bDescriptorType: 0x%04x\n", config_des->bDescriptorType); debug_param("wTotalLength: 0x%04x\n", config_des->wTotalLength); debug_param("bNumInterfaces: 0x%04x\n", config_des->bNumInterfaces); debug_param("bConfigurationValue:0x%04x\n", config_des->bConfigurationValue); debug_param("iConfiguration: 0x%04x\n", config_des->iConfiguration); debug_param("bmAttributes: 0x%04x\n", config_des->bmAttributes); debug_param("bMaxPower : 0x%04x\n", config_des->bMaxPower); debug_info("**************************************************************\n\n"); /*to record the number of interfaces*/ debug_param("The configuration has %d interfaces\n", config_des->bNumInterfaces); kfree(config_des);}void zc0301_get_interface_descriptor(struct zc0301_device *cam){ struct usb_host_interface *host_intf = NULL; struct usb_interface_descriptor *intf_des = NULL; struct usb_device *udev = NULL; if (cam == NULL) { debug_error("zc0301_get_interface_descriptor:cam is null\n"); return; } udev = cam->usbdev; host_intf = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 7); if (host_intf == NULL) { debug_error("zc0301_get_interface_descriptor:host_intf is null\n"); return; } intf_des = &host_intf->desc; if (intf_des == NULL) { debug_error("zc0301_get_interface_descriptor:intf_des is null\n"); return; } /*if (!(intf_des = kzalloc(sizeof(struct usb_interface_descriptor), GFP_KERNEL))) { debug_error("interface descriptor alloc failed\n"); return; } usb_get_descriptor(udev, USB_DT_INTERFACE, 7, intf_des, sizeof(struct usb_interface_descriptor)); { debug_error("get usb interface descriptor failed\n"); return; }*/ debug_info("**************USB INTERFACE DESCRIPTOR LIST**********************\n"); debug_param("bLength: 0x%04x\n", intf_des->bLength); debug_param("bDescriptorType: 0x%04x\n", intf_des->bDescriptorType); debug_param("bInterfaceNumber: 0x%04x\n", intf_des->bInterfaceNumber); debug_param("bAlternateSetting: 0x%04x\n", intf_des->bAlternateSetting); debug_param("bNumEndpoints: 0x%04x\n", intf_des->bNumEndpoints); debug_param("bInterfaceClass: 0x%04x\n", intf_des->bInterfaceClass); debug_param("bInterfaceSubClass:0x%04x\n", intf_des->bInterfaceSubClass); debug_param("bInterfaceProtocol:0x%04x\n", intf_des->bInterfaceProtocol); debug_param("iInterface: 0x%04x\n", intf_des->iInterface); debug_info("*****************************************************************\n\n"); /*to record the number of endpoints*/ debug_param("The Device has %d endpoints\n", intf_des->bNumEndpoints);}void zc0301_get_endpoint_descriptor(struct zc0301_device *cam){ struct usb_endpoint_descriptor *endp_des = NULL; struct usb_device *udev = NULL; struct usb_host_interface *altsetting = NULL; if (cam == NULL) { debug_error("zc0301_get_endpoint_descriptor:cam is null\n"); return; } udev = cam->usbdev; altsetting = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 7); endp_des = &(altsetting->endpoint[0].desc); /*host_endp = &udev->ep0; endp_des = &host_endp->desc; if (!(endp_des = kzalloc(sizeof(struct usb_endpoint_descriptor), GFP_KERNEL))) { debug_error("endpoint descriptor alloc failed\n"); return; } if ((usb_get_descriptor(udev, USB_DT_ENDPOINT, 0, endp_des, sizeof(struct usb_endpoint_descriptor))) <= 0) { debug_error("get usb endpoint descriptor failed\n"); return; }*/ debug_info("**************USB ENDPOINT[0] DESCRIPTOR LIST*****************\n"); debug_param("bLength: 0x%04x\n", endp_des->bLength); debug_param("bDescriptorType: 0x%04x\n", endp_des->bDescriptorType); debug_param("bEndpointAddress:0x%04x\n", endp_des->bEndpointAddress); debug_param("bmAttributes: 0x%04x\n", endp_des->bmAttributes); debug_param("wMaxPacketSize: 0x%04x\n", endp_des->wMaxPacketSize); debug_param("bInterval: 0x%04x\n", endp_des->bInterval); debug_info("**************************************************************\n\n"); //kfree(endp_des); endp_des = &(altsetting->endpoint[1].desc); debug_info("**************USB ENDPOINT[1] DESCRIPTOR LIST*****************\n"); debug_param("bLength: 0x%04x\n", endp_des->bLength); debug_param("bDescriptorType: 0x%04x\n", endp_des->bDescriptorType); debug_param("bEndpointAddress:0x%04x\n", endp_des->bEndpointAddress); debug_param("bmAttributes: 0x%04x\n", endp_des->bmAttributes); debug_param("wMaxPacketSize: 0x%04x\n", endp_des->wMaxPacketSize); debug_param("bInterval: 0x%04x\n", endp_des->bInterval); debug_info("**************************************************************\n\n");}void zc0301_get_string_descriptor(struct zc0301_device *cam){ struct usb_string_descriptor *str_des = NULL; struct usb_device *udev = NULL; if (cam == NULL) { debug_error("zc0301_get_string_descriptor:cam is null\n"); return; } udev = cam->usbdev; if (!(str_des = kzalloc(sizeof(struct usb_string_descriptor), GFP_KERNEL))) { debug_error("string descriptor alloc failed\n"); return; } if ((usb_get_descriptor(udev, USB_DT_STRING, 0, str_des, sizeof(struct usb_string_descriptor))) < 0) { debug_error("get usb string descriptor failed\n"); kfree(str_des); return; } debug_info("**************USB STRING DESCRIPTOR LIST**********************\n"); debug_param("bLength: 0x%04x\n", str_des->bLength); debug_param("bDescriptorType:0x%04x\n", str_des->bDescriptorType); debug_param("wData[1]: 0x%04x\n", str_des->wData[1]); debug_info("**************************************************************\n\n"); kfree(str_des);}EXPORT_SYMBOL(zc0301_get_device_descriptor);EXPORT_SYMBOL(zc0301_get_config_descriptor);EXPORT_SYMBOL(zc0301_get_interface_descriptor);EXPORT_SYMBOL(zc0301_get_endpoint_descriptor);EXPORT_SYMBOL(zc0301_get_string_descriptor);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -