Changes in / [2ef036a:fcf07e6] in mainline


Ignore:
Location:
uspace
Files:
2 added
3 deleted
4 edited

Legend:

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

    r2ef036a rfcf07e6  
    107107        dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
    108108
    109         rc = EOK;
    110         goto leave;
    111 
    112109        /*
    113110         * Get first configuration descriptor and dump it.
  • uspace/app/usbinfo/main.c

    r2ef036a rfcf07e6  
    4343#include <devman.h>
    4444#include <devmap.h>
    45 #include <usb/usbdevice.h>
    46 #include <usb/pipes.h>
    4745#include "usbinfo.h"
     46
     47enum {
     48        ACTION_HELP = 256,
     49        ACTION_DEVICE_ADDRESS,
     50        ACTION_HOST_CONTROLLER,
     51        ACTION_DEVICE,
     52};
     53
     54static struct option long_options[] = {
     55        {"help", no_argument, NULL, ACTION_HELP},
     56        {"address", required_argument, NULL, ACTION_DEVICE_ADDRESS},
     57        {"host-controller", required_argument, NULL, ACTION_HOST_CONTROLLER},
     58        {"device", required_argument, NULL, ACTION_DEVICE},
     59        {0, 0, NULL, 0}
     60};
     61static const char *short_options = "ha:t:d:";
    4862
    4963static void print_usage(char *app_name)
     
    5165#define INDENT "      "
    5266        printf(NAME ": query USB devices for descriptors\n\n");
    53         printf("Usage: %s [options] device [device [device [ ... ]]]\n",
    54             app_name);
    55         printf(INDENT "The device is a devman path to the device.\n");
     67        printf("Usage: %s [options]\n", app_name);
     68        printf(" -h --help\n" INDENT \
     69            "Display this help.\n");
     70        printf(" -tID --host-controller ID\n" INDENT \
     71            "Set host controller (ID can be path or class number)\n");
     72        printf(" -aADDR --address ADDR\n" INDENT \
     73            "Set device address\n");
    5674        printf("\n");
    5775#undef INDENT
    5876}
    5977
    60 static bool resolve_hc_handle_and_dev_addr(const char *devpath,
    61     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
     78static int get_host_controller_handle(const char *path,
     79    devman_handle_t *hc_handle)
    6280{
    6381        int rc;
    6482
    65         char *path = str_dup(devpath);
    66         if (path == NULL) {
    67                 return ENOMEM;
     83        if (str_cmp(path, "uhci") == 0) {
     84                path = "/hw/pci0/00:01.2/uhci-hc";
    6885        }
    6986
    70         devman_handle_t hc = 0;
    71         bool hc_found = false;
    72         usb_address_t addr = 0;
    73         bool addr_found = false;
     87        devman_handle_t handle;
     88        rc = devman_device_get_handle(path, &handle, 0);
     89        if (rc != EOK) {
     90                fprintf(stderr,
     91                    NAME ": failed getting handle of `devman::/%s'.\n",
     92                    path);
     93                return rc;
     94        }
     95        *hc_handle = handle;
    7496
    75         /* Remove suffixes and hope that we will encounter device node. */
    76         while (str_length(path) > 0) {
    77                 /* Get device handle first. */
    78                 devman_handle_t dev_handle;
    79                 rc = devman_device_get_handle(path, &dev_handle, 0);
    80                 if (rc != EOK) {
    81                         free(path);
    82                         return false;
    83                 }
     97        return EOK;
     98}
    8499
    85                 /* Try to find its host controller. */
    86                 if (!hc_found) {
    87                         rc = usb_hc_find(dev_handle, &hc);
    88                         if (rc == EOK) {
    89                                 hc_found = true;
    90                         }
    91                 }
    92                 /* Try to get its address. */
    93                 if (!addr_found) {
    94                         addr = usb_device_get_assigned_address(dev_handle);
    95                         if (addr >= 0) {
    96                                 addr_found = true;
    97                         }
    98                 }
    99 
    100                 /* Speed-up. */
    101                 if (hc_found && addr_found) {
    102                         break;
    103                 }
    104 
    105                 /* Remove the last suffix. */
    106                 char *slash_pos = str_rchr(path, '/');
    107                 if (slash_pos != NULL) {
    108                         *slash_pos = 0;
    109                 }
     100static int get_device_address(const char *str_address, usb_address_t *address)
     101{
     102        usb_address_t addr = (usb_address_t) strtol(str_address, NULL, 0);
     103        if ((addr < 0) || (addr >= USB11_ADDRESS_MAX)) {
     104                fprintf(stderr, NAME ": USB address out of range.\n");
     105                return ERANGE;
    110106        }
    111107
    112         free(path);
     108        *address = addr;
     109        return EOK;
     110}
    113111
    114         if (hc_found && addr_found) {
    115                 if (out_hc_handle != NULL) {
    116                         *out_hc_handle = hc;
    117                 }
    118                 if (out_device_address != NULL) {
    119                         *out_device_address = addr;
    120                 }
    121                 return true;
    122         } else {
    123                 return false;
    124         }
    125 }
    126112
    127113int main(int argc, char *argv[])
    128114{
     115        devman_handle_t hc_handle = (devman_handle_t) -1;
     116        usb_address_t device_address = (usb_address_t) -1;
     117
    129118        if (argc <= 1) {
    130119                print_usage(argv[0]);
     
    132121        }
    133122
    134         /*
    135          * Process command-line options. They determine what shall be
    136          * done with the device.
    137          */
     123        int i;
     124        do {
     125                i = getopt_long(argc, argv, short_options, long_options, NULL);
     126                switch (i) {
     127                        case -1:
     128                                break;
    138129
    139         /* TODO */
     130                        case '?':
     131                                print_usage(argv[0]);
     132                                return -1;
    140133
    141         /*
    142          * Go through all devices given on the command line and run the
    143          * specified actions.
    144          */
    145         int i;
    146         for (i = 1; i < argc; i++) {
    147                 char *devpath = argv[i];
     134                        case 'h':
     135                        case ACTION_HELP:
     136                                print_usage(argv[0]);
     137                                return 0;
    148138
    149                 /* The initialization is here only to make compiler happy. */
    150                 devman_handle_t hc_handle = 0;
    151                 usb_address_t dev_addr = 0;
    152                 bool found = resolve_hc_handle_and_dev_addr(devpath,
    153                     &hc_handle, &dev_addr);
    154                 if (!found) {
    155                         fprintf(stderr, NAME ": device `%s' not found "
    156                             "or not of USB kind, skipping.\n",
    157                             devpath);
    158                         continue;
     139                        case 'a':
     140                        case ACTION_DEVICE_ADDRESS: {
     141                                int rc = get_device_address(optarg,
     142                                    &device_address);
     143                                if (rc != EOK) {
     144                                        return rc;
     145                                }
     146                                break;
     147                        }
     148
     149                        case 't':
     150                        case ACTION_HOST_CONTROLLER: {
     151                                int rc = get_host_controller_handle(optarg,
     152                                   &hc_handle);
     153                                if (rc != EOK) {
     154                                        return rc;
     155                                }
     156                                break;
     157                        }
     158
     159                        case 'd':
     160                        case ACTION_DEVICE:
     161                                break;
     162
     163                        default:
     164                                break;
    159165                }
    160166
    161                 printf("Device `%s':\n------------\n", devpath);
    162                 dump_device(hc_handle, dev_addr);
     167        } while (i != -1);
     168
     169        if ((hc_handle == (devman_handle_t) -1)
     170            || (device_address == (usb_address_t) -1)) {
     171                fprintf(stderr, NAME ": no target specified.\n");
     172                return EINVAL;
    163173        }
     174
     175        dump_device(hc_handle, device_address);
    164176
    165177        return 0;
  • uspace/lib/usb/include/usb/pipes.h

    r2ef036a rfcf07e6  
    123123
    124124int usb_device_get_assigned_interface(ddf_dev_t *);
    125 usb_address_t usb_device_get_assigned_address(devman_handle_t);
    126125
    127126int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
  • uspace/lib/usb/src/pipes.c

    r2ef036a rfcf07e6  
    5252        sysarg_t address;
    5353
     54
    5455        /*
    5556         * We are sending special value as a handle - zero - to get
     
    9394
    9495        return (int) iface_no;
    95 }
    96 
    97 /** Tell USB address assigned to given device.
    98  *
    99  * @param dev_handle Devman handle of the USB device in question.
    100  * @return USB address or negative error code.
    101  */
    102 usb_address_t usb_device_get_assigned_address(devman_handle_t dev_handle)
    103 {
    104         int parent_phone = devman_parent_device_connect(dev_handle,
    105             IPC_FLAG_BLOCKING);
    106         if (parent_phone < 0) {
    107                 return parent_phone;
    108         }
    109 
    110         sysarg_t address;
    111 
    112         int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    113             IPC_M_USB_GET_ADDRESS,
    114             dev_handle, &address);
    115 
    116         if (rc != EOK) {
    117                 return rc;
    118         }
    119 
    120         async_hangup(parent_phone);
    121 
    122         return (usb_address_t) address;
    12396}
    12497
Note: See TracChangeset for help on using the changeset viewer.