Ignore:
File:
1 edited

Legend:

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

    r9b95dbcf r82783b0  
    7373}
    7474
    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  */
    88 int 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 {
    94         /* Prepare the target. */
    95         usb_target_t target = {
    96                 .address = address,
    97                 .endpoint = 0
    98         };
    99 
    100         /* Prepare the setup packet. */
    101         usb_device_request_setup_packet_t setup_packet = {
    102                 .request_type = 128 | (request_type << 5),
    103                 .request = USB_DEVREQ_GET_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 
    11875/** Retrieve device descriptor of connected USB device.
    11976 *
     
    13087                return EBADMEM;
    13188        }
    132        
     89
     90        /* Prepare the target. */
     91        usb_target_t target = {
     92                .address = address,
     93                .endpoint = 0
     94        };
     95
     96        /* Prepare the setup packet. */
     97        usb_device_request_setup_packet_t setup_packet = {
     98                .request_type = 128,
     99                .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. */
    133107        size_t actually_transferred = 0;
    134108        usb_standard_device_descriptor_t descriptor_tmp;
    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);
     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);
    141114
    142115        if (rc != EOK) {
     
    177150                return EBADMEM;
    178151        }
    179        
     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. */
    180170        size_t actually_transferred = 0;
    181171        usb_standard_configuration_descriptor_t descriptor_tmp;
    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);
     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);
    188177
    189178        if (rc != EOK) {
     
    225214        }
    226215
    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);
     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);
    233236
    234237        return rc;
Note: See TracChangeset for help on using the changeset viewer.