Changeset e51a514 in mainline
- Timestamp:
- 2011-05-31T20:58:25Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- df29f24, eb522e8
- Parents:
- 61ebd99b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/info.c
r61ebd99b re51a514 246 246 } 247 247 248 static void find_string_indexes_callback(uint8_t *descriptor, 249 size_t depth, void *arg) 250 { 251 size_t descriptor_length = descriptor[0]; 252 if (descriptor_length <= 1) { 253 return; 254 } 255 256 /*printf("Found string in %s->%s: %zu\n", 257 #descr_struct, #descr_item, __str_index); */ 258 #define SET_STRING_INDEX(descr, mask, descr_type, descr_struct, descr_item) \ 259 do { \ 260 if ((descr)[1] == (descr_type)) { \ 261 descr_struct *__type_descr = (descr_struct *) (descr); \ 262 size_t __str_index = __type_descr->descr_item; \ 263 if ((__str_index > 0) && (__str_index < 64)) { \ 264 mask = (mask) | (1 << __str_index); \ 265 } \ 266 } \ 267 } while (0) 268 269 uint64_t *mask = arg; 270 271 #define SET_STR(descr_type, descr_struct, descr_item) \ 272 SET_STRING_INDEX(descriptor, (*mask), descr_type, descr_struct, descr_item) 273 274 SET_STR(USB_DESCTYPE_DEVICE, usb_standard_device_descriptor_t, 275 str_manufacturer); 276 SET_STR(USB_DESCTYPE_DEVICE, usb_standard_device_descriptor_t, 277 str_product); 278 SET_STR(USB_DESCTYPE_DEVICE, usb_standard_device_descriptor_t, 279 str_serial_number); 280 SET_STR(USB_DESCTYPE_CONFIGURATION, usb_standard_configuration_descriptor_t, 281 str_configuration); 282 SET_STR(USB_DESCTYPE_INTERFACE, usb_standard_interface_descriptor_t, 283 str_interface); 284 } 285 248 286 249 287 void dump_strings(usbinfo_device_t *dev) … … 268 306 printf(".\n"); 269 307 308 /* Find used indexes. Device with more than 64 strings are very rare. 309 */ 310 uint64_t str_mask = 0; 311 find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0, 312 &str_mask); 313 usb_dp_walk_simple(dev->full_configuration_descriptor, 314 dev->full_configuration_descriptor_size, 315 usb_dp_standard_descriptor_nesting, 316 find_string_indexes_callback, 317 &str_mask); 318 270 319 /* Get all strings and dump them. */ 271 320 for (i = 0; i < langs_count; i++) { … … 274 323 printf("%sStrings in %s:\n", get_indent(0), 275 324 str_l18_win_locale(lang)); 276 /* 277 * Try only the first 15 strings 278 * (typically, device will not have much more anyway). 279 */ 325 280 326 size_t idx; 281 for (idx = 1; idx < 0x0F; idx++) { 282 char *string; 327 for (idx = 1; idx < 64; idx++) { 328 if ((str_mask & ((uint64_t)1 << idx)) == 0) { 329 continue; 330 } 331 char *string = NULL; 283 332 rc = usb_request_get_string(&dev->ctrl_pipe, idx, lang, 284 333 &string); 285 if (rc != EOK) { 334 if ((rc != EOK) && (rc != EEMPTY)) { 335 printf("%sWarn: failed to retrieve string #%zu: %s.\n", 336 get_indent(1), idx, str_error(rc)); 286 337 continue; 287 338 } 288 339 printf("%sString #%zu: \"%s\"\n", get_indent(1), 289 idx, string); 290 free(string); 340 idx, rc == EOK ? string : ""); 341 if (string != NULL) { 342 free(string); 343 } 291 344 } 292 345 }
Note:
See TracChangeset
for help on using the changeset viewer.