Changes in uspace/app/usbinfo/main.c [eb48f61:c377bc50] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/main.c
reb48f61 rc377bc50 27 27 */ 28 28 29 /** @addtogroup usb info29 /** @addtogroup usb 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * USB querying.34 * @brief USB querying. 35 35 */ 36 36 … … 43 43 #include <devman.h> 44 44 #include <devmap.h> 45 #include <usb/usbdrv.h> 45 46 #include "usbinfo.h" 46 47 … … 76 77 } 77 78 78 static int get_host_controller_handle(const char *path, 79 devman_handle_t *hc_handle) 79 static int set_new_host_controller(int *phone, const char *path) 80 80 { 81 81 int rc; 82 83 if (str_cmp(path, "uhci") == 0) { 84 path = "/hw/pci0/00:01.2/uhci"; 85 } 86 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; 82 int tmp_phone; 83 84 if (path[0] != '/') { 85 int hc_class_index = (int) strtol(path, NULL, 10); 86 char *dev_path; 87 rc = asprintf(&dev_path, "class/usbhc\\%d", hc_class_index); 88 if (rc < 0) { 89 internal_error(rc); 90 return rc; 91 } 92 devmap_handle_t handle; 93 rc = devmap_device_get_handle(dev_path, &handle, 0); 94 if (rc < 0) { 95 fprintf(stderr, 96 NAME ": failed getting handle of `devman://%s'.\n", 97 dev_path); 98 free(dev_path); 99 return rc; 100 } 101 tmp_phone = devmap_device_connect(handle, 0); 102 if (tmp_phone < 0) { 103 fprintf(stderr, 104 NAME ": could not connect to `%s'.\n", 105 dev_path); 106 free(dev_path); 107 return tmp_phone; 108 } 109 free(dev_path); 110 } else { 111 devman_handle_t handle; 112 rc = devman_device_get_handle(path, &handle, 0); 113 if (rc != EOK) { 114 fprintf(stderr, 115 NAME ": failed getting handle of `devmap::/%s'.\n", 116 path); 117 return rc; 118 } 119 tmp_phone = devman_device_connect(handle, 0); 120 if (tmp_phone < 0) { 121 fprintf(stderr, 122 NAME ": could not connect to `%s'.\n", 123 path); 124 return tmp_phone; 125 } 126 } 127 128 *phone = tmp_phone; 96 129 97 130 return EOK; 98 131 } 99 132 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)) {133 static int connect_with_address(int hc_phone, const char *str_address) 134 { 135 usb_address_t address = (usb_address_t) strtol(str_address, NULL, 0); 136 if ((address < 0) || (address >= USB11_ADDRESS_MAX)) { 104 137 fprintf(stderr, NAME ": USB address out of range.\n"); 105 138 return ERANGE; 106 139 } 107 140 108 *address = addr; 109 return EOK; 141 if (hc_phone < 0) { 142 fprintf(stderr, NAME ": no active host controller.\n"); 143 return ENOENT; 144 } 145 146 return dump_device(hc_phone, address); 110 147 } 111 148 … … 113 150 int main(int argc, char *argv[]) 114 151 { 115 devman_handle_t hc_handle = (devman_handle_t) -1; 116 usb_address_t device_address = (usb_address_t) -1; 152 int hc_phone = -1; 117 153 118 154 if (argc <= 1) { … … 139 175 case 'a': 140 176 case ACTION_DEVICE_ADDRESS: { 141 int rc = get_device_address(optarg, 142 &device_address); 177 int rc = connect_with_address(hc_phone, optarg); 143 178 if (rc != EOK) { 144 179 return rc; … … 149 184 case 't': 150 185 case ACTION_HOST_CONTROLLER: { 151 int rc = get_host_controller_handle(optarg,152 &hc_handle);186 int rc = set_new_host_controller(&hc_phone, 187 optarg); 153 188 if (rc != EOK) { 154 189 return rc; … … 167 202 } while (i != -1); 168 203 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;173 }174 175 dump_device(hc_handle, device_address);176 177 204 return 0; 178 205 }
Note:
See TracChangeset
for help on using the changeset viewer.