Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/usbdrvreq.c

    r82783b0 r9b95dbcf  
    7373}
    7474
    75 /** Retrieve device descriptor of connected USB device.
    76  *
    77  * @param[in] phone Open phone to HC driver.
    78  * @param[in] address Device USB address.
    79  * @param[out] descriptor Storage for the device descriptor.
    80  * @return Error code.
    81  * @retval EBADMEM @p descriptor is NULL.
    82  */
    83 int usb_drv_req_get_device_descriptor(int phone, usb_address_t address,
    84     usb_standard_device_descriptor_t *descriptor)
    85 {
    86         if (descriptor == NULL) {
    87                 return EBADMEM;
    88         }
    89 
     75/** Retrieve USB descriptor of connected USB device.
     76 *
     77 * @param[in] hc_phone Open phone to HC driver.
     78 * @param[in] address Device USB address.
     79 * @param[in] request_type Request type (standard/class/vendor).
     80 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
     81 * @param[in] descriptor_index Descriptor index.
     82 * @param[in] langauge Language index.
     83 * @param[out] buffer Buffer where to store the retrieved descriptor.
     84 * @param[in] size Size of the @p buffer.
     85 * @param[out] actual_size Number of bytes actually transferred.
     86 * @return Error code.
     87 */
     88int usb_drv_req_get_descriptor(int hc_phone, usb_address_t address,
     89    usb_request_type_t request_type,
     90    uint8_t descriptor_type, uint8_t descriptor_index,
     91    uint16_t language,
     92    void *buffer, size_t size, size_t *actual_size)
     93{
    9094        /* Prepare the target. */
    9195        usb_target_t target = {
     
    96100        /* Prepare the setup packet. */
    97101        usb_device_request_setup_packet_t setup_packet = {
    98                 .request_type = 128,
     102                .request_type = 128 | (request_type << 5),
    99103                .request = USB_DEVREQ_GET_DESCRIPTOR,
    100                 .index = 0,
    101                 .length = sizeof(usb_standard_device_descriptor_t)
    102         };
    103         setup_packet.value_high = USB_DESCTYPE_DEVICE;
    104         setup_packet.value_low = 0;
    105 
    106         /* Prepare local descriptor. */
     104                .index = language,
     105                .length = (uint16_t) size,
     106        };
     107        setup_packet.value_high = descriptor_type;
     108        setup_packet.value_low = descriptor_index;
     109       
     110        /* Perform CONTROL READ */
     111        int rc = usb_drv_psync_control_read(hc_phone, target,
     112            &setup_packet, sizeof(setup_packet),
     113            buffer, size, actual_size);
     114       
     115        return rc;
     116}
     117
     118/** Retrieve device descriptor of connected USB device.
     119 *
     120 * @param[in] phone Open phone to HC driver.
     121 * @param[in] address Device USB address.
     122 * @param[out] descriptor Storage for the device descriptor.
     123 * @return Error code.
     124 * @retval EBADMEM @p descriptor is NULL.
     125 */
     126int usb_drv_req_get_device_descriptor(int phone, usb_address_t address,
     127    usb_standard_device_descriptor_t *descriptor)
     128{
     129        if (descriptor == NULL) {
     130                return EBADMEM;
     131        }
     132       
    107133        size_t actually_transferred = 0;
    108134        usb_standard_device_descriptor_t descriptor_tmp;
    109 
    110         /* Perform the control read transaction. */
    111         int rc = usb_drv_psync_control_read(phone, target,
    112             &setup_packet, sizeof(setup_packet),
    113             &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred);
     135        int rc = usb_drv_req_get_descriptor(phone, address,
     136            USB_REQUEST_TYPE_STANDARD,
     137            USB_DESCTYPE_DEVICE, 0,
     138            0,
     139            &descriptor_tmp, sizeof(descriptor_tmp),
     140            &actually_transferred);
    114141
    115142        if (rc != EOK) {
     
    150177                return EBADMEM;
    151178        }
    152 
    153         /* Prepare the target. */
    154         usb_target_t target = {
    155                 .address = address,
    156                 .endpoint = 0
    157         };
    158 
    159         /* Prepare the setup packet. */
    160         usb_device_request_setup_packet_t setup_packet = {
    161                 .request_type = 128,
    162                 .request = USB_DEVREQ_GET_DESCRIPTOR,
    163                 .index = 0,
    164                 .length = sizeof(usb_standard_configuration_descriptor_t)
    165         };
    166         setup_packet.value_high = USB_DESCTYPE_CONFIGURATION;
    167         setup_packet.value_low = index;
    168 
    169         /* Prepare local descriptor. */
     179       
    170180        size_t actually_transferred = 0;
    171181        usb_standard_configuration_descriptor_t descriptor_tmp;
    172 
    173         /* Perform the control read transaction. */
    174         int rc = usb_drv_psync_control_read(phone, target,
    175             &setup_packet, sizeof(setup_packet),
    176             &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred);
     182        int rc = usb_drv_req_get_descriptor(phone, address,
     183            USB_REQUEST_TYPE_STANDARD,
     184            USB_DESCTYPE_CONFIGURATION, 0,
     185            0,
     186            &descriptor_tmp, sizeof(descriptor_tmp),
     187            &actually_transferred);
    177188
    178189        if (rc != EOK) {
     
    214225        }
    215226
    216         /* Prepare the target. */
    217         usb_target_t target = {
    218                 .address = address,
    219                 .endpoint = 0
    220         };
    221 
    222         /* Prepare the setup packet. */
    223         usb_device_request_setup_packet_t setup_packet = {
    224                 .request_type = 128,
    225                 .request = USB_DEVREQ_GET_DESCRIPTOR,
    226                 .index = 0,
    227                 .length = buffer_size
    228         };
    229         setup_packet.value_high = USB_DESCTYPE_CONFIGURATION;
    230         setup_packet.value_low = index;
    231 
    232         /* Perform the control read transaction. */
    233         int rc = usb_drv_psync_control_read(phone, target,
    234             &setup_packet, sizeof(setup_packet),
    235             buffer, buffer_size, actual_buffer_size);
     227        int rc = usb_drv_req_get_descriptor(phone, address,
     228            USB_REQUEST_TYPE_STANDARD,
     229            USB_DESCTYPE_CONFIGURATION, 0,
     230            0,
     231            buffer, buffer_size,
     232            actual_buffer_size);
    236233
    237234        return rc;
Note: See TracChangeset for help on using the changeset viewer.