Changeset d70e0a3c in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-03-02T18:17:27Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a6567ed
Parents:
4723444
Message:

Allocating "get full config desc" put into action

Yes, all that removed code is now replaced with a single function.
And yes, it was the same in all drivers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    r4723444 rd70e0a3c  
    149149        }
    150150
    151         //configuration descriptor
    152         /// \TODO check other configurations?
    153         usb_standard_configuration_descriptor_t config_descriptor;
    154         opResult = usb_request_get_bare_configuration_descriptor(
     151        /* Retrieve full configuration descriptor. */
     152        uint8_t *descriptors = NULL;
     153        size_t descriptors_size = 0;
     154        opResult = usb_request_get_full_configuration_descriptor_alloc(
    155155            &hub->endpoints.control, 0,
    156         &config_descriptor);
    157         if(opResult!=EOK){
    158                 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult);
     156            (void **) &descriptors, &descriptors_size);
     157        if (opResult != EOK) {
     158                usb_log_error("Could not get configuration descriptor: %s.\n",
     159                    str_error(opResult));
    159160                return opResult;
    160161        }
    161         //set configuration
     162        usb_standard_configuration_descriptor_t *config_descriptor
     163            = (usb_standard_configuration_descriptor_t *) descriptors;
     164
     165        /* Set configuration. */
    162166        opResult = usb_request_set_configuration(&hub->endpoints.control,
    163                 config_descriptor.configuration_number);
    164 
    165         if (opResult != EOK) {
    166                 dprintf(USB_LOG_LEVEL_ERROR,
    167                                 "something went wrong when setting hub`s configuration, %d",
    168                                 opResult);
     167            config_descriptor->configuration_number);
     168
     169        if (opResult != EOK) {
     170                usb_log_error("Failed to set hub configuration: %s.\n",
     171                    str_error(opResult));
    169172                return opResult;
    170173        }
    171174        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",
    172                         config_descriptor.configuration_number);
    173 
    174         //full configuration descriptor
    175         size_t transferred = 0;
    176         uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length);
    177         if (descriptors == NULL) {
    178                 dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory");
    179                 return ENOMEM;
    180         }
    181         opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control,
    182             0, descriptors,
    183             config_descriptor.total_length, &transferred);
    184         if(opResult!=EOK){
    185                 free(descriptors);
    186                 dprintf(USB_LOG_LEVEL_ERROR,
    187                                 "could not get full configuration descriptor, %d",opResult);
    188                 return opResult;
    189         }
    190         if (transferred != config_descriptor.total_length) {
    191                 dprintf(USB_LOG_LEVEL_ERROR,
    192                                 "received incorrect full configuration descriptor");
    193                 return ELIMIT;
    194         }
     175                        config_descriptor->configuration_number);
    195176
    196177        usb_endpoint_mapping_t endpoint_mapping[1] = {
     
    204185        opResult = usb_endpoint_pipe_initialize_from_configuration(
    205186            endpoint_mapping, 1,
    206             descriptors, config_descriptor.total_length,
     187            descriptors, descriptors_size,
    207188            &hub->device_connection);
    208189        if (opResult != EOK) {
Note: See TracChangeset for help on using the changeset viewer.