source: mainline/uspace/app/usbinfo/dev.c@ 538bb6b

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

Rename usb_endpoint_pipe_*() ⇒ usb_pipe_*()

No change in functionality.

  • Property mode set to 100644
File size: 3.4 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 * Representation of queried device.
35 */
36#include <usb/pipes.h>
37#include <errno.h>
38#include <str_error.h>
39#include <usb/request.h>
40#include "usbinfo.h"
41
42usbinfo_device_t *prepare_device(devman_handle_t hc_handle,
43 usb_address_t dev_addr)
44{
45 usbinfo_device_t *dev = malloc(sizeof(usbinfo_device_t));
46 if (dev == NULL) {
47 fprintf(stderr, NAME ": memory allocation failed.\n");
48 return NULL;
49 }
50
51 int rc;
52
53 rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr);
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
61 rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
62 &dev->wire);
63 if (rc != EOK) {
64 fprintf(stderr,
65 NAME ": failed to create default control pipe: %s.\n",
66 str_error(rc));
67 goto leave;
68 }
69
70 rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
71 if (rc != EOK) {
72 fprintf(stderr,
73 NAME ": probing default control pipe failed: %s.\n",
74 str_error(rc));
75 goto leave;
76 }
77
78 rc = usb_pipe_start_session(&dev->ctrl_pipe);
79 if (rc != EOK) {
80 fprintf(stderr,
81 NAME ": failed to start session on control pipe: %s.\n",
82 str_error(rc));
83 goto leave;
84 }
85
86 rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
87 &dev->device_descriptor);
88 if (rc != EOK) {
89 fprintf(stderr,
90 NAME ": failed to retrieve device descriptor: %s.\n",
91 str_error(rc));
92 goto leave;
93 }
94
95 rc = usb_request_get_full_configuration_descriptor_alloc(
96 &dev->ctrl_pipe, 0, (void **)&dev->full_configuration_descriptor,
97 &dev->full_configuration_descriptor_size);
98 if (rc != EOK) {
99 fprintf(stderr,
100 NAME ": failed to retrieve configuration descriptor: %s.\n",
101 str_error(rc));
102 goto leave;
103 }
104
105 return dev;
106
107
108leave:
109 if (usb_pipe_is_session_started(&dev->ctrl_pipe)) {
110 usb_pipe_end_session(&dev->ctrl_pipe);
111 }
112
113 free(dev);
114
115 return NULL;
116}
117
118void destroy_device(usbinfo_device_t *dev)
119{
120 usb_pipe_end_session(&dev->ctrl_pipe);
121 free(dev);
122}
123
124/** @}
125 */
Note: See TracBrowser for help on using the repository browser.