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
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <errno.h>
00040 #include <str_error.h>
00041 #include <bool.h>
00042
00043 #include <usb/usb.h>
00044 #include <usb/descriptor.h>
00045 #include <usb/debug.h>
00046 #include <usb/classes/classes.h>
00047
00048 #include "usbinfo.h"
00049 #include <usb/dev/dp.h>
00050
00051 static void browse_descriptor_tree_internal(usb_dp_parser_t *parser,
00052 usb_dp_parser_data_t *data, uint8_t *root, size_t depth,
00053 dump_descriptor_in_tree_t callback, void *arg)
00054 {
00055 if (root == NULL) {
00056 return;
00057 }
00058 callback(root, depth, arg);
00059 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
00060 do {
00061 browse_descriptor_tree_internal(parser, data, child, depth + 1,
00062 callback, arg);
00063 child = usb_dp_get_sibling_descriptor(parser, data,
00064 root, child);
00065 } while (child != NULL);
00066 }
00067
00068 void browse_descriptor_tree(uint8_t *descriptors, size_t descriptors_size,
00069 usb_dp_descriptor_nesting_t *descriptor_nesting,
00070 dump_descriptor_in_tree_t callback, size_t initial_depth, void *arg)
00071 {
00072 usb_dp_parser_data_t data = {
00073 .data = descriptors,
00074 .size = descriptors_size,
00075 .arg = NULL
00076 };
00077
00078 usb_dp_parser_t parser = {
00079 .nesting = descriptor_nesting
00080 };
00081
00082 browse_descriptor_tree_internal(&parser, &data, descriptors,
00083 initial_depth, callback, arg);
00084 }
00085