Changeset 7943c43 in mainline for uspace/lib/usb/src/dev.c
- Timestamp:
- 2012-01-16T22:45:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32817cc, 3fe58d3c
- Parents:
- 9117ef9b (diff), 3ea725e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/dev.c
r9117ef9b r7943c43 1 1 /* 2 * Copyright (c) 2011 Jan Vesely 2 3 * Copyright (c) 2011 Vojtech Horky 3 4 * All rights reserved. … … 27 28 */ 28 29 29 /** @addtogroup libusb 30 * @{ 31 */ 32 /** @file 33 * 34 */ 35 #include <inttypes.h> 30 #include <usb/dev.h> 36 31 #include <usb/hc.h> 37 #include <devman.h>38 32 #include <errno.h> 33 #include <usb_iface.h> 39 34 #include <str.h> 40 35 #include <stdio.h> 41 36 42 37 #define MAX_DEVICE_PATH 1024 38 39 /** Find host controller handle, address and iface number for the device. 40 * 41 * @param[in] device_handle Device devman handle. 42 * @param[out] hc_handle Where to store handle of host controller 43 * controlling device with @p device_handle handle. 44 * @param[out] address Place to store the device's address 45 * @param[out] iface Place to stoer the assigned USB interface number. 46 * @return Error code. 47 */ 48 int usb_get_info_by_handle(devman_handle_t device_handle, 49 devman_handle_t *hc_handle, usb_address_t *address, int *iface) 50 { 51 async_sess_t *parent_sess = 52 devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle, 53 IPC_FLAG_BLOCKING); 54 if (!parent_sess) 55 return ENOMEM; 56 57 async_exch_t *exch = async_exchange_begin(parent_sess); 58 if (!exch) { 59 async_hangup(parent_sess); 60 return ENOMEM; 61 } 62 63 usb_address_t tmp_address; 64 devman_handle_t tmp_handle; 65 int tmp_iface; 66 67 if (address) { 68 const int ret = usb_get_my_address(exch, &tmp_address); 69 if (ret != EOK) { 70 async_exchange_end(exch); 71 async_hangup(parent_sess); 72 return ret; 73 } 74 } 75 76 if (hc_handle) { 77 const int ret = usb_get_hc_handle(exch, &tmp_handle); 78 if (ret != EOK) { 79 async_exchange_end(exch); 80 async_hangup(parent_sess); 81 return ret; 82 } 83 } 84 85 if (iface) { 86 const int ret = usb_get_my_interface(exch, &tmp_iface); 87 switch (ret) { 88 case ENOTSUP: 89 /* Implementing GET_MY_INTERFACE is voluntary. */ 90 tmp_iface = -1; 91 case EOK: 92 break; 93 default: 94 async_exchange_end(exch); 95 async_hangup(parent_sess); 96 return ret; 97 } 98 } 99 100 if (hc_handle) 101 *hc_handle = tmp_handle; 102 103 if (address) 104 *address = tmp_address; 105 106 if (iface) 107 *iface = tmp_iface; 108 109 async_exchange_end(exch); 110 async_hangup(parent_sess); 111 112 return EOK; 113 } 43 114 44 115 static bool try_parse_bus_and_address(const char *path, … … 77 148 devman_handle_t *dev_handle) 78 149 { 79 int rc;80 150 usb_hc_connection_t conn; 81 82 151 usb_hc_connection_initialize(&conn, hc_handle); 83 rc = usb_hc_connection_open(&conn); 84 if (rc != EOK) { 85 return rc; 86 } 87 88 rc = usb_hc_get_handle_by_address(&conn, addr, dev_handle); 89 90 usb_hc_connection_close(&conn); 152 153 const int rc = usb_hc_get_handle_by_address(&conn, addr, dev_handle); 91 154 92 155 return rc; … … 151 214 } 152 215 if (str_length(func_start) > 0) { 153 char tmp_path[MAX_DEVICE_PATH 216 char tmp_path[MAX_DEVICE_PATH]; 154 217 rc = devman_fun_get_path(dev_handle, 155 218 tmp_path, MAX_DEVICE_PATH); … … 192 255 /* Try to find its host controller. */ 193 256 if (!found_hc) { 194 rc = usb_ hc_find(tmp_handle, &hc_handle);257 rc = usb_get_hc_by_handle(tmp_handle, &hc_handle); 195 258 if (rc == EOK) { 196 259 found_hc = true; … … 200 263 /* Try to get its address. */ 201 264 if (!found_addr) { 202 dev_addr = usb_get_address_by_handle(tmp_handle);203 if ( dev_addr >= 0) {265 rc = usb_get_address_by_handle(tmp_handle, &dev_addr); 266 if (rc == 0) { 204 267 found_addr = true; 205 268 } … … 237 300 return EOK; 238 301 } 239 240 241 /**242 * @}243 */244
Note:
See TracChangeset
for help on using the changeset viewer.