Changeset 5dfee52 in mainline


Ignore:
Timestamp:
2011-05-08T13:39:20Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
19065c7, 7b6f116
Parents:
df25ab6
Message:

lsusb prints attached devices as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/lsusb/main.c

    rdf25ab6 r5dfee52  
    4444#include <devman.h>
    4545#include <devmap.h>
     46#include <usb/hub.h>
    4647#include <usb/host.h>
    4748
    4849#define NAME "lsusb"
    4950
    50 #define MAX_FAILED_ATTEMPTS 4
     51#define MAX_FAILED_ATTEMPTS 10
    5152#define MAX_PATH_LENGTH 1024
     53
     54static void print_found_hc(size_t class_index, const char *path)
     55{
     56        // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);
     57        printf("Bus %02zu: %s\n", class_index, path);
     58}
     59static void print_found_dev(usb_address_t addr, const char *path)
     60{
     61        // printf(NAME ":     device with address %d is `%s'.\n", addr, path);
     62        printf("  Device %02d: %s\n", addr, path);
     63}
     64
     65static void print_hc_devices(devman_handle_t hc_handle)
     66{
     67        int rc;
     68        usb_hc_connection_t conn;
     69
     70        usb_hc_connection_initialize(&conn, hc_handle);
     71        rc = usb_hc_connection_open(&conn);
     72        if (rc != EOK) {
     73                printf(NAME ": failed to connect to HC: %s.\n",
     74                    str_error(rc));
     75                return;
     76        }
     77        usb_address_t addr;
     78        for (addr = 1; addr < 5; addr++) {
     79                devman_handle_t dev_handle;
     80                rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
     81                if (rc != EOK) {
     82                        continue;
     83                }
     84                char path[MAX_PATH_LENGTH];
     85                rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
     86                if (rc != EOK) {
     87                        continue;
     88                }
     89                print_found_dev(addr, path);
     90        }
     91        usb_hc_connection_close(&conn);
     92}
    5293
    5394int main(int argc, char *argv[])
     
    69110                        continue;
    70111                }
    71                 printf(NAME ": host controller %zu is `%s'.\n",
    72                     class_index, path);
     112                print_found_hc(class_index, path);
     113                print_hc_devices(hc_handle);
    73114        }
    74115
Note: See TracChangeset for help on using the changeset viewer.