Ignore:
File:
1 edited

Legend:

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

    r1dc4a5e r0edf7c7  
    4343#include <getopt.h>
    4444#include <devman.h>
    45 #include <loc.h>
     45#include <devmap.h>
    4646#include <usb/dev/hub.h>
    4747#include <usb/hc.h>
     
    5050
    5151#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
     52#define MAX_FAILED_ATTEMPTS 10
    5253#define MAX_PATH_LENGTH 1024
    5354
    54 static void print_found_hc(service_id_t sid, const char *path)
     55static void print_found_hc(size_t class_index, const char *path)
    5556{
    56         printf("Bus %" PRIun ": %s\n", sid, path);
     57        // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);
     58        printf("Bus %02zu: %s\n", class_index, path);
    5759}
    5860static void print_found_dev(usb_address_t addr, const char *path)
    5961{
     62        // printf(NAME ":     device with address %d is `%s'.\n", addr, path);
    6063        printf("  Device %02d: %s\n", addr, path);
    6164}
     
    9295int main(int argc, char *argv[])
    9396{
    94         category_id_t usbhc_cat;
    95         service_id_t *svcs;
    96         size_t count;
    97         size_t i;
    98         int rc;
     97        size_t class_index = 0;
     98        size_t failed_attempts = 0;
    9999
    100         rc = loc_category_get_id(USB_HC_CATEGORY, &usbhc_cat, 0);
    101         if (rc != EOK) {
    102                 printf(NAME ": Error resolving category '%s'",
    103                     USB_HC_CATEGORY);
    104                 return 1;
    105         }
    106 
    107         rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
    108         if (rc != EOK) {
    109                 printf(NAME ": Error getting list of host controllers.\n");
    110                 return 1;
    111         }
    112 
    113         for (i = 0; i < count; i++) {
     100        while (failed_attempts < MAX_FAILED_ATTEMPTS) {
     101                class_index++;
    114102                devman_handle_t hc_handle = 0;
    115                 int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
     103                int rc = usb_ddf_get_hc_handle_by_class(class_index, &hc_handle);
    116104                if (rc != EOK) {
    117                         printf(NAME ": Error resolving handle of HC with SID %"
    118                             PRIun ", skipping.\n", svcs[i]);
     105                        failed_attempts++;
    119106                        continue;
    120107                }
     
    122109                rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
    123110                if (rc != EOK) {
    124                         printf(NAME ": Error resolving path of HC with SID %"
    125                             PRIun ", skipping.\n", svcs[i]);
    126111                        continue;
    127112                }
    128                 print_found_hc(svcs[i], path);
     113                print_found_hc(class_index, path);
    129114                print_hc_devices(hc_handle);
    130115        }
    131 
    132         free(svcs);
    133116
    134117        return 0;
Note: See TracChangeset for help on using the changeset viewer.