[59b8639] | 1 | /*
|
---|
| 2 | * Copyright (c) 2017 Petr Manek
|
---|
| 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 | /** @addtogroup libusbdiag
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[64d138b] | 33 | * USB diagnostic device remote interface.
|
---|
[59b8639] | 34 | */
|
---|
| 35 |
|
---|
[a8723748] | 36 | #include <async.h>
|
---|
[64d138b] | 37 | #include <assert.h>
|
---|
| 38 | #include <macros.h>
|
---|
| 39 | #include <errno.h>
|
---|
| 40 | #include <devman.h>
|
---|
[59b8639] | 41 |
|
---|
[64d138b] | 42 | #include <usb/diag/iface.h>
|
---|
| 43 | #include "ddf/driver.h"
|
---|
| 44 |
|
---|
| 45 | typedef enum {
|
---|
| 46 | IPC_M_USB_DIAG_TEST,
|
---|
| 47 | } usb_iface_funcs_t;
|
---|
| 48 |
|
---|
| 49 | async_sess_t *usb_diag_connect(devman_handle_t handle)
|
---|
| 50 | {
|
---|
| 51 | return devman_device_connect(handle, IPC_FLAG_BLOCKING);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void usb_diag_disconnect(async_sess_t *sess)
|
---|
| 55 | {
|
---|
| 56 | if (sess)
|
---|
| 57 | async_hangup(sess);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | int usb_diag_test(async_exch_t *exch, int x, int *y)
|
---|
| 61 | {
|
---|
| 62 | if (!exch)
|
---|
| 63 | return EBADMEM;
|
---|
| 64 |
|
---|
| 65 | sysarg_t y_;
|
---|
| 66 | const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USB_DIAG_TEST, x, &y_);
|
---|
| 67 |
|
---|
| 68 | if (y)
|
---|
| 69 | *y = (int) y_;
|
---|
| 70 |
|
---|
| 71 | return ret;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | static void remote_usb_diag_test(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 75 |
|
---|
| 76 | /** Remote USB diagnostic interface operations. */
|
---|
| 77 | static const remote_iface_func_ptr_t remote_usb_diag_iface_ops [] = {
|
---|
| 78 | [IPC_M_USB_DIAG_TEST] = remote_usb_diag_test,
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 | /** Remote USB diagnostic interface structure. */
|
---|
| 82 | const remote_iface_t remote_usb_diag_iface = {
|
---|
| 83 | .method_count = ARRAY_SIZE(remote_usb_diag_iface_ops),
|
---|
| 84 | .methods = remote_usb_diag_iface_ops,
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | void remote_usb_diag_test(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
[59b8639] | 88 | {
|
---|
[64d138b] | 89 | const usb_diag_iface_t *diag_iface = (usb_diag_iface_t *) iface;
|
---|
[a8723748] | 90 |
|
---|
[64d138b] | 91 | if (diag_iface->test == NULL) {
|
---|
| 92 | async_answer_0(callid, ENOTSUP);
|
---|
| 93 | return;
|
---|
| 94 | }
|
---|
[a8723748] | 95 |
|
---|
[64d138b] | 96 | int x = DEV_IPC_GET_ARG1(*call);
|
---|
| 97 | int y;
|
---|
| 98 | const int ret = diag_iface->test(fun, x, &y);
|
---|
| 99 | if (ret != EOK) {
|
---|
| 100 | async_answer_0(callid, ret);
|
---|
| 101 | } else {
|
---|
| 102 | async_answer_1(callid, EOK, y);
|
---|
| 103 | }
|
---|
[59b8639] | 104 | }
|
---|
| 105 |
|
---|
| 106 | /**
|
---|
| 107 | * @}
|
---|
| 108 | */
|
---|