Changeset e160da4d in mainline


Ignore:
Timestamp:
2011-03-17T21:11:52Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
da77278
Parents:
81ca204
Message:

Add printing of descriptor tree to usbinfo

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

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/Makefile

    r81ca204 re160da4d  
    3434
    3535SOURCES = \
     36        desctree.c \
    3637        dev.c \
    3738        dump.c \
  • uspace/app/usbinfo/dev.c

    r81ca204 re160da4d  
    9393        }
    9494
     95        rc = usb_request_get_full_configuration_descriptor_alloc(
     96            &dev->ctrl_pipe, 0, (void **)&dev->full_configuration_descriptor,
     97            &dev->full_configuration_descriptor_size);
     98        if (rc != EOK) {
     99                fprintf(stderr,
     100                    NAME ": failed to retrieve configuration descriptor: %s.\n",
     101                    str_error(rc));
     102                goto leave;
     103        }
     104
    95105        return dev;
    96106
  • uspace/app/usbinfo/info.c

    r81ca204 re160da4d  
    4040#include <usb/recognise.h>
    4141#include <usb/request.h>
     42#include <usb/classes/classes.h>
    4243#include "usbinfo.h"
    4344
     
    5657            &dev->device_descriptor, &matches);
    5758        dump_match_ids(&matches, get_indent(0));
     59}
     60
     61static void dump_descriptor_tree_brief_device(const char *prefix,
     62    usb_standard_device_descriptor_t *descriptor)
     63{
     64        printf("%sDevice (0x%04x by 0x%04x, %s)\n", prefix,
     65            (int) descriptor->product_id,
     66            (int) descriptor->vendor_id,
     67            usb_str_class(descriptor->device_class));
     68}
     69
     70static void dump_descriptor_tree_brief_configuration(const char *prefix,
     71    usb_standard_configuration_descriptor_t *descriptor)
     72{
     73        printf("%sConfiguration #%d\n", prefix,
     74            (int) descriptor->configuration_number);
     75}
     76
     77static void dump_descriptor_tree_brief_interface(const char *prefix,
     78    usb_standard_interface_descriptor_t *descriptor)
     79{
     80        printf("%sInterface #%d (%s, 0x%02x, 0x%02x)\n", prefix,
     81            (int) descriptor->interface_number,
     82            usb_str_class(descriptor->interface_class),
     83            (int) descriptor->interface_subclass,
     84            (int) descriptor->interface_protocol);
     85}
     86
     87static void dump_descriptor_tree_brief_endpoint(const char *prefix,
     88    usb_standard_endpoint_descriptor_t *descriptor)
     89{
     90        usb_endpoint_t endpoint_no = descriptor->endpoint_address & 0xF;
     91        usb_transfer_type_t transfer = descriptor->attributes & 0x3;
     92        usb_direction_t direction = descriptor->endpoint_address & 0x80
     93            ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
     94        printf("%sEndpoint #%d (%s %s, %zu)\n", prefix,
     95            endpoint_no, usb_str_transfer_type(transfer),
     96            direction == USB_DIRECTION_IN ? "in" : "out",
     97            (size_t) descriptor->max_packet_size);
     98}
     99
     100
     101static void dump_descriptor_tree_brief_callback(uint8_t *descriptor,
     102    size_t depth, void *arg)
     103{
     104        const char *indent = get_indent(depth);
     105
     106        int descr_type = -1;
     107        size_t descr_size = descriptor[0];
     108        if (descr_size > 0) {
     109                descr_type = descriptor[1];
     110        }
     111
     112        switch (descr_type) {
     113
     114#define _BRANCH(type_enum, descriptor_type, callback) \
     115        case type_enum: \
     116                if (descr_size >= sizeof(descriptor_type)) { \
     117                        callback(indent, (descriptor_type *) descriptor); \
     118                } else { \
     119                        descr_type = -1; \
     120                } \
     121                break;
     122
     123                _BRANCH(USB_DESCTYPE_DEVICE,
     124                    usb_standard_device_descriptor_t,
     125                    dump_descriptor_tree_brief_device);
     126                _BRANCH(USB_DESCTYPE_CONFIGURATION,
     127                    usb_standard_configuration_descriptor_t,
     128                    dump_descriptor_tree_brief_configuration);
     129                _BRANCH(USB_DESCTYPE_INTERFACE,
     130                    usb_standard_interface_descriptor_t,
     131                    dump_descriptor_tree_brief_interface);
     132                _BRANCH(USB_DESCTYPE_ENDPOINT,
     133                    usb_standard_endpoint_descriptor_t,
     134                    dump_descriptor_tree_brief_endpoint);
     135
     136                default:
     137                        break;
     138        }
     139
     140        if (descr_type == -1) {
     141                printf("%sInvalid descriptor.\n", indent);
     142        }
     143}
     144
     145void dump_descriptor_tree_brief(usbinfo_device_t *dev)
     146{
     147        dump_descriptor_tree_brief_callback((uint8_t *)&dev->device_descriptor,
     148            0, NULL);
     149        browse_descriptor_tree(dev->full_configuration_descriptor,
     150            dev->full_configuration_descriptor_size,
     151            usb_dp_standard_descriptor_nesting,
     152            dump_descriptor_tree_brief_callback,
     153            1,
     154            NULL);
    58155}
    59156
  • uspace/app/usbinfo/main.c

    r81ca204 re160da4d  
    4747#include "usbinfo.h"
    4848
    49 static void print_usage(char *app_name)
    50 {
    51 #define INDENT "      "
    52         printf(NAME ": query USB devices for descriptors\n\n");
    53         printf("Usage: %s [options] device [device [device [ ... ]]]\n",
    54             app_name);
    55         printf(INDENT "The device is a devman path to the device.\n");
    56         printf("\n");
    57 #undef INDENT
    58 }
    59 
    6049static bool resolve_hc_handle_and_dev_addr(const char *devpath,
    6150    devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
     
    130119}
    131120
     121static void print_usage(char *app_name)
     122{
     123#define _INDENT "      "
     124#define _OPTION(opt, description) \
     125        printf(_INDENT opt "\n" _INDENT _INDENT description "\n")
     126
     127        printf(NAME ": query USB devices for descriptors\n\n");
     128        printf("Usage: %s [options] device [device [device [ ... ]]]\n",
     129            app_name);
     130        printf(_INDENT "The device is a devman path to the device.\n");
     131
     132        _OPTION("-h --help", "Print this help and exit.");
     133        _OPTION("-i --identification", "Brief device identification.");
     134        _OPTION("-m --match-ids", "Print match ids generated for the device.");
     135        _OPTION("-t --descriptor-tree", "Print descriptor tree.");
     136
     137        printf("\n");
     138        printf("If no option is specified, `-i' is considered default.\n");
     139        printf("\n");
     140
     141#undef _OPTION
     142#undef _INDENT
     143}
     144
    132145static struct option long_options[] = {
    133146        {"help", no_argument, NULL, 'h'},
    134147        {"identification", no_argument, NULL, 'i'},
    135148        {"match-ids", no_argument, NULL, 'm'},
     149        {"descriptor-tree", no_argument, NULL, 't'},
    136150        {0, 0, NULL, 0}
    137151};
    138 static const char *short_options = "him";
     152static const char *short_options = "himt";
    139153
    140154int main(int argc, char *argv[])
     
    147161        bool action_print_short_identification = false;
    148162        bool action_print_match_ids = false;
     163        bool action_print_descriptor_tree = false;
    149164
    150165        /*
     
    171186                                action_print_match_ids = true;
    172187                                break;
     188                        case 't':
     189                                action_print_descriptor_tree = true;
     190                                break;
    173191                        default:
     192                                assert(false && "unreachable code");
    174193                                break;
    175194                }
     
    177196
    178197        /* Set the default action. */
    179         if (!action_print_match_ids && !action_print_short_identification) {
     198        if (!action_print_match_ids
     199            && !action_print_short_identification
     200            && !action_print_descriptor_tree) {
    180201                action_print_short_identification = true;
    181202        }
     
    215236                        dump_device_match_ids(dev);
    216237                }
     238                if (action_print_descriptor_tree) {
     239                        dump_descriptor_tree_brief(dev);
     240                }
    217241
    218242                /* Destroy the control pipe (close the session etc.). */
  • uspace/app/usbinfo/usbinfo.h

    r81ca204 re160da4d  
    4040#include <usb/pipes.h>
    4141#include <usb/debug.h>
     42#include <usb/dp.h>
    4243#include <ipc/devman.h>
    4344
     
    4647        usb_device_connection_t wire;
    4748        usb_standard_device_descriptor_t device_descriptor;
     49        uint8_t *full_configuration_descriptor;
     50        size_t full_configuration_descriptor_size;
    4851} usbinfo_device_t;
    4952
     
    6568void destroy_device(usbinfo_device_t *);
    6669
     70typedef void (*dump_descriptor_in_tree_t)(uint8_t *, size_t, void *);
     71void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
     72    dump_descriptor_in_tree_t, size_t, void *);
     73
    6774
    6875void dump_short_device_identification(usbinfo_device_t *);
    6976void dump_device_match_ids(usbinfo_device_t *);
     77void dump_descriptor_tree_brief(usbinfo_device_t *);
     78
    7079
    7180#endif
Note: See TracChangeset for help on using the changeset viewer.