00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <inttypes.h>
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <errno.h>
00041 #include <str_error.h>
00042 #include <bool.h>
00043 #include <getopt.h>
00044 #include <devman.h>
00045 #include <devmap.h>
00046 #include <usb/dev/hub.h>
00047 #include <usb/hc.h>
00048
00049 #define NAME "lsusb"
00050
00051 #define MAX_USB_ADDRESS USB11_ADDRESS_MAX
00052 #define MAX_FAILED_ATTEMPTS 10
00053 #define MAX_PATH_LENGTH 1024
00054
00055 static void print_found_hc(size_t class_index, const char *path)
00056 {
00057
00058 printf("Bus %02zu: %s\n", class_index, path);
00059 }
00060 static void print_found_dev(usb_address_t addr, const char *path)
00061 {
00062
00063 printf(" Device %02d: %s\n", addr, path);
00064 }
00065
00066 static void print_hc_devices(devman_handle_t hc_handle)
00067 {
00068 int rc;
00069 usb_hc_connection_t conn;
00070
00071 usb_hc_connection_initialize(&conn, hc_handle);
00072 rc = usb_hc_connection_open(&conn);
00073 if (rc != EOK) {
00074 printf(NAME ": failed to connect to HC: %s.\n",
00075 str_error(rc));
00076 return;
00077 }
00078 usb_address_t addr;
00079 for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
00080 devman_handle_t dev_handle;
00081 rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
00082 if (rc != EOK) {
00083 continue;
00084 }
00085 char path[MAX_PATH_LENGTH];
00086 rc = devman_get_device_path(dev_handle, path, MAX_PATH_LENGTH);
00087 if (rc != EOK) {
00088 continue;
00089 }
00090 print_found_dev(addr, path);
00091 }
00092 usb_hc_connection_close(&conn);
00093 }
00094
00095 int main(int argc, char *argv[])
00096 {
00097 size_t class_index = 0;
00098 size_t failed_attempts = 0;
00099
00100 while (failed_attempts < MAX_FAILED_ATTEMPTS) {
00101 class_index++;
00102 devman_handle_t hc_handle = 0;
00103 int rc = usb_ddf_get_hc_handle_by_class(class_index, &hc_handle);
00104 if (rc != EOK) {
00105 failed_attempts++;
00106 continue;
00107 }
00108 char path[MAX_PATH_LENGTH];
00109 rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
00110 if (rc != EOK) {
00111 continue;
00112 }
00113 print_found_hc(class_index, path);
00114 print_hc_devices(hc_handle);
00115 }
00116
00117 return 0;
00118 }
00119
00120