source: mainline/uspace/drv/usbkbd/descdump.c@ 1c13dac

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1c13dac was 1c13dac, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Add Doxygen groups to usbkbd driver

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