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
00036 #include <errno.h>
00037 #include <str_error.h>
00038 #include <stdlib.h>
00039 #include <usb/dev/pipes.h>
00040 #include <usb/dev/dp.h>
00041 #include <usb/classes/classes.h>
00042 #include "usbmid.h"
00043
00049 static void dump_tree_descriptor(uint8_t *data, size_t depth)
00050 {
00051 if (data == NULL) {
00052 return;
00053 }
00054 int type = (int) *(data + 1);
00055 if (type == USB_DESCTYPE_INTERFACE) {
00056 usb_standard_interface_descriptor_t *descriptor
00057 = (usb_standard_interface_descriptor_t *) data;
00058 usb_log_info("Found interface: %s (0x%02x/0x%02x/0x%02x).\n",
00059 usb_str_class(descriptor->interface_class),
00060 (int) descriptor->interface_class,
00061 (int) descriptor->interface_subclass,
00062 (int) descriptor->interface_protocol);
00063 }
00064 }
00065
00073 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
00074 uint8_t *root, size_t depth)
00075 {
00076 if (root == NULL) {
00077 return;
00078 }
00079 dump_tree_descriptor(root, depth);
00080 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
00081 do {
00082 dump_tree_internal(parser, data, child, depth + 1);
00083 child = usb_dp_get_sibling_descriptor(parser, data, root, child);
00084 } while (child != NULL);
00085 }
00086
00092 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data)
00093 {
00094 uint8_t *ptr = data->data;
00095 dump_tree_internal(parser, data, ptr, 0);
00096 }
00097
00103 void usbmid_dump_descriptors(uint8_t *descriptors, size_t length)
00104 {
00105 usb_dp_parser_data_t data = {
00106 .data = descriptors,
00107 .size = length,
00108 .arg = NULL
00109 };
00110
00111 usb_dp_parser_t parser = {
00112 .nesting = usb_dp_standard_descriptor_nesting
00113 };
00114
00115 dump_tree(&parser, &data);
00116 }
00117