annotate serial/main.c @ 85:c179deb9bb39

uicc/writecmd.c: forgot to update #include header set
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Apr 2021 02:48:22 +0000
parents fbedb67d234f
children
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;
53
fbedb67d234f serial: fix parity for inverse coding convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
9 extern int inverse_coding;
40
8f505d413815 serial: full baud/spenh argument parsing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
10
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 main(argc, argv)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char **argv;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
43
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
14 char inbuf[576];
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
15 u_char cmd[260];
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int rc;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (argc != 3) {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 fprintf(stderr, "usage: %s ttyport baud\n", argv[0]);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 exit(1);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 open_serial_port(argv[1]);
40
8f505d413815 serial: full baud/spenh argument parsing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
23 parse_baud_spenh_arg(argv[2]);
53
fbedb67d234f serial: fix parity for inverse coding convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
24 set_serial_params(baud_base, -1);
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 set_serial_nonblock(0);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 serial_card_reset();
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 rc = collect_atr();
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (rc < 0)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
41
5ee00413b8af serial: beginning of fcsim-serial-be
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
30 print_atr("A");
53
fbedb67d234f serial: fix parity for inverse coding convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
31 set_serial_params(baud_base, inverse_coding);
42
6cc3eea720cb serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
32 if (baud_spenh)
6cc3eea720cb serial: speed enhancement implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
33 spenh_logic();
43
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
34 putchar('\n');
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
35 fflush(stdout);
41
5ee00413b8af serial: beginning of fcsim-serial-be
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
36
43
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
37 for (; fgets(inbuf, sizeof inbuf, stdin); fflush(stdout)) {
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
38 rc = parse_hex_input(inbuf, cmd);
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
39 if (rc < 0)
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
40 continue;
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
41 if (rc < 5) {
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
42 printf("error: command APDU is too short\n");
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
43 continue;
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 apdu_exchange(cmd, rc);
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
46 }
be27d1c85861 serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
47
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(0);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }