2 * HLR/AuC testing gateway for hostapd EAP-SIM/AKA database/authenticator
3 * Copyright (c) 2005-2007, 2012-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * This is an example implementation of the EAP-SIM/AKA database/authentication
9 * gateway interface to HLR/AuC. It is expected to be replaced with an
10 * implementation of SS7 gateway to GSM/UMTS authentication center (HLR/AuC) or
11 * a local implementation of SIM triplet and AKA authentication data generator.
13 * hostapd will send SIM/AKA authentication queries over a UNIX domain socket
14 * to and external program, e.g., this hlr_auc_gw. This interface uses simple
17 * EAP-SIM / GSM triplet query/response:
18 * SIM-REQ-AUTH <IMSI> <max_chal>
19 * SIM-RESP-AUTH <IMSI> Kc1:SRES1:RAND1 Kc2:SRES2:RAND2 [Kc3:SRES3:RAND3]
20 * SIM-RESP-AUTH <IMSI> FAILURE
21 * GSM-AUTH-REQ <IMSI> RAND1:RAND2[:RAND3]
22 * GSM-AUTH-RESP <IMSI> Kc1:SRES1:Kc2:SRES2[:Kc3:SRES3]
23 * GSM-AUTH-RESP <IMSI> FAILURE
25 * EAP-AKA / UMTS query/response:
27 * AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES>
28 * AKA-RESP-AUTH <IMSI> FAILURE
30 * EAP-AKA / UMTS AUTS (re-synchronization):
31 * AKA-AUTS <IMSI> <AUTS> <RAND>
33 * IMSI and max_chal are sent as an ASCII string,
34 * Kc/SRES/RAND/AUTN/IK/CK/RES/AUTS as hex strings.
36 * An example implementation here reads GSM authentication triplets from a
37 * text file in IMSI:Kc:SRES:RAND format, IMSI in ASCII, other fields as hex
38 * strings. This is used to simulate an HLR/AuC. As such, it is not very useful
39 * for real life authentication, but it is useful both as an example
40 * implementation and for EAP-SIM/AKA/AKA' testing.
42 * For a stronger example design, Milenage and GSM-Milenage algorithms can be
43 * used to dynamically generate authenticatipn information for EAP-AKA/AKA' and
44 * EAP-SIM, respectively, if Ki is known.
46 * SQN generation follows the not time-based Profile 2 described in
47 * 3GPP TS 33.102 Annex C.3.2. The length of IND is 5 bits by default, but this
48 * can be changed with a command line options if needed.
55 #endif /* CONFIG_SQLITE */
58 #include "crypto/milenage.h"
59 #include "crypto/random.h"
61 static const char *default_socket_path = "/tmp/hlr_auc_gw.sock";
62 static const char *socket_path;
63 static int serv_sock = -1;
64 static char *milenage_file = NULL;
65 static int update_milenage = 0;
66 static int sqn_changes = 0;
67 static int ind_len = 5;
68 static int stdout_debug = 1;
72 struct gsm_triplet *next;
79 static struct gsm_triplet *gsm_db = NULL, *gsm_db_pos = NULL;
81 /* OPc and AMF parameters for Milenage (Example algorithms for AKA). */
82 struct milenage_parameters {
83 struct milenage_parameters *next;
92 static struct milenage_parameters *milenage_db = NULL;
94 #define EAP_SIM_MAX_CHAL 3
96 #define EAP_AKA_RAND_LEN 16
97 #define EAP_AKA_AUTN_LEN 16
98 #define EAP_AKA_AUTS_LEN 14
99 #define EAP_AKA_RES_MAX_LEN 16
100 #define EAP_AKA_IK_LEN 16
101 #define EAP_AKA_CK_LEN 16
106 static sqlite3 *sqlite_db = NULL;
107 static struct milenage_parameters db_tmp_milenage;
110 static int db_table_exists(sqlite3 *db, const char *name)
113 os_snprintf(cmd, sizeof(cmd), "SELECT 1 FROM %s;", name);
114 return sqlite3_exec(db, cmd, NULL, NULL, NULL) == SQLITE_OK;
118 static int db_table_create_milenage(sqlite3 *db)
122 "CREATE TABLE milenage("
123 " imsi INTEGER PRIMARY KEY NOT NULL,"
124 " ki CHAR(32) NOT NULL,"
125 " opc CHAR(32) NOT NULL,"
126 " amf CHAR(4) NOT NULL,"
127 " sqn CHAR(12) NOT NULL"
130 printf("Adding database table for milenage information\n");
131 if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
132 printf("SQLite error: %s\n", err);
141 static sqlite3 * db_open(const char *db_file)
145 if (sqlite3_open(db_file, &db)) {
146 printf("Failed to open database %s: %s\n",
147 db_file, sqlite3_errmsg(db));
152 if (!db_table_exists(db, "milenage") &&
153 db_table_create_milenage(db) < 0) {
162 static int get_milenage_cb(void *ctx, int argc, char *argv[], char *col[])
164 struct milenage_parameters *m = ctx;
169 for (i = 0; i < argc; i++) {
170 if (os_strcmp(col[i], "ki") == 0 && argv[i] &&
171 hexstr2bin(argv[i], m->ki, sizeof(m->ki))) {
172 printf("Invalid ki value in database\n");
176 if (os_strcmp(col[i], "opc") == 0 && argv[i] &&
177 hexstr2bin(argv[i], m->opc, sizeof(m->opc))) {
178 printf("Invalid opcvalue in database\n");
182 if (os_strcmp(col[i], "amf") == 0 && argv[i] &&
183 hexstr2bin(argv[i], m->amf, sizeof(m->amf))) {
184 printf("Invalid amf value in database\n");
188 if (os_strcmp(col[i], "sqn") == 0 && argv[i] &&
189 hexstr2bin(argv[i], m->sqn, sizeof(m->sqn))) {
190 printf("Invalid sqn value in database\n");
199 static struct milenage_parameters * db_get_milenage(const char *imsi_txt)
202 unsigned long long imsi;
204 os_memset(&db_tmp_milenage, 0, sizeof(db_tmp_milenage));
205 imsi = atoll(imsi_txt);
206 os_snprintf(db_tmp_milenage.imsi, sizeof(db_tmp_milenage.imsi),
208 os_snprintf(cmd, sizeof(cmd),
209 "SELECT ki,opc,amf,sqn FROM milenage WHERE imsi=%llu;",
211 if (sqlite3_exec(sqlite_db, cmd, get_milenage_cb, &db_tmp_milenage,
215 if (!db_tmp_milenage.set)
217 return &db_tmp_milenage;
221 static int db_update_milenage_sqn(struct milenage_parameters *m)
223 char cmd[128], val[13], *pos;
225 if (sqlite_db == NULL)
229 pos += wpa_snprintf_hex(pos, sizeof(val), m->sqn, 6);
231 os_snprintf(cmd, sizeof(cmd),
232 "UPDATE milenage SET sqn='%s' WHERE imsi=%s;",
234 if (sqlite3_exec(sqlite_db, cmd, NULL, NULL, NULL) != SQLITE_OK) {
235 printf("Failed to update SQN in database for IMSI %s\n",
242 #endif /* CONFIG_SQLITE */
245 static int open_socket(const char *path)
247 struct sockaddr_un addr;
250 s = socket(PF_UNIX, SOCK_DGRAM, 0);
252 perror("socket(PF_UNIX)");
256 memset(&addr, 0, sizeof(addr));
257 addr.sun_family = AF_UNIX;
258 os_strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
259 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
260 perror("hlr-auc-gw: bind(PF_UNIX)");
269 static int read_gsm_triplets(const char *fname)
272 char buf[200], *pos, *pos2;
273 struct gsm_triplet *g = NULL;
279 f = fopen(fname, "r");
281 printf("Could not open GSM tripler data file '%s'\n", fname);
286 while (fgets(buf, sizeof(buf), f)) {
289 /* Parse IMSI:Kc:SRES:RAND */
290 buf[sizeof(buf) - 1] = '\0';
294 while (*pos != '\0' && *pos != '\n')
302 g = os_zalloc(sizeof(*g));
309 pos2 = strchr(pos, ':');
311 printf("%s:%d - Invalid IMSI (%s)\n",
317 if (strlen(pos) >= sizeof(g->imsi)) {
318 printf("%s:%d - Too long IMSI (%s)\n",
323 os_strlcpy(g->imsi, pos, sizeof(g->imsi));
327 pos2 = strchr(pos, ':');
329 printf("%s:%d - Invalid Kc (%s)\n", fname, line, pos);
334 if (strlen(pos) != 16 || hexstr2bin(pos, g->kc, 8)) {
335 printf("%s:%d - Invalid Kc (%s)\n", fname, line, pos);
342 pos2 = strchr(pos, ':');
344 printf("%s:%d - Invalid SRES (%s)\n", fname, line,
350 if (strlen(pos) != 8 || hexstr2bin(pos, g->sres, 4)) {
351 printf("%s:%d - Invalid SRES (%s)\n", fname, line,
359 pos2 = strchr(pos, ':');
362 if (strlen(pos) != 32 || hexstr2bin(pos, g->_rand, 16)) {
363 printf("%s:%d - Invalid RAND (%s)\n", fname, line,
382 static struct gsm_triplet * get_gsm_triplet(const char *imsi)
384 struct gsm_triplet *g = gsm_db_pos;
387 if (strcmp(g->imsi, imsi) == 0) {
388 gsm_db_pos = g->next;
395 while (g && g != gsm_db_pos) {
396 if (strcmp(g->imsi, imsi) == 0) {
397 gsm_db_pos = g->next;
407 static int read_milenage(const char *fname)
410 char buf[200], *pos, *pos2;
411 struct milenage_parameters *m = NULL;
417 f = fopen(fname, "r");
419 printf("Could not open Milenage data file '%s'\n", fname);
424 while (fgets(buf, sizeof(buf), f)) {
427 /* Parse IMSI Ki OPc AMF SQN */
428 buf[sizeof(buf) - 1] = '\0';
432 while (*pos != '\0' && *pos != '\n')
440 m = os_zalloc(sizeof(*m));
447 pos2 = strchr(pos, ' ');
449 printf("%s:%d - Invalid IMSI (%s)\n",
455 if (strlen(pos) >= sizeof(m->imsi)) {
456 printf("%s:%d - Too long IMSI (%s)\n",
461 os_strlcpy(m->imsi, pos, sizeof(m->imsi));
465 pos2 = strchr(pos, ' ');
467 printf("%s:%d - Invalid Ki (%s)\n", fname, line, pos);
472 if (strlen(pos) != 32 || hexstr2bin(pos, m->ki, 16)) {
473 printf("%s:%d - Invalid Ki (%s)\n", fname, line, pos);
480 pos2 = strchr(pos, ' ');
482 printf("%s:%d - Invalid OPc (%s)\n", fname, line, pos);
487 if (strlen(pos) != 32 || hexstr2bin(pos, m->opc, 16)) {
488 printf("%s:%d - Invalid OPc (%s)\n", fname, line, pos);
495 pos2 = strchr(pos, ' ');
497 printf("%s:%d - Invalid AMF (%s)\n", fname, line, pos);
502 if (strlen(pos) != 4 || hexstr2bin(pos, m->amf, 2)) {
503 printf("%s:%d - Invalid AMF (%s)\n", fname, line, pos);
510 pos2 = strchr(pos, ' ');
513 if (strlen(pos) != 12 || hexstr2bin(pos, m->sqn, 6)) {
514 printf("%s:%d - Invalid SEQ (%s)\n", fname, line, pos);
520 m->next = milenage_db;
532 static void update_milenage_file(const char *fname)
536 char *end = buf + sizeof(buf);
537 struct milenage_parameters *m;
540 f = fopen(fname, "r");
542 printf("Could not open Milenage data file '%s'\n", fname);
546 snprintf(buf, sizeof(buf), "%s.new", fname);
547 f2 = fopen(buf, "w");
549 printf("Could not write Milenage data file '%s'\n", buf);
554 while (fgets(buf, sizeof(buf), f)) {
555 /* IMSI Ki OPc AMF SQN */
556 buf[sizeof(buf) - 1] = '\0';
558 pos = strchr(buf, ' ');
559 if (buf[0] == '#' || pos == NULL || pos - buf >= 20)
562 imsi_len = pos - buf;
564 for (m = milenage_db; m; m = m->next) {
565 if (strncmp(buf, m->imsi, imsi_len) == 0 &&
566 m->imsi[imsi_len] == '\0')
574 pos += snprintf(pos, end - pos, "%s ", m->imsi);
575 pos += wpa_snprintf_hex(pos, end - pos, m->ki, 16);
577 pos += wpa_snprintf_hex(pos, end - pos, m->opc, 16);
579 pos += wpa_snprintf_hex(pos, end - pos, m->amf, 2);
581 pos += wpa_snprintf_hex(pos, end - pos, m->sqn, 6);
585 fprintf(f2, "%s", buf);
591 snprintf(buf, sizeof(buf), "%s.bak", fname);
592 if (rename(fname, buf) < 0) {
597 snprintf(buf, sizeof(buf), "%s.new", fname);
598 if (rename(buf, fname) < 0) {
606 static struct milenage_parameters * get_milenage(const char *imsi)
608 struct milenage_parameters *m = milenage_db;
611 if (strcmp(m->imsi, imsi) == 0)
618 m = db_get_milenage(imsi);
619 #endif /* CONFIG_SQLITE */
625 static int sim_req_auth(char *imsi, char *resp, size_t resp_len)
627 int count, max_chal, ret;
630 struct milenage_parameters *m;
631 struct gsm_triplet *g;
635 pos = strchr(imsi, ' ');
638 max_chal = atoi(pos);
639 if (max_chal < 1 || max_chal > EAP_SIM_MAX_CHAL)
640 max_chal = EAP_SIM_MAX_CHAL;
642 max_chal = EAP_SIM_MAX_CHAL;
644 rend = resp + resp_len;
646 ret = snprintf(rpos, rend - rpos, "SIM-RESP-AUTH %s", imsi);
647 if (ret < 0 || ret >= rend - rpos)
651 m = get_milenage(imsi);
653 u8 _rand[16], sres[4], kc[8];
654 for (count = 0; count < max_chal; count++) {
655 if (random_get_bytes(_rand, 16) < 0)
657 gsm_milenage(m->opc, m->ki, _rand, sres, kc);
659 rpos += wpa_snprintf_hex(rpos, rend - rpos, kc, 8);
661 rpos += wpa_snprintf_hex(rpos, rend - rpos, sres, 4);
663 rpos += wpa_snprintf_hex(rpos, rend - rpos, _rand, 16);
670 while (count < max_chal && (g = get_gsm_triplet(imsi))) {
671 if (strcmp(g->imsi, imsi) != 0)
676 rpos += wpa_snprintf_hex(rpos, rend - rpos, g->kc, 8);
679 rpos += wpa_snprintf_hex(rpos, rend - rpos, g->sres, 4);
682 rpos += wpa_snprintf_hex(rpos, rend - rpos, g->_rand, 16);
687 printf("No GSM triplets found for %s\n", imsi);
688 ret = snprintf(rpos, rend - rpos, " FAILURE");
689 if (ret < 0 || ret >= rend - rpos)
698 static int gsm_auth_req(char *imsi, char *resp, size_t resp_len)
701 char *pos, *rpos, *rend;
702 struct milenage_parameters *m;
706 pos = os_strchr(imsi, ' ');
711 rend = resp + resp_len;
713 ret = os_snprintf(rpos, rend - rpos, "GSM-AUTH-RESP %s", imsi);
714 if (os_snprintf_error(rend - rpos, ret))
718 m = get_milenage(imsi);
720 u8 _rand[16], sres[4], kc[8];
721 for (count = 0; count < EAP_SIM_MAX_CHAL; count++) {
722 if (hexstr2bin(pos, _rand, 16) != 0)
724 gsm_milenage(m->opc, m->ki, _rand, sres, kc);
725 *rpos++ = count == 0 ? ' ' : ':';
726 rpos += wpa_snprintf_hex(rpos, rend - rpos, kc, 8);
728 rpos += wpa_snprintf_hex(rpos, rend - rpos, sres, 4);
738 printf("No GSM triplets found for %s\n", imsi);
739 ret = os_snprintf(rpos, rend - rpos, " FAILURE");
740 if (os_snprintf_error(rend - rpos, ret))
748 static void inc_sqn(u8 *sqn)
753 * SQN = SEQ | IND = SEQ1 | SEQ2 | IND
755 * The mechanism used here is not time-based, so SEQ2 is void and
756 * SQN = SEQ1 | IND. The length of IND is ind_len bits and the length
757 * of SEQ1 is 48 - ind_len bits.
760 /* Increment both SEQ and IND by one */
761 val = ((u64) WPA_GET_BE32(sqn) << 16) | ((u64) WPA_GET_BE16(sqn + 4));
762 seq = (val >> ind_len) + 1;
763 ind = (val + 1) & ((1 << ind_len) - 1);
764 val = (seq << ind_len) | ind;
765 WPA_PUT_BE32(sqn, val >> 16);
766 WPA_PUT_BE16(sqn + 4, val & 0xffff);
770 static int aka_req_auth(char *imsi, char *resp, size_t resp_len)
772 /* AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES> */
774 u8 _rand[EAP_AKA_RAND_LEN];
775 u8 autn[EAP_AKA_AUTN_LEN];
776 u8 ik[EAP_AKA_IK_LEN];
777 u8 ck[EAP_AKA_CK_LEN];
778 u8 res[EAP_AKA_RES_MAX_LEN];
781 struct milenage_parameters *m;
784 m = get_milenage(imsi);
786 if (random_get_bytes(_rand, EAP_AKA_RAND_LEN) < 0)
788 res_len = EAP_AKA_RES_MAX_LEN;
791 db_update_milenage_sqn(m);
792 #endif /* CONFIG_SQLITE */
795 printf("AKA: Milenage with SQN=%02x%02x%02x%02x%02x%02x\n",
796 m->sqn[0], m->sqn[1], m->sqn[2],
797 m->sqn[3], m->sqn[4], m->sqn[5]);
799 milenage_generate(m->opc, m->amf, m->ki, m->sqn, _rand,
800 autn, ik, ck, res, &res_len);
802 printf("Unknown IMSI: %s\n", imsi);
803 #ifdef AKA_USE_FIXED_TEST_VALUES
804 printf("Using fixed test values for AKA\n");
805 memset(_rand, '0', EAP_AKA_RAND_LEN);
806 memset(autn, '1', EAP_AKA_AUTN_LEN);
807 memset(ik, '3', EAP_AKA_IK_LEN);
808 memset(ck, '4', EAP_AKA_CK_LEN);
809 memset(res, '2', EAP_AKA_RES_MAX_LEN);
810 res_len = EAP_AKA_RES_MAX_LEN;
811 #else /* AKA_USE_FIXED_TEST_VALUES */
813 #endif /* AKA_USE_FIXED_TEST_VALUES */
817 end = resp + resp_len;
818 ret = snprintf(pos, end - pos, "AKA-RESP-AUTH %s ", imsi);
819 if (ret < 0 || ret >= end - pos)
823 ret = snprintf(pos, end - pos, "FAILURE");
824 if (ret < 0 || ret >= end - pos)
829 pos += wpa_snprintf_hex(pos, end - pos, _rand, EAP_AKA_RAND_LEN);
831 pos += wpa_snprintf_hex(pos, end - pos, autn, EAP_AKA_AUTN_LEN);
833 pos += wpa_snprintf_hex(pos, end - pos, ik, EAP_AKA_IK_LEN);
835 pos += wpa_snprintf_hex(pos, end - pos, ck, EAP_AKA_CK_LEN);
837 pos += wpa_snprintf_hex(pos, end - pos, res, res_len);
843 static int aka_auts(char *imsi, char *resp, size_t resp_len)
846 u8 _auts[EAP_AKA_AUTS_LEN], _rand[EAP_AKA_RAND_LEN], sqn[6];
847 struct milenage_parameters *m;
851 /* AKA-AUTS <IMSI> <AUTS> <RAND> */
853 auts = strchr(imsi, ' ');
858 __rand = strchr(auts, ' ');
864 printf("AKA-AUTS: IMSI=%s AUTS=%s RAND=%s\n",
867 if (hexstr2bin(auts, _auts, EAP_AKA_AUTS_LEN) ||
868 hexstr2bin(__rand, _rand, EAP_AKA_RAND_LEN)) {
869 printf("Could not parse AUTS/RAND\n");
873 m = get_milenage(imsi);
875 printf("Unknown IMSI: %s\n", imsi);
879 if (milenage_auts(m->opc, m->ki, _rand, _auts, sqn)) {
880 printf("AKA-AUTS: Incorrect MAC-S\n");
882 memcpy(m->sqn, sqn, 6);
884 printf("AKA-AUTS: Re-synchronized: "
885 "SQN=%02x%02x%02x%02x%02x%02x\n",
886 sqn[0], sqn[1], sqn[2], sqn[3], sqn[4], sqn[5]);
889 db_update_milenage_sqn(m);
890 #endif /* CONFIG_SQLITE */
898 static int process_cmd(char *cmd, char *resp, size_t resp_len)
900 if (os_strncmp(cmd, "SIM-REQ-AUTH ", 13) == 0)
901 return sim_req_auth(cmd + 13, resp, resp_len);
903 if (os_strncmp(cmd, "GSM-AUTH-REQ ", 13) == 0)
904 return gsm_auth_req(cmd + 13, resp, resp_len);
906 if (os_strncmp(cmd, "AKA-REQ-AUTH ", 13) == 0)
907 return aka_req_auth(cmd + 13, resp, resp_len);
909 if (os_strncmp(cmd, "AKA-AUTS ", 9) == 0)
910 return aka_auts(cmd + 9, resp, resp_len);
912 printf("Unknown request: %s\n", cmd);
917 static int process(int s)
919 char buf[1000], resp[1000];
920 struct sockaddr_un from;
924 fromlen = sizeof(from);
925 res = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &from,
935 if ((size_t) res >= sizeof(buf))
936 res = sizeof(buf) - 1;
939 printf("Received: %s\n", buf);
941 if (process_cmd(buf, resp, sizeof(resp)) < 0) {
942 printf("Failed to process request\n");
946 if (resp[0] == '\0') {
947 printf("No response\n");
951 printf("Send: %s\n", resp);
953 if (sendto(s, resp, os_strlen(resp), 0, (struct sockaddr *) &from,
961 static void cleanup(void)
963 struct gsm_triplet *g, *gprev;
964 struct milenage_parameters *m, *prev;
966 if (update_milenage && milenage_file && sqn_changes)
967 update_milenage_file(milenage_file);
990 sqlite3_close(sqlite_db);
993 #endif /* CONFIG_SQLITE */
997 static void handle_term(int sig)
999 printf("Signal %d - terminate\n", sig);
1004 static void usage(void)
1006 printf("HLR/AuC testing gateway for hostapd EAP-SIM/AKA "
1007 "database/authenticator\n"
1008 "Copyright (c) 2005-2007, 2012-2013, Jouni Malinen <j@w1.fi>\n"
1011 "hlr_auc_gw [-hu] [-s<socket path>] [-g<triplet file>] "
1012 "[-m<milenage file>] \\\n"
1013 " [-D<DB file>] [-i<IND len in bits>] [command]\n"
1016 " -h = show this usage help\n"
1017 " -u = update SQN in Milenage file on exit\n"
1018 " -s<socket path> = path for UNIX domain socket\n"
1020 " -g<triplet file> = path for GSM authentication triplets\n"
1021 " -m<milenage file> = path for Milenage keys\n"
1022 " -D<DB file> = path to SQLite database\n"
1023 " -i<IND len in bits> = IND length for SQN (default: 5)\n"
1025 "If the optional command argument, like "
1026 "\"AKA-REQ-AUTH <IMSI>\" is used, a single\n"
1027 "command is processed with response sent to stdout. Otherwise, "
1028 "hlr_auc_gw opens\n"
1029 "a control interface and processes commands sent through it "
1030 "(e.g., by EAP server\n"
1032 default_socket_path);
1036 int main(int argc, char *argv[])
1039 char *gsm_triplet_file = NULL;
1040 char *sqlite_db_file = NULL;
1043 if (os_program_init())
1046 socket_path = default_socket_path;
1049 c = getopt(argc, argv, "D:g:hi:m:s:u");
1054 #ifdef CONFIG_SQLITE
1055 sqlite_db_file = optarg;
1057 #else /* CONFIG_SQLITE */
1058 printf("No SQLite support included in the build\n");
1060 #endif /* CONFIG_SQLITE */
1062 gsm_triplet_file = optarg;
1068 ind_len = atoi(optarg);
1069 if (ind_len < 0 || ind_len > 32) {
1070 printf("Invalid IND length\n");
1075 milenage_file = optarg;
1078 socket_path = optarg;
1081 update_milenage = 1;
1089 if (!gsm_triplet_file && !milenage_file && !sqlite_db_file) {
1094 #ifdef CONFIG_SQLITE
1095 if (sqlite_db_file && (sqlite_db = db_open(sqlite_db_file)) == NULL)
1097 #endif /* CONFIG_SQLITE */
1099 if (gsm_triplet_file && read_gsm_triplets(gsm_triplet_file) < 0)
1102 if (milenage_file && read_milenage(milenage_file) < 0)
1105 if (optind == argc) {
1106 serv_sock = open_socket(socket_path);
1110 printf("Listening for requests on %s\n", socket_path);
1113 signal(SIGTERM, handle_term);
1114 signal(SIGINT, handle_term);
1122 if (process_cmd(argv[optind], buf, sizeof(buf)) < 0) {
1126 printf("%s\n", buf);
1131 #ifdef CONFIG_SQLITE
1133 sqlite3_close(sqlite_db);
1136 #endif /* CONFIG_SQLITE */
1138 os_program_deinit();