Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 06f9a9c9 in mainline


Ignore:
Timestamp:
2013-01-27T13:17:49Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
e2dfa86
Parents:
5b401b9
Message:

usbinfo: Switch to library provided usb_device_t.

Location:
uspace/app/usbinfo
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/Makefile

    r5b401b9 r06f9a9c9  
    4343SOURCES = \
    4444        desctree.c \
    45         dev.c \
    4645        dump.c \
    4746        hid.c \
  • uspace/app/usbinfo/hid.c

    r5b401b9 r06f9a9c9  
    3636#include <stdio.h>
    3737#include <str_error.h>
     38#include <usb/debug.h>
    3839#include <usb/classes/classes.h>
    3940#include <usb/dev/request.h>
     
    5051
    5152typedef struct {
    52         usbinfo_device_t *dev;
     53        usb_device_t *usb_dev;
    5354        hid_dump_type_t dump_type;
    5455        usb_standard_interface_descriptor_t *last_iface;
     
    213214
    214215        retrieve_and_dump_hid_report(context->dump_type,
    215             &context->dev->ctrl_pipe, context->last_iface->interface_number,
    216             report_size);
    217 }
    218 
    219 
    220 void dump_hidreport_raw(usbinfo_device_t *dev)
     216            usb_device_get_default_pipe(context->usb_dev),
     217            context->last_iface->interface_number, report_size);
     218}
     219
     220
     221void dump_hidreport_raw(usb_device_t *usb_dev)
    221222{
    222223        descriptor_walk_context_t context = {
    223                 .dev = dev,
     224                .usb_dev = usb_dev,
    224225                .dump_type = HID_DUMP_RAW,
    225226                .last_iface = NULL
    226227        };
    227228
    228         usb_dp_walk_simple(dev->full_configuration_descriptor,
    229             dev->full_configuration_descriptor_size,
    230             usb_dp_standard_descriptor_nesting,
     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,
    231234            descriptor_walk_callback, &context);
    232235}
    233236
    234 void dump_hidreport_usages(usbinfo_device_t *dev)
     237void dump_hidreport_usages(usb_device_t *usb_dev)
    235238{
    236239        descriptor_walk_context_t context = {
    237                 .dev = dev,
     240                .usb_dev = usb_dev,
    238241                .dump_type = HID_DUMP_USAGES,
    239242                .last_iface = NULL
    240243        };
    241244
    242         usb_dp_walk_simple(dev->full_configuration_descriptor,
    243             dev->full_configuration_descriptor_size,
    244             usb_dp_standard_descriptor_nesting,
     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,
    245250            descriptor_walk_callback, &context);
    246251}
  • uspace/app/usbinfo/info.c

    r5b401b9 r06f9a9c9  
    3737#include <str_error.h>
    3838#include <errno.h>
     39#include <usb/debug.h>
    3940#include <usb/dev/pipes.h>
    4041#include <usb/dev/recognise.h>
     
    4445#include "usbinfo.h"
    4546
    46 void dump_short_device_identification(usbinfo_device_t *dev)
     47void dump_short_device_identification(usb_device_t *usb_dev)
    4748{
    4849        printf("%sDevice 0x%04x by vendor 0x%04x\n", get_indent(0),
    49             (int) dev->device_descriptor.product_id,
    50             (int) dev->device_descriptor.vendor_id);
     50            (int) usb_device_get_device_descriptor(usb_dev)->product_id,
     51            (int) usb_device_get_device_descriptor(usb_dev)->vendor_id);
    5152}
    5253
     
    6667        }
    6768
    68         usbinfo_device_t *dev = (usbinfo_device_t *) arg;
     69        usb_device_t *usb_dev = arg;
     70        assert(usb_dev);
    6971
    7072        usb_standard_interface_descriptor_t *iface
     
    8082        match_id_list_t matches;
    8183        init_match_ids(&matches);
    82         usb_device_create_match_ids_from_interface(&dev->device_descriptor,
    83             iface, &matches);
     84        usb_device_create_match_ids_from_interface(
     85            usb_device_get_device_descriptor(usb_dev), iface, &matches);
    8486        dump_match_ids(&matches, get_indent(1));
    8587        clean_match_ids(&matches);
    8688}
    8789
    88 void dump_device_match_ids(usbinfo_device_t *dev)
     90void dump_device_match_ids(usb_device_t *usb_dev)
    8991{
    9092        match_id_list_t matches;
    9193        init_match_ids(&matches);
    92         usb_device_create_match_ids_from_device_descriptor(
    93             &dev->device_descriptor, &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);
    9497        printf("%sDevice match ids (0x%04x by 0x%04x, %s)\n", get_indent(0),
    95             (int) dev->device_descriptor.product_id,
    96             (int) dev->device_descriptor.vendor_id,
    97             usb_str_class(dev->device_descriptor.device_class));
     98            (int) dev_desc->product_id, (int) dev_desc->vendor_id,
     99            usb_str_class(dev_desc->device_class));
    98100        dump_match_ids(&matches, get_indent(1));
    99101        clean_match_ids(&matches);
    100102
    101         usb_dp_walk_simple(dev->full_configuration_descriptor,
    102             dev->full_configuration_descriptor_size,
    103             usb_dp_standard_descriptor_nesting,
    104             dump_match_ids_from_interface,
    105             dev);
     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,
     108            dump_match_ids_from_interface, usb_dev);
    106109}
    107110
     
    224227}
    225228
    226 void dump_descriptor_tree_brief(usbinfo_device_t *dev)
    227 {
    228         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
     229void dump_descriptor_tree_brief(usb_device_t *usb_dev)
     230{
     231        dump_descriptor_tree_callback(
     232            (const uint8_t *)usb_device_get_device_descriptor(usb_dev),
    229233            (size_t) -1, NULL);
    230         usb_dp_walk_simple(dev->full_configuration_descriptor,
    231             dev->full_configuration_descriptor_size,
    232             usb_dp_standard_descriptor_nesting,
    233             dump_descriptor_tree_callback,
    234             NULL);
    235 }
    236 
    237 void dump_descriptor_tree_full(usbinfo_device_t *dev)
    238 {
    239         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
    240             (size_t) -1, dev);
    241         usb_dp_walk_simple(dev->full_configuration_descriptor,
    242             dev->full_configuration_descriptor_size,
    243             usb_dp_standard_descriptor_nesting,
    244             dump_descriptor_tree_callback,
    245             dev);
     234
     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,
     240            dump_descriptor_tree_callback, NULL);
     241}
     242
     243void dump_descriptor_tree_full(usb_device_t *usb_dev)
     244{
     245        dump_descriptor_tree_callback(
     246            (const uint8_t *)usb_device_get_device_descriptor(usb_dev),
     247            (size_t) -1, usb_dev);
     248
     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,
     254            dump_descriptor_tree_callback, usb_dev);
    246255}
    247256
     
    285294
    286295
    287 void dump_strings(usbinfo_device_t *dev)
     296void dump_strings(usb_device_t *usb_dev)
    288297{
    289298        /* Find used indexes. Devices with more than 64 strings are very rare.*/
    290299        uint64_t str_mask = 0;
    291         find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,
     300        find_string_indexes_callback(
     301            (const uint8_t *)usb_device_get_device_descriptor(usb_dev), 0,
    292302            &str_mask);
    293         usb_dp_walk_simple(dev->full_configuration_descriptor,
    294             dev->full_configuration_descriptor_size,
    295             usb_dp_standard_descriptor_nesting,
    296             find_string_indexes_callback,
    297             &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,
     308            find_string_indexes_callback, &str_mask);
    298309
    299310        if (str_mask == 0) {
     
    305316        l18_win_locales_t *langs;
    306317        size_t langs_count;
    307         int rc = usb_request_get_supported_languages(&dev->ctrl_pipe,
    308             &langs, &langs_count);
     318        int rc = usb_request_get_supported_languages(
     319            usb_device_get_default_pipe(usb_dev), &langs, &langs_count);
    309320        if (rc != EOK) {
    310321                fprintf(stderr,
     
    334345                        }
    335346                        char *string = NULL;
    336                         rc = usb_request_get_string(&dev->ctrl_pipe, idx, lang,
     347                        rc = usb_request_get_string(
     348                            usb_device_get_default_pipe(usb_dev), idx, lang,
    337349                            &string);
    338350                        if ((rc != EOK) && (rc != EEMPTY)) {
     
    351363
    352364
    353 void dump_status(usbinfo_device_t *dev)
     365void dump_status(usb_device_t *usb_dev)
    354366{
    355367        int rc;
     
    357369
    358370        /* Device status first. */
    359         rc = usb_request_get_status(&dev->ctrl_pipe,
     371        rc = usb_request_get_status(usb_device_get_default_pipe(usb_dev),
    360372            USB_REQUEST_RECIPIENT_DEVICE, 0, &status);
    361373        if (rc != EOK) {
     
    373385        /* Control endpoint zero. */
    374386        status = 0;
    375         rc = usb_request_get_status(&dev->ctrl_pipe,
     387        rc = usb_request_get_status(usb_device_get_default_pipe(usb_dev),
    376388            USB_REQUEST_RECIPIENT_ENDPOINT, 0, &status);
    377389        if (rc != EOK) {
  • uspace/app/usbinfo/main.c

    r5b401b9 r06f9a9c9  
    198198
    199199                /* The initialization is here only to make compiler happy. */
    200                 devman_handle_t hc_handle = 0;
    201                 usb_address_t dev_addr = 0;
     200                devman_handle_t handle = 0;
    202201                int rc = usb_resolve_device_handle(devpath,
    203                     &hc_handle, &dev_addr, NULL);
     202                    NULL, NULL, &handle);
    204203                if (rc != EOK) {
    205204                        fprintf(stderr, NAME ": device `%s' not found "
     
    209208                }
    210209
    211                 usbinfo_device_t *dev = prepare_device(devpath,
    212                     hc_handle, dev_addr);
    213                 if (dev == NULL) {
     210                usb_device_t *usb_dev = usb_device_create(handle);
     211
     212                if (usb_dev == NULL) {
    214213                        continue;
    215214                }
     
    221220                while (actions[action].opt != 0) {
    222221                        if (actions[action].active) {
    223                                 actions[action].action(dev);
     222                                actions[action].action(usb_dev);
    224223                        }
    225224                        action++;
    226225                }
    227226
    228                 /* Destroy the control pipe (close the session etc.). */
    229                 destroy_device(dev);
     227                usb_device_destroy(usb_dev);
    230228        }
    231229
  • uspace/app/usbinfo/usbinfo.h

    r5b401b9 r06f9a9c9  
    3838#include <usb/usb.h>
    3939#include <usb/descriptor.h>
    40 #include <usb/dev/pipes.h>
    41 #include <usb/debug.h>
     40#include <usb/dev/device.h>
    4241#include <usb/dev/dp.h>
    4342#include <ipc/devman.h>
    4443
    4544typedef struct {
    46         usb_hc_connection_t hc_conn;
    47         usb_device_connection_t wire;
    48         usb_pipe_t ctrl_pipe;
    49         usb_standard_device_descriptor_t device_descriptor;
    50         uint8_t *full_configuration_descriptor;
    51         size_t full_configuration_descriptor_size;
    52 } usbinfo_device_t;
    53 
    54 typedef struct {
    5545        int opt;
    56         void (*action)(usbinfo_device_t *dev);
     46        void (*action)(usb_device_t *usb_dev);
    5747        bool active;
    5848} usbinfo_action_t;
     
    7262}
    7363
    74 usbinfo_device_t *prepare_device(const char *, devman_handle_t, usb_address_t);
    75 void destroy_device(usbinfo_device_t *);
    76 
    7764typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *);
    7865void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
     
    8168void list(void);
    8269
    83 void dump_short_device_identification(usbinfo_device_t *);
    84 void dump_device_match_ids(usbinfo_device_t *);
    85 void dump_descriptor_tree_brief(usbinfo_device_t *);
    86 void dump_descriptor_tree_full(usbinfo_device_t *);
    87 void dump_strings(usbinfo_device_t *);
    88 void dump_status(usbinfo_device_t *);
    89 void dump_hidreport_raw(usbinfo_device_t *);
    90 void dump_hidreport_usages(usbinfo_device_t *);
    91 
     70void dump_short_device_identification(usb_device_t *);
     71void dump_device_match_ids(usb_device_t *);
     72void dump_descriptor_tree_brief(usb_device_t *);
     73void dump_descriptor_tree_full(usb_device_t *);
     74void dump_strings(usb_device_t *);
     75void dump_status(usb_device_t *);
     76void dump_hidreport_raw(usb_device_t *);
     77void dump_hidreport_usages(usb_device_t *);
    9278
    9379#endif
Note: See TracChangeset for help on using the changeset viewer.