Changes in uspace/lib/usb/src/request.c [bc1c6fb:9cf1c5a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/request.c
rbc1c6fb r9cf1c5a 157 157 } 158 158 159 /** Retrieve status of a USB device. 160 * 161 * @param[in] pipe Control endpoint pipe (session must be already started). 162 * @param[in] index Recipient index (in native endianness). 163 * @param[in] recipient Recipient of the GET_STATUS request. 164 * @param[out] status Recipient status (in native endianness). 165 * @return Error code. 166 */ 167 int usb_request_get_status(usb_endpoint_pipe_t *pipe, 168 usb_request_recipient_t recipient, uint16_t index, 169 uint16_t *status) 170 { 171 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) { 172 return EINVAL; 173 } 174 175 if (status == NULL) { 176 return EBADMEM; 177 } 178 179 uint16_t status_usb_endianess; 180 size_t data_transfered_size; 181 int rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD, 182 recipient, USB_DEVREQ_GET_STATUS, 0, uint16_host2usb(index), 183 &status_usb_endianess, 2, &data_transfered_size); 184 if (rc != EOK) { 185 return rc; 186 } 187 if (data_transfered_size != 2) { 188 return ELIMIT; 189 } 190 191 *status = uint16_usb2host(status_usb_endianess); 192 193 return EOK; 194 } 195 196 /** Clear or disable specific device feature. 197 * 198 * @param[in] pipe Control endpoint pipe (session must be already started). 199 * @param[in] request_type Request type (standard/class/vendor). 200 * @param[in] recipient Recipient of the CLEAR_FEATURE request. 201 * @param[in] feature_selector Feature selector (in native endianness). 202 * @param[in] index Recipient index (in native endianness). 203 * @return Error code. 204 */ 205 int usb_request_clear_feature(usb_endpoint_pipe_t *pipe, 206 usb_request_type_t request_type, usb_request_recipient_t recipient, 207 uint16_t feature_selector, uint16_t index) 208 { 209 if (request_type == USB_REQUEST_TYPE_STANDARD) { 210 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 211 && (index != 0)) { 212 return EINVAL; 213 } 214 } 215 216 int rc = usb_control_request_set(pipe, request_type, recipient, 217 USB_DEVREQ_CLEAR_FEATURE, 218 uint16_host2usb(feature_selector), uint16_host2usb(index), 219 NULL, 0); 220 221 return rc; 222 } 223 224 /** Set or enable specific device feature. 225 * 226 * @param[in] pipe Control endpoint pipe (session must be already started). 227 * @param[in] request_type Request type (standard/class/vendor). 228 * @param[in] recipient Recipient of the SET_FEATURE request. 229 * @param[in] feature_selector Feature selector (in native endianness). 230 * @param[in] index Recipient index (in native endianness). 231 * @return Error code. 232 */ 233 int usb_request_set_feature(usb_endpoint_pipe_t *pipe, 234 usb_request_type_t request_type, usb_request_recipient_t recipient, 235 uint16_t feature_selector, uint16_t index) 236 { 237 if (request_type == USB_REQUEST_TYPE_STANDARD) { 238 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 239 && (index != 0)) { 240 return EINVAL; 241 } 242 } 243 244 int rc = usb_control_request_set(pipe, request_type, recipient, 245 USB_DEVREQ_SET_FEATURE, 246 uint16_host2usb(feature_selector), uint16_host2usb(index), 247 NULL, 0); 248 249 return rc; 250 } 251 159 252 /** Change address of connected device. 160 253 * This function automatically updates the backing connection to point to … … 473 566 } 474 567 568 /** Update existing or add new USB descriptor to a USB device. 569 * 570 * @param[in] pipe Control endpoint pipe (session must be already started). 571 * @param[in] request_type Request type (standard/class/vendor). 572 * @param[in] recipient Request recipient (device/interface/endpoint). 573 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...). 574 * @param[in] descriptor_index Descriptor index. 575 * @param[in] language Language index (in native endianness). 576 * @param[in] buffer Buffer with the new descriptor (in USB endianness). 577 * @param[in] size Size of the @p buffer in bytes (in native endianness). 578 * @return Error code. 579 */ 580 int usb_request_set_descriptor(usb_endpoint_pipe_t *pipe, 581 usb_request_type_t request_type, usb_request_recipient_t recipient, 582 uint8_t descriptor_type, uint8_t descriptor_index, 583 uint16_t language, 584 void *buffer, size_t size) 585 { 586 if (buffer == NULL) { 587 return EBADMEM; 588 } 589 if (size == 0) { 590 return EINVAL; 591 } 592 593 /* FIXME: proper endianness. */ 594 uint16_t wValue = descriptor_index | (descriptor_type << 8); 595 596 return usb_control_request_set(pipe, 597 request_type, recipient, 598 USB_DEVREQ_SET_DESCRIPTOR, 599 wValue, language, 600 buffer, size); 601 } 602 603 /** Get current configuration value of USB device. 604 * 605 * @param[in] pipe Control endpoint pipe (session must be already started). 606 * @param[out] configuration_value Current configuration value. 607 * @return Error code. 608 */ 609 int usb_request_get_configuration(usb_endpoint_pipe_t *pipe, 610 uint8_t *configuration_value) 611 { 612 uint8_t value; 613 size_t actual_size; 614 615 int rc = usb_control_request_get(pipe, 616 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 617 USB_DEVREQ_GET_CONFIGURATION, 618 0, 0, 619 &value, 1, &actual_size); 620 621 if (rc != EOK) { 622 return rc; 623 } 624 if (actual_size != 1) { 625 return ELIMIT; 626 } 627 628 if (configuration_value != NULL) { 629 *configuration_value = value; 630 } 631 632 return EOK; 633 } 634 475 635 /** Set configuration of USB device. 476 636 * … … 488 648 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 489 649 USB_DEVREQ_SET_CONFIGURATION, config_value, 0, 650 NULL, 0); 651 } 652 653 /** Get selected alternate setting for USB interface. 654 * 655 * @param[in] pipe Control endpoint pipe (session must be already started). 656 * @param[in] interface_index Interface index. 657 * @param[out] alternate_setting Alternate setting for the interface. 658 * @return Error code. 659 */ 660 int usb_request_get_interface(usb_endpoint_pipe_t *pipe, 661 uint8_t interface_index, uint8_t *alternate_setting) 662 { 663 uint8_t value; 664 size_t actual_size; 665 666 int rc = usb_control_request_get(pipe, 667 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 668 USB_DEVREQ_GET_INTERFACE, 669 0, uint16_host2usb((uint16_t) interface_index), 670 &value, 1, &actual_size); 671 672 if (rc != EOK) { 673 return rc; 674 } 675 if (actual_size != 1) { 676 return ELIMIT; 677 } 678 679 if (alternate_setting != NULL) { 680 *alternate_setting = value; 681 } 682 683 return EOK; 684 } 685 686 /** Select alternate setting for USB interface. 687 * 688 * @param[in] pipe Control endpoint pipe (session must be already started). 689 * @param[in] interface_index Interface index. 690 * @param[in] alternate_setting Alternate setting to select. 691 * @return Error code. 692 */ 693 int usb_request_set_interface(usb_endpoint_pipe_t *pipe, 694 uint8_t interface_index, uint8_t alternate_setting) 695 { 696 return usb_control_request_set(pipe, 697 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 698 USB_DEVREQ_SET_INTERFACE, 699 uint16_host2usb((uint16_t) alternate_setting), 700 uint16_host2usb((uint16_t) interface_index), 490 701 NULL, 0); 491 702 }
Note:
See TracChangeset
for help on using the changeset viewer.