Changeset 69b264a9 in mainline


Ignore:
Timestamp:
2013-07-24T17:43:30Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
205261f
Parents:
db71e2a
Message:

usbinfo: refactor usb device listing

File:
1 edited

Legend:

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

    rdb71e2a r69b264a9  
    5050#define MAX_PATH_LENGTH 1024
    5151
    52 static void print_found_hc(service_id_t sid, const char *path)
     52static void print_usb_device(devman_handle_t handle)
    5353{
    54         printf("Bus %" PRIun ": %s\n", sid, path);
    55 }
    56 static void print_found_dev(usb_address_t addr, const char *path)
    57 {
    58         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
     58                    "\n", handle);
     59                return;
     60        }
     61        // TODO remove this. Device name contains USB address
     62        // and addresses as external id are going away
     63        usb_dev_session_t *sess = usb_dev_connect(handle);
     64        if (!sess) {
     65                printf(NAME "Failed to connect to device %" PRIun "\n", handle);
     66                return;
     67        }
     68        async_exch_t *exch = async_exchange_begin(sess);
     69        if (!exch) {
     70                printf("Failed to create exchange to dev %" PRIun "\n", handle);
     71                usb_dev_disconnect(sess);
     72                return;
     73        }
     74        usb_address_t address;
     75        rc = usb_get_my_address(exch, &address);
     76        async_exchange_end(exch);
     77        usb_dev_disconnect(sess);
     78        if (rc != EOK) {
     79                printf("Failed to get address for device %" PRIun "\n", handle);
     80                return;
     81        }
     82        printf("\tDevice %02d: %s\n", address, path);
    5983}
    6084
    61 static void print_usb_devices(devman_handle_t bus_handle,
    62     devman_handle_t *fhs, size_t count)
     85static void print_usb_bus(service_id_t svc)
    6386{
     87        devman_handle_t hc_handle = 0;
     88        int rc = devman_fun_sid_to_handle(svc, &hc_handle);
     89        if (rc != EOK) {
     90                printf(NAME ": Error resolving handle of HC with SID %"
     91                    PRIun ", skipping.\n", svc);
     92                return;
     93        }
     94
     95        char path[MAX_PATH_LENGTH];
     96        rc = devman_fun_get_path(hc_handle, path, sizeof(path));
     97        if (rc != EOK) {
     98                printf(NAME ": Error resolving path of HC with SID %"
     99                    PRIun ", skipping.\n", svc);
     100                return;
     101        }
     102        printf("Bus %" PRIun ": %s\n", svc, path);
     103
     104        /* Construct device's path.
     105         * That's "hc function path" - ( '/' + "hc function name" ) */
     106        // TODO replace this with something sane
     107
     108        /* Get function name */
     109        char name[10];
     110        rc = devman_fun_get_name(hc_handle, name, sizeof(name));
     111        if (rc != EOK) {
     112                printf(NAME ": Error resolving name of HC with SID %"
     113                    PRIun ", skipping.\n", svc);
     114                return;
     115        }
     116
     117        /* Get handle of parent device */
     118        devman_handle_t fh;
     119        path[str_size(path) - str_size(name) - 1] = '\0';
     120        rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
     121        if (rc != EOK) {
     122                printf(NAME ": Error resolving parent handle of HC with"
     123                    " SID %" PRIun ", skipping.\n", svc);
     124                return;
     125        }
     126
     127        /* Get child handle */
     128        devman_handle_t dh;
     129        rc = devman_fun_get_child(fh, &dh);
     130        if (rc != EOK) {
     131                printf(NAME ": Error resolving parent handle of HC with"
     132                    " SID %" PRIun ", skipping.\n", svc);
     133                return;
     134        }
     135       
     136        devman_handle_t *fhs = 0;
     137        size_t count;
     138        rc = devman_dev_get_functions(dh, &fhs, &count);
     139        if (rc != EOK) {
     140                printf(NAME ": Error siblings of HC with"
     141                    " SID %" PRIun ", skipping.\n", svc);
     142                return;
     143        }
     144
    64145        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);
    70                 if (rc != EOK) {
    71                         printf(NAME "Failed to get path for device %" PRIun
    72                             "\n", fhs[i]);
    73                         continue;
    74                 }
    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]);
    81                         continue;
    82                 }
    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 
     146                if (fhs[i] != hc_handle)
     147                        print_usb_device(fhs[i]);
    101148        }
     149        free(fhs);
    102150}
    103151
     
    123171
    124172        for (unsigned i = 0; i < count; ++i) {
    125                 devman_handle_t hc_handle = 0;
    126                 int rc = devman_fun_sid_to_handle(svcs[i], &hc_handle);
    127                 if (rc != EOK) {
    128                         printf(NAME ": Error resolving handle of HC with SID %"
    129                             PRIun ", skipping.\n", svcs[i]);
    130                         continue;
    131                 }
    132 
    133                 char path[MAX_PATH_LENGTH];
    134                 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
    135                 if (rc != EOK) {
    136                         printf(NAME ": Error resolving path of HC with SID %"
    137                             PRIun ", skipping.\n", svcs[i]);
    138                         continue;
    139                 }
    140                 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);
     173                print_usb_bus(svcs[i]);
    178174        }
    179175
Note: See TracChangeset for help on using the changeset viewer.