FreeCalypso > hg > freecalypso-sw
annotate rvinterf/lowlevel/clientcmd.c @ 180:59ee5817b194
rvinterf: packet sending implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 23 Nov 2013 22:42:19 +0000 |
parents | 7ab6b29e76bb |
children | ec040f521cc2 |
rev | line source |
---|---|
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This rvinterf module implements the handling of client commands. |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <string.h> |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <strings.h> |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdlib.h> |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <unistd.h> |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "../pktmux.h" |
180
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
12 #include "../limits.h" |
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "../localsock.h" |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "client.h" |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 void |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 process_msg_from_client(cli) |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 struct client *cli; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 int c; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 switch (cli->rx_buf[0]) { |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 case CLI2RVI_WANT_RVTRACE: |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 if (cli->rx_msglen != 9) { |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 send_local_msg_to_client(cli, "-Bad command length"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 return; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 } |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 c = cli->int_rvt_count; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 if (c >= MAX_RVT_INTEREST) { |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 send_local_msg_to_client(cli, |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 "-Error: too many RVT interests"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 return; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 } |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 cli->int_rvt_mask[c] = cli->rx_buf[1] << 24 | |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 cli->rx_buf[2] << 16 | |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 cli->rx_buf[3] << 8 | cli->rx_buf[4]; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 cli->int_rvt_match[c] = cli->rx_buf[5] << 24 | |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 cli->rx_buf[6] << 16 | |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 cli->rx_buf[7] << 8 | cli->rx_buf[8]; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 cli->int_rvt_count++; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 send_local_msg_to_client(cli, "+OK"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 return; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 case CLI2RVI_WANT_MUXPROTO: |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (cli->rx_msglen != 2) { |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 send_local_msg_to_client(cli, "-Bad command length"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 return; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (cli->rx_buf[1] < 0x12 || cli->rx_buf[1] > 0x18) { |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 send_local_msg_to_client(cli, |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 "-Unsupported protocol MUX value"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 return; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 } |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 cli->int_proto[cli->rx_buf[1] - 0x12] = 1; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 send_local_msg_to_client(cli, "+OK"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 return; |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 case CLI2RVI_PKT_TO_TARGET: |
180
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
57 c = cli->rx_msglen - 1; |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
58 if (c < 1 || c > MAX_PKT_TO_TARGET) { |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
59 send_local_msg_to_client(cli, |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
60 "-Invalid Tx packet length"); |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
61 return; |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
62 } |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
63 send_pkt_to_target(cli->rx_buf + 1, c); |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
64 log_sent_packet(cli->rx_buf + 1, c); |
59ee5817b194
rvinterf: packet sending implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
65 return; |
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 case CLI2RVI_RAWBYTES_TO_TARGET: |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 /* To be implemented */ |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 default: |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 send_local_msg_to_client(cli, "-Unimplemented command"); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 } |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 } |