Changeset 5f635ca in mainline
- Timestamp:
- 2011-01-14T13:38:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6fe1ab4
- Parents:
- 60b2b69
- Location:
- uspace/app/usbinfo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dump.c
r60b2b69 r5f635ca 56 56 #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a)) 57 57 58 static void dump_descriptor_by_type(size_t, uint8_t *, size_t); 59 60 typedef struct { 61 int descriptor; 62 void (*dump)(size_t indent, uint8_t *descriptor, size_t length); 63 } descriptor_dump_t; 64 65 static void dump_descriptor_device(size_t, uint8_t *, size_t); 66 static void dump_descriptor_configuration(size_t, uint8_t *, size_t); 67 static void dump_descriptor_interface(size_t, uint8_t *, size_t); 68 static void dump_descriptor_string(size_t, uint8_t *, size_t); 69 static void dump_descriptor_endpoint(size_t, uint8_t *, size_t); 70 static void dump_descriptor_hid(size_t, uint8_t *, size_t); 71 static void dump_descriptor_hub(size_t, uint8_t *, size_t); 72 static void dump_descriptor_generic(size_t, uint8_t *, size_t); 73 74 static descriptor_dump_t descriptor_dumpers[] = { 75 { USB_DESCTYPE_DEVICE, dump_descriptor_device }, 76 { USB_DESCTYPE_CONFIGURATION, dump_descriptor_configuration }, 77 { USB_DESCTYPE_STRING, dump_descriptor_string }, 78 { USB_DESCTYPE_INTERFACE, dump_descriptor_interface }, 79 { USB_DESCTYPE_ENDPOINT, dump_descriptor_endpoint }, 80 { USB_DESCTYPE_HID, dump_descriptor_hid }, 81 { USB_DESCTYPE_HUB, dump_descriptor_hub }, 82 { -1, dump_descriptor_generic }, 83 { -1, NULL } 84 }; 85 58 86 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 59 87 { 60 printf("%s\n", msg); 88 if (msg != NULL) { 89 printf("%s\n", msg); 90 } 61 91 62 92 size_t i; … … 70 100 } 71 101 72 void dump_match_ids(match_id_list_t *matches) 73 { 74 printf("Match ids:\n"); 75 link_t *link; 76 for (link = matches->ids.next; 77 link != &matches->ids; 78 link = link->next) { 79 match_id_t *match = list_get_instance(link, match_id_t, link); 80 81 printf(INDENT "%d %s\n", match->score, match->id); 82 } 83 } 84 85 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *d) 86 { 87 printf("Standard device descriptor:\n"); 88 102 void dump_descriptor_by_type(size_t indent, uint8_t *d, size_t length) 103 { 104 if (length < 2) { 105 return; 106 } 107 int type = d[1]; 108 109 descriptor_dump_t *dumper = descriptor_dumpers; 110 while (dumper->dump != NULL) { 111 if ((dumper->descriptor == type) || (dumper->descriptor < 0)) { 112 dumper->dump(indent, d, length); 113 return; 114 } 115 dumper++; 116 } 117 } 118 119 void dump_usb_descriptor(uint8_t *descriptor, size_t size) 120 { 121 dump_descriptor_by_type(0, descriptor, size); 122 } 123 124 void dump_descriptor_device(size_t indent, uint8_t *descr, size_t size) 125 { 126 usb_standard_device_descriptor_t *d 127 = (usb_standard_device_descriptor_t *) descr; 128 if (size != sizeof(*d)) { 129 return; 130 } 131 89 132 printf(INDENT "bLength = %d\n", d->length); 90 133 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type); … … 104 147 } 105 148 106 void dump_standard_configuration_descriptor( 107 int index, usb_standard_configuration_descriptor_t *d) 108 { 149 void dump_descriptor_configuration(size_t indent, uint8_t *descr, size_t size) 150 { 151 usb_standard_configuration_descriptor_t *d 152 = (usb_standard_configuration_descriptor_t *) descr; 153 if (size != sizeof(*d)) { 154 return; 155 } 156 109 157 bool self_powered = d->attributes & 64; 110 158 bool remote_wakeup = d->attributes & 32; 111 159 112 printf("Standard configuration descriptor #%d\n", index);113 160 printf(INDENT "bLength = %d\n", d->length); 114 161 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type); … … 123 170 printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power, 124 171 2 * d->max_power); 125 // printf(INDENT " = %d\n", d->); 172 } 173 174 void dump_descriptor_interface(size_t indent, uint8_t *descr, size_t size) 175 { 176 dump_descriptor_generic(indent, descr, size); 177 } 178 179 void dump_descriptor_string(size_t indent, uint8_t *descr, size_t size) 180 { 181 dump_descriptor_generic(indent, descr, size); 182 } 183 184 void dump_descriptor_endpoint(size_t indent, uint8_t *descr, size_t size) 185 { 186 dump_descriptor_generic(indent, descr, size); 187 } 188 189 void dump_descriptor_hid(size_t indent, uint8_t *descr, size_t size) 190 { 191 dump_descriptor_generic(indent, descr, size); 192 } 193 194 void dump_descriptor_hub(size_t indent, uint8_t *descr, size_t size) 195 { 196 dump_descriptor_generic(indent, descr, size); 197 } 198 199 void dump_descriptor_generic(size_t indent, uint8_t *descr, size_t size) 200 { 201 dump_buffer(NULL, descr, size); 202 } 203 204 205 void dump_match_ids(match_id_list_t *matches) 206 { 207 printf("Match ids:\n"); 208 link_t *link; 209 for (link = matches->ids.next; 210 link != &matches->ids; 211 link = link->next) { 212 match_id_t *match = list_get_instance(link, match_id_t, link); 213 214 printf(INDENT "%d %s\n", match->score, match->id); 215 } 126 216 } 127 217 … … 152 242 } 153 243 printf("0x%02x (%s)\n", type, name); 244 dump_descriptor_by_type(depth, descriptor, descriptor[0]); 245 154 246 } 155 247 -
uspace/app/usbinfo/info.c
r60b2b69 r5f635ca 72 72 return rc; 73 73 } 74 dump_ standard_device_descriptor(&device_descriptor);74 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor)); 75 75 76 76 /* … … 91 91 return rc; 92 92 } 93 dump_standard_configuration_descriptor(config_index, 94 &config_descriptor); 93 //dump_standard_configuration_descriptor(config_index, &config_descriptor); 95 94 96 95 void *full_config_descriptor = malloc(config_descriptor.total_length); -
uspace/app/usbinfo/usbinfo.h
r60b2b69 r5f635ca 46 46 void dump_buffer(const char *, const uint8_t *, size_t); 47 47 void dump_match_ids(match_id_list_t *matches); 48 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *); 49 void dump_standard_configuration_descriptor(int, 50 usb_standard_configuration_descriptor_t *); 48 void dump_usb_descriptor(uint8_t *, size_t); 51 49 int dump_device(int, usb_address_t); 52 50 void dump_descriptor_tree(uint8_t *, size_t);
Note:
See TracChangeset
for help on using the changeset viewer.