FreeCalypso > hg > freecalypso-hwlab
annotate simtool/dispatch.c @ 101:454ff8bd0b83
fc-simtool: update-bin command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 25 Jan 2021 01:54:43 +0000 |
parents | fa7005185b84 |
children | 29cc5612797a |
rev | line source |
---|---|
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the command dispatch for fc-simtool |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <pcsclite.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <winscard.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "globals.h" |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
96
a5dfab380a90
fc-simtool: iccid high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
15 extern int cmd_iccid(); |
97
597c4e87a1f4
fc-simtool: imsi high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
16 extern int cmd_imsi(); |
90
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
17 extern int cmd_readbin(); |
95
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
18 extern int cmd_readef(); |
91
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
19 extern int cmd_readrec(); |
100
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
20 extern int cmd_restore_file(); |
99
2e35070d289f
fc-simtool: savebin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
98
diff
changeset
|
21 extern int cmd_savebin(); |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern int cmd_select(); |
98
66c0cb0e9876
fc-simtool: telecom-sum (summary info) command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
23 extern int cmd_telecom_sum(); |
101
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
24 extern int cmd_update_bin(); |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
88
91486a77643e
fc-simtool: implement hex display of full SIM responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
26 extern int display_sim_resp_in_hex(); |
91486a77643e
fc-simtool: implement hex display of full SIM responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
27 |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 cmd_exit() |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 SCardDisconnect(hCard, SCARD_UNPOWER_CARD); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 SCardReleaseContext(hContext); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(0); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 static struct cmdtab { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 char *cmd; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 int minargs; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 int maxargs; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int (*func)(); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } cmdtab[] = { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 {"exit", 0, 0, cmd_exit}, |
96
a5dfab380a90
fc-simtool: iccid high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
42 {"iccid", 0, 0, cmd_iccid}, |
97
597c4e87a1f4
fc-simtool: imsi high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
43 {"imsi", 0, 0, cmd_imsi}, |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 {"quit", 0, 0, cmd_exit}, |
90
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
45 {"readbin", 2, 2, cmd_readbin}, |
95
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
46 {"readef", 1, 1, cmd_readef}, |
91
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
47 {"readrec", 1, 2, cmd_readrec}, |
100
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
48 {"restore-file", 2, 2, cmd_restore_file}, |
99
2e35070d289f
fc-simtool: savebin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
98
diff
changeset
|
49 {"savebin", 2, 2, cmd_savebin}, |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 {"select", 1, 1, cmd_select}, |
88
91486a77643e
fc-simtool: implement hex display of full SIM responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
51 {"sim-resp", 0, 0, display_sim_resp_in_hex}, |
98
66c0cb0e9876
fc-simtool: telecom-sum (summary info) command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
52 {"telecom-sum", 0, 0, cmd_telecom_sum}, |
101
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
53 {"update-bin", 2, 2, cmd_update_bin}, |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 {0, 0, 0, 0} |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 }; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 simtool_dispatch_cmd(cmd) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 char *cmd; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 char *argv[10]; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 char *cp, **ap; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 struct cmdtab *tp; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 for (cp = cmd; isspace(*cp); cp++) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 ; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!*cp || *cp == '#') |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 return(0); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 argv[0] = cp; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 while (*cp && !isspace(*cp)) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 cp++; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (*cp) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 *cp++ = '\0'; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (tp = cmdtab; tp->cmd; tp++) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!strcmp(tp->cmd, argv[0])) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 break; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (!tp->func) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fprintf(stderr, "error: no such command\n"); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 return(-1); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 for (ap = argv + 1; ; ) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 while (isspace(*cp)) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 cp++; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (!*cp || *cp == '#') |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 break; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (ap - argv - 1 >= tp->maxargs) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 fprintf(stderr, "error: too many arguments\n"); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 return(-1); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 *ap++ = cp; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 while (*cp && !isspace(*cp)) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 cp++; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (*cp) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 *cp++ = '\0'; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (ap - argv - 1 < tp->minargs) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 fprintf(stderr, "error: too few arguments\n"); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 return(-1); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 *ap = 0; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 return tp->func(ap - argv, argv); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |