Changes in uspace/lib/usb/src/request.c [ad4562c2:bc1c6fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/request.c
rad4562c2 rbc1c6fb 110 110 * (must be in USB endianness). 111 111 * @param data Buffer where to store data accepted during the DATA stage. 112 * (they will come in USB endian ess).112 * (they will come in USB endianness). 113 113 * @param data_size Size of the @p data buffer 114 114 * (in native endianness). … … 161 161 * the new address. 162 162 * 163 * @see usb_drv_reserve_default_address164 * @see usb_drv_release_default_address165 * @see usb_drv_request_address166 * @see usb_drv_release_address167 * @see usb_drv_bind_address168 *169 163 * @param pipe Control endpoint pipe (session must be already started). 170 164 * @param new_address New USB address to be set (in native endianness). … … 201 195 * @param[in] pipe Control endpoint pipe (session must be already started). 202 196 * @param[in] request_type Request type (standard/class/vendor). 197 * @param[in] recipient Request recipient (device/interface/endpoint). 203 198 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...). 204 199 * @param[in] descriptor_index Descriptor index. … … 235 230 * @param[in] pipe Control endpoint pipe (session must be already started). 236 231 * @param[in] request_type Request type (standard/class/vendor). 232 * @param[in] recipient Request recipient (device/interface/endpoint). 237 233 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...). 238 234 * @param[in] descriptor_index Descriptor index. … … 412 408 } 413 409 410 /** Retrieve full configuration descriptor, allocate space for it. 411 * 412 * The function takes care that full configuration descriptor is returned 413 * (i.e. the function will fail when less data then descriptor.totalLength 414 * is returned). 415 * 416 * @param[in] pipe Control endpoint pipe (session must be already started). 417 * @param[in] index Configuration index. 418 * @param[out] descriptor_ptr Where to store pointer to allocated buffer. 419 * @param[out] descriptor_size Where to store the size of the descriptor. 420 * @return Error code. 421 */ 422 int usb_request_get_full_configuration_descriptor_alloc( 423 usb_endpoint_pipe_t *pipe, int index, 424 void **descriptor_ptr, size_t *descriptor_size) 425 { 426 int rc; 427 428 if (descriptor_ptr == NULL) { 429 return EBADMEM; 430 } 431 432 usb_standard_configuration_descriptor_t bare_config; 433 rc = usb_request_get_bare_configuration_descriptor(pipe, index, 434 &bare_config); 435 if (rc != EOK) { 436 return rc; 437 } 438 439 if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) { 440 return ENOENT; 441 } 442 if (bare_config.total_length < sizeof(bare_config)) { 443 return ELIMIT; 444 } 445 446 void *buffer = malloc(bare_config.total_length); 447 if (buffer == NULL) { 448 return ENOMEM; 449 } 450 451 size_t transferred = 0; 452 rc = usb_request_get_full_configuration_descriptor(pipe, index, 453 buffer, bare_config.total_length, &transferred); 454 if (rc != EOK) { 455 free(buffer); 456 return rc; 457 } 458 459 if (transferred != bare_config.total_length) { 460 free(buffer); 461 return ELIMIT; 462 } 463 464 /* Everything looks okay, copy the pointers. */ 465 466 *descriptor_ptr = buffer; 467 468 if (descriptor_size != NULL) { 469 *descriptor_size = bare_config.total_length; 470 } 471 472 return EOK; 473 } 474 414 475 /** Set configuration of USB device. 415 476 * … … 463 524 return EEMPTY; 464 525 } 465 /* Sub stract first 2 bytes (length and descriptor type). */526 /* Subtract first 2 bytes (length and descriptor type). */ 466 527 string_descriptor_size -= 2; 467 528 … … 483 544 size_t i; 484 545 for (i = 0; i < langs_count; i++) { 485 /* Language code from the descriptor is in USB endian ess. */546 /* Language code from the descriptor is in USB endianness. */ 486 547 /* FIXME: is this really correct? */ 487 548 uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8) … … 504 565 * 505 566 * @param[in] pipe Control endpoint pipe (session must be already started). 506 * @param[in] index String index (in native endianess). 507 * @param[in] lang String language (in native endianess). 567 * @param[in] index String index (in native endianness), 568 * first index has number 1 (index from descriptors can be used directly). 569 * @param[in] lang String language (in native endianness). 508 570 * @param[out] string_ptr Where to store allocated string in native encoding. 509 571 * @return Error code. … … 515 577 return EBADMEM; 516 578 } 517 /* Index is actually one byte value. */ 518 if (index > 0xFF) { 579 /* 580 * Index is actually one byte value and zero index is used 581 * to retrieve list of supported languages. 582 */ 583 if ((index < 1) || (index > 0xFF)) { 519 584 return ERANGE; 520 585 } … … 544 609 goto leave; 545 610 } 546 /* Sub stract first 2 bytes (length and descriptor type). */611 /* Subtract first 2 bytes (length and descriptor type). */ 547 612 string_size -= 2; 548 613
Note:
See TracChangeset
for help on using the changeset viewer.