| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2011 Vojtech Horky
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /** @addtogroup libusbdev
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | * USB descriptor parser.
|
|---|
| 12 | */
|
|---|
| 13 | #ifndef LIBUSBDEV_DP_H_
|
|---|
| 14 | #define LIBUSBDEV_DP_H_
|
|---|
| 15 |
|
|---|
| 16 | #include <stddef.h>
|
|---|
| 17 | #include <stdint.h>
|
|---|
| 18 |
|
|---|
| 19 | /** USB descriptors nesting.
|
|---|
| 20 | * The nesting describes the logical tree USB descriptors form
|
|---|
| 21 | * (e.g. that endpoint descriptor belongs to interface or that
|
|---|
| 22 | * interface belongs to configuration).
|
|---|
| 23 | *
|
|---|
| 24 | * See usb_descriptor_type_t for descriptor constants.
|
|---|
| 25 | */
|
|---|
| 26 | typedef struct {
|
|---|
| 27 | /** Child descriptor id. */
|
|---|
| 28 | int child;
|
|---|
| 29 | /** Parent descriptor id. */
|
|---|
| 30 | int parent;
|
|---|
| 31 | } usb_dp_descriptor_nesting_t;
|
|---|
| 32 |
|
|---|
| 33 | extern const usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[];
|
|---|
| 34 |
|
|---|
| 35 | /** Descriptor parser structure. */
|
|---|
| 36 | typedef struct {
|
|---|
| 37 | /** Used descriptor nesting. */
|
|---|
| 38 | const usb_dp_descriptor_nesting_t *nesting;
|
|---|
| 39 | } usb_dp_parser_t;
|
|---|
| 40 |
|
|---|
| 41 | /** Descriptor parser data. */
|
|---|
| 42 | typedef struct {
|
|---|
| 43 | /** Data to be parsed. */
|
|---|
| 44 | const uint8_t *data;
|
|---|
| 45 | /** Size of input data in bytes. */
|
|---|
| 46 | size_t size;
|
|---|
| 47 | /** Custom argument. */
|
|---|
| 48 | void *arg;
|
|---|
| 49 | } usb_dp_parser_data_t;
|
|---|
| 50 |
|
|---|
| 51 | typedef void (*walk_callback_t)(const uint8_t *, size_t, void *);
|
|---|
| 52 |
|
|---|
| 53 | const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *,
|
|---|
| 54 | const usb_dp_parser_data_t *, const uint8_t *);
|
|---|
| 55 | const uint8_t *usb_dp_get_sibling_descriptor(const usb_dp_parser_t *,
|
|---|
| 56 | const usb_dp_parser_data_t *, const uint8_t *, const uint8_t *);
|
|---|
| 57 |
|
|---|
| 58 | void usb_dp_walk_simple(const uint8_t *, size_t,
|
|---|
| 59 | const usb_dp_descriptor_nesting_t *, walk_callback_t, void *);
|
|---|
| 60 |
|
|---|
| 61 | #endif
|
|---|
| 62 | /**
|
|---|
| 63 | * @}
|
|---|
| 64 | */
|
|---|