1 | /*
|
---|
2 | * Copyright (c) 2010 Lubos Slovak
|
---|
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 | /** @addtogroup drvusbhid
|
---|
29 | * @{
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include <usb/classes/hid.h>
|
---|
33 |
|
---|
34 | #include "descdump.h"
|
---|
35 |
|
---|
36 | /*----------------------------------------------------------------------------*/
|
---|
37 |
|
---|
38 | #define BYTES_PER_LINE 12
|
---|
39 |
|
---|
40 | static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
|
---|
41 | {
|
---|
42 | printf("%s\n", msg);
|
---|
43 |
|
---|
44 | size_t i;
|
---|
45 | for (i = 0; i < length; i++) {
|
---|
46 | printf(" 0x%02X", buffer[i]);
|
---|
47 | if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
|
---|
48 | || (i + 1 == length)) {
|
---|
49 | printf("\n");
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | /*----------------------------------------------------------------------------*/
|
---|
55 |
|
---|
56 | #define INDENT " "
|
---|
57 |
|
---|
58 | void dump_standard_configuration_descriptor(
|
---|
59 | int index, const usb_standard_configuration_descriptor_t *d)
|
---|
60 | {
|
---|
61 | bool self_powered = d->attributes & 64;
|
---|
62 | bool remote_wakeup = d->attributes & 32;
|
---|
63 |
|
---|
64 | printf("Standard configuration descriptor #%d\n", index);
|
---|
65 | printf(INDENT "bLength = %d\n", d->length);
|
---|
66 | printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
|
---|
67 | printf(INDENT "wTotalLength = %d\n", d->total_length);
|
---|
68 | printf(INDENT "bNumInterfaces = %d\n", d->interface_count);
|
---|
69 | printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);
|
---|
70 | printf(INDENT "iConfiguration = %d\n", d->str_configuration);
|
---|
71 | printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,
|
---|
72 | self_powered ? "self-powered" : "",
|
---|
73 | (self_powered & remote_wakeup) ? ", " : "",
|
---|
74 | remote_wakeup ? "remote-wakeup" : "");
|
---|
75 | printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
|
---|
76 | 2 * d->max_power);
|
---|
77 | // printf(INDENT " = %d\n", d->);
|
---|
78 | }
|
---|
79 |
|
---|
80 | void dump_standard_interface_descriptor(
|
---|
81 | const usb_standard_interface_descriptor_t *d)
|
---|
82 | {
|
---|
83 | printf("Standard interface descriptor\n");
|
---|
84 | printf(INDENT "bLength = %d\n", d->length);
|
---|
85 | printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
|
---|
86 | printf(INDENT "bInterfaceNumber = %d\n", d->interface_number);
|
---|
87 | printf(INDENT "bAlternateSetting = %d\n", d->alternate_setting);
|
---|
88 | printf(INDENT "bNumEndpoints = %d\n", d->endpoint_count);
|
---|
89 | printf(INDENT "bInterfaceClass = %d\n", d->interface_class);
|
---|
90 | printf(INDENT "bInterfaceSubClass = %d\n", d->interface_subclass);
|
---|
91 | printf(INDENT "bInterfaceProtocol = %d\n", d->interface_protocol);
|
---|
92 | printf(INDENT "iInterface = %d\n", d->str_interface);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void dump_standard_endpoint_descriptor(
|
---|
96 | const usb_standard_endpoint_descriptor_t *d)
|
---|
97 | {
|
---|
98 | const char *transfer_type;
|
---|
99 | switch (d->attributes & 3) {
|
---|
100 | case USB_TRANSFER_CONTROL:
|
---|
101 | transfer_type = "control";
|
---|
102 | break;
|
---|
103 | case USB_TRANSFER_ISOCHRONOUS:
|
---|
104 | transfer_type = "isochronous";
|
---|
105 | break;
|
---|
106 | case USB_TRANSFER_BULK:
|
---|
107 | transfer_type = "bulk";
|
---|
108 | break;
|
---|
109 | case USB_TRANSFER_INTERRUPT:
|
---|
110 | transfer_type = "interrupt";
|
---|
111 | break;
|
---|
112 | }
|
---|
113 |
|
---|
114 | printf("Standard endpoint descriptor\n");
|
---|
115 | printf(INDENT "bLength = %d\n", d->length);
|
---|
116 | printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
|
---|
117 | printf(INDENT "bmAttributes = %d [%s]\n", d->attributes, transfer_type);
|
---|
118 | printf(INDENT "wMaxPacketSize = %d\n", d->max_packet_size);
|
---|
119 | printf(INDENT "bInterval = %d\n", d->poll_interval);
|
---|
120 | }
|
---|
121 |
|
---|
122 | void dump_standard_hid_descriptor_header(
|
---|
123 | const usb_standard_hid_descriptor_t *d)
|
---|
124 | {
|
---|
125 | printf("Standard HID descriptor\n");
|
---|
126 | printf(INDENT "bLength = %d\n", d->length);
|
---|
127 | printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
|
---|
128 | printf(INDENT "bcdHID = %d\n", d->spec_release);
|
---|
129 | printf(INDENT "bCountryCode = %d\n", d->country_code);
|
---|
130 | printf(INDENT "bNumDescriptors = %d\n", d->class_desc_count);
|
---|
131 | printf(INDENT "bDescriptorType = %d\n", d->report_desc_info.type);
|
---|
132 | printf(INDENT "wDescriptorLength = %d\n", d->report_desc_info.length);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void dump_standard_hid_class_descriptor_info(
|
---|
136 | const usb_standard_hid_class_descriptor_info_t *d)
|
---|
137 | {
|
---|
138 | printf(INDENT "bDescriptorType = %d\n", d->type);
|
---|
139 | printf(INDENT "wDescriptorLength = %d\n", d->length);
|
---|
140 | }
|
---|
141 |
|
---|
142 | void dump_hid_class_descriptor(int index, uint8_t type,
|
---|
143 | const uint8_t *d, size_t size )
|
---|
144 | {
|
---|
145 | printf("Class-specific descriptor #%d (type: %u)\n", index, type);
|
---|
146 | assert(d != NULL);
|
---|
147 | dump_buffer("", d, size);
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * @}
|
---|
152 | */
|
---|
153 |
|
---|