2 * HLR/AuC testing gateway for hostapd EAP-SIM/AKA database/authenticator
3 * Copyright (c) 2005-2007, 2012, 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
22 * EAP-AKA / UMTS query/response:
24 * AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES>
25 * AKA-RESP-AUTH <IMSI> FAILURE
27 * EAP-AKA / UMTS AUTS (re-synchronization):
28 * AKA-AUTS <IMSI> <AUTS> <RAND>
30 * IMSI and max_chal are sent as an ASCII string,
31 * Kc/SRES/RAND/AUTN/IK/CK/RES/AUTS as hex strings.
33 * The example implementation here reads GSM authentication triplets from a
34 * text file in IMSI:Kc:SRES:RAND format, IMSI in ASCII, other fields as hex
35 * strings. This is used to simulate an HLR/AuC. As such, it is not very useful
36 * for real life authentication, but it is useful both as an example
37 * implementation and for EAP-SIM/AKA/AKA' testing.
39 * SQN generation follows the not time-based Profile 2 described in
40 * 3GPP TS 33.102 Annex C.3.2. The length of IND is 5 bits by default, but this
41 * can be changed with a command line options if needed.
48 #endif /* CONFIG_SQLITE */
51 #include "crypto/milenage.h"
52 #include "crypto/random.h"
54 static const char *default_socket_path
= "/tmp/hlr_auc_gw.sock";
55 static const char *socket_path
;
56 static int serv_sock
= -1;
57 static char *milenage_file
= NULL
;
58 static int update_milenage
= 0;
59 static int sqn_changes
= 0;
60 static int ind_len
= 5;
64 struct gsm_triplet
*next
;
71 static struct gsm_triplet
*gsm_db
= NULL
, *gsm_db_pos
= NULL
;
73 /* OPc and AMF parameters for Milenage (Example algorithms for AKA). */
74 struct milenage_parameters
{
75 struct milenage_parameters
*next
;
83 static struct milenage_parameters
*milenage_db
= NULL
;
85 #define EAP_SIM_MAX_CHAL 3
87 #define EAP_AKA_RAND_LEN 16
88 #define EAP_AKA_AUTN_LEN 16
89 #define EAP_AKA_AUTS_LEN 14
90 #define EAP_AKA_RES_MAX_LEN 16
91 #define EAP_AKA_IK_LEN 16
92 #define EAP_AKA_CK_LEN 16
97 static sqlite3
*sqlite_db
= NULL
;
98 static struct milenage_parameters db_tmp_milenage
;
101 static int db_table_exists(sqlite3
*db
, const char *name
)
104 os_snprintf(cmd
, sizeof(cmd
), "SELECT 1 FROM %s;", name
);
105 return sqlite3_exec(db
, cmd
, NULL
, NULL
, NULL
) == SQLITE_OK
;
109 static int db_table_create_milenage(sqlite3
*db
)
113 "CREATE TABLE milenage("
114 " imsi INTEGER PRIMARY KEY NOT NULL,"
115 " ki CHAR(32) NOT NULL,"
116 " opc CHAR(32) NOT NULL,"
117 " amf CHAR(4) NOT NULL,"
118 " sqn CHAR(12) NOT NULL"
121 printf("Adding database table for milenage information\n");
122 if (sqlite3_exec(db
, sql
, NULL
, NULL
, &err
) != SQLITE_OK
) {
123 printf("SQLite error: %s\n", err
);
132 static sqlite3
* db_open(const char *db_file
)
136 if (sqlite3_open(db_file
, &db
)) {
137 printf("Failed to open database %s: %s\n",
138 db_file
, sqlite3_errmsg(db
));
143 if (!db_table_exists(db
, "milenage") &&
144 db_table_create_milenage(db
) < 0) {
153 static int get_milenage_cb(void *ctx
, int argc
, char *argv
[], char *col
[])
155 struct milenage_parameters
*m
= ctx
;
158 for (i
= 0; i
< argc
; i
++) {
159 if (os_strcmp(col
[i
], "ki") == 0 && argv
[i
] &&
160 hexstr2bin(argv
[i
], m
->ki
, sizeof(m
->ki
))) {
161 printf("Invalid ki value in database\n");
165 if (os_strcmp(col
[i
], "opc") == 0 && argv
[i
] &&
166 hexstr2bin(argv
[i
], m
->opc
, sizeof(m
->opc
))) {
167 printf("Invalid opcvalue in database\n");
171 if (os_strcmp(col
[i
], "amf") == 0 && argv
[i
] &&
172 hexstr2bin(argv
[i
], m
->amf
, sizeof(m
->amf
))) {
173 printf("Invalid amf value in database\n");
177 if (os_strcmp(col
[i
], "sqn") == 0 && argv
[i
] &&
178 hexstr2bin(argv
[i
], m
->sqn
, sizeof(m
->sqn
))) {
179 printf("Invalid sqn value in database\n");
188 static struct milenage_parameters
* db_get_milenage(const char *imsi_txt
)
191 unsigned long long imsi
;
193 os_memset(&db_tmp_milenage
, 0, sizeof(db_tmp_milenage
));
194 imsi
= atoll(imsi_txt
);
195 os_snprintf(db_tmp_milenage
.imsi
, sizeof(db_tmp_milenage
.imsi
),
197 os_snprintf(cmd
, sizeof(cmd
),
198 "SELECT ki,opc,amf,sqn FROM milenage WHERE imsi=%llu;",
200 if (sqlite3_exec(sqlite_db
, cmd
, get_milenage_cb
, &db_tmp_milenage
,
204 return &db_tmp_milenage
;
208 static int db_update_milenage_sqn(struct milenage_parameters
*m
)
210 char cmd
[128], val
[13], *pos
;
213 pos
+= wpa_snprintf_hex(pos
, sizeof(val
), m
->sqn
, 6);
215 os_snprintf(cmd
, sizeof(cmd
),
216 "UPDATE milenage SET sqn='%s' WHERE imsi=%s;",
218 if (sqlite3_exec(sqlite_db
, cmd
, NULL
, NULL
, NULL
) != SQLITE_OK
) {
219 printf("Failed to update SQN in database for IMSI %s\n",
226 #endif /* CONFIG_SQLITE */
229 static int open_socket(const char *path
)
231 struct sockaddr_un addr
;
234 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
236 perror("socket(PF_UNIX)");
240 memset(&addr
, 0, sizeof(addr
));
241 addr
.sun_family
= AF_UNIX
;
242 os_strlcpy(addr
.sun_path
, path
, sizeof(addr
.sun_path
));
243 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
244 perror("hlr-auc-gw: bind(PF_UNIX)");
253 static int read_gsm_triplets(const char *fname
)
256 char buf
[200], *pos
, *pos2
;
257 struct gsm_triplet
*g
= NULL
;
263 f
= fopen(fname
, "r");
265 printf("Could not open GSM tripler data file '%s'\n", fname
);
270 while (fgets(buf
, sizeof(buf
), f
)) {
273 /* Parse IMSI:Kc:SRES:RAND */
274 buf
[sizeof(buf
) - 1] = '\0';
278 while (*pos
!= '\0' && *pos
!= '\n')
286 g
= os_zalloc(sizeof(*g
));
293 pos2
= strchr(pos
, ':');
295 printf("%s:%d - Invalid IMSI (%s)\n",
301 if (strlen(pos
) >= sizeof(g
->imsi
)) {
302 printf("%s:%d - Too long IMSI (%s)\n",
307 os_strlcpy(g
->imsi
, pos
, sizeof(g
->imsi
));
311 pos2
= strchr(pos
, ':');
313 printf("%s:%d - Invalid Kc (%s)\n", fname
, line
, pos
);
318 if (strlen(pos
) != 16 || hexstr2bin(pos
, g
->kc
, 8)) {
319 printf("%s:%d - Invalid Kc (%s)\n", fname
, line
, pos
);
326 pos2
= strchr(pos
, ':');
328 printf("%s:%d - Invalid SRES (%s)\n", fname
, line
,
334 if (strlen(pos
) != 8 || hexstr2bin(pos
, g
->sres
, 4)) {
335 printf("%s:%d - Invalid SRES (%s)\n", fname
, line
,
343 pos2
= strchr(pos
, ':');
346 if (strlen(pos
) != 32 || hexstr2bin(pos
, g
->_rand
, 16)) {
347 printf("%s:%d - Invalid RAND (%s)\n", fname
, line
,
366 static struct gsm_triplet
* get_gsm_triplet(const char *imsi
)
368 struct gsm_triplet
*g
= gsm_db_pos
;
371 if (strcmp(g
->imsi
, imsi
) == 0) {
372 gsm_db_pos
= g
->next
;
379 while (g
&& g
!= gsm_db_pos
) {
380 if (strcmp(g
->imsi
, imsi
) == 0) {
381 gsm_db_pos
= g
->next
;
391 static int read_milenage(const char *fname
)
394 char buf
[200], *pos
, *pos2
;
395 struct milenage_parameters
*m
= NULL
;
401 f
= fopen(fname
, "r");
403 printf("Could not open Milenage data file '%s'\n", fname
);
408 while (fgets(buf
, sizeof(buf
), f
)) {
411 /* Parse IMSI Ki OPc AMF SQN */
412 buf
[sizeof(buf
) - 1] = '\0';
416 while (*pos
!= '\0' && *pos
!= '\n')
424 m
= os_zalloc(sizeof(*m
));
431 pos2
= strchr(pos
, ' ');
433 printf("%s:%d - Invalid IMSI (%s)\n",
439 if (strlen(pos
) >= sizeof(m
->imsi
)) {
440 printf("%s:%d - Too long IMSI (%s)\n",
445 os_strlcpy(m
->imsi
, pos
, sizeof(m
->imsi
));
449 pos2
= strchr(pos
, ' ');
451 printf("%s:%d - Invalid Ki (%s)\n", fname
, line
, pos
);
456 if (strlen(pos
) != 32 || hexstr2bin(pos
, m
->ki
, 16)) {
457 printf("%s:%d - Invalid Ki (%s)\n", fname
, line
, pos
);
464 pos2
= strchr(pos
, ' ');
466 printf("%s:%d - Invalid OPc (%s)\n", fname
, line
, pos
);
471 if (strlen(pos
) != 32 || hexstr2bin(pos
, m
->opc
, 16)) {
472 printf("%s:%d - Invalid OPc (%s)\n", fname
, line
, pos
);
479 pos2
= strchr(pos
, ' ');
481 printf("%s:%d - Invalid AMF (%s)\n", fname
, line
, pos
);
486 if (strlen(pos
) != 4 || hexstr2bin(pos
, m
->amf
, 2)) {
487 printf("%s:%d - Invalid AMF (%s)\n", fname
, line
, pos
);
494 pos2
= strchr(pos
, ' ');
497 if (strlen(pos
) != 12 || hexstr2bin(pos
, m
->sqn
, 6)) {
498 printf("%s:%d - Invalid SEQ (%s)\n", fname
, line
, pos
);
504 m
->next
= milenage_db
;
516 static void update_milenage_file(const char *fname
)
520 char *end
= buf
+ sizeof(buf
);
521 struct milenage_parameters
*m
;
524 f
= fopen(fname
, "r");
526 printf("Could not open Milenage data file '%s'\n", fname
);
530 snprintf(buf
, sizeof(buf
), "%s.new", fname
);
531 f2
= fopen(buf
, "w");
533 printf("Could not write Milenage data file '%s'\n", buf
);
538 while (fgets(buf
, sizeof(buf
), f
)) {
539 /* IMSI Ki OPc AMF SQN */
540 buf
[sizeof(buf
) - 1] = '\0';
542 pos
= strchr(buf
, ' ');
543 if (buf
[0] == '#' || pos
== NULL
|| pos
- buf
>= 20)
546 imsi_len
= pos
- buf
;
548 for (m
= milenage_db
; m
; m
= m
->next
) {
549 if (strncmp(buf
, m
->imsi
, imsi_len
) == 0 &&
550 m
->imsi
[imsi_len
] == '\0')
558 pos
+= snprintf(pos
, end
- pos
, "%s ", m
->imsi
);
559 pos
+= wpa_snprintf_hex(pos
, end
- pos
, m
->ki
, 16);
561 pos
+= wpa_snprintf_hex(pos
, end
- pos
, m
->opc
, 16);
563 pos
+= wpa_snprintf_hex(pos
, end
- pos
, m
->amf
, 2);
565 pos
+= wpa_snprintf_hex(pos
, end
- pos
, m
->sqn
, 6);
569 fprintf(f2
, "%s", buf
);
575 snprintf(buf
, sizeof(buf
), "%s.bak", fname
);
576 if (rename(fname
, buf
) < 0) {
581 snprintf(buf
, sizeof(buf
), "%s.new", fname
);
582 if (rename(buf
, fname
) < 0) {
590 static struct milenage_parameters
* get_milenage(const char *imsi
)
592 struct milenage_parameters
*m
= milenage_db
;
595 if (strcmp(m
->imsi
, imsi
) == 0)
602 m
= db_get_milenage(imsi
);
603 #endif /* CONFIG_SQLITE */
609 static void sim_req_auth(int s
, struct sockaddr_un
*from
, socklen_t fromlen
,
612 int count
, max_chal
, ret
;
614 char reply
[1000], *rpos
, *rend
;
615 struct milenage_parameters
*m
;
616 struct gsm_triplet
*g
;
620 pos
= strchr(imsi
, ' ');
623 max_chal
= atoi(pos
);
624 if (max_chal
< 1 || max_chal
< EAP_SIM_MAX_CHAL
)
625 max_chal
= EAP_SIM_MAX_CHAL
;
627 max_chal
= EAP_SIM_MAX_CHAL
;
629 rend
= &reply
[sizeof(reply
)];
631 ret
= snprintf(rpos
, rend
- rpos
, "SIM-RESP-AUTH %s", imsi
);
632 if (ret
< 0 || ret
>= rend
- rpos
)
636 m
= get_milenage(imsi
);
638 u8 _rand
[16], sres
[4], kc
[8];
639 for (count
= 0; count
< max_chal
; count
++) {
640 if (random_get_bytes(_rand
, 16) < 0)
642 gsm_milenage(m
->opc
, m
->ki
, _rand
, sres
, kc
);
644 rpos
+= wpa_snprintf_hex(rpos
, rend
- rpos
, kc
, 8);
646 rpos
+= wpa_snprintf_hex(rpos
, rend
- rpos
, sres
, 4);
648 rpos
+= wpa_snprintf_hex(rpos
, rend
- rpos
, _rand
, 16);
655 while (count
< max_chal
&& (g
= get_gsm_triplet(imsi
))) {
656 if (strcmp(g
->imsi
, imsi
) != 0)
661 rpos
+= wpa_snprintf_hex(rpos
, rend
- rpos
, g
->kc
, 8);
664 rpos
+= wpa_snprintf_hex(rpos
, rend
- rpos
, g
->sres
, 4);
667 rpos
+= wpa_snprintf_hex(rpos
, rend
- rpos
, g
->_rand
, 16);
672 printf("No GSM triplets found for %s\n", imsi
);
673 ret
= snprintf(rpos
, rend
- rpos
, " FAILURE");
674 if (ret
< 0 || ret
>= rend
- rpos
)
680 printf("Send: %s\n", reply
);
681 if (sendto(s
, reply
, rpos
- reply
, 0,
682 (struct sockaddr
*) from
, fromlen
) < 0)
687 static void inc_sqn(u8
*sqn
)
692 * SQN = SEQ | IND = SEQ1 | SEQ2 | IND
694 * The mechanism used here is not time-based, so SEQ2 is void and
695 * SQN = SEQ1 | IND. The length of IND is ind_len bits and the length
696 * of SEQ1 is 48 - ind_len bits.
699 /* Increment both SEQ and IND by one */
700 val
= ((u64
) WPA_GET_BE32(sqn
) << 16) | ((u64
) WPA_GET_BE16(sqn
+ 4));
701 seq
= (val
>> ind_len
) + 1;
702 ind
= (val
+ 1) & ((1 << ind_len
) - 1);
703 val
= (seq
<< ind_len
) | ind
;
704 WPA_PUT_BE32(sqn
, val
>> 16);
705 WPA_PUT_BE16(sqn
+ 4, val
& 0xffff);
709 static void aka_req_auth(int s
, struct sockaddr_un
*from
, socklen_t fromlen
,
712 /* AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES> */
713 char reply
[1000], *pos
, *end
;
714 u8 _rand
[EAP_AKA_RAND_LEN
];
715 u8 autn
[EAP_AKA_AUTN_LEN
];
716 u8 ik
[EAP_AKA_IK_LEN
];
717 u8 ck
[EAP_AKA_CK_LEN
];
718 u8 res
[EAP_AKA_RES_MAX_LEN
];
721 struct milenage_parameters
*m
;
724 m
= get_milenage(imsi
);
726 if (random_get_bytes(_rand
, EAP_AKA_RAND_LEN
) < 0)
728 res_len
= EAP_AKA_RES_MAX_LEN
;
731 db_update_milenage_sqn(m
);
732 #endif /* CONFIG_SQLITE */
734 printf("AKA: Milenage with SQN=%02x%02x%02x%02x%02x%02x\n",
735 m
->sqn
[0], m
->sqn
[1], m
->sqn
[2],
736 m
->sqn
[3], m
->sqn
[4], m
->sqn
[5]);
737 milenage_generate(m
->opc
, m
->amf
, m
->ki
, m
->sqn
, _rand
,
738 autn
, ik
, ck
, res
, &res_len
);
740 printf("Unknown IMSI: %s\n", imsi
);
741 #ifdef AKA_USE_FIXED_TEST_VALUES
742 printf("Using fixed test values for AKA\n");
743 memset(_rand
, '0', EAP_AKA_RAND_LEN
);
744 memset(autn
, '1', EAP_AKA_AUTN_LEN
);
745 memset(ik
, '3', EAP_AKA_IK_LEN
);
746 memset(ck
, '4', EAP_AKA_CK_LEN
);
747 memset(res
, '2', EAP_AKA_RES_MAX_LEN
);
748 res_len
= EAP_AKA_RES_MAX_LEN
;
749 #else /* AKA_USE_FIXED_TEST_VALUES */
751 #endif /* AKA_USE_FIXED_TEST_VALUES */
755 end
= &reply
[sizeof(reply
)];
756 ret
= snprintf(pos
, end
- pos
, "AKA-RESP-AUTH %s ", imsi
);
757 if (ret
< 0 || ret
>= end
- pos
)
761 ret
= snprintf(pos
, end
- pos
, "FAILURE");
762 if (ret
< 0 || ret
>= end
- pos
)
767 pos
+= wpa_snprintf_hex(pos
, end
- pos
, _rand
, EAP_AKA_RAND_LEN
);
769 pos
+= wpa_snprintf_hex(pos
, end
- pos
, autn
, EAP_AKA_AUTN_LEN
);
771 pos
+= wpa_snprintf_hex(pos
, end
- pos
, ik
, EAP_AKA_IK_LEN
);
773 pos
+= wpa_snprintf_hex(pos
, end
- pos
, ck
, EAP_AKA_CK_LEN
);
775 pos
+= wpa_snprintf_hex(pos
, end
- pos
, res
, res_len
);
778 printf("Send: %s\n", reply
);
780 if (sendto(s
, reply
, pos
- reply
, 0, (struct sockaddr
*) from
,
786 static void aka_auts(int s
, struct sockaddr_un
*from
, socklen_t fromlen
,
790 u8 _auts
[EAP_AKA_AUTS_LEN
], _rand
[EAP_AKA_RAND_LEN
], sqn
[6];
791 struct milenage_parameters
*m
;
793 /* AKA-AUTS <IMSI> <AUTS> <RAND> */
795 auts
= strchr(imsi
, ' ');
800 __rand
= strchr(auts
, ' ');
805 printf("AKA-AUTS: IMSI=%s AUTS=%s RAND=%s\n", imsi
, auts
, __rand
);
806 if (hexstr2bin(auts
, _auts
, EAP_AKA_AUTS_LEN
) ||
807 hexstr2bin(__rand
, _rand
, EAP_AKA_RAND_LEN
)) {
808 printf("Could not parse AUTS/RAND\n");
812 m
= get_milenage(imsi
);
814 printf("Unknown IMSI: %s\n", imsi
);
818 if (milenage_auts(m
->opc
, m
->ki
, _rand
, _auts
, sqn
)) {
819 printf("AKA-AUTS: Incorrect MAC-S\n");
821 memcpy(m
->sqn
, sqn
, 6);
822 printf("AKA-AUTS: Re-synchronized: "
823 "SQN=%02x%02x%02x%02x%02x%02x\n",
824 sqn
[0], sqn
[1], sqn
[2], sqn
[3], sqn
[4], sqn
[5]);
826 db_update_milenage_sqn(m
);
827 #endif /* CONFIG_SQLITE */
833 static int process(int s
)
836 struct sockaddr_un from
;
840 fromlen
= sizeof(from
);
841 res
= recvfrom(s
, buf
, sizeof(buf
), 0, (struct sockaddr
*) &from
,
851 if ((size_t) res
>= sizeof(buf
))
852 res
= sizeof(buf
) - 1;
855 printf("Received: %s\n", buf
);
857 if (strncmp(buf
, "SIM-REQ-AUTH ", 13) == 0)
858 sim_req_auth(s
, &from
, fromlen
, buf
+ 13);
859 else if (strncmp(buf
, "AKA-REQ-AUTH ", 13) == 0)
860 aka_req_auth(s
, &from
, fromlen
, buf
+ 13);
861 else if (strncmp(buf
, "AKA-AUTS ", 9) == 0)
862 aka_auts(s
, &from
, fromlen
, buf
+ 9);
864 printf("Unknown request: %s\n", buf
);
870 static void cleanup(void)
872 struct gsm_triplet
*g
, *gprev
;
873 struct milenage_parameters
*m
, *prev
;
875 if (update_milenage
&& milenage_file
&& sqn_changes
)
876 update_milenage_file(milenage_file
);
897 sqlite3_close(sqlite_db
);
900 #endif /* CONFIG_SQLITE */
904 static void handle_term(int sig
)
906 printf("Signal %d - terminate\n", sig
);
911 static void usage(void)
913 printf("HLR/AuC testing gateway for hostapd EAP-SIM/AKA "
914 "database/authenticator\n"
915 "Copyright (c) 2005-2007, 2012, Jouni Malinen <j@w1.fi>\n"
918 "hlr_auc_gw [-hu] [-s<socket path>] [-g<triplet file>] "
919 "[-m<milenage file>] \\\n"
920 " [-D<DB file>] [-i<IND len in bits>]\n"
923 " -h = show this usage help\n"
924 " -u = update SQN in Milenage file on exit\n"
925 " -s<socket path> = path for UNIX domain socket\n"
927 " -g<triplet file> = path for GSM authentication triplets\n"
928 " -m<milenage file> = path for Milenage keys\n"
929 " -D<DB file> = path to SQLite database\n"
930 " -i<IND len in bits> = IND length for SQN (default: 5)\n",
931 default_socket_path
);
935 int main(int argc
, char *argv
[])
938 char *gsm_triplet_file
= NULL
;
939 char *sqlite_db_file
= NULL
;
941 if (os_program_init())
944 socket_path
= default_socket_path
;
947 c
= getopt(argc
, argv
, "D:g:hi:m:s:u");
953 sqlite_db_file
= optarg
;
955 #else /* CONFIG_SQLITE */
956 printf("No SQLite support included in the build\n");
958 #endif /* CONFIG_SQLITE */
960 gsm_triplet_file
= optarg
;
966 ind_len
= atoi(optarg
);
967 if (ind_len
< 0 || ind_len
> 32) {
968 printf("Invalid IND length\n");
973 milenage_file
= optarg
;
976 socket_path
= optarg
;
987 if (!gsm_triplet_file
&& !milenage_file
&& !sqlite_db_file
) {
993 if (sqlite_db_file
&& (sqlite_db
= db_open(sqlite_db_file
)) == NULL
)
995 #endif /* CONFIG_SQLITE */
997 if (gsm_triplet_file
&& read_gsm_triplets(gsm_triplet_file
) < 0)
1000 if (milenage_file
&& read_milenage(milenage_file
) < 0)
1003 serv_sock
= open_socket(socket_path
);
1007 printf("Listening for requests on %s\n", socket_path
);
1010 signal(SIGTERM
, handle_term
);
1011 signal(SIGINT
, handle_term
);
1016 #ifdef CONFIG_SQLITE
1018 sqlite3_close(sqlite_db
);
1021 #endif /* CONFIG_SQLITE */
1023 os_program_deinit();