Changes in / [2ef036a:fcf07e6] in mainline
- Location:
- uspace
- Files:
-
- 2 added
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/info.c
r2ef036a rfcf07e6 107 107 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor)); 108 108 109 rc = EOK;110 goto leave;111 112 109 /* 113 110 * Get first configuration descriptor and dump it. -
uspace/app/usbinfo/main.c
r2ef036a rfcf07e6 43 43 #include <devman.h> 44 44 #include <devmap.h> 45 #include <usb/usbdevice.h>46 #include <usb/pipes.h>47 45 #include "usbinfo.h" 46 47 enum { 48 ACTION_HELP = 256, 49 ACTION_DEVICE_ADDRESS, 50 ACTION_HOST_CONTROLLER, 51 ACTION_DEVICE, 52 }; 53 54 static struct option long_options[] = { 55 {"help", no_argument, NULL, ACTION_HELP}, 56 {"address", required_argument, NULL, ACTION_DEVICE_ADDRESS}, 57 {"host-controller", required_argument, NULL, ACTION_HOST_CONTROLLER}, 58 {"device", required_argument, NULL, ACTION_DEVICE}, 59 {0, 0, NULL, 0} 60 }; 61 static const char *short_options = "ha:t:d:"; 48 62 49 63 static void print_usage(char *app_name) … … 51 65 #define INDENT " " 52 66 printf(NAME ": query USB devices for descriptors\n\n"); 53 printf("Usage: %s [options] device [device [device [ ... ]]]\n", 54 app_name); 55 printf(INDENT "The device is a devman path to the device.\n"); 67 printf("Usage: %s [options]\n", app_name); 68 printf(" -h --help\n" INDENT \ 69 "Display this help.\n"); 70 printf(" -tID --host-controller ID\n" INDENT \ 71 "Set host controller (ID can be path or class number)\n"); 72 printf(" -aADDR --address ADDR\n" INDENT \ 73 "Set device address\n"); 56 74 printf("\n"); 57 75 #undef INDENT 58 76 } 59 77 60 static bool resolve_hc_handle_and_dev_addr(const char *devpath,61 devman_handle_t * out_hc_handle, usb_address_t *out_device_address)78 static int get_host_controller_handle(const char *path, 79 devman_handle_t *hc_handle) 62 80 { 63 81 int rc; 64 82 65 char *path = str_dup(devpath); 66 if (path == NULL) { 67 return ENOMEM; 83 if (str_cmp(path, "uhci") == 0) { 84 path = "/hw/pci0/00:01.2/uhci-hc"; 68 85 } 69 86 70 devman_handle_t hc = 0; 71 bool hc_found = false; 72 usb_address_t addr = 0; 73 bool addr_found = false; 87 devman_handle_t handle; 88 rc = devman_device_get_handle(path, &handle, 0); 89 if (rc != EOK) { 90 fprintf(stderr, 91 NAME ": failed getting handle of `devman::/%s'.\n", 92 path); 93 return rc; 94 } 95 *hc_handle = handle; 74 96 75 /* Remove suffixes and hope that we will encounter device node. */ 76 while (str_length(path) > 0) { 77 /* Get device handle first. */ 78 devman_handle_t dev_handle; 79 rc = devman_device_get_handle(path, &dev_handle, 0); 80 if (rc != EOK) { 81 free(path); 82 return false; 83 } 97 return EOK; 98 } 84 99 85 /* Try to find its host controller. */ 86 if (!hc_found) { 87 rc = usb_hc_find(dev_handle, &hc); 88 if (rc == EOK) { 89 hc_found = true; 90 } 91 } 92 /* Try to get its address. */ 93 if (!addr_found) { 94 addr = usb_device_get_assigned_address(dev_handle); 95 if (addr >= 0) { 96 addr_found = true; 97 } 98 } 99 100 /* Speed-up. */ 101 if (hc_found && addr_found) { 102 break; 103 } 104 105 /* Remove the last suffix. */ 106 char *slash_pos = str_rchr(path, '/'); 107 if (slash_pos != NULL) { 108 *slash_pos = 0; 109 } 100 static int get_device_address(const char *str_address, usb_address_t *address) 101 { 102 usb_address_t addr = (usb_address_t) strtol(str_address, NULL, 0); 103 if ((addr < 0) || (addr >= USB11_ADDRESS_MAX)) { 104 fprintf(stderr, NAME ": USB address out of range.\n"); 105 return ERANGE; 110 106 } 111 107 112 free(path); 108 *address = addr; 109 return EOK; 110 } 113 111 114 if (hc_found && addr_found) {115 if (out_hc_handle != NULL) {116 *out_hc_handle = hc;117 }118 if (out_device_address != NULL) {119 *out_device_address = addr;120 }121 return true;122 } else {123 return false;124 }125 }126 112 127 113 int main(int argc, char *argv[]) 128 114 { 115 devman_handle_t hc_handle = (devman_handle_t) -1; 116 usb_address_t device_address = (usb_address_t) -1; 117 129 118 if (argc <= 1) { 130 119 print_usage(argv[0]); … … 132 121 } 133 122 134 /* 135 * Process command-line options. They determine what shall be 136 * done with the device. 137 */ 123 int i; 124 do { 125 i = getopt_long(argc, argv, short_options, long_options, NULL); 126 switch (i) { 127 case -1: 128 break; 138 129 139 /* TODO */ 130 case '?': 131 print_usage(argv[0]); 132 return -1; 140 133 141 /* 142 * Go through all devices given on the command line and run the 143 * specified actions. 144 */ 145 int i; 146 for (i = 1; i < argc; i++) { 147 char *devpath = argv[i]; 134 case 'h': 135 case ACTION_HELP: 136 print_usage(argv[0]); 137 return 0; 148 138 149 /* The initialization is here only to make compiler happy. */ 150 devman_handle_t hc_handle = 0; 151 usb_address_t dev_addr = 0; 152 bool found = resolve_hc_handle_and_dev_addr(devpath, 153 &hc_handle, &dev_addr); 154 if (!found) { 155 fprintf(stderr, NAME ": device `%s' not found " 156 "or not of USB kind, skipping.\n", 157 devpath); 158 continue; 139 case 'a': 140 case ACTION_DEVICE_ADDRESS: { 141 int rc = get_device_address(optarg, 142 &device_address); 143 if (rc != EOK) { 144 return rc; 145 } 146 break; 147 } 148 149 case 't': 150 case ACTION_HOST_CONTROLLER: { 151 int rc = get_host_controller_handle(optarg, 152 &hc_handle); 153 if (rc != EOK) { 154 return rc; 155 } 156 break; 157 } 158 159 case 'd': 160 case ACTION_DEVICE: 161 break; 162 163 default: 164 break; 159 165 } 160 166 161 printf("Device `%s':\n------------\n", devpath); 162 dump_device(hc_handle, dev_addr); 167 } while (i != -1); 168 169 if ((hc_handle == (devman_handle_t) -1) 170 || (device_address == (usb_address_t) -1)) { 171 fprintf(stderr, NAME ": no target specified.\n"); 172 return EINVAL; 163 173 } 174 175 dump_device(hc_handle, device_address); 164 176 165 177 return 0; -
uspace/lib/usb/include/usb/pipes.h
r2ef036a rfcf07e6 123 123 124 124 int usb_device_get_assigned_interface(ddf_dev_t *); 125 usb_address_t usb_device_get_assigned_address(devman_handle_t);126 125 127 126 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *, -
uspace/lib/usb/src/pipes.c
r2ef036a rfcf07e6 52 52 sysarg_t address; 53 53 54 54 55 /* 55 56 * We are sending special value as a handle - zero - to get … … 93 94 94 95 return (int) iface_no; 95 }96 97 /** Tell USB address assigned to given device.98 *99 * @param dev_handle Devman handle of the USB device in question.100 * @return USB address or negative error code.101 */102 usb_address_t usb_device_get_assigned_address(devman_handle_t dev_handle)103 {104 int parent_phone = devman_parent_device_connect(dev_handle,105 IPC_FLAG_BLOCKING);106 if (parent_phone < 0) {107 return parent_phone;108 }109 110 sysarg_t address;111 112 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),113 IPC_M_USB_GET_ADDRESS,114 dev_handle, &address);115 116 if (rc != EOK) {117 return rc;118 }119 120 async_hangup(parent_phone);121 122 return (usb_address_t) address;123 96 } 124 97
Note:
See TracChangeset
for help on using the changeset viewer.