Changeset d450964 in mainline


Ignore:
Timestamp:
2011-01-14T12:37:58Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00c2d035
Parents:
8426912a (diff), 5ccb15c (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:

Merged vojtechhorky/ - descriptor parser

Location:
uspace
Files:
2 added
5 edited

Legend:

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

    r8426912a rd450964  
    4545
    4646#include "usbinfo.h"
     47#include <usb/dp.h>
    4748
    4849#define INDENT "  "
     
    125126}
    126127
     128static void dump_tree_descriptor(uint8_t *descriptor, size_t depth)
     129{
     130        if (descriptor == NULL) {
     131                return;
     132        }
     133        while (depth > 0) {
     134                printf("  ");
     135                depth--;
     136        }
     137        int type = (int) *(descriptor + 1);
     138        const char *name = "unknown";
     139        switch (type) {
     140#define _TYPE(descriptor_type) \
     141                case USB_DESCTYPE_##descriptor_type: name = #descriptor_type; break
     142                _TYPE(DEVICE);
     143                _TYPE(CONFIGURATION);
     144                _TYPE(STRING);
     145                _TYPE(INTERFACE);
     146                _TYPE(ENDPOINT);
     147                _TYPE(HID);
     148                _TYPE(HID_REPORT);
     149                _TYPE(HID_PHYSICAL);
     150                _TYPE(HUB);
     151#undef _TYPE
     152        }
     153        printf("0x%02x (%s)\n", type, name);
     154}
     155
     156static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
     157    uint8_t *root, size_t depth)
     158{
     159        if (root == NULL) {
     160                return;
     161        }
     162        dump_tree_descriptor(root, depth);
     163        uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     164        do {
     165                dump_tree_internal(parser, data, child, depth + 1);
     166                child = usb_dp_get_sibling_descriptor(parser, data, root, child);
     167        } while (child != NULL);
     168}
     169
     170static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data)
     171{
     172        uint8_t *ptr = data->data;
     173        printf("Descriptor tree:\n");
     174        dump_tree_internal(parser, data, ptr, 1);
     175}
     176
     177#define NESTING(parentname, childname) \
     178        { \
     179                .child = USB_DESCTYPE_##childname, \
     180                .parent = USB_DESCTYPE_##parentname, \
     181        }
     182#define LAST_NESTING { -1, -1 }
     183
     184static usb_dp_descriptor_nesting_t descriptor_nesting[] = {
     185        NESTING(CONFIGURATION, INTERFACE),
     186        NESTING(INTERFACE, ENDPOINT),
     187        NESTING(INTERFACE, HUB),
     188        NESTING(INTERFACE, HID),
     189        NESTING(HID, HID_REPORT),
     190        LAST_NESTING
     191};
     192
     193static usb_dp_parser_t parser = {
     194        .nesting = descriptor_nesting
     195};
     196
     197void dump_descriptor_tree(uint8_t *descriptors, size_t length)
     198{
     199        usb_dp_parser_data_t data = {
     200                .data = descriptors,
     201                .size = length,
     202                .arg = NULL
     203        };
     204
     205        dump_tree(&parser, &data);
     206}
    127207
    128208/** @}
  • uspace/app/usbinfo/info.c

    r8426912a rd450964  
    112112            full_config_descriptor, config_descriptor.total_length);
    113113
     114        dump_descriptor_tree(full_config_descriptor,
     115            config_descriptor.total_length);
     116
    114117        return EOK;
    115118}
  • uspace/app/usbinfo/usbinfo.h

    r8426912a rd450964  
    5050    usb_standard_configuration_descriptor_t *);
    5151int dump_device(int, usb_address_t);
     52void dump_descriptor_tree(uint8_t *, size_t);
    5253
    5354static inline void internal_error(int err)
  • uspace/lib/usb/Makefile

    r8426912a rd450964  
    3636        src/class.c \
    3737        src/debug.c \
     38        src/dp.c \
    3839        src/drvpsync.c \
    3940        src/hcdhubd.c \
  • uspace/lib/usb/src/recognise.c

    r8426912a rd450964  
    346346    usb_address_t address, devman_handle_t *child_handle)
    347347{
     348        static size_t device_name_index = 0;
     349
    348350        device_t *child = NULL;
    349351        char *child_name = NULL;
     
    357359
    358360        /*
    359          * TODO: some better child naming
    360          */
    361         rc = asprintf(&child_name, "usb%p", child);
     361         * TODO: Once the device driver framework support persistent
     362         * naming etc., something more descriptive could be created.
     363         */
     364        rc = asprintf(&child_name, "usbdev%02zu", device_name_index);
    362365        if (rc < 0) {
    363366                goto failure;
     
    381384        }
    382385       
     386        device_name_index++;
     387
    383388        return EOK;
    384389
Note: See TracChangeset for help on using the changeset viewer.