Changeset b7068da in mainline for uspace/lib/usb/src/dev.c


Ignore:
Timestamp:
2012-02-09T20:35:12Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
591762c6
Parents:
7cede12c (diff), 3d4750f (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.
Message:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/dev.c

    r7cede12c rb7068da  
    11/*
     2 * Copyright (c) 2011 Jan Vesely
    23 * Copyright (c) 2011 Vojtech Horky
    34 * All rights reserved.
     
    2728 */
    2829
    29 /** @addtogroup libusb
    30  * @{
    31  */
    32 /** @file
    33  *
    34  */
    35 #include <inttypes.h>
     30#include <usb/dev.h>
    3631#include <usb/hc.h>
    37 #include <devman.h>
    3832#include <errno.h>
     33#include <usb_iface.h>
    3934#include <str.h>
    4035#include <stdio.h>
    4136
    4237#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 */
     48int 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}
    43114
    44115static bool try_parse_bus_and_address(const char *path,
     
    77148    devman_handle_t *dev_handle)
    78149{
    79         int rc;
    80150        usb_hc_connection_t conn;
    81 
    82151        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);
    91154
    92155        return rc;
     
    151214                }
    152215                if (str_length(func_start) > 0) {
    153                         char tmp_path[MAX_DEVICE_PATH ];
     216                        char tmp_path[MAX_DEVICE_PATH];
    154217                        rc = devman_fun_get_path(dev_handle,
    155218                            tmp_path, MAX_DEVICE_PATH);
     
    192255                /* Try to find its host controller. */
    193256                if (!found_hc) {
    194                         rc = usb_hc_find(tmp_handle, &hc_handle);
     257                        rc = usb_get_hc_by_handle(tmp_handle, &hc_handle);
    195258                        if (rc == EOK) {
    196259                                found_hc = true;
     
    200263                /* Try to get its address. */
    201264                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) {
    204267                                found_addr = true;
    205268                        }
     
    237300        return EOK;
    238301}
    239 
    240 
    241 /**
    242  * @}
    243  */
    244 
Note: See TracChangeset for help on using the changeset viewer.