source: mainline/uspace/drv/usbkbd/descdump.c@ 6336b6e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6336b6e was 45019865, checked in by Lubos Slovak <lubos.slovak@…>, 15 years ago

Fixed descriptor parsing.

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