source: mainline/uspace/lib/usb/src/dev.c@ 29e479f

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

libusb: Add device_connection_t.

  • Property mode set to 100644
File size: 3.4 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/** Tell USB address assigned to device with given handle.
34 *
35 * @param dev_handle Devman handle of the USB device in question.
36 * @return USB address or negative error code.
37 */
38usb_address_t usb_get_address_by_handle(devman_handle_t dev_handle)
39{
40 async_sess_t *parent_sess =
41 devman_parent_device_connect(EXCHANGE_ATOMIC, dev_handle,
42 IPC_FLAG_BLOCKING);
43 if (!parent_sess)
44 return ENOMEM;
45
46 async_exch_t *exch = async_exchange_begin(parent_sess);
47 if (!exch) {
48 async_hangup(parent_sess);
49 return ENOMEM;
50 }
51 usb_address_t address;
52 const int ret = usb_get_my_address(exch, &address);
53
54 async_exchange_end(exch);
55 async_hangup(parent_sess);
56
57 if (ret != EOK)
58 return ret;
59
60 return address;
61}
62/*----------------------------------------------------------------------------*/
63/** Find host controller handle for the device.
64 *
65 * @param[in] device_handle Device devman handle.
66 * @param[out] hc_handle Where to store handle of host controller
67 * controlling device with @p device_handle handle.
68 * @return Error code.
69 */
70int usb_get_hc_by_handle(devman_handle_t device_handle,
71 devman_handle_t *hc_handle)
72{
73 async_sess_t *parent_sess =
74 devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
75 IPC_FLAG_BLOCKING);
76 if (!parent_sess)
77 return ENOMEM;
78
79 async_exch_t *exch = async_exchange_begin(parent_sess);
80 if (!exch) {
81 async_hangup(parent_sess);
82 return ENOMEM;
83 }
84 const int ret = usb_get_hc_handle(exch, hc_handle);
85
86 async_exchange_end(exch);
87 async_hangup(parent_sess);
88
89 return ret;
90}
91/*----------------------------------------------------------------------------*/
92int usb_device_connection_initialize(usb_device_connection_t *connection,
93 usb_hc_connection_t *hc_connection, usb_address_t address)
94{
95 assert(connection);
96
97 if (hc_connection == NULL) {
98 return EBADMEM;
99 }
100
101 if ((address < 0) || (address >= USB11_ADDRESS_MAX)) {
102 return EINVAL;
103 }
104
105 connection->hc_connection = hc_connection;
106 connection->address = address;
107 return EOK;
108}
Note: See TracBrowser for help on using the repository browser.