annotate uicc/sws.c @ 70:ce3752d3d3b4

doc/SIM-in-Calypso-phone: update for fc-host-tools-r15 release
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 27 Mar 2021 19:44:31 +0000
parents 97646b363eaa
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);
61
97646b363eaa fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
63 return verify_pin_func(0x0A, pin);
31
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);
61
97646b363eaa fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
78 return verify_pin_func(0x01, pin);
32
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);
61
97646b363eaa fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents: 33
diff changeset
93 return verify_pin_func(0x81, pin);
32
d0be3802410a fc-simtool sws-auth-pin[12] implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 31
diff changeset
94 }