source: mainline/uspace/app/usbinfo/info.c@ cd50486

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

Merge mainline changes

  • Property mode set to 100644
File size: 4.5 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/usbdrv.h>
40#include <usb/pipes.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 ctrl_pipe.hc_phone = -1;
50
51 int hc_phone = devman_device_connect(hc_handle, 0);
52 if (hc_phone < 0) {
53 fprintf(stderr,
54 NAME ": failed to connect to host controller (%zu): %s.\n",
55 (size_t) hc_handle, str_error(hc_phone));
56 return hc_phone;
57 }
58
59 /*
60 * Dump information about possible match ids.
61 */
62 match_id_list_t match_id_list;
63 init_match_ids(&match_id_list);
64 rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);
65 if (rc != EOK) {
66 fprintf(stderr,
67 NAME ": failed to fetch match ids of the device: %s.\n",
68 str_error(rc));
69 goto leave;
70 }
71 dump_match_ids(&match_id_list);
72
73 /*
74 * Initialize pipes.
75 */
76 rc = usb_device_connection_initialize(&wire, hc_handle, address);
77 if (rc != EOK) {
78 fprintf(stderr,
79 NAME ": failed to create connection to the device: %s.\n",
80 str_error(rc));
81 goto leave;
82 }
83 rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe, &wire);
84 if (rc != EOK) {
85 fprintf(stderr,
86 NAME ": failed to create default control pipe: %s.\n",
87 str_error(rc));
88 goto leave;
89 }
90 rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
91 if (rc != EOK) {
92 fprintf(stderr,
93 NAME ": failed to start session on control pipe: %s.\n",
94 str_error(rc));
95 goto leave;
96 }
97
98 /*
99 * Get device descriptor and dump it.
100 */
101 usb_standard_device_descriptor_t device_descriptor;
102 rc = usb_request_get_device_descriptor(&ctrl_pipe, &device_descriptor);
103 if (rc != EOK) {
104 fprintf(stderr,
105 NAME ": failed to fetch standard device descriptor: %s.\n",
106 str_error(rc));
107 goto leave;
108 }
109 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor));
110
111 /*
112 * Get first configuration descriptor and dump it.
113 */
114 usb_standard_configuration_descriptor_t config_descriptor;
115 int config_index = 0;
116 rc = usb_request_get_bare_configuration_descriptor(&ctrl_pipe,
117 config_index, &config_descriptor);
118 if (rc != EOK) {
119 fprintf(stderr,
120 NAME ": failed to fetch standard configuration descriptor: %s.\n",
121 str_error(rc));
122 goto leave;
123 }
124 //dump_standard_configuration_descriptor(config_index, &config_descriptor);
125
126 void *full_config_descriptor = malloc(config_descriptor.total_length);
127 rc = usb_request_get_full_configuration_descriptor(&ctrl_pipe,
128 config_index,
129 full_config_descriptor, config_descriptor.total_length, NULL);
130 if (rc != EOK) {
131 fprintf(stderr,
132 NAME ": failed to fetch full configuration descriptor: %s.\n",
133 str_error(rc));
134 goto leave;
135 }
136
137 dump_descriptor_tree(full_config_descriptor,
138 config_descriptor.total_length);
139
140 rc = EOK;
141leave:
142 /* Ignoring errors here. */
143 async_hangup(hc_phone);
144 usb_endpoint_pipe_end_session(&ctrl_pipe);
145
146 return rc;
147}
148
149/** @}
150 */
Note: See TracBrowser for help on using the repository browser.