Changeset 96f2aa6 in mainline
- Timestamp:
- 2011-05-20T20:24:17Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e8f826b
- Parents:
- a9ab7f47
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/main.c
ra9ab7f47 r96f2aa6 44 44 #include <devmap.h> 45 45 #include <usb/hc.h> 46 #include <usb/driver.h> 46 47 #include <usb/dev/pipes.h> 47 48 #include <usb/driver.h> 48 49 #include "usbinfo.h" 49 50 static bool try_parse_class_and_address(const char *path,51 devman_handle_t *out_hc_handle, usb_address_t *out_device_address)52 {53 size_t class_index;54 size_t address;55 int rc;56 char *ptr;57 58 rc = str_size_t(path, &ptr, 10, false, &class_index);59 if (rc != EOK) {60 return false;61 }62 if ((*ptr == ':') || (*ptr == '.')) {63 ptr++;64 } else {65 return false;66 }67 rc = str_size_t(ptr, NULL, 10, true, &address);68 if (rc != EOK) {69 return false;70 }71 rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);72 if (rc != EOK) {73 return false;74 }75 if (out_device_address != NULL) {76 *out_device_address = (usb_address_t) address;77 }78 return true;79 }80 81 static bool resolve_hc_handle_and_dev_addr(const char *devpath,82 devman_handle_t *out_hc_handle, usb_address_t *out_device_address)83 {84 int rc;85 86 /* Hack for QEMU to save-up on typing ;-). */87 if (str_cmp(devpath, "qemu") == 0) {88 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1";89 }90 91 /* Hack for virtual keyboard. */92 if (str_cmp(devpath, "virt") == 0) {93 devpath = "/virt/usbhc/usb00_a1/usb00_a2";94 }95 96 if (try_parse_class_and_address(devpath,97 out_hc_handle, out_device_address)) {98 return true;99 }100 101 char *path = str_dup(devpath);102 if (path == NULL) {103 return ENOMEM;104 }105 106 devman_handle_t hc = 0;107 bool hc_found = false;108 usb_address_t addr = 0;109 bool addr_found = false;110 111 /* Remove suffixes and hope that we will encounter device node. */112 while (str_length(path) > 0) {113 /* Get device handle first. */114 devman_handle_t dev_handle;115 rc = devman_device_get_handle(path, &dev_handle, 0);116 if (rc != EOK) {117 free(path);118 return false;119 }120 121 /* Try to find its host controller. */122 if (!hc_found) {123 rc = usb_hc_find(dev_handle, &hc);124 if (rc == EOK) {125 hc_found = true;126 }127 }128 /* Try to get its address. */129 if (!addr_found) {130 addr = usb_hc_get_address_by_handle(dev_handle);131 if (addr >= 0) {132 addr_found = true;133 }134 }135 136 /* Speed-up. */137 if (hc_found && addr_found) {138 break;139 }140 141 /* Remove the last suffix. */142 char *slash_pos = str_rchr(path, '/');143 if (slash_pos != NULL) {144 *slash_pos = 0;145 }146 }147 148 free(path);149 150 if (hc_found && addr_found) {151 if (out_hc_handle != NULL) {152 *out_hc_handle = hc;153 }154 if (out_device_address != NULL) {155 *out_device_address = addr;156 }157 return true;158 } else {159 return false;160 }161 }162 50 163 51 static void print_usage(char *app_name) … … 299 187 devman_handle_t hc_handle = 0; 300 188 usb_address_t dev_addr = 0; 301 bool found = resolve_hc_handle_and_dev_addr(devpath,302 &hc_handle, &dev_addr );303 if ( !found) {189 int rc = usb_resolve_device_handle(devpath, 190 &hc_handle, &dev_addr, NULL); 191 if (rc != EOK) { 304 192 fprintf(stderr, NAME ": device `%s' not found " 305 193 "or not of USB kind, skipping.\n",
Note:
See TracChangeset
for help on using the changeset viewer.