Changes in uspace/app/usbinfo/dump.c [b1c6e58:5ccb15c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dump.c
rb1c6e58 r5ccb15c 27 27 */ 28 28 29 /** @addtogroup usb info29 /** @addtogroup usb 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * USB querying.34 * @brief USB querying. 35 35 */ 36 36 … … 43 43 #include <usb/usb.h> 44 44 #include <usb/descriptor.h> 45 #include <usb/debug.h>46 #include <usb/classes/classes.h>47 45 48 46 #include "usbinfo.h" … … 52 50 #define BYTES_PER_LINE 12 53 51 54 55 const char *get_indent(size_t level) 56 { 57 static const char *indents[] = { 58 INDENT, 59 INDENT INDENT, 60 INDENT INDENT INDENT, 61 INDENT INDENT INDENT INDENT, 62 INDENT INDENT INDENT INDENT INDENT 63 }; 64 static size_t indents_count = sizeof(indents)/sizeof(indents[0]); 65 if (level >= indents_count) { 66 return indents[indents_count - 1]; 67 } 68 return indents[level]; 69 } 70 71 void dump_buffer(const char *msg, size_t indent, 72 const uint8_t *buffer, size_t length) 73 { 74 if (msg != NULL) { 75 printf("%s\n", msg); 76 } 52 #define BCD_INT(a) (((unsigned int)(a)) / 256) 53 #define BCD_FRAC(a) (((unsigned int)(a)) % 256) 54 55 #define BCD_FMT "%x.%x" 56 #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a)) 57 58 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 59 { 60 printf("%s\n", msg); 77 61 78 62 size_t i; 79 if (length > 0) {80 printf("%s", get_indent(indent));81 }82 63 for (i = 0; i < length; i++) { 83 printf(" 0x%02X", buffer[i]);64 printf(" 0x%02X", buffer[i]); 84 65 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 85 66 || (i + 1 == length)) { 86 67 printf("\n"); 87 if (i + 1 < length) {88 printf("%s", get_indent(indent));89 }90 } else {91 printf(" ");92 68 } 93 69 } 94 }95 96 void dump_usb_descriptor(uint8_t *descriptor, size_t size)97 {98 printf("Device descriptor:\n");99 usb_dump_standard_descriptor(stdout, get_indent(0), "\n",100 descriptor, size);101 70 } 102 71 … … 114 83 } 115 84 85 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *d) 86 { 87 printf("Standard device descriptor:\n"); 88 89 printf(INDENT "bLength = %d\n", d->length); 90 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type); 91 printf(INDENT "bcdUSB = %d (" BCD_FMT ")\n", d->usb_spec_version, 92 BCD_ARGS(d->usb_spec_version)); 93 printf(INDENT "bDeviceClass = 0x%02x\n", d->device_class); 94 printf(INDENT "bDeviceSubClass = 0x%02x\n", d->device_subclass); 95 printf(INDENT "bDeviceProtocol = 0x%02x\n", d->device_protocol); 96 printf(INDENT "bMaxPacketSize0 = %d\n", d->max_packet_size); 97 printf(INDENT "idVendor = %d\n", d->vendor_id); 98 printf(INDENT "idProduct = %d\n", d->product_id); 99 printf(INDENT "bcdDevice = %d\n", d->device_version); 100 printf(INDENT "iManufacturer = %d\n", d->str_manufacturer); 101 printf(INDENT "iProduct = %d\n", d->str_product); 102 printf(INDENT "iSerialNumber = %d\n", d->str_serial_number); 103 printf(INDENT "bNumConfigurations = %d\n", d->configuration_count); 104 } 105 106 void dump_standard_configuration_descriptor( 107 int index, usb_standard_configuration_descriptor_t *d) 108 { 109 bool self_powered = d->attributes & 64; 110 bool remote_wakeup = d->attributes & 32; 111 112 printf("Standard configuration descriptor #%d\n", index); 113 printf(INDENT "bLength = %d\n", d->length); 114 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type); 115 printf(INDENT "wTotalLength = %d\n", d->total_length); 116 printf(INDENT "bNumInterfaces = %d\n", d->interface_count); 117 printf(INDENT "bConfigurationValue = %d\n", d->configuration_number); 118 printf(INDENT "iConfiguration = %d\n", d->str_configuration); 119 printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes, 120 self_powered ? "self-powered" : "", 121 (self_powered & remote_wakeup) ? ", " : "", 122 remote_wakeup ? "remote-wakeup" : ""); 123 printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power, 124 2 * d->max_power); 125 // printf(INDENT " = %d\n", d->); 126 } 127 116 128 static void dump_tree_descriptor(uint8_t *descriptor, size_t depth) 117 129 { 118 130 if (descriptor == NULL) { 119 131 return; 132 } 133 while (depth > 0) { 134 printf(" "); 135 depth--; 120 136 } 121 137 int type = (int) *(descriptor + 1); … … 135 151 #undef _TYPE 136 152 } 137 printf("%s%s (0x%02X):\n", get_indent(depth), name, type); 138 usb_dump_standard_descriptor(stdout, get_indent(depth), "\n", 139 descriptor, descriptor[0]); 153 printf("0x%02x (%s)\n", type, name); 140 154 } 141 155 … … 158 172 uint8_t *ptr = data->data; 159 173 printf("Descriptor tree:\n"); 160 dump_tree_internal(parser, data, ptr, 0);174 dump_tree_internal(parser, data, ptr, 1); 161 175 } 162 176
Note:
See TracChangeset
for help on using the changeset viewer.