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


Ignore:
Timestamp:
2011-12-12T11:59:35Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a38701
Parents:
899f1a9
Message:

libusb, libusbdev: Provide generic usb_get_info_by_handle function.

Add separate wrappers for host controller handle, address and interface number.

File:
1 edited

Legend:

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

    r899f1a9 rc24c157d  
    3131#include <usb_iface.h>
    3232
    33 /** Tell USB address assigned to device with given handle.
     33/** Find host controller handle, address and iface number for the device.
    3434 *
    35  * @param dev_handle Devman handle of the USB device in question.
    36  * @return USB address or negative error code.
     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.
    3741 */
    38 usb_address_t usb_get_address_by_handle(devman_handle_t dev_handle)
     42int usb_get_info_by_handle(devman_handle_t device_handle,
     43    devman_handle_t *hc_handle, usb_address_t *address, int *iface)
    3944{
    4045        async_sess_t *parent_sess =
    41             devman_parent_device_connect(EXCHANGE_ATOMIC, dev_handle,
    42             IPC_FLAG_BLOCKING);
     46            devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
     47                IPC_FLAG_BLOCKING);
    4348        if (!parent_sess)
    4449                return ENOMEM;
     
    4954                return ENOMEM;
    5055        }
    51         usb_address_t address;
    52         const int ret = usb_get_my_address(exch, &address);
     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;
    53102
    54103        async_exchange_end(exch);
    55104        async_hangup(parent_sess);
    56105
    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  */
    70 int 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;
     106        return EOK;
    90107}
    91108/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.