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