Changeset 361e61b in mainline for uspace/app/usbinfo/info.c
- Timestamp:
- 2011-03-21T14:23:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 55e388a1
- Parents:
- c32688d (diff), 48fe0c9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/info.c
rc32688d r361e61b 40 40 #include <usb/recognise.h> 41 41 #include <usb/request.h> 42 #include <usb/classes/classes.h> 43 #include <usb/classes/hid.h> 44 #include <usb/classes/hub.h> 42 45 #include "usbinfo.h" 43 46 44 int dump_device(devman_handle_t hc_handle, usb_address_t address) 45 { 46 int rc; 47 usb_device_connection_t wire; 48 usb_endpoint_pipe_t ctrl_pipe; 49 50 /* 51 * Initialize pipes. 52 */ 53 rc = usb_device_connection_initialize(&wire, hc_handle, address); 54 if (rc != EOK) { 55 fprintf(stderr, 56 NAME ": failed to create connection to the device: %s.\n", 57 str_error(rc)); 58 goto leave; 59 } 60 rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe, &wire); 61 if (rc != EOK) { 62 fprintf(stderr, 63 NAME ": failed to create default control pipe: %s.\n", 64 str_error(rc)); 65 goto leave; 66 } 67 rc = usb_endpoint_pipe_start_session(&ctrl_pipe); 68 if (rc != EOK) { 69 fprintf(stderr, 70 NAME ": failed to start session on control pipe: %s.\n", 71 str_error(rc)); 72 goto leave; 73 } 74 75 /* 76 * Dump information about possible match ids. 77 */ 78 match_id_list_t match_id_list; 79 init_match_ids(&match_id_list); 80 rc = usb_device_create_match_ids(&ctrl_pipe, &match_id_list); 81 if (rc != EOK) { 82 fprintf(stderr, 83 NAME ": failed to fetch match ids of the device: %s.\n", 84 str_error(rc)); 85 goto leave; 86 } 87 dump_match_ids(&match_id_list); 88 89 /* 90 * Get device descriptor and dump it. 91 */ 92 usb_standard_device_descriptor_t device_descriptor; 93 rc = usb_request_get_device_descriptor(&ctrl_pipe, &device_descriptor); 94 if (rc != EOK) { 95 fprintf(stderr, 96 NAME ": failed to fetch standard device descriptor: %s.\n", 97 str_error(rc)); 98 goto leave; 99 } 100 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor)); 101 102 /* 103 * Get first configuration descriptor and dump it. 104 */ 105 usb_standard_configuration_descriptor_t config_descriptor; 106 int config_index = 0; 107 rc = usb_request_get_bare_configuration_descriptor(&ctrl_pipe, 108 config_index, &config_descriptor); 109 if (rc != EOK) { 110 fprintf(stderr, 111 NAME ": failed to fetch standard configuration descriptor: %s.\n", 112 str_error(rc)); 113 goto leave; 114 } 115 //dump_standard_configuration_descriptor(config_index, &config_descriptor); 116 117 void *full_config_descriptor = malloc(config_descriptor.total_length); 118 rc = usb_request_get_full_configuration_descriptor(&ctrl_pipe, 119 config_index, 120 full_config_descriptor, config_descriptor.total_length, NULL); 121 if (rc != EOK) { 122 fprintf(stderr, 123 NAME ": failed to fetch full configuration descriptor: %s.\n", 124 str_error(rc)); 125 goto leave; 126 } 127 128 dump_descriptor_tree(full_config_descriptor, 129 config_descriptor.total_length); 130 131 /* 132 * Get supported languages of STRING descriptors. 133 */ 47 void dump_short_device_identification(usbinfo_device_t *dev) 48 { 49 printf("%sDevice 0x%04x by vendor 0x%04x\n", get_indent(0), 50 (int) dev->device_descriptor.product_id, 51 (int) dev->device_descriptor.vendor_id); 52 } 53 54 static void dump_match_ids_from_interface(uint8_t *descriptor, size_t depth, 55 void *arg) 56 { 57 if (depth != 1) { 58 return; 59 } 60 size_t descr_size = descriptor[0]; 61 if (descr_size < sizeof(usb_standard_interface_descriptor_t)) { 62 return; 63 } 64 int descr_type = descriptor[1]; 65 if (descr_type != USB_DESCTYPE_INTERFACE) { 66 return; 67 } 68 69 usbinfo_device_t *dev = (usbinfo_device_t *) arg; 70 71 usb_standard_interface_descriptor_t *iface 72 = (usb_standard_interface_descriptor_t *) descriptor; 73 74 printf("%sInterface #%d match ids (%s, 0x%02x, 0x%02x)\n", 75 get_indent(0), 76 (int) iface->interface_number, 77 usb_str_class(iface->interface_class), 78 (int) iface->interface_subclass, 79 (int) iface->interface_protocol); 80 81 match_id_list_t matches; 82 init_match_ids(&matches); 83 usb_device_create_match_ids_from_interface(&dev->device_descriptor, 84 iface, &matches); 85 dump_match_ids(&matches, get_indent(1)); 86 clean_match_ids(&matches); 87 } 88 89 void dump_device_match_ids(usbinfo_device_t *dev) 90 { 91 match_id_list_t matches; 92 init_match_ids(&matches); 93 usb_device_create_match_ids_from_device_descriptor( 94 &dev->device_descriptor, &matches); 95 printf("%sDevice match ids (0x%04x by 0x%04x, %s)\n", get_indent(0), 96 (int) dev->device_descriptor.product_id, 97 (int) dev->device_descriptor.vendor_id, 98 usb_str_class(dev->device_descriptor.device_class)); 99 dump_match_ids(&matches, get_indent(1)); 100 clean_match_ids(&matches); 101 102 usb_dp_walk_simple(dev->full_configuration_descriptor, 103 dev->full_configuration_descriptor_size, 104 usb_dp_standard_descriptor_nesting, 105 dump_match_ids_from_interface, 106 dev); 107 } 108 109 static void dump_descriptor_tree_brief_device(const char *prefix, 110 usb_standard_device_descriptor_t *descriptor) 111 { 112 printf("%sDevice (0x%04x by 0x%04x, %s, %zu configurations)\n", prefix, 113 (int) descriptor->product_id, 114 (int) descriptor->vendor_id, 115 usb_str_class(descriptor->device_class), 116 (size_t) descriptor->configuration_count); 117 } 118 119 static void dump_descriptor_tree_brief_configuration(const char *prefix, 120 usb_standard_configuration_descriptor_t *descriptor) 121 { 122 printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix, 123 (int) descriptor->configuration_number, 124 (size_t) descriptor->interface_count, 125 (size_t) descriptor->total_length); 126 } 127 128 static void dump_descriptor_tree_brief_interface(const char *prefix, 129 usb_standard_interface_descriptor_t *descriptor) 130 { 131 printf("%sInterface #%d (%s, 0x%02x, 0x%02x), alternate %d\n", prefix, 132 (int) descriptor->interface_number, 133 usb_str_class(descriptor->interface_class), 134 (int) descriptor->interface_subclass, 135 (int) descriptor->interface_protocol, 136 (int) descriptor->alternate_setting); 137 } 138 139 static void dump_descriptor_tree_brief_endpoint(const char *prefix, 140 usb_standard_endpoint_descriptor_t *descriptor) 141 { 142 usb_endpoint_t endpoint_no = descriptor->endpoint_address & 0xF; 143 usb_transfer_type_t transfer = descriptor->attributes & 0x3; 144 usb_direction_t direction = descriptor->endpoint_address & 0x80 145 ? USB_DIRECTION_IN : USB_DIRECTION_OUT; 146 printf("%sEndpoint #%d (%s %s, %zu)\n", prefix, 147 endpoint_no, usb_str_transfer_type(transfer), 148 direction == USB_DIRECTION_IN ? "in" : "out", 149 (size_t) descriptor->max_packet_size); 150 } 151 152 static void dump_descriptor_tree_brief_hid(const char *prefix, 153 usb_standard_hid_descriptor_t *descriptor) 154 { 155 printf("%sHID (country %d, %d descriptors)\n", prefix, 156 (int) descriptor->country_code, 157 (int) descriptor->class_desc_count); 158 } 159 160 static void dump_descriptor_tree_brief_hub(const char *prefix, 161 usb_hub_descriptor_header_t *descriptor) 162 { 163 printf("%shub (%d ports)\n", prefix, 164 (int) descriptor->port_count); 165 } 166 167 168 static void dump_descriptor_tree_callback(uint8_t *descriptor, 169 size_t depth, void *arg) 170 { 171 const char *indent = get_indent(depth + 1); 172 173 int descr_type = -1; 174 size_t descr_size = descriptor[0]; 175 if (descr_size > 0) { 176 descr_type = descriptor[1]; 177 } 178 179 switch (descr_type) { 180 181 #define _BRANCH(type_enum, descriptor_type, callback) \ 182 case type_enum: \ 183 if (descr_size >= sizeof(descriptor_type)) { \ 184 callback(indent, (descriptor_type *) descriptor); \ 185 if (arg != NULL) { \ 186 usb_dump_standard_descriptor(stdout, \ 187 get_indent(depth +2), "\n", \ 188 descriptor, descr_size); \ 189 } \ 190 } else { \ 191 descr_type = -1; \ 192 } \ 193 break; 194 195 _BRANCH(USB_DESCTYPE_DEVICE, 196 usb_standard_device_descriptor_t, 197 dump_descriptor_tree_brief_device); 198 _BRANCH(USB_DESCTYPE_CONFIGURATION, 199 usb_standard_configuration_descriptor_t, 200 dump_descriptor_tree_brief_configuration); 201 _BRANCH(USB_DESCTYPE_INTERFACE, 202 usb_standard_interface_descriptor_t, 203 dump_descriptor_tree_brief_interface); 204 _BRANCH(USB_DESCTYPE_ENDPOINT, 205 usb_standard_endpoint_descriptor_t, 206 dump_descriptor_tree_brief_endpoint); 207 _BRANCH(USB_DESCTYPE_HID, 208 usb_standard_hid_descriptor_t, 209 dump_descriptor_tree_brief_hid); 210 /* 211 * Probably useless, hub descriptor shall not be part of 212 * configuration descriptor. 213 */ 214 _BRANCH(USB_DESCTYPE_HUB, 215 usb_hub_descriptor_header_t, 216 dump_descriptor_tree_brief_hub); 217 218 default: 219 break; 220 } 221 222 if (descr_type == -1) { 223 printf("%sInvalid descriptor.\n", indent); 224 } 225 } 226 227 void dump_descriptor_tree_brief(usbinfo_device_t *dev) 228 { 229 dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor, 230 (size_t) -1, NULL); 231 usb_dp_walk_simple(dev->full_configuration_descriptor, 232 dev->full_configuration_descriptor_size, 233 usb_dp_standard_descriptor_nesting, 234 dump_descriptor_tree_callback, 235 NULL); 236 } 237 238 void dump_descriptor_tree_full(usbinfo_device_t *dev) 239 { 240 dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor, 241 (size_t) -1, dev); 242 usb_dp_walk_simple(dev->full_configuration_descriptor, 243 dev->full_configuration_descriptor_size, 244 usb_dp_standard_descriptor_nesting, 245 dump_descriptor_tree_callback, 246 dev); 247 } 248 249 250 void dump_strings(usbinfo_device_t *dev) 251 { 252 /* Get supported languages. */ 134 253 l18_win_locales_t *langs; 135 254 size_t langs_count; 136 rc = usb_request_get_supported_languages(&ctrl_pipe,255 int rc = usb_request_get_supported_languages(&dev->ctrl_pipe, 137 256 &langs, &langs_count); 138 257 if (rc != EOK) { … … 140 259 NAME ": failed to get list of supported languages: %s.\n", 141 260 str_error(rc)); 142 goto skip_strings;143 } 144 145 printf(" String languages (%zu):", langs_count);261 return; 262 } 263 264 printf("%sString languages (%zu):", get_indent(0), langs_count); 146 265 size_t i; 147 266 for (i = 0; i < langs_count; i++) { … … 150 269 printf(".\n"); 151 270 152 /* 153 * Dump all strings in all available langages; 154 */ 271 /* Get all strings and dump them. */ 155 272 for (i = 0; i < langs_count; i++) { 156 273 l18_win_locales_t lang = langs[i]; 157 274 158 printf("%sStrings for language 0x%04x:\n", get_indent(0), 159 (int) lang); 160 275 printf("%sStrings in %s:\n", get_indent(0), 276 str_l18_win_locale(lang)); 161 277 /* 162 * Try all indexes - we will see what pops-up ;-). 163 * However, to speed things up, we will stop after 164 * encountering several broken (or nonexistent ones) 165 * descriptors in line. 278 * Try only the first 15 strings 279 * (typically, device will not have much more anyway). 166 280 */ 167 281 size_t idx; 168 size_t failed_count = 0; 169 for (idx = 1; idx < 0xFF; idx++) { 282 for (idx = 1; idx < 0x0F; idx++) { 170 283 char *string; 171 rc = usb_request_get_string(& ctrl_pipe, idx, lang,284 rc = usb_request_get_string(&dev->ctrl_pipe, idx, lang, 172 285 &string); 173 286 if (rc != EOK) { 174 failed_count++;175 if (failed_count > 3) {176 break;177 }178 287 continue; 179 288 } … … 181 290 idx, string); 182 291 free(string); 183 failed_count = 0; /* Reset failed counter. */184 292 } 185 293 } 186 187 188 skip_strings:189 190 rc = EOK;191 192 leave:193 /* Ignoring errors here. */194 usb_endpoint_pipe_end_session(&ctrl_pipe);195 196 return rc;197 294 } 198 295
Note:
See TracChangeset
for help on using the changeset viewer.