Changeset 945d66c in mainline


Ignore:
Timestamp:
2013-01-25T22:55:22Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e79a2f
Parents:
c39e9fb
Message:

libusbdev: Don't use the descriptor field directly.

Make descriptor handling functions static.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/usbhid.c

    rc39e9fb r945d66c  
    114114    const usb_hid_subdriver_mapping_t *mapping)
    115115{
    116         assert(hid_dev != NULL);
    117         assert(hid_dev->usb_dev != NULL);
    118 
    119         return (hid_dev->usb_dev->descriptors.device.vendor_id
    120             == mapping->vendor_id
    121             && hid_dev->usb_dev->descriptors.device.product_id
    122             == mapping->product_id);
     116        assert(hid_dev);
     117        assert(hid_dev->usb_dev);
     118        assert(mapping);
     119        const usb_standard_device_descriptor_t *d =
     120            usb_device_get_device_descriptor(hid_dev->usb_dev);
     121
     122        return (d->vendor_id == mapping->vendor_id)
     123            && (d->product_id == mapping->product_id);
    123124}
    124125
  • uspace/drv/bus/usb/usbmid/explore.c

    rc39e9fb r945d66c  
    118118                usbmid_interface_t *iface = NULL;
    119119                const int rc = usbmid_spawn_interface_child(usb_dev, &iface,
    120                     &usb_dev->descriptors.device, interface);
     120                        usb_device_get_device_descriptor(usb_dev), interface);
    121121                if (rc != EOK) {
    122122                        //TODO: Do something about that failure.
     
    142142int usbmid_explore_device(usb_device_t *dev)
    143143{
    144         const unsigned dev_class = dev->descriptors.device.device_class;
     144        const unsigned dev_class =
     145            usb_device_get_device_descriptor(dev)->device_class;
    145146        if (dev_class != USB_CLASS_USE_INTERFACE) {
    146147                usb_log_warning(
     
    152153        }
    153154
    154         /* Shortcuts to save on typing ;-). */
    155         const void *config_descriptor_raw = dev->descriptors.configuration;
    156         size_t config_descriptor_size = dev->descriptors.configuration_size;
     155        /* Get coonfiguration descriptor. */
     156        size_t config_descriptor_size = 0;
     157        const void *config_descriptor_raw =
     158            usb_device_get_configuration_descriptor(dev,
     159            &config_descriptor_size);
    157160        const usb_standard_configuration_descriptor_t *config_descriptor =
    158161            config_descriptor_raw;
  • uspace/lib/usbdev/include/usb/dev/driver.h

    rc39e9fb r945d66c  
    4242#include <usb_iface.h>
    4343
    44 /** Descriptors for USB device. */
    45 typedef struct {
    46         /** Standard device descriptor. */
    47         usb_standard_device_descriptor_t device;
    48         /** Full configuration descriptor of current configuration. */
    49         const uint8_t *configuration;
    50         size_t configuration_size;
    51 } usb_device_descriptors_t;
    5244
    5345/** Wrapper for data related to alternate interface setting.
     
    8476        /** The default control pipe. */
    8577        usb_pipe_t ctrl_pipe;
     78
    8679        /** Other endpoint pipes.
    8780         * This is an array of other endpoint pipes in the same order as
     
    10093        usb_alternate_interfaces_t alternate_interfaces;
    10194
    102         /** Some useful descriptors. */
    103         usb_device_descriptors_t descriptors;
     95        /** Some useful descriptors for USB device. */
     96        struct {
     97                /** Standard device descriptor. */
     98                usb_standard_device_descriptor_t device;
     99                /** Full configuration descriptor of current configuration. */
     100                const uint8_t *configuration;
     101                size_t configuration_size;
     102        } descriptors;
    104103
    105104        /** Generic DDF device backing this one. DO NOT TOUCH! */
     
    179178    const usb_endpoint_description_t **);
    180179
    181 int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
    182 void usb_device_release_descriptors(usb_device_descriptors_t *);
    183 
    184180int usb_device_create_pipes(usb_device_connection_t *,
    185181    const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
     
    188184usb_pipe_t *usb_device_get_default_pipe(usb_device_t *);
    189185usb_pipe_t *usb_device_get_pipe(usb_device_t *, usb_endpoint_t, usb_direction_t);
     186
     187const usb_standard_device_descriptor_t *
     188usb_device_get_device_descriptor(usb_device_t *);
     189const void * usb_device_get_configuration_descriptor(usb_device_t *, size_t *);
     190
    190191
    191192void * usb_device_data_alloc(usb_device_t *, size_t);
  • uspace/lib/usbdev/src/devdrv.c

    rc39e9fb r945d66c  
    233233 * @return Error code.
    234234 */
    235 int usb_device_retrieve_descriptors(usb_pipe_t *ctrl_pipe,
    236     usb_device_descriptors_t *descriptors)
    237 {
    238         assert(descriptors != NULL);
    239 
    240         descriptors->configuration = NULL;
    241 
    242         int rc;
     235static int usb_device_retrieve_descriptors(usb_device_t *usb_dev)
     236{
     237        assert(usb_dev);
     238        assert(usb_dev->descriptors.configuration == NULL);
    243239
    244240        /* It is worth to start a long transfer. */
    245         usb_pipe_start_long_transfer(ctrl_pipe);
     241        usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
    246242
    247243        /* Get the device descriptor. */
    248         rc = usb_request_get_device_descriptor(ctrl_pipe, &descriptors->device);
     244        int rc = usb_request_get_device_descriptor(&usb_dev->ctrl_pipe,
     245            &usb_dev->descriptors.device);
    249246        if (rc != EOK) {
    250247                goto leave;
     
    253250        /* Get the full configuration descriptor. */
    254251        rc = usb_request_get_full_configuration_descriptor_alloc(
    255             ctrl_pipe, 0, (void **) &descriptors->configuration,
    256             &descriptors->configuration_size);
     252            &usb_dev->ctrl_pipe, 0,
     253            (void **) &usb_dev->descriptors.configuration,
     254            &usb_dev->descriptors.configuration_size);
    257255
    258256leave:
    259         usb_pipe_end_long_transfer(ctrl_pipe);
     257        usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
    260258
    261259        return rc;
     
    266264 * @param[in] descriptors Where to store the descriptors.
    267265 */
    268 void usb_device_release_descriptors(usb_device_descriptors_t *descriptors)
    269 {
    270         assert(descriptors);
    271         free(descriptors->configuration);
    272         descriptors->configuration = NULL;
     266static void usb_device_release_descriptors(usb_device_t *usb_dev)
     267{
     268        assert(usb_dev);
     269        free(usb_dev->descriptors.configuration);
     270        usb_dev->descriptors.configuration = NULL;
     271        usb_dev->descriptors.configuration_size = 0;
    273272}
    274273
     
    394393}
    395394
     395const usb_standard_device_descriptor_t *
     396usb_device_get_device_descriptor(usb_device_t *usb_dev)
     397{
     398        assert(usb_dev);
     399        return &usb_dev->descriptors.device;
     400}
     401
     402const void * usb_device_get_configuration_descriptor(
     403    usb_device_t *usb_dev, size_t *size)
     404{
     405        assert(usb_dev);
     406        if (size)
     407                *size = usb_dev->descriptors.configuration_size;
     408        return usb_dev->descriptors.configuration;
     409}
     410
    396411/** Initialize new instance of USB device.
    397412 *
     
    462477
    463478        /* Retrieve standard descriptors. */
    464         rc = usb_device_retrieve_descriptors(
    465             &usb_dev->ctrl_pipe, &usb_dev->descriptors);
     479        rc = usb_device_retrieve_descriptors(usb_dev);
    466480        if (rc != EOK) {
    467481                *errstr_ptr = "descriptor retrieval";
     
    489503                usb_hc_connection_close(&usb_dev->hc_conn);
    490504                /* Full configuration descriptor is allocated. */
    491                 usb_device_release_descriptors(&usb_dev->descriptors);
     505                usb_device_release_descriptors(usb_dev);
    492506                /* Alternate interfaces may be allocated */
    493507                usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces);
     
    515529                usb_hc_connection_deinitialize(&dev->hc_conn);
    516530                usb_alternate_interfaces_deinit(&dev->alternate_interfaces);
    517                 usb_device_release_descriptors(&dev->descriptors);
     531                usb_device_release_descriptors(dev);
    518532                free(dev->driver_data);
    519533                dev->driver_data = NULL;
Note: See TracChangeset for help on using the changeset viewer.