Ignore:
File:
1 edited

Legend:

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

    rfe9d542 r3e6a98c5  
    4444#include <devman.h>
    4545#include <loc.h>
    46 #include <usb_iface.h>
     46#include <usb/dev/hub.h>
     47#include <usb/hc.h>
    4748
    4849#include "usbinfo.h"
    4950
     51#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
    5052#define MAX_PATH_LENGTH 1024
    5153
     
    5961}
    6062
    61 static void print_usb_devices(devman_handle_t bus_handle,
    62     devman_handle_t *fhs, size_t count)
     63static void print_hc_devices(devman_handle_t hc_handle)
    6364{
    64         for (size_t i = 0; i < count; ++i) {
    65                 /* Skip hc ctl function */
    66                 if (fhs[i] == bus_handle)
    67                         continue;
    68                 char path[MAX_PATH_LENGTH];
    69                 int rc = devman_fun_get_path(fhs[i], path, MAX_PATH_LENGTH);
     65        int rc;
     66        usb_hc_connection_t conn;
     67
     68        usb_hc_connection_initialize(&conn, hc_handle);
     69        rc = usb_hc_connection_open(&conn);
     70        if (rc != EOK) {
     71                printf(NAME ": failed to connect to HC: %s.\n",
     72                    str_error(rc));
     73                return;
     74        }
     75        usb_address_t addr;
     76        for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
     77                devman_handle_t dev_handle;
     78                rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
    7079                if (rc != EOK) {
    71                         printf(NAME "Failed to get path for device %" PRIun
    72                             "\n", fhs[i]);
    7380                        continue;
    7481                }
    75                 // TODO remove this. Device name contains USB address
    76                 // and addresses as external id are going away
    77                 usb_dev_session_t *sess = usb_dev_connect(fhs[i]);
    78                 if (!sess) {
    79                         printf(NAME "Failed to connect to device %" PRIun
    80                             "\n", fhs[i]);
     82                char path[MAX_PATH_LENGTH];
     83                rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
     84                if (rc != EOK) {
    8185                        continue;
    8286                }
    83                 async_exch_t *exch = async_exchange_begin(sess);
    84                 if (!exch) {
    85                         printf("Failed to create exchange to dev %" PRIun
    86                             "\n", fhs[i]);
    87                         usb_dev_disconnect(sess);
    88                         continue;
    89                 }
    90                 usb_address_t address;
    91                 rc = usb_get_my_address(exch, &address);
    92                 async_exchange_end(exch);
    93                 usb_dev_disconnect(sess);
    94                 if (rc != EOK) {
    95                         printf("Failed to get address for device %" PRIun
    96                             "\n", fhs[i]);
    97                         continue;
    98                 }
    99                 print_found_dev(address, path);
    100 
     87                print_found_dev(addr, path);
    10188        }
     89        usb_hc_connection_close(&conn);
    10290}
    10391
     
    10795        service_id_t *svcs;
    10896        size_t count;
     97        size_t i;
    10998        int rc;
    11099
     
    122111        }
    123112
    124         for (unsigned i = 0; i < count; ++i) {
     113        for (i = 0; i < count; i++) {
    125114                devman_handle_t hc_handle = 0;
    126                 int rc = devman_fun_sid_to_handle(svcs[i], &hc_handle);
     115                int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
    127116                if (rc != EOK) {
    128117                        printf(NAME ": Error resolving handle of HC with SID %"
     
    130119                        continue;
    131120                }
    132 
    133121                char path[MAX_PATH_LENGTH];
    134122                rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
     
    139127                }
    140128                print_found_hc(svcs[i], path);
    141 
    142                 /* Construct device's path.
    143                  * That's "hc function path" - ( '/' + "hc function name" ) */
    144                 // TODO replace this with something sane
    145                 char name[10];
    146                 rc = devman_fun_get_name(hc_handle, name, 10);
    147                 if (rc != EOK) {
    148                         printf(NAME ": Error resolving name of HC with SID %"
    149                             PRIun ", skipping.\n", svcs[i]);
    150                         continue;
    151                 }
    152 
    153                 devman_handle_t fh;
    154                 path[str_size(path) - str_size(name) - 1] = '\0';
    155                 rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
    156                 if (rc != EOK) {
    157                         printf(NAME ": Error resolving parent handle of HC with"
    158                             " SID %" PRIun ", skipping.\n", svcs[i]);
    159                         continue;
    160                 }
    161                 devman_handle_t dh;
    162                 rc = devman_fun_get_child(fh, &dh);
    163                 if (rc != EOK) {
    164                         printf(NAME ": Error resolving parent handle of HC with"
    165                             " SID %" PRIun ", skipping.\n", svcs[i]);
    166                         continue;
    167                 }
    168                 devman_handle_t *fhs = 0;
    169                 size_t count;
    170                 rc = devman_dev_get_functions(dh, &fhs, &count);
    171                 if (rc != EOK) {
    172                         printf(NAME ": Error siblings of HC with"
    173                             " SID %" PRIun ", skipping.\n", svcs[i]);
    174                         continue;
    175                 }
    176                 print_usb_devices(hc_handle, fhs, count);
    177                 free(fhs);
     129                print_hc_devices(hc_handle);
    178130        }
    179131
Note: See TracChangeset for help on using the changeset viewer.