📄 usbdesc.c
字号:
printf ("\t" "bPwrOn2PwrGood ........ %0d (%dms)\n", hubdesc->bPwrOn2PwrGood, hubdesc->bPwrOn2PwrGood * 2); printf ("\t" "bHubContrCurrent ...... %0d (%dms)\n", hubdesc->bHubContrCurrent, hubdesc->bHubContrCurrent); /* 枛旜偺壜曄晹暘 */ fixed_size = sizeof_HubDesc - sizeof (hubdesc->DeviceRemovable) - sizeof (hubdesc->PortPowerCtrlMask); bytes = (hubdesc->bLength - fixed_size) / 2; printf ("\t" "DeviceRemovable ....... 0x"); hexdump (hubdesc->DeviceRemovable, bytes); printf ("\n"); printf ("\t" "PortPwrCtrlMask ....... 0x"); hexdump (((unsigned char*) hubdesc->DeviceRemovable) + bytes, bytes); printf ("\n");}/* 僨僗僋儕僾僞偺僿僢僟晹暘傪昞帵偡傞 */static intprint_desc_header (void* desc, int len_min, int len_max){ DevDesc* devdesc = (DevDesc*) desc; printf ("[%s Descriptor]\n", descriptor_type_name (devdesc->bDescriptorType)); if (devdesc->bLength < len_min || len_max < devdesc->bLength) { printf ("枹懳墳偺僒僀僘偱偡.\n"); return -1; } else { printf ("\t" "bLength ............... %d\n", devdesc->bLength); printf ("\t" "bDescriptorType ....... 0x%02x (%s)\n", devdesc->bDescriptorType, descriptor_type_name (devdesc->bDescriptorType)); } return 0;}/* 僐儞僼傿僊儏儗乕僔儑儞僨僗僋儕僾僞傪昞帵偡傞 */static voidprint_confdesc_sub (ConfDesc* confdesc){ if (print_desc_header (confdesc, sizeof_ConfDesc, sizeof_ConfDesc) < 0) return; printf ("\t" "wTotalLength .......... %d\n", read_w (confdesc->wTotalLength)); printf ("\t" "bNumInterfaces ........ %d\n", confdesc->bNumInterfaces); printf ("\t" "bConfigurationValue ... %d\n", confdesc->bConfigurationValue); printf ("\t" "iConfiguration ........ %d\n", confdesc->iConfiguration); printf ("\t" "bmAttributes .......... 0x%02x (%s-powered%s)\n", confdesc->bmAttributes, (confdesc->bmAttributes & (1 << 6)) ? "Self" : "Bus", (confdesc->bmAttributes & (1 << 5)) ? ", Remote Wakeup" : ""); printf ("\t" "bMaxPower ............. %d (%dmA)\n", confdesc->bMaxPower, confdesc->bMaxPower * 2);}/* 僨僗僋儕僾僞僞僀僾偺柤徧傪曉偡 */const char*descriptor_type_name (int type){ switch (type) { /* Standard */ case DES_DEVICE: return "Device"; case DES_CONFIGURATION: return "Configuration"; case DES_STRING: return "String"; case DES_INTERFACE: return "Interface"; case DES_ENDPOINT: return "EndPoint"; /* USB2.0 */ case DES_DEVICE_QUALIFIER: return "Device Qualifier"; case DES_OTHER_SPEED_CONFIGURATION: return "Other Speed Configuration"; case DES_INTERFACE_POWER: return "Interface Power"; /* HID Class */ case DES_HID: return "HID"; case DES_HID_REPORT: return "HID Report"; case DES_HID_PHYSICAL: return "HID Physical"; /* HUB Class */ case DES_HUB: return "HUB"; default: break; } return "Unknown";}/* 僨僶僀僗僋儔僗偺柤徧傪曉偡 */const char*device_class_name (int class){ switch (class) { case DEVCLASS_AT_INTERFACE_LEVEL: return "at interface level"; case DEVCLASS_COMMUNICATION: return "Communication"; case DEVCLASS_HUB: return "HUB"; case DEVCLASS_DIAGNOSTIC: return "Diagnostic Device"; case DEVCLASS_WIRELESS_CONTROLLER: return "Wireless Controller"; case DEVCLASS_MISCELLANEOUS: return "Miscellaneous"; case DEVCLASS_VENDOR_SPECIFIC: return "Vendor-Specific"; default: break; } return "Unknown";}/* 僀儞僞乕僼僃僀僗僋儔僗偺柤徧傪曉偡 */const char*interface_class_name (int class){ switch (class) { case CLASS_AUDIO: return "Audio"; case CLASS_CDC_CONTROL: return "CDC-Control"; case CLASS_HID: return "HID"; case CLASS_PHYSICAL: return "Physical"; case CLASS_IMAGE: return "Image"; case CLASS_PRINTER: return "Printer"; case CLASS_MASS_STORAGE: return "Mass-Storage"; case CLASS_HUB: return "HUB"; case CLASS_CDC_DATA: return "CDC-Data"; case CLASS_CHIP_SMART_CARD: return "Chip/Smart Card"; case CLASS_CONTENT_SECURITY: return "Content-Security"; case CLASS_VIDEO: return "Video"; case CLASS_DIAGNOSTIC: return "Giagnostic Device"; case CLASS_WIRELESS_CONTROLLER: return "Wireless Controller"; case CLASS_APPLICATION_SPECIFIC: return "Application-Specific"; case CLASS_VENDOR_SPECIFIC: return "Vendor-Specific"; default: break; } return "Unknown";}/* 僇儞僩儕乕僐乕僪偺柤徧傪曉偡 */const char*country_code_name (int cc){ const char* cc_table[] = { "Not Supported", /* 0x00 */ "Arabic", /* 0x01 */ "Belgian", /* 0x02 */ "Canadian-Bilingual", /* 0x03 */ "Canadian-French", /* 0x04 */ "Czech Republic", /* 0x05 */ "Danish", /* 0x06 */ "Finnish", /* 0x07 */ "French", /* 0x08 */ "German", /* 0x09 */ "Greek", /* 0x0a */ "Hebrew", /* 0x0b */ "Hungary", /* 0x0c */ "International(ISO)", /* 0x0d */ "Italian", /* 0x0e */ "Japan(Katakana)", /* 0x0f */ "Korean", /* 0x10 */ "Latin American", /* 0x11 */ "Netherlands/Dutch", /* 0x12 */ "Norwegian", /* 0x13 */ "Persian(Farsi)", /* 0x14 */ "Poland", /* 0x15 */ "Portuguese", /* 0x16 */ "Russia", /* 0x17 */ "Slovakia", /* 0x18 */ "Spanish", /* 0x19 */ "Swedish", /* 0x1a */ "Swiss/French", /* 0x1b */ "Swiss/German", /* 0x1c */ "Switzerland", /* 0x1d */ "Taiwan", /* 0x1e */ "Turkish-Q", /* 0x1f */ "UK", /* 0x20 */ "US", /* 0x21 */ "Yugoslavia", /* 0x22 */ "Turkish-F", /* 0x23 */ }; const cc_num = sizeof (cc_table) / sizeof (cc_table[0]); return (cc < cc_num) ? cc_table[cc] : "Reserved";}/* 僨僗僋儕僾僞僞僀僾偺斣崋傪曉偡 */intdescriptor_type_num (const char* name){ struct { setupDescriptorType type; const char* name; } table[] = { { DES_DEVICE, "device" }, { DES_CONFIGURATION, "configuration" }, { DES_STRING, "string" }, { DES_INTERFACE, "interface" }, { DES_ENDPOINT, "endpoint" }, { DES_DEVICE_QUALIFIER, "devicequalifier" }, { DES_OTHER_SPEED_CONFIGURATION, "otherspeedconfiguration" }, { DES_INTERFACE_POWER, "interfacepower" }, { DES_HID, "hid" }, { DES_HID_REPORT, "hidreport" }, { DES_HID_PHYSICAL, "hidphysical" }, { DES_HUB, "hub" }, /* 暿柤(徣棯擖椡梡) */ { DES_HID_REPORT, "report" }, { DES_HID_PHYSICAL, "physical" }, }; const int table_size = sizeof (table) / sizeof (table[0]); const len = strlen (name); int i; for (i = 0; i < table_size; ++i) { if (strnicmp (name, table[i].name, len) == 0) return (int) table[i].type; } return -1;}/* 憖嶌懳徾偺斣崋傪曉偡 */setupRecipientget_recipient_type (const char* name){ struct { setupRecipient rec; const char* name; } table[] = { { REC_DEVICE, "device" }, { REC_INTERFACE, "interface" }, { REC_INTERFACE, "if" }, { REC_ENDPOINT, "endpoint" }, { REC_ENDPOINT, "ep" }, { REC_OTHER, "other" }, }; const int table_size = sizeof (table) / sizeof (table[0]); const len = strlen (name); int i; for (i = 0; i < table_size; ++i) { if (strnicmp (name, table[i].name, len) == 0) return table[i].rec; } return (setupRecipient)-1;}/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -