FreeCalypso > hg > fc-sim-tools
comparison uicc/sws.c @ 61:97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 Mar 2021 06:07:06 +0000 |
parents | simtool/sws.c@c83ec3bd9d67 |
children |
comparison
equal
deleted
inserted
replaced
60:a4ffd4e44b76 | 61:97646b363eaa |
---|---|
1 /* | |
2 * This module implements a few high-level commands for working with | |
3 * Sysmocom webshop SIM cards, using sws-card-db to look up per-card data. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include "../libutil/dbread.h" | |
9 | |
10 static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db"; | |
11 | |
12 static | |
13 lookup_sws_card(dbs) | |
14 struct dbread_state *dbs; | |
15 { | |
16 int rc; | |
17 char iccid[21]; | |
18 | |
19 rc = retrieve_iccid(iccid); | |
20 if (rc < 0) | |
21 return(rc); | |
22 return dbread_find_record(sws_card_db_file, dbs, "ICCID", iccid); | |
23 } | |
24 | |
25 cmd_sws_lookup(argc, argv, outf) | |
26 char **argv; | |
27 FILE *outf; | |
28 { | |
29 int rc; | |
30 struct dbread_state dbs; | |
31 char **kp, *val; | |
32 | |
33 rc = lookup_sws_card(&dbs); | |
34 if (rc < 0) | |
35 return(rc); | |
36 if (argc == 2) { | |
37 val = dbread_find_key_req(&dbs, argv[1]); | |
38 if (!val) | |
39 return(-1); | |
40 fprintf(outf, "%s\n", val); | |
41 return(0); | |
42 } | |
43 for (kp = argv + 1; *kp; kp++) { | |
44 val = dbread_find_key(&dbs, *kp); | |
45 if (val) | |
46 fprintf(outf, "%s=%s\n", *kp, val); | |
47 } | |
48 return(0); | |
49 } | |
50 | |
51 cmd_sws_auth_adm1() | |
52 { | |
53 int rc; | |
54 struct dbread_state dbs; | |
55 char *pin; | |
56 | |
57 rc = lookup_sws_card(&dbs); | |
58 if (rc < 0) | |
59 return(rc); | |
60 pin = dbread_find_key_req(&dbs, "ADM1"); | |
61 if (!pin) | |
62 return(-1); | |
63 return verify_pin_func(0x0A, pin); | |
64 } | |
65 | |
66 cmd_sws_auth_pin1() | |
67 { | |
68 int rc; | |
69 struct dbread_state dbs; | |
70 char *pin; | |
71 | |
72 rc = lookup_sws_card(&dbs); | |
73 if (rc < 0) | |
74 return(rc); | |
75 pin = dbread_find_key_req(&dbs, "PIN1"); | |
76 if (!pin) | |
77 return(-1); | |
78 return verify_pin_func(0x01, pin); | |
79 } | |
80 | |
81 cmd_sws_auth_pin2() | |
82 { | |
83 int rc; | |
84 struct dbread_state dbs; | |
85 char *pin; | |
86 | |
87 rc = lookup_sws_card(&dbs); | |
88 if (rc < 0) | |
89 return(rc); | |
90 pin = dbread_find_key_req(&dbs, "PIN2"); | |
91 if (!pin) | |
92 return(-1); | |
93 return verify_pin_func(0x81, pin); | |
94 } |