FreeCalypso > hg > freecalypso-tools
comparison rvinterf/l1filter/rvif_rx.c @ 855:ea458ee48691
rvinterf/l1filter: new program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 09 Nov 2021 23:14:22 +0000 |
parents | rvinterf/libasync/interf.c@09b4fd9b3827 |
children |
comparison
equal
deleted
inserted
replaced
854:74331b35b1da | 855:ea458ee48691 |
---|---|
1 /* | |
2 * This module implements message Rx from rvinterf. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <unistd.h> | |
9 #include "localsock.h" | |
10 #include "exitcodes.h" | |
11 | |
12 extern int sock; | |
13 | |
14 u_char rvi_msg[LOCALSOCK_MAX_MSG]; | |
15 int rvi_msg_len; | |
16 | |
17 static int rx_state, rx_left; | |
18 static u_char *rx_ptr; | |
19 | |
20 void | |
21 localsock_prep_for_length_rx() | |
22 { | |
23 rx_state = 0; | |
24 rx_ptr = rvi_msg; | |
25 rx_left = 2; | |
26 } | |
27 | |
28 static void | |
29 prep_for_message_rx() | |
30 { | |
31 rx_state = 1; | |
32 rx_ptr = rvi_msg; | |
33 rx_left = rvi_msg_len; | |
34 } | |
35 | |
36 void | |
37 process_msg_from_rvinterf() | |
38 { | |
39 switch (rvi_msg[0]) { | |
40 case RVI2CLI_PKT_FROM_TARGET: | |
41 process_pkt_from_target(); | |
42 return; | |
43 case RVI2CLI_LOCAL_CMD_RESP: | |
44 if (rvi_msg_len < 2) | |
45 goto bad; | |
46 if (rvi_msg[1] == '+') | |
47 return; | |
48 fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1, | |
49 rvi_msg + 1); | |
50 exit(ERROR_RVINTERF); | |
51 default: | |
52 bad: | |
53 fprintf(stderr, | |
54 "Error: unexpected message type %02X from rvinterf\n", | |
55 rvi_msg[0]); | |
56 exit(ERROR_RVINTERF); | |
57 } | |
58 } | |
59 | |
60 void | |
61 handle_rvinterf_input() | |
62 { | |
63 int cc; | |
64 | |
65 cc = read(sock, rx_ptr, rx_left); | |
66 if (cc <= 0) { | |
67 perror("read from rvinterf socket"); | |
68 exit(ERROR_RVINTERF); | |
69 } | |
70 rx_ptr += cc; | |
71 rx_left -= cc; | |
72 if (rx_left) | |
73 return; | |
74 /* got the thing, process it */ | |
75 if (rx_state) { | |
76 process_msg_from_rvinterf(); | |
77 localsock_prep_for_length_rx(); | |
78 } else { | |
79 rvi_msg_len = rvi_msg[0] << 8 | rvi_msg[1]; | |
80 if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) { | |
81 fprintf(stderr, | |
82 "Invalid length from rvinterf: %02X%02X\n", | |
83 rvi_msg[0], rvi_msg[1]); | |
84 exit(ERROR_RVINTERF); | |
85 } | |
86 prep_for_message_rx(); | |
87 } | |
88 } |