annotate uicc/dispatch.c @ 22:1b1468869ccf

new trimmed fc-uicc-tool is here
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 04:34:53 +0000
parents
children d368051576d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the command dispatch for fc-uicc-tool
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <ctype.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern int cmd_dir();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern int cmd_exec();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int cmd_iccid();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int cmd_readbin();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int cmd_readef();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern int cmd_readrec();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int cmd_select();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern int cmd_select_aid();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern int cmd_select_isim();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern int cmd_select_usim();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern int cmd_update_bin();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern int cmd_update_bin_imm();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int cmd_update_rec();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern int display_sim_resp_in_hex();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern int good_exit();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static struct cmdtab {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 char *cmd;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 int minargs;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int maxargs;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int (*func)();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 } cmdtab[] = {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {"dir", 0, 0, cmd_dir},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"exec", 1, 1, cmd_exec},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"exit", 0, 0, good_exit},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"iccid", 0, 0, cmd_iccid},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {"quit", 0, 0, good_exit},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {"readbin", 2, 2, cmd_readbin},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {"readef", 1, 1, cmd_readef},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {"readrec", 1, 2, cmd_readrec},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {"select", 1, 1, cmd_select},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {"select-aid", 1, 1, cmd_select_aid},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {"select-isim", 0, 0, cmd_select_isim},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {"select-usim", 0, 0, cmd_select_usim},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {"sim-resp", 0, 0, display_sim_resp_in_hex},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {"update-bin", 2, 2, cmd_update_bin},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {"update-bin-imm", 2, 2, cmd_update_bin_imm},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 {"update-rec", 2, 2, cmd_update_rec},
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {0, 0, 0, 0}
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 };
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 simtool_dispatch_cmd(cmd, is_script)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 char *cmd;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 char *argv[10];
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char *cp, **ap;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 struct cmdtab *tp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 for (cp = cmd; isspace(*cp); cp++)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 ;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (!*cp || *cp == '#')
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (is_script)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 printf("Script command: %s\n", cp);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 argv[0] = cp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 while (*cp && !isspace(*cp))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (*cp)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 *cp++ = '\0';
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 for (tp = cmdtab; tp->cmd; tp++)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (!strcmp(tp->cmd, argv[0]))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (!tp->func) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fprintf(stderr, "error: no such command\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (ap = argv + 1; ; ) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 while (isspace(*cp))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (!*cp || *cp == '#')
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (ap - argv - 1 >= tp->maxargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 fprintf(stderr, "error: too many arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (*cp == '"') {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 *ap++ = ++cp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 for (;;) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (!*cp) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 unterm_qstring: fprintf(stderr,
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 "error: unterminated quoted string\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (*cp == '"')
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (*cp++ == '\\') {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (!*cp)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 goto unterm_qstring;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 *cp++ = '\0';
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 } else {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 *ap++ = cp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 while (*cp && !isspace(*cp))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (*cp)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 *cp++ = '\0';
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (ap - argv - 1 < tp->minargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 fprintf(stderr, "error: too few arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 *ap = 0;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 return tp->func(ap - argv, argv);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 dispatch_ready_argv(argc, argv)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 char **argv;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 struct cmdtab *tp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 for (tp = cmdtab; tp->cmd; tp++)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (!strcmp(tp->cmd, argv[0]))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 if (!tp->func) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 fprintf(stderr, "error: no such command\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (argc - 1 > tp->maxargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 fprintf(stderr, "error: too many arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (argc - 1 < tp->minargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 fprintf(stderr, "error: too few arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 return tp->func(argc, argv);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }