annotate simtool/sws.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 c83ec3bd9d67
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements a few high-level commands for working with
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * Sysmocom webshop SIM cards, using sws-card-db to look up per-card data.
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "../libutil/dbread.h"
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db";
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 lookup_sws_card(dbs)
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 struct dbread_state *dbs;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int rc;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char iccid[21];
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 rc = retrieve_iccid(iccid);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (rc < 0)
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(rc);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return dbread_find_record(sws_card_db_file, dbs, "ICCID", iccid);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd_sws_lookup(argc, argv, outf)
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char **argv;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 FILE *outf;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 int rc;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct dbread_state dbs;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char **kp, *val;
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 rc = lookup_sws_card(&dbs);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (rc < 0)
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(rc);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (argc == 2) {
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 val = dbread_find_key_req(&dbs, argv[1]);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!val)
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(-1);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(outf, "%s\n", val);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return(0);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (kp = argv + 1; *kp; kp++) {
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 val = dbread_find_key(&dbs, *kp);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (val)
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(outf, "%s=%s\n", *kp, val);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return(0);
25530c262137 fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
31
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
50
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
51 cmd_sws_auth_adm1()
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
52 {
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
53 int rc;
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
54 struct dbread_state dbs;
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
55 char *pin;
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
56
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
57 rc = lookup_sws_card(&dbs);
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
58 if (rc < 0)
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
59 return(rc);
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
60 pin = dbread_find_key_req(&dbs, "ADM1");
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
61 if (!pin)
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
62 return(-1);
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
63 return verify_chv_func(0x0A, pin);
cca7d0528f89 fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 30
diff changeset
64 }
32
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
65
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
66 cmd_sws_auth_pin1()
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
67 {
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
68 int rc;
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
69 struct dbread_state dbs;
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
70 char *pin;
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
71
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
72 rc = lookup_sws_card(&dbs);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
73 if (rc < 0)
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
74 return(rc);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
75 pin = dbread_find_key_req(&dbs, "PIN1");
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
76 if (!pin)
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
77 return(-1);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
78 return verify_chv_func(0x01, pin);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
79 }
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
80
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
81 cmd_sws_auth_pin2()
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
82 {
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
83 int rc;
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
84 struct dbread_state dbs;
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
85 char *pin;
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
86
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
87 rc = lookup_sws_card(&dbs);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
88 if (rc < 0)
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
89 return(rc);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
90 pin = dbread_find_key_req(&dbs, "PIN2");
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
91 if (!pin)
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
92 return(-1);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
93 return verify_chv_func(0x02, pin);
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
94 }
33
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
95
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
96 cmd_sws_pin1_disable()
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
97 {
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
98 int rc;
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
99 struct dbread_state dbs;
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
100 char *pin;
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
101
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
102 rc = lookup_sws_card(&dbs);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
103 if (rc < 0)
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
104 return(rc);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
105 pin = dbread_find_key_req(&dbs, "PIN1");
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
106 if (!pin)
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
107 return(-1);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
108 return disable_chv_func(0x01, pin);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
109 }
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
110
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
111 cmd_sws_pin1_enable()
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
112 {
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
113 int rc;
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
114 struct dbread_state dbs;
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
115 char *pin;
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
116
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
117 rc = lookup_sws_card(&dbs);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
118 if (rc < 0)
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
119 return(rc);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
120 pin = dbread_find_key_req(&dbs, "PIN1");
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
121 if (!pin)
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
122 return(-1);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
123 return enable_chv_func(0x01, pin);
c83ec3bd9d67 fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
124 }