Changes in uspace/app/usbinfo/list.c [fe9d542:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/list.c
rfe9d542 r3e6a98c5 44 44 #include <devman.h> 45 45 #include <loc.h> 46 #include <usb_iface.h> 46 #include <usb/dev/hub.h> 47 #include <usb/hc.h> 47 48 48 49 #include "usbinfo.h" 49 50 51 #define MAX_USB_ADDRESS USB11_ADDRESS_MAX 50 52 #define MAX_PATH_LENGTH 1024 51 53 … … 59 61 } 60 62 61 static void print_usb_devices(devman_handle_t bus_handle, 62 devman_handle_t *fhs, size_t count) 63 static void print_hc_devices(devman_handle_t hc_handle) 63 64 { 64 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); 65 int rc; 66 usb_hc_connection_t conn; 67 68 usb_hc_connection_initialize(&conn, hc_handle); 69 rc = usb_hc_connection_open(&conn); 70 if (rc != EOK) { 71 printf(NAME ": failed to connect to HC: %s.\n", 72 str_error(rc)); 73 return; 74 } 75 usb_address_t addr; 76 for (addr = 1; addr < MAX_USB_ADDRESS; addr++) { 77 devman_handle_t dev_handle; 78 rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle); 70 79 if (rc != EOK) { 71 printf(NAME "Failed to get path for device %" PRIun72 "\n", fhs[i]);73 80 continue; 74 81 } 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]); 82 char path[MAX_PATH_LENGTH]; 83 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH); 84 if (rc != EOK) { 81 85 continue; 82 86 } 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 87 print_found_dev(addr, path); 101 88 } 89 usb_hc_connection_close(&conn); 102 90 } 103 91 … … 107 95 service_id_t *svcs; 108 96 size_t count; 97 size_t i; 109 98 int rc; 110 99 … … 122 111 } 123 112 124 for ( unsigned i = 0; i < count; ++i) {113 for (i = 0; i < count; i++) { 125 114 devman_handle_t hc_handle = 0; 126 int rc = devman_fun_sid_to_handle(svcs[i], &hc_handle);115 int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle); 127 116 if (rc != EOK) { 128 117 printf(NAME ": Error resolving handle of HC with SID %" … … 130 119 continue; 131 120 } 132 133 121 char path[MAX_PATH_LENGTH]; 134 122 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH); … … 139 127 } 140 128 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); 129 print_hc_devices(hc_handle); 178 130 } 179 131
Note:
See TracChangeset
for help on using the changeset viewer.