annotate sw/sniff-dec/command.c @ 58:95ed46b5f8f1 default tip

doc/Sniffing-hw-setup: mv-sniffer is here
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 04 Oct 2023 05:55:09 +0000
parents eb4274e7f4da
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }
56
966a54303d68 simsniff-dec: factor out high-level decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
62 decode_cmd_opcode(cmd_hdr[1]);
45
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
63 if (cmd_hdr[4])
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
64 data_total = cmd_hdr[4];
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
65 else
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
66 data_total = 256;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
67 data_sofar = 0;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
68 state = STATE_CMD_PROC;
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
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
71 static void
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
72 print_data()
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
73 {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
74 unsigned n;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
75
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
76 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
77 for (n = 0; n < data_sofar; n++) {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
78 printf(" %02X", data_buf[n]);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
79 if ((n & 15) == 15 || n == data_sofar - 1)
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
80 putchar('\n');
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
81 }
41
118a12e9483b simtrace3-sniff-dec started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
45
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
83
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
84 static void
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
85 handle_sw1()
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
86 {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
87 strcpy(sw1_timestamp, linebuf);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
88 sw1_line = lineno;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
89 sw1 = rx_byte;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
90 if (data_sofar)
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
91 print_data();
57
eb4274e7f4da simsniff-dec: decode SELECT file IDs
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
92 if (cmd_hdr[1] == 0xA4 && cmd_hdr[4] == 2 && data_sofar == 2)
eb4274e7f4da simsniff-dec: decode SELECT file IDs
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
93 decode_file_id((data_buf[0] << 8) | data_buf[1]);
45
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
94 state = STATE_CMD_SW;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
95 }
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 void
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
98 handle_ack(single)
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
99 {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
100 if (data_sofar >= data_total) {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
101 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
102 linebuf, lineno);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
103 state = STATE_ERROR;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
104 return;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
105 }
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
106 if (!data_sofar) {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
107 strcpy(data_start_timestamp, linebuf);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
108 data_start_line = lineno;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
109 }
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
110 if (single)
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
111 data_thistime = 1;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
112 else
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
113 data_thistime = data_total - data_sofar;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
114 state = STATE_CMD_DATA;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
115 }
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 void
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
118 cmd_proc_byte_in()
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
119 {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
120 if (rx_byte == 0x60)
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 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
123 handle_sw1();
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
124 return;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
125 }
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
126 if (rx_byte == cmd_hdr[1]) {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
127 handle_ack(0);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
128 return;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
129 }
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
130 if (rx_byte == (cmd_hdr[1] ^ 0xFF)) {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
131 handle_ack(1);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
132 return;
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 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
135 state = STATE_ERROR;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
136 }
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 void
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
139 cmd_data_byte_in()
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
140 {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
141 data_buf[data_sofar++] = rx_byte;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
142 data_thistime--;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
143 if (data_thistime)
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
144 return;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
145 state = STATE_CMD_PROC;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
146 }
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 void
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
149 cmd_sw2_byte_in()
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
150 {
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
151 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
152 rx_byte);
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
153 state = STATE_READY_FOR_CMD;
b0524d1dc6ef simtrace3-sniff-dec: implement command decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
154 }