source: mainline/uspace/lib/drv/generic/remote_usbdiag.c@ 0bb4738

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

usbdiag: untracked headers and sources are untracked no more

  • 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 libdrv
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 "usbdiag_iface.h"
43
44typedef enum {
45 IPC_M_USBDIAG_TEST,
46} usb_iface_funcs_t;
47
48async_sess_t *usbdiag_connect(devman_handle_t handle)
49{
50 return devman_device_connect(handle, IPC_FLAG_BLOCKING);
51}
52
53void usbdiag_disconnect(async_sess_t *sess)
54{
55 if (sess)
56 async_hangup(sess);
57}
58
59int usbdiag_test(async_exch_t *exch, int x, int *y)
60{
61 if (!exch)
62 return EBADMEM;
63
64 sysarg_t y_;
65 const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_TEST, x, &y_);
66
67 if (y)
68 *y = (int) y_;
69
70 return ret;
71}
72
73static void remote_usbdiag_test(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
74
75/** Remote USB diagnostic interface operations. */
76static const remote_iface_func_ptr_t remote_usbdiag_iface_ops [] = {
77 [IPC_M_USBDIAG_TEST] = remote_usbdiag_test,
78};
79
80/** Remote USB diagnostic interface structure. */
81const remote_iface_t remote_usbdiag_iface = {
82 .method_count = ARRAY_SIZE(remote_usbdiag_iface_ops),
83 .methods = remote_usbdiag_iface_ops,
84};
85
86void remote_usbdiag_test(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
87{
88 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
89
90 if (diag_iface->test == NULL) {
91 async_answer_0(callid, ENOTSUP);
92 return;
93 }
94
95 int x = DEV_IPC_GET_ARG1(*call);
96 int y;
97 const int ret = diag_iface->test(fun, x, &y);
98 if (ret != EOK) {
99 async_answer_0(callid, ret);
100 } else {
101 async_answer_1(callid, EOK, y);
102 }
103}
104
105/**
106 * @}
107 */
Note: See TracBrowser for help on using the repository browser.