Changeset f8d43aa in mainline
- Timestamp:
- 2012-12-22T21:45:53Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 971fbfde
- Parents:
- b591cab
- Location:
- uspace/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/l18n/langs.c
rb591cab rf8d43aa 66 66 case L18N_WIN_LOCALE_ZULU: 67 67 return "Zulu"; 68 default: 69 break; 68 70 } 69 71 -
uspace/lib/c/include/l18n/langs.h
rb591cab rf8d43aa 54 54 L18N_WIN_LOCALE_SPANISH_TRADITIONAL = 0x040A, 55 55 /* ... */ 56 L18N_WIN_LOCALE_ZULU = 0x0435 56 L18N_WIN_LOCALE_ZULU = 0x0435, 57 L18N_WIN_LOCALE_MAX = 0xFFFF 57 58 } l18_win_locales_t; 58 59 -
uspace/lib/usbdev/include/usb/dev/request.h
rb591cab rf8d43aa 113 113 int usb_control_request_set(usb_pipe_t *, 114 114 usb_request_type_t, usb_request_recipient_t, uint8_t, 115 uint16_t, uint16_t, void *, size_t);115 uint16_t, uint16_t, const void *, size_t); 116 116 117 117 int usb_control_request_get(usb_pipe_t *, … … 139 139 int, void **, size_t *); 140 140 int usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t, 141 usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t);141 usb_request_recipient_t, uint8_t, uint8_t, uint16_t, const void *, size_t); 142 142 143 143 int usb_request_get_configuration(usb_pipe_t *, uint8_t *); -
uspace/lib/usbdev/src/request.c
rb591cab rf8d43aa 49 49 * @param request Actual request (e.g. GET_DESCRIPTOR). 50 50 * @param value Value of @c wValue field of setup packet 51 * 51 * (must be in USB endianness). 52 52 * @param index Value of @c wIndex field of setup packet 53 * 53 * (must be in USB endianness). 54 54 * @param data Data to be sent during DATA stage 55 * 55 * (expected to be in USB endianness). 56 56 * @param data_size Size of the @p data buffer (in native endianness). 57 57 * @return Error code. … … 62 62 int usb_control_request_set(usb_pipe_t *pipe, 63 63 usb_request_type_t request_type, usb_request_recipient_t recipient, 64 uint8_t request, 65 uint16_t value, uint16_t index, 66 void *data, size_t data_size) 64 uint8_t request, uint16_t value, uint16_t index, 65 const void *data, size_t data_size) 67 66 { 68 67 if (pipe == NULL) { … … 83 82 */ 84 83 85 usb_device_request_setup_packet_t setup_packet; 86 setup_packet.request_type = (request_type << 5) | recipient; 87 setup_packet.request = request; 88 setup_packet.value = value; 89 setup_packet.index = index; 90 setup_packet.length = (uint16_t) data_size; 91 92 int rc = usb_pipe_control_write(pipe, 93 &setup_packet, sizeof(setup_packet), 94 data, data_size); 95 96 return rc; 84 const usb_device_request_setup_packet_t setup_packet = { 85 .request_type = (request_type << 5) | recipient, 86 .request = request, 87 .value = value, 88 .index = index, 89 .length = (uint16_t) data_size, 90 }; 91 92 return usb_pipe_control_write(pipe, 93 &setup_packet, sizeof(setup_packet), data, data_size); 97 94 } 98 95 … … 106 103 * @param request Actual request (e.g. GET_DESCRIPTOR). 107 104 * @param value Value of @c wValue field of setup packet 108 * 105 * (must be in USB endianness). 109 106 * @param index Value of @c wIndex field of setup packet 110 107 * (must be in USB endianness). … … 114 111 * (in native endianness). 115 112 * @param actual_data_size Actual size of transfered data 116 * 113 * (in native endianness). 117 114 * @return Error code. 118 115 * @retval EBADMEM @p pipe is NULL. … … 122 119 int usb_control_request_get(usb_pipe_t *pipe, 123 120 usb_request_type_t request_type, usb_request_recipient_t recipient, 124 uint8_t request, 125 uint16_t value, uint16_t index, 121 uint8_t request, uint16_t value, uint16_t index, 126 122 void *data, size_t data_size, size_t *actual_data_size) 127 123 { … … 207 203 { 208 204 if (request_type == USB_REQUEST_TYPE_STANDARD) { 209 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 210 && (index != 0)){205 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) 206 { 211 207 return EINVAL; 212 208 } 213 209 } 214 210 215 int rc = usb_control_request_set(pipe, request_type, recipient, 216 USB_DEVREQ_CLEAR_FEATURE, 217 uint16_host2usb(feature_selector), uint16_host2usb(index), 218 NULL, 0); 219 220 return rc; 211 return usb_control_request_set(pipe, 212 request_type, recipient, USB_DEVREQ_CLEAR_FEATURE, 213 uint16_host2usb(feature_selector), uint16_host2usb(index), NULL, 0); 221 214 } 222 215 … … 235 228 { 236 229 if (request_type == USB_REQUEST_TYPE_STANDARD) { 237 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 238 && (index != 0)){230 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) 231 { 239 232 return EINVAL; 240 233 } 241 234 } 242 235 243 int rc = usb_control_request_set(pipe, request_type, recipient, 244 USB_DEVREQ_SET_FEATURE, 245 uint16_host2usb(feature_selector), uint16_host2usb(index), 246 NULL, 0); 247 248 return rc; 236 return usb_control_request_set(pipe, 237 request_type, recipient, USB_DEVREQ_SET_FEATURE, 238 uint16_host2usb(feature_selector), uint16_host2usb(index), NULL, 0); 249 239 } 250 240 … … 314 304 * Get only first byte to retrieve descriptor length. 315 305 */ 316 uint8_t tmp_buffer [1];306 uint8_t tmp_buffer; 317 307 size_t bytes_transfered; 318 308 rc = usb_request_get_descriptor(pipe, request_type, recipient, 319 309 descriptor_type, descriptor_index, language, 320 &tmp_buffer, 1, &bytes_transfered);310 &tmp_buffer, sizeof(tmp_buffer), &bytes_transfered); 321 311 if (rc != EOK) { 322 312 return rc; 323 313 } 324 314 if (bytes_transfered != 1) { 325 /* FIXME: some better error code? */ 326 return ESTALL; 327 } 328 329 size_t size = tmp_buffer[0]; 315 return ELIMIT; 316 } 317 318 const size_t size = tmp_buffer; 330 319 if (size == 0) { 331 /* FIXME: some better error code? */ 332 return ESTALL; 320 return ELIMIT; 333 321 } 334 322 … … 350 338 if (bytes_transfered != size) { 351 339 free(buffer); 352 /* FIXME: some better error code? */ 353 return ESTALL; 340 return ELIMIT; 354 341 } 355 342 … … 379 366 int rc = usb_request_get_descriptor(pipe, 380 367 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 381 USB_DESCTYPE_DEVICE, 0, 0, 382 &descriptor_tmp, sizeof(descriptor_tmp), 368 USB_DESCTYPE_DEVICE, 0, 0, &descriptor_tmp, sizeof(descriptor_tmp), 383 369 &actually_transferred); 384 370 … … 422 408 size_t actually_transferred = 0; 423 409 usb_standard_configuration_descriptor_t descriptor_tmp; 424 int rc = usb_request_get_descriptor(pipe,410 const int rc = usb_request_get_descriptor(pipe, 425 411 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 426 412 USB_DESCTYPE_CONFIGURATION, index, 0, … … 547 533 usb_request_type_t request_type, usb_request_recipient_t recipient, 548 534 uint8_t descriptor_type, uint8_t descriptor_index, 549 uint16_t language, 550 void *buffer, size_t size) 535 uint16_t language, const void *buffer, size_t size) 551 536 { 552 537 if (buffer == NULL) { … … 561 546 562 547 return usb_control_request_set(pipe, 563 request_type, recipient, 564 USB_DEVREQ_SET_DESCRIPTOR, 565 wValue, language, 566 buffer, size); 548 request_type, recipient, USB_DEVREQ_SET_DESCRIPTOR, 549 wValue, language, buffer, size); 567 550 } 568 551 … … 579 562 size_t actual_size; 580 563 581 int rc = usb_control_request_get(pipe,564 const int rc = usb_control_request_get(pipe, 582 565 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 583 USB_DEVREQ_GET_CONFIGURATION, 584 0, 0, 585 &value, 1, &actual_size); 566 USB_DEVREQ_GET_CONFIGURATION, 0, 0, &value, 1, &actual_size); 586 567 587 568 if (rc != EOK) { … … 608 589 uint8_t configuration_value) 609 590 { 610 uint16_t config_value591 const uint16_t config_value 611 592 = uint16_host2usb((uint16_t) configuration_value); 612 593 … … 630 611 size_t actual_size; 631 612 632 int rc = usb_control_request_get(pipe,613 const int rc = usb_control_request_get(pipe, 633 614 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 634 615 USB_DEVREQ_GET_INTERFACE, 635 616 0, uint16_host2usb((uint16_t) interface_index), 636 &value, 1, &actual_size);617 &value, sizeof(value), &actual_size); 637 618 638 619 if (rc != EOK) { … … 679 660 l18_win_locales_t **languages_ptr, size_t *languages_count) 680 661 { 681 int rc; 682 683 if (languages_ptr == NULL) { 684 return EBADMEM; 685 } 686 if (languages_count == NULL) { 662 if (languages_ptr == NULL || languages_count == NULL) { 687 663 return EBADMEM; 688 664 } … … 690 666 uint8_t *string_descriptor = NULL; 691 667 size_t string_descriptor_size = 0; 692 rc = usb_request_get_descriptor_alloc(pipe,668 const int rc = usb_request_get_descriptor_alloc(pipe, 693 669 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 694 670 USB_DESCTYPE_STRING, 0, 0, … … 711 687 } 712 688 713 size_t langs_count = string_descriptor_size / 2;714 l18_win_locales_t *langs 715 = malloc(sizeof(l18_win_locales_t) * langs_count);689 const size_t langs_count = string_descriptor_size / 2; 690 l18_win_locales_t *langs = 691 calloc(langs_count, sizeof(l18_win_locales_t)); 716 692 if (langs == NULL) { 717 693 free(string_descriptor); … … 719 695 } 720 696 721 size_t i; 722 for (i = 0; i < langs_count; i++) { 697 for (size_t i = 0; i < langs_count; i++) { 723 698 /* Language code from the descriptor is in USB endianness. */ 724 699 /* FIXME: is this really correct? */ 725 uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8) 700 const uint16_t lang_code = 701 (string_descriptor[2 + 2 * i + 1] << 8) 726 702 + string_descriptor[2 + 2 * i]; 727 703 langs[i] = uint16_usb2host(lang_code); … … 762 738 } 763 739 /* Language is actually two byte value. */ 764 if (lang > 0xFFFF) {740 if (lang > L18N_WIN_LOCALE_MAX) { 765 741 return ERANGE; 766 742 } … … 796 772 } 797 773 798 size_t string_char_count = string_size / 2;774 const size_t string_char_count = string_size / 2; 799 775 string_chars = malloc(sizeof(wchar_t) * (string_char_count + 1)); 800 776 if (string_chars == NULL) { … … 808 784 * do not have them). 809 785 */ 810 size_t i; 811 for (i = 0; i < string_char_count; i++) { 812 uint16_t uni_char = (string[2 + 2 * i + 1] << 8) 786 for (size_t i = 0; i < string_char_count; i++) { 787 const uint16_t uni_char = (string[2 + 2 * i + 1] << 8) 813 788 + string[2 + 2 * i]; 814 789 string_chars[i] = uni_char; … … 828 803 829 804 leave: 830 if (string != NULL) { 831 free(string); 832 } 833 if (string_chars != NULL) { 834 free(string_chars); 835 } 805 free(string); 806 free(string_chars); 836 807 837 808 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.