1 | /*
|
---|
2 | * Copyright (c) 2011 Vojtech Horky
|
---|
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 usb
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file
|
---|
34 | * @brief
|
---|
35 | */
|
---|
36 | #include <stdio.h>
|
---|
37 | #include <str_error.h>
|
---|
38 | #include <errno.h>
|
---|
39 | #include <usb/usbdrv.h>
|
---|
40 | #include "usbinfo.h"
|
---|
41 |
|
---|
42 | int dump_device(int hc_phone, usb_address_t address)
|
---|
43 | {
|
---|
44 | /*
|
---|
45 | * Dump information about possible match ids.
|
---|
46 | */
|
---|
47 | match_id_list_t match_id_list;
|
---|
48 | init_match_ids(&match_id_list);
|
---|
49 | int rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);
|
---|
50 | if (rc != EOK) {
|
---|
51 | fprintf(stderr,
|
---|
52 | NAME ": failed to fetch match ids of the device: %s.\n",
|
---|
53 | str_error(rc));
|
---|
54 | return rc;
|
---|
55 | }
|
---|
56 | dump_match_ids(&match_id_list);
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * Get device descriptor and dump it.
|
---|
60 | */
|
---|
61 | usb_standard_device_descriptor_t device_descriptor;
|
---|
62 | usb_dprintf(NAME, 1,
|
---|
63 | "usb_drv_req_get_device_descriptor(%d, %d, %p)\n",
|
---|
64 | hc_phone, (int) address, &device_descriptor);
|
---|
65 |
|
---|
66 | rc = usb_drv_req_get_device_descriptor(hc_phone, address,
|
---|
67 | &device_descriptor);
|
---|
68 | if (rc != EOK) {
|
---|
69 | fprintf(stderr,
|
---|
70 | NAME ": failed to fetch standard device descriptor: %s.\n",
|
---|
71 | str_error(rc));
|
---|
72 | return rc;
|
---|
73 | }
|
---|
74 | dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * Get first configuration descriptor and dump it.
|
---|
78 | */
|
---|
79 | usb_standard_configuration_descriptor_t config_descriptor;
|
---|
80 | int config_index = 0;
|
---|
81 | usb_dprintf(NAME, 1,
|
---|
82 | "usb_drv_req_get_bare_configuration_descriptor(%d, %d, %d, %p)\n",
|
---|
83 | hc_phone, (int) address, config_index, &config_descriptor);
|
---|
84 |
|
---|
85 | rc = usb_drv_req_get_bare_configuration_descriptor(hc_phone, address,
|
---|
86 | config_index, &config_descriptor );
|
---|
87 | if (rc != EOK) {
|
---|
88 | fprintf(stderr,
|
---|
89 | NAME ": failed to fetch standard configuration descriptor: %s.\n",
|
---|
90 | str_error(rc));
|
---|
91 | return rc;
|
---|
92 | }
|
---|
93 | //dump_standard_configuration_descriptor(config_index, &config_descriptor);
|
---|
94 |
|
---|
95 | void *full_config_descriptor = malloc(config_descriptor.total_length);
|
---|
96 | usb_dprintf(NAME, 1,
|
---|
97 | "usb_drv_req_get_full_configuration_descriptor(%d, %d, %d, %p, %zu)\n",
|
---|
98 | hc_phone, (int) address, config_index,
|
---|
99 | full_config_descriptor, config_descriptor.total_length);
|
---|
100 |
|
---|
101 | rc = usb_drv_req_get_full_configuration_descriptor(hc_phone, address,
|
---|
102 | config_index,
|
---|
103 | full_config_descriptor, config_descriptor.total_length, NULL);
|
---|
104 | if (rc != EOK) {
|
---|
105 | fprintf(stderr,
|
---|
106 | NAME ": failed to fetch full configuration descriptor: %s.\n",
|
---|
107 | str_error(rc));
|
---|
108 | return rc;
|
---|
109 | }
|
---|
110 | dump_buffer("Full configuration descriptor:",
|
---|
111 | full_config_descriptor, config_descriptor.total_length);
|
---|
112 |
|
---|
113 | dump_descriptor_tree(full_config_descriptor,
|
---|
114 | config_descriptor.total_length);
|
---|
115 |
|
---|
116 | return EOK;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /** @}
|
---|
120 | */
|
---|