source: mainline/uspace/lib/usb/src/dev.c@ 1a38701

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1a38701 was 1a38701, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

libusb, libusbdev: Move usb_device_connection to separate header in libusbdev.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
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#include <usb/dev.h>
30#include <errno.h>
31#include <usb_iface.h>
32
33/** Find host controller handle, address and iface number for the device.
34 *
35 * @param[in] device_handle Device devman handle.
36 * @param[out] hc_handle Where to store handle of host controller
37 * controlling device with @p device_handle handle.
38 * @param[out] address Place to store the device's address
39 * @param[out] iface Place to stoer the assigned USB interface number.
40 * @return Error code.
41 */
42int usb_get_info_by_handle(devman_handle_t device_handle,
43 devman_handle_t *hc_handle, usb_address_t *address, int *iface)
44{
45 async_sess_t *parent_sess =
46 devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
47 IPC_FLAG_BLOCKING);
48 if (!parent_sess)
49 return ENOMEM;
50
51 async_exch_t *exch = async_exchange_begin(parent_sess);
52 if (!exch) {
53 async_hangup(parent_sess);
54 return ENOMEM;
55 }
56
57 usb_address_t tmp_address;
58 devman_handle_t tmp_handle;
59 int tmp_iface;
60
61 if (address) {
62 const int ret = usb_get_my_address(exch, &tmp_address);
63 if (ret != EOK) {
64 async_exchange_end(exch);
65 async_hangup(parent_sess);
66 return ret;
67 }
68 }
69
70 if (hc_handle) {
71 const int ret = usb_get_hc_handle(exch, &tmp_handle);
72 if (ret != EOK) {
73 async_exchange_end(exch);
74 async_hangup(parent_sess);
75 return ret;
76 }
77 }
78
79 if (iface) {
80 const int ret = usb_get_my_interface(exch, &tmp_iface);
81 switch (ret) {
82 case ENOTSUP:
83 /* Implementing GET_MY_INTERFACE is voluntary. */
84 tmp_iface = -1;
85 case EOK:
86 break;
87 default:
88 async_exchange_end(exch);
89 async_hangup(parent_sess);
90 return ret;
91 }
92 }
93
94 if (hc_handle)
95 *hc_handle = tmp_handle;
96
97 if (address)
98 *address = tmp_address;
99
100 if (iface)
101 *iface = tmp_iface;
102
103 async_exchange_end(exch);
104 async_hangup(parent_sess);
105
106 return EOK;
107}
Note: See TracBrowser for help on using the repository browser.