Changeset 6f53811 in mainline for uspace/lib/usb/src/dump.c


Ignore:
Timestamp:
2013-01-06T00:28:15Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3185a5
Parents:
1da979d
Message:

libusb: Implement hub descriptor dump.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/dump.c

    r1da979d r6f53811  
    4141#include <usb/descriptor.h>
    4242#include <usb/classes/classes.h>
     43#include <usb/classes/hub.h>
    4344
    4445/** Mapping between descriptor id and dumping function. */
     
    276277    const uint8_t *descriptor, size_t descriptor_length)
    277278{
    278         /* TODO */
     279        usb_hub_descriptor_header_t *d =
     280            (usb_hub_descriptor_header_t *) descriptor;
     281        if (descriptor_length < sizeof(d))
     282                return;
     283
     284        PRINTLINE("bDescLength: = %d", d->length);
     285        PRINTLINE("bDescriptorType = 0x%02x", d->descriptor_type);
     286        PRINTLINE("bNbrPorts = %d", d->port_count);
     287        PRINTLINE("bHubCharacteristics = 0x%02x%02x (%s;%s%s)",
     288            d->characteristics_reserved, d->characteristics,
     289            (d->characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG) ?
     290                "No Power Switching" :
     291                ((d->characteristics & HUB_CHAR_POWER_PER_PORT_FLAG) ?
     292                    "Per-Port Switching" : "Ganged Power Switching"),
     293            (d->characteristics & HUB_CHAR_COMPOUND_DEVICE) ?
     294                "Compound Device;" : "",
     295            (d->characteristics & HUB_CHAR_NO_OC_FLAG) ?
     296                "No OC Protection" :
     297                    ((d->characteristics & HUB_CHAR_OC_PER_PORT_FLAG) ?
     298                        "Individual Port OC Protection" :
     299                            "Global OC Protection")
     300        );
     301        PRINTLINE("bPwrOn2PwrGood = %d (%d ms)",
     302            d->power_good_time, d->power_good_time * 2);
     303        PRINTLINE("bHubContrCurrent = %d (%d mA)",
     304            d->max_current, d->max_current);
     305        const size_t port_bytes = (descriptor_length - sizeof(*d)) / 2;
     306        const uint8_t *removable_mask = descriptor + sizeof(*d);
     307        const uint8_t *powered_mask = descriptor + sizeof(*d) + port_bytes;
     308
     309        if (port_bytes == 0
     310            || port_bytes > (((d->port_count / (unsigned)8) + 1) * 2)) {
     311                PRINTLINE("::CORRUPTED DESCRIPTOR:: (%zu bytes remain)",
     312                    port_bytes * 2);
     313        }
     314
     315        fprintf(output, "%sDeviceRemovable = 0x",
     316            line_prefix ? line_prefix : " - ");
     317        for (unsigned i = port_bytes; i > 0; --i)
     318                fprintf(output, "%02x", removable_mask[i - 1]);
     319        fprintf(output, " (0b1 - Device non-removable)%s",
     320            line_suffix ? line_suffix : "\n");
     321
     322        fprintf(output, "%sPortPwrCtrlMask = 0x",
     323            line_prefix ? line_prefix : " - ");
     324        for (unsigned i = port_bytes; i > 0; --i)
     325                fprintf(output, "%02x", powered_mask[i - 1]);
     326        fprintf(output, " (Legacy - All should be 0b1)%s",
     327            line_suffix ? line_suffix : "\n");
    279328}
    280329
Note: See TracChangeset for help on using the changeset viewer.