Changeset e2dfa86 in mainline


Ignore:
Timestamp:
2013-01-27T13:54:40Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eb2a0f
Parents:
06f9a9c9
Message:

usb_device: Change API to allow direct(RO) access to descriptors.

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/hid.c

    r06f9a9c9 re2dfa86  
    227227        };
    228228
    229         size_t desc_size = 0;
    230         const void *desc =
    231             usb_device_get_configuration_descriptor(usb_dev, &desc_size);
    232 
    233         usb_dp_walk_simple(desc, desc_size, usb_dp_standard_descriptor_nesting,
     229        usb_dp_walk_simple(
     230            usb_device_descriptors(usb_dev)->full_config,
     231            usb_device_descriptors(usb_dev)->full_config_size,
     232            usb_dp_standard_descriptor_nesting,
    234233            descriptor_walk_callback, &context);
    235234}
     
    243242        };
    244243
    245         size_t desc_size = 0;
    246         const void *desc =
    247             usb_device_get_configuration_descriptor(usb_dev, &desc_size);
    248 
    249         usb_dp_walk_simple(desc, desc_size, usb_dp_standard_descriptor_nesting,
     244        usb_dp_walk_simple(
     245            usb_device_descriptors(usb_dev)->full_config,
     246            usb_device_descriptors(usb_dev)->full_config_size,
     247            usb_dp_standard_descriptor_nesting,
    250248            descriptor_walk_callback, &context);
    251249}
  • uspace/app/usbinfo/info.c

    r06f9a9c9 re2dfa86  
    4848{
    4949        printf("%sDevice 0x%04x by vendor 0x%04x\n", get_indent(0),
    50             (int) usb_device_get_device_descriptor(usb_dev)->product_id,
    51             (int) usb_device_get_device_descriptor(usb_dev)->vendor_id);
     50            usb_device_descriptors(usb_dev)->device.product_id,
     51            usb_device_descriptors(usb_dev)->device.vendor_id);
    5252}
    5353
     
    8383        init_match_ids(&matches);
    8484        usb_device_create_match_ids_from_interface(
    85             usb_device_get_device_descriptor(usb_dev), iface, &matches);
     85            &usb_device_descriptors(usb_dev)->device, iface, &matches);
    8686        dump_match_ids(&matches, get_indent(1));
    8787        clean_match_ids(&matches);
     
    9292        match_id_list_t matches;
    9393        init_match_ids(&matches);
    94         const usb_standard_device_descriptor_t *dev_desc =
    95             usb_device_get_device_descriptor(usb_dev);
    96         usb_device_create_match_ids_from_device_descriptor(dev_desc, &matches);
     94        usb_device_create_match_ids_from_device_descriptor(
     95                &usb_device_descriptors(usb_dev)->device, &matches);
    9796        printf("%sDevice match ids (0x%04x by 0x%04x, %s)\n", get_indent(0),
    98             (int) dev_desc->product_id, (int) dev_desc->vendor_id,
    99             usb_str_class(dev_desc->device_class));
     97            usb_device_descriptors(usb_dev)->device.product_id,
     98            usb_device_descriptors(usb_dev)->device.vendor_id,
     99            usb_str_class(usb_device_descriptors(usb_dev)->device.device_class));
    100100        dump_match_ids(&matches, get_indent(1));
    101101        clean_match_ids(&matches);
    102102
    103         size_t desc_size = 0;
    104         const void *desc =
    105             usb_device_get_configuration_descriptor(usb_dev, &desc_size);
    106 
    107         usb_dp_walk_simple(desc, desc_size, usb_dp_standard_descriptor_nesting,
     103        usb_dp_walk_simple(
     104            usb_device_descriptors(usb_dev)->full_config,
     105            usb_device_descriptors(usb_dev)->full_config_size,
     106            usb_dp_standard_descriptor_nesting,
    108107            dump_match_ids_from_interface, usb_dev);
    109108}
     
    230229{
    231230        dump_descriptor_tree_callback(
    232             (const uint8_t *)usb_device_get_device_descriptor(usb_dev),
     231            (const uint8_t *)&usb_device_descriptors(usb_dev)->device,
    233232            (size_t) -1, NULL);
    234233
    235         size_t desc_size = 0;
    236         const void *desc =
    237             usb_device_get_configuration_descriptor(usb_dev, &desc_size);
    238 
    239         usb_dp_walk_simple(desc, desc_size, usb_dp_standard_descriptor_nesting,
     234        usb_dp_walk_simple(
     235            usb_device_descriptors(usb_dev)->full_config,
     236            usb_device_descriptors(usb_dev)->full_config_size,
     237            usb_dp_standard_descriptor_nesting,
    240238            dump_descriptor_tree_callback, NULL);
    241239}
     
    244242{
    245243        dump_descriptor_tree_callback(
    246             (const uint8_t *)usb_device_get_device_descriptor(usb_dev),
     244            (const uint8_t *)&usb_device_descriptors(usb_dev)->device,
    247245            (size_t) -1, usb_dev);
    248246
    249         size_t desc_size = 0;
    250         const void *desc =
    251             usb_device_get_configuration_descriptor(usb_dev, &desc_size);
    252 
    253         usb_dp_walk_simple(desc, desc_size, usb_dp_standard_descriptor_nesting,
     247        usb_dp_walk_simple(
     248            usb_device_descriptors(usb_dev)->full_config,
     249            usb_device_descriptors(usb_dev)->full_config_size,
     250            usb_dp_standard_descriptor_nesting,
    254251            dump_descriptor_tree_callback, usb_dev);
    255252}
     
    299296        uint64_t str_mask = 0;
    300297        find_string_indexes_callback(
    301             (const uint8_t *)usb_device_get_device_descriptor(usb_dev), 0,
     298            (const uint8_t *)&usb_device_descriptors(usb_dev)->device, 0,
    302299            &str_mask);
    303         size_t desc_size = 0;
    304         const void *desc =
    305             usb_device_get_configuration_descriptor(usb_dev, &desc_size);
    306 
    307         usb_dp_walk_simple(desc, desc_size, usb_dp_standard_descriptor_nesting,
     300
     301        usb_dp_walk_simple(
     302            usb_device_descriptors(usb_dev)->full_config,
     303            usb_device_descriptors(usb_dev)->full_config_size,
     304            usb_dp_standard_descriptor_nesting,
    308305            find_string_indexes_callback, &str_mask);
    309306
  • uspace/drv/bus/usb/usbhid/usbhid.c

    r06f9a9c9 re2dfa86  
    120120        assert(mapping);
    121121        const usb_standard_device_descriptor_t *d =
    122             usb_device_get_device_descriptor(hid_dev->usb_dev);
     122            &usb_device_descriptors(hid_dev->usb_dev)->device;
    123123
    124124        return (d->vendor_id == mapping->vendor_id)
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r06f9a9c9 re2dfa86  
    359359        /* Get number of possible configurations from device descriptor */
    360360        const size_t configuration_count =
    361             usb_device_get_device_descriptor(usb_device)->configuration_count;
     361            usb_device_descriptors(usb_device)->device.configuration_count;
    362362        usb_log_debug("Hub has %zu configurations.\n", configuration_count);
    363363
     
    368368
    369369        // TODO: Make sure that the cast is correct
    370         size_t config_size = 0;
     370        const size_t config_size =
     371            usb_device_descriptors(usb_device)->full_config_size;
    371372        const usb_standard_configuration_descriptor_t *config_descriptor =
    372             usb_device_get_configuration_descriptor(usb_device, &config_size);
     373            usb_device_descriptors(usb_device)->full_config;
    373374
    374375        if (config_size < sizeof(usb_standard_configuration_descriptor_t)) {
     
    377378            return EOVERFLOW;
    378379        }
    379 
    380380
    381381        /* Set configuration. Use the configuration that was in
  • uspace/drv/bus/usb/usbmid/explore.c

    r06f9a9c9 re2dfa86  
    118118                usbmid_interface_t *iface = NULL;
    119119                const int rc = usbmid_spawn_interface_child(usb_dev, &iface,
    120                         usb_device_get_device_descriptor(usb_dev), interface);
     120                        &usb_device_descriptors(usb_dev)->device, interface);
    121121                if (rc != EOK) {
    122122                        //TODO: Do something about that failure.
     
    142142int usbmid_explore_device(usb_device_t *dev)
    143143{
     144        assert(dev);
    144145        const unsigned dev_class =
    145             usb_device_get_device_descriptor(dev)->device_class;
     146            usb_device_descriptors(dev)->device.device_class;
    146147        if (dev_class != USB_CLASS_USE_INTERFACE) {
    147148                usb_log_warning(
     
    154155
    155156        /* Get coonfiguration descriptor. */
    156         size_t config_descriptor_size = 0;
     157        const size_t config_descriptor_size =
     158            usb_device_descriptors(dev)->full_config_size;
    157159        const void *config_descriptor_raw =
    158             usb_device_get_configuration_descriptor(dev,
    159             &config_descriptor_size);
     160            usb_device_descriptors(dev)->full_config;
    160161        const usb_standard_configuration_descriptor_t *config_descriptor =
    161162            config_descriptor_raw;
  • uspace/lib/usbdev/include/usb/dev/device.h

    r06f9a9c9 re2dfa86  
    4141#include <usb/dev/pipes.h>
    4242
     43/** Some useful descriptors for USB device. */
     44typedef struct {
     45        /** Standard device descriptor. */
     46        usb_standard_device_descriptor_t device;
     47        /** Full configuration descriptor of current configuration. */
     48        const void *full_config;
     49        size_t full_config_size;
     50} usb_device_descriptors_t;
     51
    4352typedef struct usb_device usb_device_t;
    4453
     
    7079int usb_device_get_iface_number(usb_device_t *);
    7180
    72 const usb_standard_device_descriptor_t *
    73 usb_device_get_device_descriptor(usb_device_t *);
    74 const void * usb_device_get_configuration_descriptor(usb_device_t *, size_t *);
     81const usb_device_descriptors_t * usb_device_descriptors(usb_device_t *);
     82
    7583const usb_alternate_interfaces_t * usb_device_get_alternative_ifaces(
    7684    usb_device_t *);
  • uspace/lib/usbdev/src/devdrv.c

    r06f9a9c9 re2dfa86  
    6868        /** Alternative interfaces. */
    6969        usb_alternate_interfaces_t alternate_interfaces;
    70 
    7170        /** Some useful descriptors for USB device. */
    72         struct {
    73                 /** Standard device descriptor. */
    74                 usb_standard_device_descriptor_t device;
    75                 /** Full configuration descriptor of current configuration. */
    76                 const uint8_t *configuration;
    77                 size_t configuration_size;
    78         } descriptors;
    79 
     71        usb_device_descriptors_t descriptors;
    8072        /** Generic DDF device backing this one. DO NOT TOUCH! */
    8173        ddf_dev_t *ddf_dev;
     
    160152{
    161153        assert(usb_dev);
    162         assert(usb_dev->descriptors.configuration == NULL);
     154        assert(usb_dev->descriptors.full_config == NULL);
    163155
    164156        /* It is worth to start a long transfer. */
     
    175167        rc = usb_request_get_full_configuration_descriptor_alloc(
    176168            &usb_dev->ctrl_pipe, 0,
    177             (void **) &usb_dev->descriptors.configuration,
    178             &usb_dev->descriptors.configuration_size);
     169            (void**)&usb_dev->descriptors.full_config,
     170            &usb_dev->descriptors.full_config_size);
    179171
    180172leave:
     
    191183{
    192184        assert(usb_dev);
    193         free(usb_dev->descriptors.configuration);
    194         usb_dev->descriptors.configuration = NULL;
    195         usb_dev->descriptors.configuration_size = 0;
     185        free(usb_dev->descriptors.full_config);
     186        usb_dev->descriptors.full_config = NULL;
     187        usb_dev->descriptors.full_config_size = 0;
    196188}
    197189
     
    219211{
    220212        assert(usb_dev);
    221         assert(usb_dev->descriptors.configuration);
     213        assert(usb_dev->descriptors.full_config);
    222214        assert(usb_dev->pipes == NULL);
    223215        assert(usb_dev->pipes_count == 0);
     
    244236        /* Find the mapping from configuration descriptor. */
    245237        int rc = usb_pipe_initialize_from_configuration(pipes, pipe_count,
    246             usb_dev->descriptors.configuration,
    247             usb_dev->descriptors.configuration_size, &usb_dev->wire);
     238            usb_dev->descriptors.full_config,
     239            usb_dev->descriptors.full_config_size, &usb_dev->wire);
    248240        if (rc != EOK) {
    249241                free(pipes);
     
    338330}
    339331
    340 const usb_standard_device_descriptor_t *
    341 usb_device_get_device_descriptor(usb_device_t *usb_dev)
    342 {
    343         assert(usb_dev);
    344         return &usb_dev->descriptors.device;
    345 }
    346 
    347 const void * usb_device_get_configuration_descriptor(
    348     usb_device_t *usb_dev, size_t *size)
    349 {
    350         assert(usb_dev);
    351         if (size)
    352                 *size = usb_dev->descriptors.configuration_size;
    353         return usb_dev->descriptors.configuration;
     332const usb_device_descriptors_t *usb_device_descriptors(usb_device_t *usb_dev)
     333{
     334        assert(usb_dev);
     335        return &usb_dev->descriptors;
    354336}
    355337
     
    430412        usb_dev->ddf_dev = ddf_dev;
    431413        usb_dev->driver_data = NULL;
    432         usb_dev->descriptors.configuration = NULL;
     414        usb_dev->descriptors.full_config = NULL;
     415        usb_dev->descriptors.full_config_size = 0;
    433416        usb_dev->pipes_count = 0;
    434417        usb_dev->pipes = NULL;
     
    500483         * controlling a device. */
    501484        rc = usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
    502             usb_dev->descriptors.configuration,
    503             usb_dev->descriptors.configuration_size, usb_dev->interface_no);
     485            usb_dev->descriptors.full_config,
     486            usb_dev->descriptors.full_config_size, usb_dev->interface_no);
    504487
    505488        if (endpoints) {
  • uspace/lib/usbhid/src/hidreport.c

    r06f9a9c9 re2dfa86  
    6060        };
    6161       
    62         size_t desc_size = 0;
    63         const void *desc =
    64             usb_device_get_configuration_descriptor(dev, &desc_size);
    65 
    6662        usb_dp_parser_data_t parser_data = {
    67                 .data = desc,
    68                 .size = desc_size,
     63                .data = usb_device_descriptors(dev)->full_config,
     64                .size = usb_device_descriptors(dev)->full_config_size,
    6965                .arg = NULL
    7066        };
     
    7470         */
    7571        const uint8_t *d =
    76             usb_dp_get_nested_descriptor(&parser, &parser_data, desc);
     72            usb_dp_get_nested_descriptor(&parser, &parser_data,
     73                usb_device_descriptors(dev)->full_config);
    7774       
    7875        /*
     
    8279        while (d != NULL && i < usb_device_get_iface_number(dev)) {
    8380                d = usb_dp_get_sibling_descriptor(&parser, &parser_data,
    84                     desc, d);
     81                    usb_device_descriptors(dev)->full_config, d);
    8582                ++i;
    8683        }
Note: See TracChangeset for help on using the changeset viewer.