FreeCalypso > hg > freecalypso-tools
annotate rvinterf/l1filter/pktsort.c @ 860:7d4f080f66db
fc-add-ramps: actually produce correct output
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 18 Dec 2021 21:17:33 +0000 |
parents | ea458ee48691 |
children |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we sort out incoming packets from the target relayed via rvinterf. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "pktmux.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "limits.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "localsock.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "localtypes.h" |
64
d43d82cbfb85
fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
14 #include "exitcodes.h" |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern u_char rvi_msg[]; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern int rvi_msg_len; |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
18 extern char **filter_list; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
20 static |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
21 is_filter_match() |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
23 char **fp; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
24 int len; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
26 for (fp = filter_list; *fp; fp++) { |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
27 len = strlen(*fp); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
28 if (rvi_msg_len < len + 3) |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
29 continue; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
30 if (strncmp(rvi_msg + 2, *fp, len)) |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
31 continue; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
32 if (rvi_msg[len+2] != ' ') |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
33 continue; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
34 return 1; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
36 return 0; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static void |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
40 print_l1_trace() |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
42 u_char *dp, *endp; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
43 int c, newline; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
45 dp = rvi_msg + 2; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
46 endp = rvi_msg + rvi_msg_len; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
47 while (dp < endp) { |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
48 c = *dp++; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
49 if (c == '\r') |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
50 continue; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
51 if (c == '\n') { |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
52 putchar(c); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
53 newline = 1; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
54 continue; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
55 } |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
56 newline = 0; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
57 if (c & 0x80) { |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
58 putchar('M'); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
59 putchar('-'); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
60 c &= 0x7F; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
61 } |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
62 if (c == 0x7F) { |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
63 putchar('^'); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
64 putchar('?'); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
65 continue; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
66 } |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
67 if (c < 0x20) { |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
68 putchar('^'); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
69 c += '@'; |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
70 } |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
71 putchar(c); |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
72 } |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
73 if (!newline) |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
74 putchar('\n'); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 static void |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
78 l1_packet_rx() |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
80 if (is_filter_match()) |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
81 print_l1_trace(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 void |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 process_pkt_from_target() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 switch (rvi_msg[1]) { |
855
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
88 case RVT_L1_HEADER: |
ea458ee48691
rvinterf/l1filter: new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
89 l1_packet_rx(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 return; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 default: |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 rvi_msg[1]); |
64
d43d82cbfb85
fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
94 exit(ERROR_RVINTERF); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |