[ab1aa871] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
| 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 | */
|
---|
| 34 |
|
---|
| 35 | #include <ipc/ipc.h>
|
---|
| 36 | #include <async.h>
|
---|
| 37 | #include <errno.h>
|
---|
| 38 |
|
---|
| 39 | #include "ioctl.h"
|
---|
| 40 | #include "driver.h"
|
---|
| 41 |
|
---|
| 42 | static void remote_ioctl(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call);
|
---|
| 43 |
|
---|
| 44 | /** Remote ioctl interface operations.
|
---|
| 45 | */
|
---|
| 46 | static remote_iface_func_ptr_t remote_ioctl_iface_ops [] = {
|
---|
| 47 | &remote_ioctl
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | /** Remote ioctl interface structure.
|
---|
| 51 | * Interface for processing request from remote clients addressed to the ioctl interface.
|
---|
| 52 | */
|
---|
| 53 | remote_iface_t remote_char_iface = {
|
---|
| 54 | .method_count = sizeof(remote_ioctl_iface_ops) / sizeof(remote_iface_func_ptr_t),
|
---|
| 55 | .methods = remote_ioctl_iface_ops
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | static void remote_ioctl(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 59 | {
|
---|
| 60 | ioctl_iface_t *ioctl_iface = (ioctl_iface_t *)iface;
|
---|
| 61 |
|
---|
| 62 | ipc_callid_t cidin, cidout;
|
---|
| 63 | int ctlcode;
|
---|
| 64 | size_t inlen = 0, outlen = 0, retlen = 0;
|
---|
| 65 | void *inbuf, *outbuf;
|
---|
| 66 | int ret;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | if (!async_data_read_receive(&cidin, &inlen)) {
|
---|
| 70 | // TODO handle protocol error
|
---|
| 71 | ipc_answer_0(callid, EINVAL);
|
---|
| 72 | return;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | if (!async_data_write_receive(&cidout, &outlen)) {
|
---|
| 76 | // TODO handle protocol error
|
---|
| 77 | ipc_answer_0(callid, EINVAL);
|
---|
| 78 | return;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | if (NULL == ioctl_iface->ioctl) {
|
---|
| 82 | async_data_read_finalize(cidin, NULL, 0);
|
---|
| 83 | async_data_write_finalize(cidout, NULL, 0);
|
---|
| 84 | ipc_answer_0(callid, ENOTSUP);
|
---|
| 85 | return;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | inbuf = malloc(inlen);
|
---|
| 89 | if (NULL == inbuf) {
|
---|
| 90 | async_data_read_finalize(cidin, NULL, 0);
|
---|
| 91 | async_data_write_finalize(cidout, NULL, 0);
|
---|
| 92 | ipc_answer_0(callid, ENOMEM);
|
---|
| 93 | return;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | outbuf = malloc(outlen);
|
---|
| 97 | if (NULL == outbuf) {
|
---|
| 98 | free(inbuf);
|
---|
| 99 | async_data_read_finalize(cidin, NULL, 0);
|
---|
| 100 | async_data_write_finalize(cidout, NULL, 0);
|
---|
| 101 | ipc_answer_0(callid, ENOMEM);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | ctlcode = (int)IPC_GET_ARG1(*call);
|
---|
| 105 |
|
---|
| 106 | async_data_read_finalize(cidin, inbuf, inlen);
|
---|
| 107 | ret = (*ioctl_iface->ioctl)(dev, ctlcode, inbuf, inlen, outbuf, outlen, &retlen);
|
---|
| 108 | async_data_write_finalize(cidout, outbuf, retlen);
|
---|
| 109 | ipc_answer_1(callid, ret, retlen);
|
---|
| 110 | free(outbuf);
|
---|
| 111 | free(inbuf);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * @}
|
---|
| 116 | */ |
---|