Changeset cdc1aa1 in mainline for uspace/app


Ignore:
Timestamp:
2010-12-10T09:50:58Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7964475, bf2063e9
Parents:
040068c (diff), 99ea659c (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:

Merge retrieval of configuration descriptor

The merge also includes extension of `usbinfo' app.

Location:
uspace/app/usbinfo
Files:
3 edited

Legend:

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

    r040068c rcdc1aa1  
    4747
    4848#define INDENT "  "
     49#define BYTES_PER_LINE 12
    4950
    5051#define BCD_INT(a) (((unsigned int)(a)) / 256)
     
    5354#define BCD_FMT "%x.%x"
    5455#define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a))
     56
     57void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
     58{
     59        printf("%s\n", msg);
     60
     61        size_t i;
     62        for (i = 0; i < length; i++) {
     63                printf("  0x%02X", buffer[i]);
     64                if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
     65                    || (i + 1 == length)) {
     66                        printf("\n");
     67                }
     68        }
     69}
    5570
    5671void dump_standard_device_descriptor(usb_standard_device_descriptor_t *d)
     
    7590}
    7691
     92void dump_standard_configuration_descriptor(
     93    int index, usb_standard_configuration_descriptor_t *d)
     94{
     95        bool self_powered = d->attributes & 64;
     96        bool remote_wakeup = d->attributes & 32;
     97       
     98        printf("Standard configuration descriptor #%d\n", index);
     99        printf(INDENT "bLength = %d\n", d->length);
     100        printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
     101        printf(INDENT "wTotalLength = %d\n", d->total_length);
     102        printf(INDENT "bNumInterfaces = %d\n", d->interface_count);
     103        printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);
     104        printf(INDENT "iConfiguration = %d\n", d->str_configuration);
     105        printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,
     106            self_powered ? "self-powered" : "",
     107            (self_powered & remote_wakeup) ? ", " : "",
     108            remote_wakeup ? "remote-wakeup" : "");
     109        printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
     110            2 * d->max_power);
     111        // printf(INDENT " = %d\n", d->);
     112}
     113
     114
    77115/** @}
    78116 */
  • uspace/app/usbinfo/main.c

    r040068c rcdc1aa1  
    4444#include "usbinfo.h"
    4545
     46#define DEFAULT_HOST_CONTROLLER_PATH "/virt/usbhc"
     47
    4648static void print_usage(char *app_name)
    4749{
    4850        printf(NAME ": query USB devices for descriptors\n\n");
    4951        printf("Usage: %s /path/to/hc usb-address\n where\n", app_name);
    50         printf("   /path/to/hc   Devman path to USB host controller\n");
     52        printf("   /path/to/hc   Devman path to USB host controller " \
     53            "(use `-' for\n");
     54        printf("                   default HC at `%s').\n",
     55            DEFAULT_HOST_CONTROLLER_PATH);
    5156        printf("   usb-address   USB address of device to be queried\n");
    5257        printf("\n");
     
    6873}
    6974
    70 int main(int argc, char * argv[])
     75int main(int argc, char *argv[])
    7176{
    7277        if (argc != 3) {
     
    8186         * Connect to given host controller driver.
    8287         */
     88        if (str_cmp(hc_path, "-") == 0) {
     89                hc_path = (char *) DEFAULT_HOST_CONTROLLER_PATH;
     90        }
    8391        int hc_phone = connect_to_hc(hc_path);
    8492        if (hc_phone < 0) {
     
    107115         */
    108116        usb_standard_device_descriptor_t device_descriptor;
    109         usb_dprintf("usbinfo", 1,
     117        usb_dprintf(NAME, 1,
    110118            "usb_drv_req_get_device_descriptor(%d, %d, %p)\n",
    111119            hc_phone, (int) address, &device_descriptor);
     
    121129        dump_standard_device_descriptor(&device_descriptor);
    122130
     131        /*
     132         * Get first configuration descriptor and dump it.
     133         */
     134        usb_standard_configuration_descriptor_t config_descriptor;
     135        int config_index = 0;
     136        usb_dprintf(NAME, 1,
     137            "usb_drv_req_get_bare_configuration_descriptor(%d, %d, %d, %p)\n",
     138            hc_phone, (int) address, config_index, &config_descriptor);
     139
     140        rc = usb_drv_req_get_bare_configuration_descriptor(hc_phone, address,
     141            config_index, &config_descriptor );
     142        if (rc != EOK) {
     143                fprintf(stderr,
     144                    NAME ": failed to fetch standard configuration descriptor: %s.\n",
     145                    str_error(rc));
     146                return rc;
     147        }
     148        dump_standard_configuration_descriptor(config_index,
     149            &config_descriptor);
     150
     151        void *full_config_descriptor = malloc(config_descriptor.total_length);
     152        usb_dprintf(NAME, 1,
     153            "usb_drv_req_get_full_configuration_descriptor(%d, %d, %d, %p, %zu)\n",
     154            hc_phone, (int) address, config_index,
     155            full_config_descriptor, config_descriptor.total_length);
     156
     157        rc = usb_drv_req_get_full_configuration_descriptor(hc_phone, address,
     158            config_index,
     159            full_config_descriptor, config_descriptor.total_length, NULL);
     160        if (rc != EOK) {
     161                fprintf(stderr,
     162                    NAME ": failed to fetch full configuration descriptor: %s.\n",
     163                    str_error(rc));
     164                return rc;
     165        }
     166        dump_buffer("Full configuration descriptor:",
     167            full_config_descriptor, config_descriptor.total_length);
    123168
    124169        return EOK;
  • uspace/app/usbinfo/usbinfo.h

    r040068c rcdc1aa1  
    4343#define NAME "usbinfo"
    4444
     45void dump_buffer(const char *, const uint8_t *, size_t);
    4546void dump_standard_device_descriptor(usb_standard_device_descriptor_t *);
     47void dump_standard_configuration_descriptor(int,
     48    usb_standard_configuration_descriptor_t *);
    4649
    4750#endif
Note: See TracChangeset for help on using the changeset viewer.