00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <async.h>
00036 #include <errno.h>
00037
00038 #include "ops/char_dev.h"
00039 #include "ddf/driver.h"
00040
00041 #define MAX_CHAR_RW_COUNT 256
00042
00043 static void remote_char_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00044 static void remote_char_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00045
00047 static remote_iface_func_ptr_t remote_char_dev_iface_ops[] = {
00048 &remote_char_read,
00049 &remote_char_write
00050 };
00051
00057 remote_iface_t remote_char_dev_iface = {
00058 .method_count = sizeof(remote_char_dev_iface_ops) /
00059 sizeof(remote_iface_func_ptr_t),
00060 .methods = remote_char_dev_iface_ops
00061 };
00062
00072 static void
00073 remote_char_read(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
00074 ipc_call_t *call)
00075 {
00076 char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops;
00077 ipc_callid_t cid;
00078
00079 size_t len;
00080 if (!async_data_read_receive(&cid, &len)) {
00081
00082 async_answer_0(callid, EINVAL);
00083 return;
00084 }
00085
00086 if (!char_dev_ops->read) {
00087 async_data_read_finalize(cid, NULL, 0);
00088 async_answer_0(callid, ENOTSUP);
00089 return;
00090 }
00091
00092 if (len > MAX_CHAR_RW_COUNT)
00093 len = MAX_CHAR_RW_COUNT;
00094
00095 char buf[MAX_CHAR_RW_COUNT];
00096 int ret = (*char_dev_ops->read)(fun, buf, len);
00097
00098 if (ret < 0) {
00099
00100 async_data_read_finalize(cid, buf, 0);
00101 async_answer_0(callid, ret);
00102 return;
00103 }
00104
00105
00106 async_data_read_finalize(cid, buf, ret);
00107 async_answer_1(callid, EOK, ret);
00108 }
00109
00119 static void
00120 remote_char_write(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
00121 ipc_call_t *call)
00122 {
00123 char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops;
00124 ipc_callid_t cid;
00125 size_t len;
00126
00127 if (!async_data_write_receive(&cid, &len)) {
00128
00129 async_answer_0(callid, EINVAL);
00130 return;
00131 }
00132
00133 if (!char_dev_ops->write) {
00134 async_data_write_finalize(cid, NULL, 0);
00135 async_answer_0(callid, ENOTSUP);
00136 return;
00137 }
00138
00139 if (len > MAX_CHAR_RW_COUNT)
00140 len = MAX_CHAR_RW_COUNT;
00141
00142 char buf[MAX_CHAR_RW_COUNT];
00143
00144 async_data_write_finalize(cid, buf, len);
00145
00146 int ret = (*char_dev_ops->write)(fun, buf, len);
00147 if (ret < 0) {
00148
00149 async_answer_0(callid, ret);
00150 } else {
00151
00152
00153
00154
00155 async_answer_1(callid, EOK, ret);
00156 }
00157 }
00158