FreeCalypso > hg > fc-sim-sniff
annotate sw/sniff-dec/command.c @ 45:b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 31 Aug 2023 09:32:48 +0000 |
parents | 118a12e9483b |
children | 5268246520de |
rev | line source |
---|---|
41
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement decoding of command APDU exchanges. |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "state.h" |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern char linebuf[]; |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int lineno; |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern unsigned rx_byte; |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int state; |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
45
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
17 static char cmd_start_timestamp[18]; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
18 static int cmd_start_line; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
19 static char data_start_timestamp[18]; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
20 static int data_start_line; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
21 static char sw1_timestamp[18]; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
22 static int sw1_line; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
23 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
24 static u_char cmd_hdr[5]; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
25 static unsigned hdr_byte_count; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
26 static unsigned data_total, data_sofar, data_thistime; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
27 static u_char data_buf[256], sw1; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
28 |
41
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 void |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 start_cmd_header() |
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
45
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
32 strcpy(cmd_start_timestamp, linebuf); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
33 cmd_start_line = lineno; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
34 cmd_hdr[0] = rx_byte; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
35 hdr_byte_count = 1; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
36 state = STATE_CMD_HDR; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
37 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
38 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
39 static void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
40 print_cmd_hdr() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
41 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
42 unsigned n; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
43 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
44 printf("%s line %d: CMD", cmd_start_timestamp, cmd_start_line); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
45 for (n = 0; n < 5; n++) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
46 printf(" %02X", cmd_hdr[n]); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
47 putchar('\n'); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
48 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
49 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
50 void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
51 cmd_hdr_byte_in() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
52 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
53 cmd_hdr[hdr_byte_count++] = rx_byte; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
54 if (hdr_byte_count < 5) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
55 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
56 print_cmd_hdr(); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
57 if ((cmd_hdr[1] & 0xF0) == 0x60 || (cmd_hdr[1] & 0xF0) == 0x90) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
58 printf(" ERROR: INS byte is invalid!\n"); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
59 state = STATE_ERROR; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
60 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
61 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
62 if (cmd_hdr[4]) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
63 data_total = cmd_hdr[4]; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
64 else |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
65 data_total = 256; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
66 data_sofar = 0; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
67 state = STATE_CMD_PROC; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
68 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
69 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
70 static void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
71 print_data() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
72 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
73 unsigned n; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
74 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
75 printf("%s line %d: DATA\n", data_start_timestamp, data_start_line); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
76 for (n = 0; n < data_sofar; n++) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
77 printf(" %02X", data_buf[n]); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
78 if ((n & 15) == 15 || n == data_sofar - 1) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
79 putchar('\n'); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
80 } |
41
118a12e9483b
simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
45
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
82 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
83 static void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
84 handle_sw1() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
85 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
86 strcpy(sw1_timestamp, linebuf); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
87 sw1_line = lineno; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
88 sw1 = rx_byte; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
89 if (data_sofar) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
90 print_data(); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
91 state = STATE_CMD_SW; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
92 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
93 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
94 void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
95 handle_ack(single) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
96 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
97 if (data_sofar >= data_total) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
98 printf("%s line %d: ERROR: ACK for more data than possible\n", |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
99 linebuf, lineno); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
100 state = STATE_ERROR; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
101 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
102 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
103 if (!data_sofar) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
104 strcpy(data_start_timestamp, linebuf); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
105 data_start_line = lineno; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
106 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
107 if (single) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
108 data_thistime = 1; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
109 else |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
110 data_thistime = data_total - data_sofar; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
111 state = STATE_CMD_DATA; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
112 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
113 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
114 void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
115 cmd_proc_byte_in() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
116 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
117 if (rx_byte == 0x60) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
118 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
119 if ((rx_byte & 0xF0) == 0x60 || (rx_byte & 0xF0) == 0x90) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
120 handle_sw1(); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
121 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
122 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
123 if (rx_byte == cmd_hdr[1]) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
124 handle_ack(0); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
125 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
126 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
127 if (rx_byte == (cmd_hdr[1] ^ 0xFF)) { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
128 handle_ack(1); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
129 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
130 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
131 printf("%s line %d: ERROR: invalid procedure byte\n", linebuf, lineno); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
132 state = STATE_ERROR; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
133 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
134 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
135 void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
136 cmd_data_byte_in() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
137 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
138 data_buf[data_sofar++] = rx_byte; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
139 data_thistime--; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
140 if (data_thistime) |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
141 return; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
142 state = STATE_CMD_PROC; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
143 } |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
144 |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
145 void |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
146 cmd_sw2_byte_in() |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
147 { |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
148 printf("%s line %d: SW %02X %02X\n", sw1_timestamp, sw1_line, sw1, |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
149 rx_byte); |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
150 state = STATE_READY_FOR_CMD; |
b0524d1dc6ef
simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
41
diff
changeset
|
151 } |