1 #include <rpc/rpc.h>
2 #include <rpc/rpc_router_ioctl.h>
3 #include <debug.h>
4
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <errno.h>
11
12 #define DUMP_DATA 0
13
r_open(const char * router)14 int r_open(const char *router)
15 {
16 int handle = open(router, O_RDWR, 0);
17
18 if(handle < 0)
19 E("error opening %s: %s\n", router, strerror(errno));
20 return handle;
21 }
22
r_close(int handle)23 void r_close(int handle)
24 {
25 if(close(handle) < 0) E("error: %s\n", strerror(errno));
26 }
27
r_read(int handle,char * buf,uint32 size)28 int r_read(int handle, char *buf, uint32 size)
29 {
30 int rc = read((int) handle, (void *)buf, size);
31 if (rc < 0)
32 E("error reading RPC packet: %d (%s)\n", errno, strerror(errno));
33 #if DUMP_DATA
34 else {
35 int len = rc / 4;
36 uint32_t *data = (uint32_t *)buf;
37 fprintf(stdout, "RPC in %02d:", rc);
38 while (len--)
39 fprintf(stdout, " %08x", *data++);
40 fprintf(stdout, "\n");
41 }
42 #endif
43 return rc;
44 }
45
r_write(int handle,const char * buf,uint32 size)46 int r_write (int handle, const char *buf, uint32 size)
47 {
48 int rc = write(handle, (void *)buf, size);
49 if (rc < 0)
50 E("error writing RPC packet: %d (%s)\n", errno, strerror(errno));
51 #if DUMP_DATA
52 else {
53 int len = rc / 4;
54 uint32_t *data = (uint32_t *)buf;
55 fprintf(stdout, "RPC out %02d:", rc);
56 while (len--)
57 fprintf(stdout, " %08x", *data++);
58 fprintf(stdout, "\n");
59 }
60 #endif
61 return rc;
62 }
63
r_control(int handle,const uint32 cmd,void * arg)64 int r_control(int handle, const uint32 cmd, void *arg)
65 {
66 return ioctl(handle, cmd, arg);
67 }
68
69
70
71