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