3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <libusb20_desc.h>
41 #define DUMP0(n,type,field,...) dump_field(pdev, " ", #field, n->field);
42 #define DUMP1(n,type,field,...) dump_field(pdev, " ", #field, n->field);
43 #define DUMP2(n,type,field,...) dump_field(pdev, " ", #field, n->field);
44 #define DUMP3(n,type,field,...) dump_field(pdev, " ", #field, n->field);
47 dump_mode(uint8_t value)
49 if (value == LIBUSB20_MODE_HOST)
55 dump_speed(uint8_t value)
59 case LIBUSB20_SPEED_LOW:
60 return ("LOW (1.5Mbps)");
61 case LIBUSB20_SPEED_FULL:
62 return ("FULL (12Mbps)");
63 case LIBUSB20_SPEED_HIGH:
64 return ("HIGH (480Mbps)");
65 case LIBUSB20_SPEED_VARIABLE:
66 return ("VARIABLE (52-480Mbps)");
67 case LIBUSB20_SPEED_SUPER:
68 return ("SUPER (4.8Gbps)");
76 dump_power_mode(uint8_t value)
80 case LIBUSB20_POWER_OFF:
82 case LIBUSB20_POWER_ON:
84 case LIBUSB20_POWER_SAVE:
86 case LIBUSB20_POWER_SUSPEND:
88 case LIBUSB20_POWER_RESUME:
96 dump_field(struct libusb20_device *pdev, const char *plevel,
97 const char *field, uint32_t value)
99 uint8_t temp_string[256];
101 printf("%s%s = 0x%04x ", plevel, field, value);
103 if ((field[0] != 'i') || (field[1] == 'd')) {
108 printf(" <no string>\n");
111 if (libusb20_dev_req_string_simple_sync(pdev, value,
112 temp_string, sizeof(temp_string))) {
113 printf(" <retrieving string failed>\n");
116 printf(" <%s>\n", temp_string);
121 dump_extra(struct libusb20_me_struct *str, const char *plevel)
128 while ((ptr = libusb20_desc_foreach(str, ptr))) {
129 printf("\n" "%sAdditional Descriptor\n\n", plevel);
130 printf("%sbLength = 0x%02x\n", plevel, ptr[0]);
131 printf("%sbDescriptorType = 0x%02x\n", plevel, ptr[1]);
133 printf("%sbDescriptorSubType = 0x%02x\n",
135 printf("%s RAW dump: ", plevel);
136 for (x = 0; x != ptr[0]; x++) {
138 printf("\n%s 0x%02x | ", plevel, x);
140 printf("0x%02x%s", ptr[x],
141 (x != (ptr[0] - 1)) ? ", " : (x % 8) ? "\n" : "");
149 dump_endpoint(struct libusb20_device *pdev,
150 struct libusb20_endpoint *ep)
152 struct LIBUSB20_ENDPOINT_DESC_DECODED *edesc;
155 LIBUSB20_ENDPOINT_DESC(DUMP3, edesc);
156 dump_extra(&ep->extra, " " " " " ");
161 dump_iface(struct libusb20_device *pdev,
162 struct libusb20_interface *iface)
164 struct LIBUSB20_INTERFACE_DESC_DECODED *idesc;
167 idesc = &iface->desc;
168 LIBUSB20_INTERFACE_DESC(DUMP2, idesc);
169 dump_extra(&iface->extra, " " " " " ");
171 for (z = 0; z != iface->num_endpoints; z++) {
172 printf("\n Endpoint %u\n", z);
173 dump_endpoint(pdev, iface->endpoints + z);
179 dump_device_info(struct libusb20_device *pdev, uint8_t show_ifdrv)
184 printf("%s, cfg=%u md=%s spd=%s pwr=%s\n",
185 libusb20_dev_get_desc(pdev),
186 libusb20_dev_get_config_index(pdev),
187 dump_mode(libusb20_dev_get_mode(pdev)),
188 dump_speed(libusb20_dev_get_speed(pdev)),
189 dump_power_mode(libusb20_dev_get_power_mode(pdev)));
194 for (n = 0; n != 255; n++) {
195 if (libusb20_dev_get_iface_desc(pdev, n, buf, sizeof(buf)))
199 printf("ugen%u.%u.%u: %s\n",
200 libusb20_dev_get_bus_number(pdev),
201 libusb20_dev_get_address(pdev), n, buf);
206 dump_be_quirk_names(struct libusb20_backend *pbe)
208 struct libusb20_quirk q;
212 memset(&q, 0, sizeof(q));
214 printf("\nDumping list of supported quirks:\n\n");
216 for (x = 0; x != 0xFFFF; x++) {
218 error = libusb20_be_get_quirk_name(pbe, x, &q);
221 printf("No quirk names - maybe the USB quirk "
222 "module has not been loaded.\n");
226 if (strcmp(q.quirkname, "UQ_NONE"))
227 printf("%s\n", q.quirkname);
234 dump_be_dev_quirks(struct libusb20_backend *pbe)
236 struct libusb20_quirk q;
240 memset(&q, 0, sizeof(q));
242 printf("\nDumping current device quirks:\n\n");
244 for (x = 0; x != 0xFFFF; x++) {
246 error = libusb20_be_get_dev_quirk(pbe, x, &q);
249 printf("No device quirks - maybe the USB quirk "
250 "module has not been loaded.\n");
254 if (strcmp(q.quirkname, "UQ_NONE")) {
255 printf("VID=0x%04x PID=0x%04x REVLO=0x%04x "
256 "REVHI=0x%04x QUIRK=%s\n",
257 q.vid, q.pid, q.bcdDeviceLow,
258 q.bcdDeviceHigh, q.quirkname);
266 dump_device_desc(struct libusb20_device *pdev)
268 struct LIBUSB20_DEVICE_DESC_DECODED *ddesc;
270 ddesc = libusb20_dev_get_device_desc(pdev);
271 LIBUSB20_DEVICE_DESC(DUMP0, ddesc);
276 dump_config(struct libusb20_device *pdev, uint8_t all_cfg)
278 struct LIBUSB20_CONFIG_DESC_DECODED *cdesc;
279 struct LIBUSB20_DEVICE_DESC_DECODED *ddesc;
280 struct libusb20_config *pcfg = NULL;
282 uint8_t cfg_index_end;
286 ddesc = libusb20_dev_get_device_desc(pdev);
290 cfg_index_end = ddesc->bNumConfigurations;
292 cfg_index = libusb20_dev_get_config_index(pdev);
293 cfg_index_end = cfg_index + 1;
296 for (; cfg_index != cfg_index_end; cfg_index++) {
298 pcfg = libusb20_dev_alloc_config(pdev, cfg_index);
302 printf("\n Configuration index %u\n\n", cfg_index);
303 cdesc = &(pcfg->desc);
304 LIBUSB20_CONFIG_DESC(DUMP1, cdesc);
305 dump_extra(&(pcfg->extra), " " " ");
307 for (x = 0; x != pcfg->num_interface; x++) {
308 printf("\n Interface %u\n", x);
309 dump_iface(pdev, pcfg->interface + x);
311 for (y = 0; y != (pcfg->interface + x)->num_altsetting; y++) {
312 printf("\n Interface %u Alt %u\n", x, y + 1);
314 (pcfg->interface + x)->altsetting + y);