annotate simtool/main.c @ 37:acf343dace04

-p reader selection implemented in fc-uicc-tool
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 17:50:42 +0000
parents 04e7e3008097
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <pcsclite.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <winscard.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "cardif.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 main(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 {
36
04e7e3008097 -p reader selection implemented in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
11 extern int optind;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char command[512];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
36
04e7e3008097 -p reader selection implemented in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
15 parse_global_options(argc, argv);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 setup_pcsc_context();
30
84d1c31d0fad first round of refactoring for selection among multiple readers
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
17 get_reader_list();
33
8a4f3d00d997 more refactoring of (select reader by number) logic
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
18 select_reader_by_num();
36
04e7e3008097 -p reader selection implemented in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
19 if (argc <= optind)
30
84d1c31d0fad first round of refactoring for selection among multiple readers
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
20 printf("Card reader name: %s\n", selected_reader);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 connect_to_card();
36
04e7e3008097 -p reader selection implemented in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
22 if (argc > optind) {
04e7e3008097 -p reader selection implemented in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
23 rc = dispatch_ready_argv(argc - optind, argv + optind);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (rc)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 error_exit();
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 good_exit();
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
28
78f93e3c9ebf fc-simtool & fc-uicc-tool: show card reader name and
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
29 retrieve_atr();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 for (;;) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (isatty(0)) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 fputs("simtool> ", stdout);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fflush(stdout);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (!fgets(command, sizeof command, stdin))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 good_exit();
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 simtool_dispatch_cmd(command, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }