[e160da4d] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup usbinfo
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * Descriptor tree dump.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <stdio.h>
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 | #include <errno.h>
|
---|
| 40 | #include <str_error.h>
|
---|
[3e6a98c5] | 41 | #include <stdbool.h>
|
---|
[e160da4d] | 42 |
|
---|
| 43 | #include <usb/usb.h>
|
---|
| 44 | #include <usb/descriptor.h>
|
---|
| 45 | #include <usb/debug.h>
|
---|
| 46 | #include <usb/classes/classes.h>
|
---|
| 47 |
|
---|
| 48 | #include "usbinfo.h"
|
---|
[7d521e24] | 49 | #include <usb/dev/dp.h>
|
---|
[e160da4d] | 50 |
|
---|
| 51 | static void browse_descriptor_tree_internal(usb_dp_parser_t *parser,
|
---|
[8a121b1] | 52 | usb_dp_parser_data_t *data, const uint8_t *root, size_t depth,
|
---|
[e160da4d] | 53 | dump_descriptor_in_tree_t callback, void *arg)
|
---|
| 54 | {
|
---|
| 55 | if (root == NULL) {
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 | callback(root, depth, arg);
|
---|
[8a121b1] | 59 | const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
|
---|
[e160da4d] | 60 | do {
|
---|
| 61 | browse_descriptor_tree_internal(parser, data, child, depth + 1,
|
---|
| 62 | callback, arg);
|
---|
| 63 | child = usb_dp_get_sibling_descriptor(parser, data,
|
---|
| 64 | root, child);
|
---|
| 65 | } while (child != NULL);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | void browse_descriptor_tree(uint8_t *descriptors, size_t descriptors_size,
|
---|
| 69 | usb_dp_descriptor_nesting_t *descriptor_nesting,
|
---|
| 70 | dump_descriptor_in_tree_t callback, size_t initial_depth, void *arg)
|
---|
| 71 | {
|
---|
| 72 | usb_dp_parser_data_t data = {
|
---|
| 73 | .data = descriptors,
|
---|
| 74 | .size = descriptors_size,
|
---|
| 75 | .arg = NULL
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | usb_dp_parser_t parser = {
|
---|
| 79 | .nesting = descriptor_nesting
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | browse_descriptor_tree_internal(&parser, &data, descriptors,
|
---|
| 83 | initial_depth, callback, arg);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** @}
|
---|
| 87 | */
|
---|