Changeset 290ea09 in mainline


Ignore:
Timestamp:
2011-01-15T11:24:09Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1d12f4
Parents:
fbddf94 (diff), 0950397a (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/ - various fixes

Fixed ticket #41 - Virtual USB devices do not set actual transfer size

Improved output of `usbinfo' application.

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    rfbddf94 r290ea09  
    109109./uspace/srv/hw/irc/apic/apic
    110110./uspace/srv/hw/irc/i8259/i8259
    111 ./uspace/srv/hw/netif/dp8390/dp8390
     111./uspace/srv/hw/netif/ne2000/dp8390
     112./uspace/srv/hw/netif/ne2000/ne2000
    112113./uspace/srv/loader/loader
    113114./uspace/srv/net/cfg/lo
  • uspace/app/usbinfo/dump.c

    rfbddf94 r290ea09  
    4343#include <usb/usb.h>
    4444#include <usb/descriptor.h>
     45#include <usb/classes/classes.h>
    4546
    4647#include "usbinfo.h"
     
    4849
    4950#define INDENT "  "
     51#define PRINTLINE(indent, fmt, ...) printf("%s - " fmt, get_indent(indent), __VA_ARGS__)
    5052#define BYTES_PER_LINE 12
    5153
     
    5658#define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a))
    5759
    58 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
    59 {
    60         printf("%s\n", msg);
     60static void dump_descriptor_by_type(size_t, uint8_t *, size_t);
     61
     62typedef struct {
     63        int descriptor;
     64        void (*dump)(size_t indent, uint8_t *descriptor, size_t length);
     65} descriptor_dump_t;
     66
     67static void dump_descriptor_device(size_t, uint8_t *, size_t);
     68static void dump_descriptor_configuration(size_t, uint8_t *, size_t);
     69static void dump_descriptor_interface(size_t, uint8_t *, size_t);
     70static void dump_descriptor_string(size_t, uint8_t *, size_t);
     71static void dump_descriptor_endpoint(size_t, uint8_t *, size_t);
     72static void dump_descriptor_hid(size_t, uint8_t *, size_t);
     73static void dump_descriptor_hub(size_t, uint8_t *, size_t);
     74static void dump_descriptor_generic(size_t, uint8_t *, size_t);
     75
     76static descriptor_dump_t descriptor_dumpers[] = {
     77        { USB_DESCTYPE_DEVICE, dump_descriptor_device },
     78        { USB_DESCTYPE_CONFIGURATION, dump_descriptor_configuration },
     79        { USB_DESCTYPE_STRING, dump_descriptor_string },
     80        { USB_DESCTYPE_INTERFACE, dump_descriptor_interface },
     81        { USB_DESCTYPE_ENDPOINT, dump_descriptor_endpoint },
     82        { USB_DESCTYPE_HID, dump_descriptor_hid },
     83        { USB_DESCTYPE_HUB, dump_descriptor_hub },
     84        { -1, dump_descriptor_generic },
     85        { -1, NULL }
     86};
     87
     88static const char *get_indent(size_t level)
     89{
     90        static const char *indents[] = {
     91                INDENT,
     92                INDENT INDENT,
     93                INDENT INDENT INDENT,
     94                INDENT INDENT INDENT INDENT,
     95                INDENT INDENT INDENT INDENT INDENT
     96        };
     97        static size_t indents_count = sizeof(indents)/sizeof(indents[0]);
     98        if (level >= indents_count) {
     99                return indents[indents_count - 1];
     100        }
     101        return indents[level];
     102}
     103
     104void dump_buffer(const char *msg, size_t indent,
     105    const uint8_t *buffer, size_t length)
     106{
     107        if (msg != NULL) {
     108                printf("%s\n", msg);
     109        }
    61110
    62111        size_t i;
     112        if (length > 0) {
     113                printf("%s", get_indent(indent));
     114        }
    63115        for (i = 0; i < length; i++) {
    64                 printf("  0x%02X", buffer[i]);
     116                printf("0x%02X", buffer[i]);
    65117                if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
    66118                    || (i + 1 == length)) {
    67119                        printf("\n");
     120                        if (i + 1 < length) {
     121                                printf("%s", get_indent(indent));
     122                        }
     123                } else {
     124                        printf("  ");
    68125                }
    69126        }
    70127}
     128
     129void dump_descriptor_by_type(size_t indent, uint8_t *d, size_t length)
     130{
     131        if (length < 2) {
     132                return;
     133        }
     134        int type = d[1];
     135       
     136        descriptor_dump_t *dumper = descriptor_dumpers;
     137        while (dumper->dump != NULL) {
     138                if ((dumper->descriptor == type) || (dumper->descriptor < 0)) {
     139                        dumper->dump(indent, d, length);
     140                        return;
     141                }
     142                dumper++;
     143        }                       
     144}
     145
     146void dump_usb_descriptor(uint8_t *descriptor, size_t size)
     147{
     148        dump_descriptor_by_type(0, descriptor, size);
     149}
     150
     151void dump_descriptor_device(size_t indent, uint8_t *descr, size_t size)
     152{
     153        usb_standard_device_descriptor_t *d
     154            = (usb_standard_device_descriptor_t *) descr;
     155        if (size != sizeof(*d)) {
     156                return;
     157        }
     158       
     159        PRINTLINE(indent, "bLength = %d\n", d->length);
     160        PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type);
     161        PRINTLINE(indent, "bcdUSB = %d (" BCD_FMT ")\n", d->usb_spec_version,
     162            BCD_ARGS(d->usb_spec_version));
     163        PRINTLINE(indent, "bDeviceClass = 0x%02x\n", d->device_class);
     164        PRINTLINE(indent, "bDeviceSubClass = 0x%02x\n", d->device_subclass);
     165        PRINTLINE(indent, "bDeviceProtocol = 0x%02x\n", d->device_protocol);
     166        PRINTLINE(indent, "bMaxPacketSize0 = %d\n", d->max_packet_size);
     167        PRINTLINE(indent, "idVendor = %d\n", d->vendor_id);
     168        PRINTLINE(indent, "idProduct = %d\n", d->product_id);
     169        PRINTLINE(indent, "bcdDevice = %d\n", d->device_version);
     170        PRINTLINE(indent, "iManufacturer = %d\n", d->str_manufacturer);
     171        PRINTLINE(indent, "iProduct = %d\n", d->str_product);
     172        PRINTLINE(indent, "iSerialNumber = %d\n", d->str_serial_number);
     173        PRINTLINE(indent, "bNumConfigurations = %d\n", d->configuration_count);
     174}
     175
     176void dump_descriptor_configuration(size_t indent, uint8_t *descr, size_t size)
     177{
     178        usb_standard_configuration_descriptor_t *d
     179            = (usb_standard_configuration_descriptor_t *) descr;
     180        if (size != sizeof(*d)) {
     181                return;
     182        }
     183       
     184        bool self_powered = d->attributes & 64;
     185        bool remote_wakeup = d->attributes & 32;
     186       
     187        PRINTLINE(indent, "bLength = %d\n", d->length);
     188        PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type);
     189        PRINTLINE(indent, "wTotalLength = %d\n", d->total_length);
     190        PRINTLINE(indent, "bNumInterfaces = %d\n", d->interface_count);
     191        PRINTLINE(indent, "bConfigurationValue = %d\n", d->configuration_number);
     192        PRINTLINE(indent, "iConfiguration = %d\n", d->str_configuration);
     193        PRINTLINE(indent, "bmAttributes = %d [%s%s%s]\n", d->attributes,
     194            self_powered ? "self-powered" : "",
     195            (self_powered & remote_wakeup) ? ", " : "",
     196            remote_wakeup ? "remote-wakeup" : "");
     197        PRINTLINE(indent, "MaxPower = %d (%dmA)\n", d->max_power,
     198            2 * d->max_power);
     199}
     200
     201void dump_descriptor_interface(size_t indent, uint8_t *descr, size_t size)
     202{
     203        usb_standard_interface_descriptor_t *d
     204            = (usb_standard_interface_descriptor_t *) descr;
     205        if (size != sizeof(*d)) {
     206                return;
     207        }
     208       
     209        PRINTLINE(indent, "bLength = %d\n", d->length);
     210        PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type);
     211        PRINTLINE(indent, "bInterfaceNumber = %d\n", d->interface_number);
     212        PRINTLINE(indent, "bAlternateSetting = %d\n", d->alternate_setting);
     213        PRINTLINE(indent, "bNumEndpoints = %d\n", d->endpoint_count);
     214        PRINTLINE(indent, "bInterfaceClass = %s\n", d->interface_class == 0
     215            ? "reserved (0)" : usb_str_class(d->interface_class));
     216        PRINTLINE(indent, "bInterfaceSubClass = %d\n", d->interface_subclass);
     217        PRINTLINE(indent, "bInterfaceProtocol = %d\n", d->interface_protocol);
     218        PRINTLINE(indent, "iInterface = %d\n", d->str_interface);
     219}
     220
     221void dump_descriptor_string(size_t indent, uint8_t *descr, size_t size)
     222{
     223        dump_descriptor_generic(indent, descr, size);
     224}
     225
     226void dump_descriptor_endpoint(size_t indent, uint8_t *descr, size_t size)
     227{
     228        usb_standard_endpoint_descriptor_t *d
     229           = (usb_standard_endpoint_descriptor_t *) descr;
     230        if (size != sizeof(*d)) {
     231                return;
     232        }
     233       
     234        int endpoint = d->endpoint_address & 15;
     235        usb_direction_t direction = d->endpoint_address & 128
     236            ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
     237       
     238        PRINTLINE(indent, "bLength = %d\n", d->length);
     239        PRINTLINE(indent, "bDescriptorType = 0x%02X\n", d->descriptor_type);
     240        PRINTLINE(indent, "bEndpointAddress = 0x%02X [%d, %s]\n",
     241            d->endpoint_address, endpoint,
     242            direction == USB_DIRECTION_IN ? "in" : "out");
     243        PRINTLINE(indent, "bmAttributes = %d\n", d->attributes);
     244        PRINTLINE(indent, "wMaxPacketSize = %d\n", d->max_packet_size);
     245        PRINTLINE(indent, "bInterval = %dms\n", d->poll_interval);
     246}
     247
     248void dump_descriptor_hid(size_t indent, uint8_t *descr, size_t size)
     249{
     250        dump_descriptor_generic(indent, descr, size);
     251}
     252
     253void dump_descriptor_hub(size_t indent, uint8_t *descr, size_t size)
     254{
     255        dump_descriptor_generic(indent, descr, size);
     256}
     257
     258void dump_descriptor_generic(size_t indent, uint8_t *descr, size_t size)
     259{
     260        dump_buffer(NULL, indent, descr, size);
     261}
     262
    71263
    72264void dump_match_ids(match_id_list_t *matches)
     
    83275}
    84276
    85 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *d)
    86 {
    87         printf("Standard device descriptor:\n");
    88 
    89         printf(INDENT "bLength = %d\n", d->length);
    90         printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
    91         printf(INDENT "bcdUSB = %d (" BCD_FMT ")\n", d->usb_spec_version,
    92             BCD_ARGS(d->usb_spec_version));
    93         printf(INDENT "bDeviceClass = 0x%02x\n", d->device_class);
    94         printf(INDENT "bDeviceSubClass = 0x%02x\n", d->device_subclass);
    95         printf(INDENT "bDeviceProtocol = 0x%02x\n", d->device_protocol);
    96         printf(INDENT "bMaxPacketSize0 = %d\n", d->max_packet_size);
    97         printf(INDENT "idVendor = %d\n", d->vendor_id);
    98         printf(INDENT "idProduct = %d\n", d->product_id);
    99         printf(INDENT "bcdDevice = %d\n", d->device_version);
    100         printf(INDENT "iManufacturer = %d\n", d->str_manufacturer);
    101         printf(INDENT "iProduct = %d\n", d->str_product);
    102         printf(INDENT "iSerialNumber = %d\n", d->str_serial_number);
    103         printf(INDENT "bNumConfigurations = %d\n", d->configuration_count);
    104 }
    105 
    106 void dump_standard_configuration_descriptor(
    107     int index, usb_standard_configuration_descriptor_t *d)
    108 {
    109         bool self_powered = d->attributes & 64;
    110         bool remote_wakeup = d->attributes & 32;
    111        
    112         printf("Standard configuration descriptor #%d\n", index);
    113         printf(INDENT "bLength = %d\n", d->length);
    114         printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
    115         printf(INDENT "wTotalLength = %d\n", d->total_length);
    116         printf(INDENT "bNumInterfaces = %d\n", d->interface_count);
    117         printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);
    118         printf(INDENT "iConfiguration = %d\n", d->str_configuration);
    119         printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,
    120             self_powered ? "self-powered" : "",
    121             (self_powered & remote_wakeup) ? ", " : "",
    122             remote_wakeup ? "remote-wakeup" : "");
    123         printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
    124             2 * d->max_power);
    125         // printf(INDENT " = %d\n", d->);
    126 }
    127 
    128277static void dump_tree_descriptor(uint8_t *descriptor, size_t depth)
    129278{
    130279        if (descriptor == NULL) {
    131280                return;
    132         }
    133         while (depth > 0) {
    134                 printf("  ");
    135                 depth--;
    136281        }
    137282        int type = (int) *(descriptor + 1);
     
    151296#undef _TYPE
    152297        }
    153         printf("0x%02x (%s)\n", type, name);
     298        printf("%s%s (0x%02X):\n", get_indent(depth), name, type);
     299        dump_descriptor_by_type(depth, descriptor, descriptor[0]);
     300       
    154301}
    155302
     
    172319        uint8_t *ptr = data->data;
    173320        printf("Descriptor tree:\n");
    174         dump_tree_internal(parser, data, ptr, 1);
     321        dump_tree_internal(parser, data, ptr, 0);
    175322}
    176323
  • uspace/app/usbinfo/info.c

    rfbddf94 r290ea09  
    7272                return rc;
    7373        }
    74         dump_standard_device_descriptor(&device_descriptor);
     74        dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
    7575
    7676        /*
     
    9191                return rc;
    9292        }
    93         dump_standard_configuration_descriptor(config_index,
    94             &config_descriptor);
     93        //dump_standard_configuration_descriptor(config_index, &config_descriptor);
    9594
    9695        void *full_config_descriptor = malloc(config_descriptor.total_length);
     
    109108                return rc;
    110109        }
    111         dump_buffer("Full configuration descriptor:",
    112             full_config_descriptor, config_descriptor.total_length);
    113110
    114111        dump_descriptor_tree(full_config_descriptor,
  • uspace/app/usbinfo/usbinfo.h

    rfbddf94 r290ea09  
    4444#define NAME "usbinfo"
    4545
    46 void dump_buffer(const char *, const uint8_t *, size_t);
     46void dump_buffer(const char *, size_t, const uint8_t *, size_t);
    4747void dump_match_ids(match_id_list_t *matches);
    48 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *);
    49 void dump_standard_configuration_descriptor(int,
    50     usb_standard_configuration_descriptor_t *);
     48void dump_usb_descriptor(uint8_t *, size_t);
    5149int dump_device(int, usb_address_t);
    5250void dump_descriptor_tree(uint8_t *, size_t);
  • uspace/drv/vhc/devices.c

    rfbddf94 r290ea09  
    138138                } else {
    139139                        async_wait_for(req, &answer_rc);
     140                        transaction->actual_len = IPC_GET_ARG1(answer_data);
    140141                        rc = (int)answer_rc;
    141142                }
  • uspace/drv/vhc/hc.c

    rfbddf94 r290ea09  
    9696            usb_str_transaction_outcome(outcome));
    9797       
    98         transaction->callback(transaction->buffer, transaction->len, outcome,
    99             transaction->callback_arg);
     98        transaction->callback(transaction->buffer, transaction->actual_len,
     99            outcome, transaction->callback_arg);
    100100}
    101101
     
    169169        transaction->buffer = buffer;
    170170        transaction->len = len;
     171        transaction->actual_len = len;
    171172        transaction->callback = callback;
    172173        transaction->callback_arg = arg;
  • uspace/drv/vhc/hc.h

    rfbddf94 r290ea09  
    6565        /** Transaction data length. */
    6666        size_t len;
     67        /** Data length actually transfered. */
     68        size_t actual_len;
    6769        /** Callback after transaction is done. */
    6870        hc_transaction_done_callback_t callback;
  • uspace/lib/usbvirt/src/callback.c

    rfbddf94 r290ea09  
    160160                        return;
    161161                }
    162                 async_data_read_finalize(callid, buffer, receive_len);
    163         }
    164        
    165         ipc_answer_0(iid, rc);
     162                if (len > receive_len) {
     163                        len = receive_len;
     164                }
     165                async_data_read_finalize(callid, buffer, len);
     166        }
     167       
     168        ipc_answer_1(iid, rc, len);
    166169}
    167170
Note: See TracChangeset for help on using the changeset viewer.