annotate serial/main.c @ 49:831a224e182b

doc/Back-end-selection article written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Mar 2021 06:24:52 +0000
parents be27d1c85861
children fbedb67d234f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
41
5ee00413b8af serial: beginning of fcsim-serial-be
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
2 * This module implements the main() function for fcsim-serial-be.
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
42
6cc3eea720cb serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
8 extern unsigned baud_base, baud_spenh;
40
8f505d413815 serial: full baud/spenh argument parsing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
9
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 main(argc, argv)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 char **argv;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
43
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
13 char inbuf[576];
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
14 u_char cmd[260];
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int rc;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (argc != 3) {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 fprintf(stderr, "usage: %s ttyport baud\n", argv[0]);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 exit(1);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 open_serial_port(argv[1]);
40
8f505d413815 serial: full baud/spenh argument parsing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
22 parse_baud_spenh_arg(argv[2]);
8f505d413815 serial: full baud/spenh argument parsing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
23 set_serial_params(baud_base);
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 set_serial_nonblock(0);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 serial_card_reset();
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = collect_atr();
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 exit(1);
41
5ee00413b8af serial: beginning of fcsim-serial-be
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
29 print_atr("A");
42
6cc3eea720cb serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
30 if (baud_spenh)
6cc3eea720cb serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
31 spenh_logic();
43
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
32 putchar('\n');
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
33 fflush(stdout);
41
5ee00413b8af serial: beginning of fcsim-serial-be
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
34
43
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
35 for (; fgets(inbuf, sizeof inbuf, stdin); fflush(stdout)) {
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
36 rc = parse_hex_input(inbuf, cmd);
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
37 if (rc < 0)
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
38 continue;
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
39 if (rc < 5) {
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
40 printf("error: command APDU is too short\n");
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
41 continue;
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
42 }
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
43 apdu_exchange(cmd, rc);
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
44 }
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
45
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exit(0);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }