Changeset e160da4d in mainline
- Timestamp:
- 2011-03-17T21:11:52Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da77278
- Parents:
- 81ca204
- Location:
- uspace/app/usbinfo
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/Makefile
r81ca204 re160da4d 34 34 35 35 SOURCES = \ 36 desctree.c \ 36 37 dev.c \ 37 38 dump.c \ -
uspace/app/usbinfo/dev.c
r81ca204 re160da4d 93 93 } 94 94 95 rc = usb_request_get_full_configuration_descriptor_alloc( 96 &dev->ctrl_pipe, 0, (void **)&dev->full_configuration_descriptor, 97 &dev->full_configuration_descriptor_size); 98 if (rc != EOK) { 99 fprintf(stderr, 100 NAME ": failed to retrieve configuration descriptor: %s.\n", 101 str_error(rc)); 102 goto leave; 103 } 104 95 105 return dev; 96 106 -
uspace/app/usbinfo/info.c
r81ca204 re160da4d 40 40 #include <usb/recognise.h> 41 41 #include <usb/request.h> 42 #include <usb/classes/classes.h> 42 43 #include "usbinfo.h" 43 44 … … 56 57 &dev->device_descriptor, &matches); 57 58 dump_match_ids(&matches, get_indent(0)); 59 } 60 61 static void dump_descriptor_tree_brief_device(const char *prefix, 62 usb_standard_device_descriptor_t *descriptor) 63 { 64 printf("%sDevice (0x%04x by 0x%04x, %s)\n", prefix, 65 (int) descriptor->product_id, 66 (int) descriptor->vendor_id, 67 usb_str_class(descriptor->device_class)); 68 } 69 70 static void dump_descriptor_tree_brief_configuration(const char *prefix, 71 usb_standard_configuration_descriptor_t *descriptor) 72 { 73 printf("%sConfiguration #%d\n", prefix, 74 (int) descriptor->configuration_number); 75 } 76 77 static void dump_descriptor_tree_brief_interface(const char *prefix, 78 usb_standard_interface_descriptor_t *descriptor) 79 { 80 printf("%sInterface #%d (%s, 0x%02x, 0x%02x)\n", prefix, 81 (int) descriptor->interface_number, 82 usb_str_class(descriptor->interface_class), 83 (int) descriptor->interface_subclass, 84 (int) descriptor->interface_protocol); 85 } 86 87 static void dump_descriptor_tree_brief_endpoint(const char *prefix, 88 usb_standard_endpoint_descriptor_t *descriptor) 89 { 90 usb_endpoint_t endpoint_no = descriptor->endpoint_address & 0xF; 91 usb_transfer_type_t transfer = descriptor->attributes & 0x3; 92 usb_direction_t direction = descriptor->endpoint_address & 0x80 93 ? USB_DIRECTION_IN : USB_DIRECTION_OUT; 94 printf("%sEndpoint #%d (%s %s, %zu)\n", prefix, 95 endpoint_no, usb_str_transfer_type(transfer), 96 direction == USB_DIRECTION_IN ? "in" : "out", 97 (size_t) descriptor->max_packet_size); 98 } 99 100 101 static void dump_descriptor_tree_brief_callback(uint8_t *descriptor, 102 size_t depth, void *arg) 103 { 104 const char *indent = get_indent(depth); 105 106 int descr_type = -1; 107 size_t descr_size = descriptor[0]; 108 if (descr_size > 0) { 109 descr_type = descriptor[1]; 110 } 111 112 switch (descr_type) { 113 114 #define _BRANCH(type_enum, descriptor_type, callback) \ 115 case type_enum: \ 116 if (descr_size >= sizeof(descriptor_type)) { \ 117 callback(indent, (descriptor_type *) descriptor); \ 118 } else { \ 119 descr_type = -1; \ 120 } \ 121 break; 122 123 _BRANCH(USB_DESCTYPE_DEVICE, 124 usb_standard_device_descriptor_t, 125 dump_descriptor_tree_brief_device); 126 _BRANCH(USB_DESCTYPE_CONFIGURATION, 127 usb_standard_configuration_descriptor_t, 128 dump_descriptor_tree_brief_configuration); 129 _BRANCH(USB_DESCTYPE_INTERFACE, 130 usb_standard_interface_descriptor_t, 131 dump_descriptor_tree_brief_interface); 132 _BRANCH(USB_DESCTYPE_ENDPOINT, 133 usb_standard_endpoint_descriptor_t, 134 dump_descriptor_tree_brief_endpoint); 135 136 default: 137 break; 138 } 139 140 if (descr_type == -1) { 141 printf("%sInvalid descriptor.\n", indent); 142 } 143 } 144 145 void dump_descriptor_tree_brief(usbinfo_device_t *dev) 146 { 147 dump_descriptor_tree_brief_callback((uint8_t *)&dev->device_descriptor, 148 0, NULL); 149 browse_descriptor_tree(dev->full_configuration_descriptor, 150 dev->full_configuration_descriptor_size, 151 usb_dp_standard_descriptor_nesting, 152 dump_descriptor_tree_brief_callback, 153 1, 154 NULL); 58 155 } 59 156 -
uspace/app/usbinfo/main.c
r81ca204 re160da4d 47 47 #include "usbinfo.h" 48 48 49 static void print_usage(char *app_name)50 {51 #define INDENT " "52 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");56 printf("\n");57 #undef INDENT58 }59 60 49 static bool resolve_hc_handle_and_dev_addr(const char *devpath, 61 50 devman_handle_t *out_hc_handle, usb_address_t *out_device_address) … … 130 119 } 131 120 121 static void print_usage(char *app_name) 122 { 123 #define _INDENT " " 124 #define _OPTION(opt, description) \ 125 printf(_INDENT opt "\n" _INDENT _INDENT description "\n") 126 127 printf(NAME ": query USB devices for descriptors\n\n"); 128 printf("Usage: %s [options] device [device [device [ ... ]]]\n", 129 app_name); 130 printf(_INDENT "The device is a devman path to the device.\n"); 131 132 _OPTION("-h --help", "Print this help and exit."); 133 _OPTION("-i --identification", "Brief device identification."); 134 _OPTION("-m --match-ids", "Print match ids generated for the device."); 135 _OPTION("-t --descriptor-tree", "Print descriptor tree."); 136 137 printf("\n"); 138 printf("If no option is specified, `-i' is considered default.\n"); 139 printf("\n"); 140 141 #undef _OPTION 142 #undef _INDENT 143 } 144 132 145 static struct option long_options[] = { 133 146 {"help", no_argument, NULL, 'h'}, 134 147 {"identification", no_argument, NULL, 'i'}, 135 148 {"match-ids", no_argument, NULL, 'm'}, 149 {"descriptor-tree", no_argument, NULL, 't'}, 136 150 {0, 0, NULL, 0} 137 151 }; 138 static const char *short_options = "him ";152 static const char *short_options = "himt"; 139 153 140 154 int main(int argc, char *argv[]) … … 147 161 bool action_print_short_identification = false; 148 162 bool action_print_match_ids = false; 163 bool action_print_descriptor_tree = false; 149 164 150 165 /* … … 171 186 action_print_match_ids = true; 172 187 break; 188 case 't': 189 action_print_descriptor_tree = true; 190 break; 173 191 default: 192 assert(false && "unreachable code"); 174 193 break; 175 194 } … … 177 196 178 197 /* Set the default action. */ 179 if (!action_print_match_ids && !action_print_short_identification) { 198 if (!action_print_match_ids 199 && !action_print_short_identification 200 && !action_print_descriptor_tree) { 180 201 action_print_short_identification = true; 181 202 } … … 215 236 dump_device_match_ids(dev); 216 237 } 238 if (action_print_descriptor_tree) { 239 dump_descriptor_tree_brief(dev); 240 } 217 241 218 242 /* Destroy the control pipe (close the session etc.). */ -
uspace/app/usbinfo/usbinfo.h
r81ca204 re160da4d 40 40 #include <usb/pipes.h> 41 41 #include <usb/debug.h> 42 #include <usb/dp.h> 42 43 #include <ipc/devman.h> 43 44 … … 46 47 usb_device_connection_t wire; 47 48 usb_standard_device_descriptor_t device_descriptor; 49 uint8_t *full_configuration_descriptor; 50 size_t full_configuration_descriptor_size; 48 51 } usbinfo_device_t; 49 52 … … 65 68 void destroy_device(usbinfo_device_t *); 66 69 70 typedef void (*dump_descriptor_in_tree_t)(uint8_t *, size_t, void *); 71 void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *, 72 dump_descriptor_in_tree_t, size_t, void *); 73 67 74 68 75 void dump_short_device_identification(usbinfo_device_t *); 69 76 void dump_device_match_ids(usbinfo_device_t *); 77 void dump_descriptor_tree_brief(usbinfo_device_t *); 78 70 79 71 80 #endif
Note:
See TracChangeset
for help on using the changeset viewer.