Changeset b4b534ac in mainline for uspace/app/usbinfo/list.c


Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 from lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

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

    r5b18137 rb4b534ac  
    4444#include <devman.h>
    4545#include <loc.h>
    46 #include <usb/dev/hub.h>
    47 #include <usb/hc.h>
     46#include <usb_iface.h>
    4847
    4948#include "usbinfo.h"
    5049
    51 #define MAX_USB_ADDRESS USB11_ADDRESS_MAX
    5250#define MAX_PATH_LENGTH 1024
    5351
    54 static void print_found_hc(service_id_t sid, const char *path)
     52static void print_usb_device(devman_handle_t handle)
    5553{
    56         printf("Bus %" PRIun ": %s\n", sid, path);
    57 }
    58 static void print_found_dev(usb_address_t addr, const char *path)
    59 {
    60         printf("  Device %02d: %s\n", addr, path);
     54        char path[MAX_PATH_LENGTH];
     55        int rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH);
     56        if (rc != EOK) {
     57                printf(NAME "Failed to get path for device %"PRIun"\n", handle);
     58                return;
     59        }
     60        printf("\tDevice %" PRIun ": %s\n", handle, path);
    6161}
    6262
    63 static void print_hc_devices(devman_handle_t hc_handle)
     63static void print_usb_bus(service_id_t svc)
    6464{
    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);
     65        devman_handle_t hc_handle = 0;
     66        int rc = devman_fun_sid_to_handle(svc, &hc_handle);
    7067        if (rc != EOK) {
    71                 printf(NAME ": failed to connect to HC: %s.\n",
    72                     str_error(rc));
     68                printf(NAME ": Error resolving handle of HC with SID %"
     69                    PRIun ", skipping.\n", svc);
    7370                return;
    7471        }
    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);
    79                 if (rc != EOK) {
    80                         continue;
    81                 }
    82                 char path[MAX_PATH_LENGTH];
    83                 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
    84                 if (rc != EOK) {
    85                         continue;
    86                 }
    87                 print_found_dev(addr, path);
     72
     73        char path[MAX_PATH_LENGTH];
     74        rc = devman_fun_get_path(hc_handle, path, sizeof(path));
     75        if (rc != EOK) {
     76                printf(NAME ": Error resolving path of HC with SID %"
     77                    PRIun ", skipping.\n", svc);
     78                return;
    8879        }
    89         usb_hc_connection_close(&conn);
     80        printf("Bus %" PRIun ": %s\n", svc, path);
     81
     82        /* Construct device's path.
     83         * That's "hc function path" - ( '/' + "hc function name" ) */
     84        // TODO replace this with something sane
     85
     86        /* Get function name */
     87        char name[10];
     88        rc = devman_fun_get_name(hc_handle, name, sizeof(name));
     89        if (rc != EOK) {
     90                printf(NAME ": Error resolving name of HC with SID %"
     91                    PRIun ", skipping.\n", svc);
     92                return;
     93        }
     94
     95        /* Get handle of parent device */
     96        devman_handle_t fh;
     97        path[str_size(path) - str_size(name) - 1] = '\0';
     98        rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
     99        if (rc != EOK) {
     100                printf(NAME ": Error resolving parent handle of HC with"
     101                    " SID %" PRIun ", skipping.\n", svc);
     102                return;
     103        }
     104
     105        /* Get child handle */
     106        devman_handle_t dh;
     107        rc = devman_fun_get_child(fh, &dh);
     108        if (rc != EOK) {
     109                printf(NAME ": Error resolving parent handle of HC with"
     110                    " SID %" PRIun ", skipping.\n", svc);
     111                return;
     112        }
     113       
     114        devman_handle_t *fhs = 0;
     115        size_t count;
     116        rc = devman_dev_get_functions(dh, &fhs, &count);
     117        if (rc != EOK) {
     118                printf(NAME ": Error siblings of HC with"
     119                    " SID %" PRIun ", skipping.\n", svc);
     120                return;
     121        }
     122
     123        for (size_t i = 0; i < count; ++i) {
     124                if (fhs[i] != hc_handle)
     125                        print_usb_device(fhs[i]);
     126        }
     127        free(fhs);
    90128}
    91129
     
    95133        service_id_t *svcs;
    96134        size_t count;
    97         size_t i;
    98135        int rc;
    99136
     
    111148        }
    112149
    113         for (i = 0; i < count; i++) {
    114                 devman_handle_t hc_handle = 0;
    115                 int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
    116                 if (rc != EOK) {
    117                         printf(NAME ": Error resolving handle of HC with SID %"
    118                             PRIun ", skipping.\n", svcs[i]);
    119                         continue;
    120                 }
    121                 char path[MAX_PATH_LENGTH];
    122                 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
    123                 if (rc != EOK) {
    124                         printf(NAME ": Error resolving path of HC with SID %"
    125                             PRIun ", skipping.\n", svcs[i]);
    126                         continue;
    127                 }
    128                 print_found_hc(svcs[i], path);
    129                 print_hc_devices(hc_handle);
     150        for (unsigned i = 0; i < count; ++i) {
     151                print_usb_bus(svcs[i]);
    130152        }
    131153
Note: See TracChangeset for help on using the changeset viewer.