source: mainline/uspace/app/usbinfo/info.c@ 206f71a

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

Getting max_packet_size for default control pipe

  • Property mode set to 100644
File size: 5.7 KB
Line 
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 usbinfo
30 * @{
31 */
32/**
33 * @file
34 * Dumping of generic device properties.
35 */
36#include <stdio.h>
37#include <str_error.h>
38#include <errno.h>
39#include <usb/pipes.h>
40#include <usb/recognise.h>
41#include <usb/request.h>
42#include "usbinfo.h"
43
44int dump_device(devman_handle_t hc_handle, usb_address_t address)
45{
46 int rc;
47 usb_device_connection_t wire;
48 usb_endpoint_pipe_t ctrl_pipe;
49
50 /*
51 * Initialize pipes.
52 */
53 rc = usb_device_connection_initialize(&wire, hc_handle, address);
54 if (rc != EOK) {
55 fprintf(stderr,
56 NAME ": failed to create connection to the device: %s.\n",
57 str_error(rc));
58 goto leave;
59 }
60 rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe, &wire);
61 if (rc != EOK) {
62 fprintf(stderr,
63 NAME ": failed to create default control pipe: %s.\n",
64 str_error(rc));
65 goto leave;
66 }
67 rc = usb_endpoint_pipe_probe_default_control(&ctrl_pipe);
68 if (rc != EOK) {
69 fprintf(stderr,
70 NAME ": probing default control pipe failed: %s.\n",
71 str_error(rc));
72 goto leave;
73 }
74 rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
75 if (rc != EOK) {
76 fprintf(stderr,
77 NAME ": failed to start session on control pipe: %s.\n",
78 str_error(rc));
79 goto leave;
80 }
81
82 /*
83 * Dump information about possible match ids.
84 */
85 match_id_list_t match_id_list;
86 init_match_ids(&match_id_list);
87 rc = usb_device_create_match_ids(&ctrl_pipe, &match_id_list);
88 if (rc != EOK) {
89 fprintf(stderr,
90 NAME ": failed to fetch match ids of the device: %s.\n",
91 str_error(rc));
92 goto leave;
93 }
94 dump_match_ids(&match_id_list);
95
96 /*
97 * Get device descriptor and dump it.
98 */
99 usb_standard_device_descriptor_t device_descriptor;
100 rc = usb_request_get_device_descriptor(&ctrl_pipe, &device_descriptor);
101 if (rc != EOK) {
102 fprintf(stderr,
103 NAME ": failed to fetch standard device descriptor: %s.\n",
104 str_error(rc));
105 goto leave;
106 }
107 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
108
109 /*
110 * Get first configuration descriptor and dump it.
111 */
112 usb_standard_configuration_descriptor_t config_descriptor;
113 int config_index = 0;
114 rc = usb_request_get_bare_configuration_descriptor(&ctrl_pipe,
115 config_index, &config_descriptor);
116 if (rc != EOK) {
117 fprintf(stderr,
118 NAME ": failed to fetch standard configuration descriptor: %s.\n",
119 str_error(rc));
120 goto leave;
121 }
122 //dump_standard_configuration_descriptor(config_index, &config_descriptor);
123
124 void *full_config_descriptor = malloc(config_descriptor.total_length);
125 rc = usb_request_get_full_configuration_descriptor(&ctrl_pipe,
126 config_index,
127 full_config_descriptor, config_descriptor.total_length, NULL);
128 if (rc != EOK) {
129 fprintf(stderr,
130 NAME ": failed to fetch full configuration descriptor: %s.\n",
131 str_error(rc));
132 goto leave;
133 }
134
135 dump_descriptor_tree(full_config_descriptor,
136 config_descriptor.total_length);
137
138 /*
139 * Get supported languages of STRING descriptors.
140 */
141 l18_win_locales_t *langs;
142 size_t langs_count;
143 rc = usb_request_get_supported_languages(&ctrl_pipe,
144 &langs, &langs_count);
145 if (rc != EOK) {
146 fprintf(stderr,
147 NAME ": failed to get list of supported languages: %s.\n",
148 str_error(rc));
149 goto skip_strings;
150 }
151
152 printf("String languages (%zu):", langs_count);
153 size_t i;
154 for (i = 0; i < langs_count; i++) {
155 printf(" 0x%04x", (int) langs[i]);
156 }
157 printf(".\n");
158
159 /*
160 * Dump all strings in all available langages;
161 */
162 for (i = 0; i < langs_count; i++) {
163 l18_win_locales_t lang = langs[i];
164
165 printf("%sStrings for language 0x%04x:\n", get_indent(0),
166 (int) lang);
167
168 /*
169 * Try all indexes - we will see what pops-up ;-).
170 * However, to speed things up, we will stop after
171 * encountering several broken (or nonexistent ones)
172 * descriptors in line.
173 */
174 size_t idx;
175 size_t failed_count = 0;
176 for (idx = 1; idx < 0xFF; idx++) {
177 char *string;
178 rc = usb_request_get_string(&ctrl_pipe, idx, lang,
179 &string);
180 if (rc != EOK) {
181 failed_count++;
182 if (failed_count > 3) {
183 break;
184 }
185 continue;
186 }
187 printf("%sString #%zu: \"%s\"\n", get_indent(1),
188 idx, string);
189 free(string);
190 failed_count = 0; /* Reset failed counter. */
191 }
192 }
193
194
195skip_strings:
196
197 rc = EOK;
198
199leave:
200 /* Ignoring errors here. */
201 usb_endpoint_pipe_end_session(&ctrl_pipe);
202
203 return rc;
204}
205
206/** @}
207 */
Note: See TracBrowser for help on using the repository browser.