Changeset 1a6a234 in mainline
- Timestamp:
- 2011-02-23T21:22:41Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7eebe2a
- Parents:
- 14670bf
- Location:
- uspace/lib/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/request.h
r14670bf r1a6a234 37 37 38 38 #include <sys/types.h> 39 #include <l18n/langs.h> 39 40 #include <usb/usb.h> 40 41 #include <usb/pipes.h> … … 106 107 int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t); 107 108 109 int usb_request_get_supported_languages(usb_endpoint_pipe_t *, 110 l18_win_locales_t **, size_t *); 111 108 112 #endif 109 113 /** -
uspace/lib/usb/src/request.c
r14670bf r1a6a234 429 429 } 430 430 431 /** Get list of supported languages by USB device. 432 * 433 * @param[in] pipe Control endpoint pipe (session must be already started). 434 * @param[out] languages_ptr Where to store pointer to allocated array of 435 * supported languages. 436 * @param[out] languages_count Number of supported languages. 437 * @return Error code. 438 */ 439 int usb_request_get_supported_languages(usb_endpoint_pipe_t *pipe, 440 l18_win_locales_t **languages_ptr, size_t *languages_count) 441 { 442 int rc; 443 444 if (languages_ptr == NULL) { 445 return EBADMEM; 446 } 447 if (languages_count == NULL) { 448 return EBADMEM; 449 } 450 451 uint8_t *string_descriptor = NULL; 452 size_t string_descriptor_size = 0; 453 rc = usb_request_get_descriptor_alloc(pipe, 454 USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_STRING, 0, 0, 455 (void **) &string_descriptor, &string_descriptor_size); 456 if (rc != EOK) { 457 return rc; 458 } 459 if (string_descriptor_size <= 2) { 460 free(string_descriptor); 461 return EEMPTY; 462 } 463 /* Substract first 2 bytes (length and descriptor type). */ 464 string_descriptor_size -= 2; 465 466 /* Odd number of bytes - descriptor is broken? */ 467 if ((string_descriptor_size % 2) != 0) { 468 /* FIXME: shall we return with error or silently ignore? */ 469 free(string_descriptor); 470 return ESTALL; 471 } 472 473 size_t langs_count = string_descriptor_size / 2; 474 l18_win_locales_t *langs 475 = malloc(sizeof(l18_win_locales_t) * langs_count); 476 if (langs == NULL) { 477 free(string_descriptor); 478 return ENOMEM; 479 } 480 481 size_t i; 482 for (i = 0; i < langs_count; i++) { 483 /* Language code from the descriptor is in USB endianess. */ 484 /* FIXME: is this really correct? */ 485 uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8) 486 + string_descriptor[2 + 2 * i]; 487 langs[i] = uint16_usb2host(lang_code); 488 } 489 490 free(string_descriptor); 491 492 *languages_ptr = langs; 493 *languages_count =langs_count; 494 495 return EOK; 496 } 497 431 498 /** 432 499 * @}
Note:
See TracChangeset
for help on using the changeset viewer.