Changes in uspace/app/usbinfo/list.c [f3922c2:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/list.c
rf3922c2 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 52 static void print_ usb_device(devman_handle_t handle)54 static void print_found_hc(service_id_t sid, const char *path) 53 55 { 54 char path[MAX_PATH_LENGTH]; 55 int rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH); 56 printf("Bus %" PRIun ": %s\n", sid, path); 57 } 58 static void print_found_dev(usb_address_t addr, const char *path) 59 { 60 printf(" Device %02d: %s\n", addr, path); 61 } 62 63 static void print_hc_devices(devman_handle_t hc_handle) 64 { 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); 56 70 if (rc != EOK) { 57 printf(NAME "Failed to get path for device %"PRIun"\n", handle); 71 printf(NAME ": failed to connect to HC: %s.\n", 72 str_error(rc)); 58 73 return; 59 74 } 60 printf("\tDevice %" PRIun ": %s\n", handle, path); 61 } 62 63 static void print_usb_bus(service_id_t svc) 64 { 65 devman_handle_t hc_handle = 0; 66 int rc = devman_fun_sid_to_handle(svc, &hc_handle); 67 if (rc != EOK) { 68 printf(NAME ": Error resolving handle of HC with SID %" 69 PRIun ", skipping.\n", svc); 70 return; 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); 79 if (rc != EOK) { 80 continue; 81 } 82 char path[MAX_PATH_LENGTH]; 83 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH); 84 if (rc != EOK) { 85 continue; 86 } 87 print_found_dev(addr, path); 71 88 } 72 73 char path[MAX_PATH_LENGTH]; 74 rc = devman_fun_get_path(hc_handle, path, sizeof(path)); 75 if (rc != EOK) { 76 printf(NAME ": Error resolving path of HC with SID %" 77 PRIun ", skipping.\n", svc); 78 return; 79 } 80 printf("Bus %" PRIun ": %s\n", svc, path); 81 82 /* Construct device's path. 83 * That's "hc function path" - ( '/' + "hc function name" ) */ 84 // TODO replace this with something sane 85 86 /* Get function name */ 87 char name[10]; 88 rc = devman_fun_get_name(hc_handle, name, sizeof(name)); 89 if (rc != EOK) { 90 printf(NAME ": Error resolving name of HC with SID %" 91 PRIun ", skipping.\n", svc); 92 return; 93 } 94 95 /* Get handle of parent device */ 96 devman_handle_t fh; 97 path[str_size(path) - str_size(name) - 1] = '\0'; 98 rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING); 99 if (rc != EOK) { 100 printf(NAME ": Error resolving parent handle of HC with" 101 " SID %" PRIun ", skipping.\n", svc); 102 return; 103 } 104 105 /* Get child handle */ 106 devman_handle_t dh; 107 rc = devman_fun_get_child(fh, &dh); 108 if (rc != EOK) { 109 printf(NAME ": Error resolving parent handle of HC with" 110 " SID %" PRIun ", skipping.\n", svc); 111 return; 112 } 113 114 devman_handle_t *fhs = 0; 115 size_t count; 116 rc = devman_dev_get_functions(dh, &fhs, &count); 117 if (rc != EOK) { 118 printf(NAME ": Error siblings of HC with" 119 " SID %" PRIun ", skipping.\n", svc); 120 return; 121 } 122 123 for (size_t i = 0; i < count; ++i) { 124 if (fhs[i] != hc_handle) 125 print_usb_device(fhs[i]); 126 } 127 free(fhs); 89 usb_hc_connection_close(&conn); 128 90 } 129 91 … … 133 95 service_id_t *svcs; 134 96 size_t count; 97 size_t i; 135 98 int rc; 136 99 … … 148 111 } 149 112 150 for (unsigned i = 0; i < count; ++i) { 151 print_usb_bus(svcs[i]); 113 for (i = 0; i < count; i++) { 114 devman_handle_t hc_handle = 0; 115 int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle); 116 if (rc != EOK) { 117 printf(NAME ": Error resolving handle of HC with SID %" 118 PRIun ", skipping.\n", svcs[i]); 119 continue; 120 } 121 char path[MAX_PATH_LENGTH]; 122 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH); 123 if (rc != EOK) { 124 printf(NAME ": Error resolving path of HC with SID %" 125 PRIun ", skipping.\n", svcs[i]); 126 continue; 127 } 128 print_found_hc(svcs[i], path); 129 print_hc_devices(hc_handle); 152 130 } 153 131
Note:
See TracChangeset
for help on using the changeset viewer.