source: mainline/uspace/lib/usbdiag/src/remote_usbdiag.c@ 64d138b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 64d138b was 64d138b, checked in by Petr Mánek <petr.manek@…>, 8 years ago

usbdiag: finalize IPC ops for tmon, simple demo waiting for test

  • Property mode set to 100644
File size: 3.0 KB
Line 
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
33 * USB diagnostic device remote interface.
34 */
35
36#include <async.h>
37#include <assert.h>
38#include <macros.h>
39#include <errno.h>
40#include <devman.h>
41
42#include <usb/diag/iface.h>
43#include "ddf/driver.h"
44
45typedef enum {
46 IPC_M_USB_DIAG_TEST,
47} usb_iface_funcs_t;
48
49async_sess_t *usb_diag_connect(devman_handle_t handle)
50{
51 return devman_device_connect(handle, IPC_FLAG_BLOCKING);
52}
53
54void usb_diag_disconnect(async_sess_t *sess)
55{
56 if (sess)
57 async_hangup(sess);
58}
59
60int 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
74static void remote_usb_diag_test(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
75
76/** Remote USB diagnostic interface operations. */
77static 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. */
82const 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
87void remote_usb_diag_test(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
88{
89 const usb_diag_iface_t *diag_iface = (usb_diag_iface_t *) iface;
90
91 if (diag_iface->test == NULL) {
92 async_answer_0(callid, ENOTSUP);
93 return;
94 }
95
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 }
104}
105
106/**
107 * @}
108 */
Note: See TracBrowser for help on using the repository browser.