annotate utils/sws-card-lookup.c @ 93:6041c601304d

fcsim1-mkprov: revert OTA key addition It appears that GrcardSIM2 cards (which is what we got for FCSIM1) do not support OTA after all, contrary to what we were previously led to believe by some tech support emails from Grcard - apparently those support emails and OTA descriptions referred to some other card model(s).
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 21 Apr 2021 05:38:39 +0000
parents fa81221ac9b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program is a simple command line utility for looking up a card
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in sws-card-db (database generated with sws-email2db) by either
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * ICCID or IMSI and retrieving other associated database fields.
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../libutil/dbread.h"
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db";
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static char *match_key, match_value[20];
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static struct dbread_state dbs;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static void
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 preen_iccid(arg)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *arg;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 u_char nibbles[19];
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (parse_decimal_shorthand(arg, nibbles, 19) < 0)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1); /* error msg already printed */
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (nibbles[18] != compute_iccid_luhn(nibbles)) {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, "error: Luhn check digit mismatch\n");
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 nibbles_to_ascii(nibbles, 19, match_value);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 static void
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 preen_imsi(arg)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 char *arg;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 u_char nibbles[15];
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (parse_decimal_shorthand(arg, nibbles, 15) < 0)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 exit(1); /* error msg already printed */
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 nibbles_to_ascii(nibbles, 15, match_value);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 static void
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 lookup_one_key(key)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 char *key;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 char *val;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
28
fa81221ac9b6 retrieval of required db fields moved into libutil
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
51 val = dbread_find_key_req(&dbs, key);
fa81221ac9b6 retrieval of required db fields moved into libutil
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
52 if (!val)
fa81221ac9b6 retrieval of required db fields moved into libutil
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
53 exit(1); /* error msg already printed */
27
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 puts(val);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 static void
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 lookup_mult_keys(keys)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 char **keys;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 char *key, *val;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 for (; *keys; keys++) {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 key = *keys;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 val = dbread_find_key(&dbs, key);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (val)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 printf("%s=%s\n", key, val);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 main(argc, argv)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 char **argv;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 int rc;
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (argc < 4) {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr,
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 "usage: %s {iccid|imsi} card-number retrieve-key\n",
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 argv[0]);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 exit(1);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 match_key = argv[1];
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (!strcmp(match_key, "iccid"))
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 preen_iccid(argv[2]);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 else if (!strcmp(match_key, "imsi"))
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 preen_imsi(argv[2]);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 else {
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 fprintf(stderr, "error: look-up key must be iccid or imsi\n");
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 exit(1);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 rc = dbread_find_record(sws_card_db_file, &dbs, match_key, match_value);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (rc < 0)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 exit(1); /* error msg already printed */
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (argc == 4)
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 lookup_one_key(argv[3]);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 else
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 lookup_mult_keys(argv + 3);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(0);
ca8a6f95826a implemented sws-card-lookup and underlying libutil functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }