Changeset f3922c2 in mainline


Ignore:
Timestamp:
2013-07-26T12:16:18Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b0fc92c
Parents:
e242fba
Message:

libusb, usbinfo: Stop using USB address as external identifier.

We already have devman handles and paths, use those.

Location:
uspace
Files:
2 edited

Legend:

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

    re242fba rf3922c2  
    5555        int rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH);
    5656        if (rc != EOK) {
    57                 printf(NAME "Failed to get path for device %" PRIun
    58                     "\n", handle);
     57                printf(NAME "Failed to get path for device %"PRIun"\n", handle);
    5958                return;
    6059        }
    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         async_exch_t *exch = async_exchange_begin(sess);
    65        
    66         usb_address_t address;
    67         rc = usb_get_my_address(exch, &address);
    68        
    69         async_exchange_end(exch);
    70         usb_dev_disconnect(sess);
    71         if (rc != EOK) {
    72                 printf("Failed to get address for device %" PRIun "\n", handle);
    73                 return;
    74         }
    75         printf("\tDevice %02d: %s\n", address, path);
     60        printf("\tDevice %" PRIun ": %s\n", handle, path);
    7661}
    7762
  • uspace/lib/usb/src/dev.c

    re242fba rf3922c2  
    3535#include <stdio.h>
    3636
    37 #define MAX_DEVICE_PATH 1024
    38 
    39 static bool try_parse_bus_and_address(const char *path,
    40     const char **func_start,
    41     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    42 {
    43         uint64_t sid;
    44         size_t address;
    45         int rc;
    46         const char *ptr;
    47 
    48         rc = str_uint64_t(path, &ptr, 10, false, &sid);
    49         if (rc != EOK) {
    50                 return false;
    51         }
    52         if ((*ptr == ':') || (*ptr == '.')) {
    53                 ptr++;
    54         } else {
    55                 return false;
    56         }
    57         rc = str_size_t(ptr, func_start, 10, false, &address);
    58         if (rc != EOK) {
    59                 return false;
    60         }
    61         rc = usb_ddf_get_hc_handle_by_sid(sid, out_hc_handle);
    62         if (rc != EOK) {
    63                 return false;
    64         }
    65         if (out_device_address != NULL) {
    66                 *out_device_address = (usb_address_t) address;
    67         }
    68         return true;
    69 }
    70 
    71 static int get_device_handle_by_address(devman_handle_t hc_handle, int addr,
    72     devman_handle_t *dev_handle)
    73 {
    74         usb_hc_connection_t conn;
    75         usb_hc_connection_initialize(&conn, hc_handle);
    76 
    77         const int rc = usb_hc_get_handle_by_address(&conn, addr, dev_handle);
    78 
    79         return rc;
    80 }
    81 
    8237/** Resolve handle and address of USB device from its path.
    8338 *
     
    10560        }
    10661
    107         devman_handle_t hc;
    108         usb_address_t addr = -1;
    109         int rc;
    110         const char *func_start = NULL;
    111         char *path = NULL;
     62        /* First, try to get the device handle. */
     63        int rc = devman_fun_get_handle(dev_path, dev_handle, 0);
    11264
    113         /* First try the BUS.ADDR format. */
    114         if (try_parse_bus_and_address(dev_path, &func_start, &hc, &addr)) {
    115                 /*
    116                  * Now get the handle of the device. We will need that
    117                  * in both cases. If there is only BUS.ADDR, it will
    118                  * be the handle to be returned to the caller, otherwise
    119                  * we will need it to resolve the path to which the
    120                  * suffix would be appended.
    121                  */
    122                 /* If there is nothing behind the BUS.ADDR, we will
    123                  * get the device handle from the host controller.
    124                  * Otherwise, we will
    125                  */
    126 
    127                 rc = get_device_handle_by_address(hc, addr, dev_handle);
    128                 if (rc != EOK) {
    129                         return rc;
    130                 }
    131                 if (str_length(func_start) > 0) {
    132                         char tmp_path[MAX_DEVICE_PATH];
    133                         rc = devman_fun_get_path(*dev_handle,
    134                             tmp_path, MAX_DEVICE_PATH);
    135                         if (rc != EOK) {
    136                                 return rc;
    137                         }
    138                         rc = asprintf(&path, "%s%s", tmp_path, func_start);
    139                         if (rc < 0) {
    140                                 return ENOMEM;
    141                         }
    142                 } else {
    143                         /* Everything is resolved. Get out of here. */
    144                         return EOK;
    145                 }
    146         } else {
    147                 path = str_dup(dev_path);
    148                 if (path == NULL) {
    149                         return ENOMEM;
    150                 }
     65        /* Next, try parsing dev_handle from the provided string */
     66        if (rc != EOK) {
     67                *dev_handle = strtoul(dev_path, NULL, 10);
     68                //FIXME: check errno
     69                rc = EOK;
    15170        }
    152 
    153         /* First try to get the device handle. */
    154         rc = devman_fun_get_handle(path, dev_handle, 0);
    155         if (rc != EOK) {
    156                 free(path);
    157                 /* Invalid path altogether. */
    158                 return rc;
    159         }
    160 
    161         /* Remove suffixes and hope that we will encounter device node. */
    162         while (str_length(path) > 0) {
    163                 /* Get device handle first. */
    164                 devman_handle_t tmp_handle;
    165                 rc = devman_fun_get_handle(path, &tmp_handle, 0);
    166                 if (rc != EOK) {
    167                         free(path);
    168                         return rc;
    169                 }
    170 
    171                 /* Remove the last suffix. */
    172                 char *slash_pos = str_rchr(path, '/');
    173                 if (slash_pos != NULL) {
    174                         *slash_pos = 0;
    175                 }
    176         }
    177 
    178         free(path);
    179 
    180 
    181         return EOK;
     71        return rc;
    18272}
Note: See TracChangeset for help on using the changeset viewer.