Ignore:
File:
1 edited

Legend:

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

    r2c5cefa reac610e  
    6767        setup_packet.value = new_address;
    6868
    69         int rc = usb_drv_psync_control_write(phone, target,
    70             &setup_packet, sizeof(setup_packet), NULL, 0);
     69        usb_handle_t handle;
     70        int rc;
    7171
    72         return rc;
     72        /* Start the control write transfer. */
     73        rc = usb_drv_async_control_write_setup(phone, target,
     74            &setup_packet, sizeof(setup_packet), &handle);
     75        if (rc != EOK) {
     76                return rc;
     77        }
     78        rc = usb_drv_async_wait_for(handle);
     79        if (rc != EOK) {
     80                return rc;
     81        }
     82
     83        /* Finish the control write transfer. */
     84        rc = usb_drv_async_control_write_status(phone, target, &handle);
     85        if (rc != EOK) {
     86                return rc;
     87        }
     88        rc = usb_drv_async_wait_for(handle);
     89        if (rc != EOK) {
     90                return rc;
     91        }
     92
     93        return EOK;
    7394}
    7495
     
    104125        setup_packet.value_low = 0;
    105126
    106         /* Prepare local descriptor. */
    107         size_t actually_transferred = 0;
    108         usb_standard_device_descriptor_t descriptor_tmp;
     127        usb_handle_t handle;
     128        int rc;
    109129
    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);
    114 
     130        /* Start the control read transfer. */
     131        rc = usb_drv_async_control_read_setup(phone, target,
     132            &setup_packet, sizeof(usb_device_request_setup_packet_t), &handle);
     133        if (rc != EOK) {
     134                return rc;
     135        }
     136        rc = usb_drv_async_wait_for(handle);
    115137        if (rc != EOK) {
    116138                return rc;
    117139        }
    118140
    119         /* Verify that all data has been transferred. */
    120         if (actually_transferred < sizeof(descriptor_tmp)) {
     141        /* Retrieve the descriptor. */
     142        size_t actually_transferred = 0;
     143        usb_standard_device_descriptor_t descriptor_tmp;
     144        rc = usb_drv_async_control_read_data(phone, target,
     145            &descriptor_tmp, sizeof(usb_standard_device_descriptor_t),
     146            &actually_transferred, &handle);
     147        if (rc != EOK) {
     148                return rc;
     149        }
     150        rc = usb_drv_async_wait_for(handle);
     151        if (rc != EOK) {
     152                return rc;
     153        }
     154
     155        /* Finish the control read transfer. */
     156        rc = usb_drv_async_control_read_status(phone, target, &handle);
     157        if (rc != EOK) {
     158                return rc;
     159        }
     160        rc = usb_drv_async_wait_for(handle);
     161        if (rc != EOK) {
     162                return rc;
     163        }
     164
     165        if (actually_transferred < sizeof(usb_standard_device_descriptor_t)) {
    121166                return ELIMIT;
    122167        }
    123168
    124         /* Everything is okay, copy the descriptor. */
     169        /*
     170         * Everything is okay, copy the descriptor.
     171         */
    125172        memcpy(descriptor, &descriptor_tmp,
    126             sizeof(descriptor_tmp));
     173            sizeof(usb_standard_device_descriptor_t));
    127174
    128175        return EOK;
     
    130177
    131178
    132 /** Retrieve configuration descriptor of connected USB device.
    133  *
    134  * The function does not retrieve additional data binded with configuration
    135  * descriptor (such as its interface and endpoint descriptors) - use
    136  * usb_drv_req_get_full_configuration_descriptor() instead.
    137  *
    138  * @param[in] phone Open phone to HC driver.
    139  * @param[in] address Device USB address.
    140  * @param[in] index Configuration descriptor index.
    141  * @param[out] descriptor Storage for the configuration descriptor.
    142  * @return Error code.
    143  * @retval EBADMEM @p descriptor is NULL.
    144  */
    145 int usb_drv_req_get_bare_configuration_descriptor(int phone,
    146     usb_address_t address, int index,
    147     usb_standard_configuration_descriptor_t *descriptor)
    148 {
    149         if (descriptor == NULL) {
    150                 return EBADMEM;
    151         }
    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_device_descriptor_t)
    165         };
    166         setup_packet.value_high = USB_DESCTYPE_CONFIGURATION;
    167         setup_packet.value_low = index;
    168 
    169         /* Prepare local descriptor. */
    170         size_t actually_transferred = 0;
    171         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);
    177 
    178         if (rc != EOK) {
    179                 return rc;
    180         }
    181 
    182         /* Verify that all data has been transferred. */
    183         if (actually_transferred < sizeof(descriptor_tmp)) {
    184                 return ELIMIT;
    185         }
    186 
    187         /* Everything is okay, copy the descriptor. */
    188         memcpy(descriptor, &descriptor_tmp,
    189             sizeof(descriptor_tmp));
    190 
    191         return EOK;
    192 }
    193 
    194 /** Retrieve full configuration descriptor of connected USB device.
    195  *
    196  * @warning The @p buffer might be touched (i.e. its contents changed)
    197  * even when error occurres.
    198  *
    199  * @param[in] phone Open phone to HC driver.
    200  * @param[in] address Device USB address.
    201  * @param[in] index Configuration descriptor index.
    202  * @param[out] buffer Buffer for the whole configuration descriptor.
    203  * @param[in] buffer_size Size of the prepared @p buffer.
    204  * @param[out] actual_buffer_size Bytes actually transfered.
    205  * @return Error code.
    206  * @retval EBADMEM @p descriptor is NULL.
    207  */
    208 int usb_drv_req_get_full_configuration_descriptor(int phone,
    209     usb_address_t address, int index,
    210     void *buffer, size_t buffer_size, size_t *actual_buffer_size)
    211 {
    212         if (buffer == NULL) {
    213                 return EBADMEM;
    214         }
    215 
    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 = sizeof(usb_standard_device_descriptor_t)
    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);
    236 
    237         return rc;
    238 }
    239 
    240179
    241180/**
Note: See TracChangeset for help on using the changeset viewer.