Imported Upstream version 013
[platform/upstream/usbutils.git] / desc-dump.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * USB descriptor dumping
4  *
5  * Copyright (C) 2017 Michael Drake <michael.drake@codethink.co.uk>
6  */
7
8 #ifndef _DESC_DUMP_H
9 #define _DESC_DUMP_H
10
11 /* ---------------------------------------------------------------------- */
12
13 /**
14  * Buffer length value indicating that the buffer length should be
15  * read from the value of the first field in the buffer, as defined
16  * by the first field descriptor definition.
17  */
18 #define DESC_BUF_LEN_FROM_BUF 0xffffffff
19
20 /**
21  * Dump descriptor using a descriptor definition array.
22  *
23  * This function dumps the USB descriptor data given in the byte array,
24  * `buf`, according to the descriptor definition array given in `desc`.
25  *
26  * The first byte(s) of `buf` must correspond to the first field definition
27  * in the `desc` descriptor definition array.
28  *
29  * \param[in] dev     LibUSB device handle.
30  * \param[in] desc    Array of descriptor field definitions to use to interpret
31  *                    `buf`.  This array constitutes the descriptor definition.
32  *                    The final entry in the array must have a NULL field name,
33  *                    which is interpreted as the end of the array.
34  * \param[in] buf     Byte array containing the descriptor data to dump.
35  * \param[in] buf_len Byte length of `buf` or `DESC_BUF_LEN_FROM_BUF` to get
36  *                    the length from the value of the first field in the
37  *                    descriptor data.
38  * \param[in] indent  Indent level to use for descriptor dump.
39  */
40 extern void desc_dump(
41                 libusb_device_handle *dev,
42                 const struct desc *desc,
43                 const unsigned char *buf,
44                 unsigned int buf_len,
45                 unsigned int indent);
46
47
48 /* ---------------------------------------------------------------------- */
49
50 #endif /* _DESC_DUMP_H */