Changes in uspace/app/usbinfo/dump.c [5ccb15c:b1c6e58] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dump.c
r5ccb15c rb1c6e58 27 27 */ 28 28 29 /** @addtogroup usb 29 /** @addtogroup usbinfo 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @briefUSB querying.34 * 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> 45 47 46 48 #include "usbinfo.h" … … 50 52 #define BYTES_PER_LINE 12 51 53 52 #define BCD_INT(a) (((unsigned int)(a)) / 256)53 #define BCD_FRAC(a) (((unsigned int)(a)) % 256)54 54 55 #define BCD_FMT "%x.%x" 56 #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a)) 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 } 57 70 58 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 71 void dump_buffer(const char *msg, size_t indent, 72 const uint8_t *buffer, size_t length) 59 73 { 60 printf("%s\n", msg); 74 if (msg != NULL) { 75 printf("%s\n", msg); 76 } 61 77 62 78 size_t i; 79 if (length > 0) { 80 printf("%s", get_indent(indent)); 81 } 63 82 for (i = 0; i < length; i++) { 64 printf(" 83 printf("0x%02X", buffer[i]); 65 84 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 66 85 || (i + 1 == length)) { 67 86 printf("\n"); 87 if (i + 1 < length) { 88 printf("%s", get_indent(indent)); 89 } 90 } else { 91 printf(" "); 68 92 } 69 93 } 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); 70 101 } 71 102 … … 83 114 } 84 115 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 128 116 static void dump_tree_descriptor(uint8_t *descriptor, size_t depth) 129 117 { 130 118 if (descriptor == NULL) { 131 119 return; 132 }133 while (depth > 0) {134 printf(" ");135 depth--;136 120 } 137 121 int type = (int) *(descriptor + 1); … … 151 135 #undef _TYPE 152 136 } 153 printf("0x%02x (%s)\n", type, name); 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]); 154 140 } 155 141 … … 172 158 uint8_t *ptr = data->data; 173 159 printf("Descriptor tree:\n"); 174 dump_tree_internal(parser, data, ptr, 1);160 dump_tree_internal(parser, data, ptr, 0); 175 161 } 176 162
Note:
See TracChangeset
for help on using the changeset viewer.