Changeset 9445aad in mainline for uspace/drv/usbmid/explore.c


Ignore:
Timestamp:
2011-03-03T23:25:34Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3c775adb, 9a422574
Parents:
bdc8ab1 (diff), 8f74140c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Development branch changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmid/explore.c

    rbdc8ab1 r9445aad  
    4242#include "usbmid.h"
    4343
    44 /** Allocate and retrieve full configuration descriptor.
    45  *
    46  * @param[in] dev USB device.
    47  * @param[in] config_index Configuration index.
    48  * @param[out] size Pointer where to store size of the allocated buffer.
    49  * @return Allocated full configuration descriptor.
    50  * @retval NULL Error occured.
    51  */
    52 static void *get_configuration_descriptor(usbmid_device_t *dev,
    53     size_t config_index, size_t *size)
    54 {
    55         usb_standard_configuration_descriptor_t config_descriptor;
    56         int rc = usb_request_get_bare_configuration_descriptor(&dev->ctrl_pipe,
    57             config_index, &config_descriptor);
    58         if (rc != EOK) {
    59                 usb_log_error("Failed getting configuration descriptor: %s.\n",
    60                     str_error(rc));
    61                 return NULL;
    62         }
    63 
    64         void *full_config_descriptor = malloc(config_descriptor.total_length);
    65         if (full_config_descriptor == NULL) {
    66                 usb_log_fatal("Out of memory (wanted: %zuB).\n",
    67                     (size_t) config_descriptor.total_length);
    68                 return NULL;
    69         }
    70 
    71         size_t full_config_descriptor_size;
    72         rc = usb_request_get_full_configuration_descriptor(&dev->ctrl_pipe,
    73             config_index,
    74             full_config_descriptor, config_descriptor.total_length,
    75             &full_config_descriptor_size);
    76         if (rc != EOK) {
    77                 usb_log_error("Failed getting configuration descriptor: %s.\n",
    78                     str_error(rc));
    79                 free(full_config_descriptor);
    80                 return NULL;
    81         }
    82 
    83         if (full_config_descriptor_size != config_descriptor.total_length) {
    84                 usb_log_error("Failed getting full configuration descriptor.\n");
    85                 free(full_config_descriptor);
    86                 return NULL;
    87         }
    88 
    89         if (size != NULL) {
    90                 *size = full_config_descriptor_size;
    91         }
    92 
    93         return full_config_descriptor;
    94 }
    95 
    9644/** Find starting indexes of all interface descriptors in a configuration.
    9745 *
     
    178126
    179127        size_t config_descriptor_size;
    180         uint8_t *config_descriptor_raw = get_configuration_descriptor(dev, 0,
    181             &config_descriptor_size);
    182         if (config_descriptor_raw == NULL) {
     128        uint8_t *config_descriptor_raw = NULL;
     129        rc = usb_request_get_full_configuration_descriptor_alloc(
     130            &dev->ctrl_pipe, 0,
     131            (void **) &config_descriptor_raw, &config_descriptor_size);
     132        if (rc != EOK) {
     133                usb_log_error("Failed getting full config descriptor: %s.\n",
     134                    str_error(rc));
    183135                return false;
    184136        }
     
    207159        }
    208160
     161        /* Select the first configuration */
     162        rc = usb_request_set_configuration(&dev->ctrl_pipe,
     163            config_descriptor->configuration_number);
     164        if (rc != EOK) {
     165                usb_log_error("Failed to set device configuration: %s.\n",
     166                    str_error(rc));
     167                free(config_descriptor_raw);
     168                free(interface_descriptors);
     169                return false;
     170        }
     171
     172
     173        /* Create control function */
    209174        ddf_fun_t *ctl_fun = ddf_fun_create(dev->dev, fun_exposed, "ctl");
    210175        if (ctl_fun == NULL) {
     
    223188        }
    224189
     190        /* Spawn interface children */
    225191        size_t i;
    226192        for (i = 0; i < interface_descriptors_count; i++) {
Note: See TracChangeset for help on using the changeset viewer.