source: mainline/uspace/app/usbinfo/info.c@ 4e8e1f5

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

Device recognition uses pipe API

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