hlr_auc_gw.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * HLR/AuC testing gateway for hostapd EAP-SIM/AKA database/authenticator
  3. * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. *
  14. * This is an example implementation of the EAP-SIM/AKA database/authentication
  15. * gateway interface to HLR/AuC. It is expected to be replaced with an
  16. * implementation of SS7 gateway to GSM/UMTS authentication center (HLR/AuC) or
  17. * a local implementation of SIM triplet and AKA authentication data generator.
  18. *
  19. * hostapd will send SIM/AKA authentication queries over a UNIX domain socket
  20. * to and external program, e.g., this hlr_auc_gw. This interface uses simple
  21. * text-based format:
  22. *
  23. * EAP-SIM / GSM triplet query/response:
  24. * SIM-REQ-AUTH <IMSI> <max_chal>
  25. * SIM-RESP-AUTH <IMSI> Kc1:SRES1:RAND1 Kc2:SRES2:RAND2 [Kc3:SRES3:RAND3]
  26. * SIM-RESP-AUTH <IMSI> FAILURE
  27. *
  28. * EAP-AKA / UMTS query/response:
  29. * AKA-REQ-AUTH <IMSI>
  30. * AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES>
  31. * AKA-RESP-AUTH <IMSI> FAILURE
  32. *
  33. * EAP-AKA / UMTS AUTS (re-synchronization):
  34. * AKA-AUTS <IMSI> <AUTS> <RAND>
  35. *
  36. * IMSI and max_chal are sent as an ASCII string,
  37. * Kc/SRES/RAND/AUTN/IK/CK/RES/AUTS as hex strings.
  38. *
  39. * The example implementation here reads GSM authentication triplets from a
  40. * text file in IMSI:Kc:SRES:RAND format, IMSI in ASCII, other fields as hex
  41. * strings. This is used to simulate an HLR/AuC. As such, it is not very useful
  42. * for real life authentication, but it is useful both as an example
  43. * implementation and for EAP-SIM testing.
  44. */
  45. #include "includes.h"
  46. #include <sys/un.h>
  47. #include "common.h"
  48. #include "crypto/milenage.h"
  49. static const char *default_socket_path = "/tmp/hlr_auc_gw.sock";
  50. static const char *socket_path;
  51. static int serv_sock = -1;
  52. /* GSM triplets */
  53. struct gsm_triplet {
  54. struct gsm_triplet *next;
  55. char imsi[20];
  56. u8 kc[8];
  57. u8 sres[4];
  58. u8 _rand[16];
  59. };
  60. static struct gsm_triplet *gsm_db = NULL, *gsm_db_pos = NULL;
  61. /* OPc and AMF parameters for Milenage (Example algorithms for AKA). */
  62. struct milenage_parameters {
  63. struct milenage_parameters *next;
  64. char imsi[20];
  65. u8 ki[16];
  66. u8 opc[16];
  67. u8 amf[2];
  68. u8 sqn[6];
  69. };
  70. static struct milenage_parameters *milenage_db = NULL;
  71. #define EAP_SIM_MAX_CHAL 3
  72. #define EAP_AKA_RAND_LEN 16
  73. #define EAP_AKA_AUTN_LEN 16
  74. #define EAP_AKA_AUTS_LEN 14
  75. #define EAP_AKA_RES_MAX_LEN 16
  76. #define EAP_AKA_IK_LEN 16
  77. #define EAP_AKA_CK_LEN 16
  78. static int open_socket(const char *path)
  79. {
  80. struct sockaddr_un addr;
  81. int s;
  82. s = socket(PF_UNIX, SOCK_DGRAM, 0);
  83. if (s < 0) {
  84. perror("socket(PF_UNIX)");
  85. return -1;
  86. }
  87. memset(&addr, 0, sizeof(addr));
  88. addr.sun_family = AF_UNIX;
  89. os_strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
  90. if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  91. perror("bind(PF_UNIX)");
  92. close(s);
  93. return -1;
  94. }
  95. return s;
  96. }
  97. static int read_gsm_triplets(const char *fname)
  98. {
  99. FILE *f;
  100. char buf[200], *pos, *pos2;
  101. struct gsm_triplet *g = NULL;
  102. int line, ret = 0;
  103. if (fname == NULL)
  104. return -1;
  105. f = fopen(fname, "r");
  106. if (f == NULL) {
  107. printf("Could not open GSM tripler data file '%s'\n", fname);
  108. return -1;
  109. }
  110. line = 0;
  111. while (fgets(buf, sizeof(buf), f)) {
  112. line++;
  113. /* Parse IMSI:Kc:SRES:RAND */
  114. buf[sizeof(buf) - 1] = '\0';
  115. if (buf[0] == '#')
  116. continue;
  117. pos = buf;
  118. while (*pos != '\0' && *pos != '\n')
  119. pos++;
  120. if (*pos == '\n')
  121. *pos = '\0';
  122. pos = buf;
  123. if (*pos == '\0')
  124. continue;
  125. g = os_zalloc(sizeof(*g));
  126. if (g == NULL) {
  127. ret = -1;
  128. break;
  129. }
  130. /* IMSI */
  131. pos2 = strchr(pos, ':');
  132. if (pos2 == NULL) {
  133. printf("%s:%d - Invalid IMSI (%s)\n",
  134. fname, line, pos);
  135. ret = -1;
  136. break;
  137. }
  138. *pos2 = '\0';
  139. if (strlen(pos) >= sizeof(g->imsi)) {
  140. printf("%s:%d - Too long IMSI (%s)\n",
  141. fname, line, pos);
  142. ret = -1;
  143. break;
  144. }
  145. os_strlcpy(g->imsi, pos, sizeof(g->imsi));
  146. pos = pos2 + 1;
  147. /* Kc */
  148. pos2 = strchr(pos, ':');
  149. if (pos2 == NULL) {
  150. printf("%s:%d - Invalid Kc (%s)\n", fname, line, pos);
  151. ret = -1;
  152. break;
  153. }
  154. *pos2 = '\0';
  155. if (strlen(pos) != 16 || hexstr2bin(pos, g->kc, 8)) {
  156. printf("%s:%d - Invalid Kc (%s)\n", fname, line, pos);
  157. ret = -1;
  158. break;
  159. }
  160. pos = pos2 + 1;
  161. /* SRES */
  162. pos2 = strchr(pos, ':');
  163. if (pos2 == NULL) {
  164. printf("%s:%d - Invalid SRES (%s)\n", fname, line,
  165. pos);
  166. ret = -1;
  167. break;
  168. }
  169. *pos2 = '\0';
  170. if (strlen(pos) != 8 || hexstr2bin(pos, g->sres, 4)) {
  171. printf("%s:%d - Invalid SRES (%s)\n", fname, line,
  172. pos);
  173. ret = -1;
  174. break;
  175. }
  176. pos = pos2 + 1;
  177. /* RAND */
  178. pos2 = strchr(pos, ':');
  179. if (pos2)
  180. *pos2 = '\0';
  181. if (strlen(pos) != 32 || hexstr2bin(pos, g->_rand, 16)) {
  182. printf("%s:%d - Invalid RAND (%s)\n", fname, line,
  183. pos);
  184. ret = -1;
  185. break;
  186. }
  187. pos = pos2 + 1;
  188. g->next = gsm_db;
  189. gsm_db = g;
  190. g = NULL;
  191. }
  192. free(g);
  193. fclose(f);
  194. return ret;
  195. }
  196. static struct gsm_triplet * get_gsm_triplet(const char *imsi)
  197. {
  198. struct gsm_triplet *g = gsm_db_pos;
  199. while (g) {
  200. if (strcmp(g->imsi, imsi) == 0) {
  201. gsm_db_pos = g->next;
  202. return g;
  203. }
  204. g = g->next;
  205. }
  206. g = gsm_db;
  207. while (g && g != gsm_db_pos) {
  208. if (strcmp(g->imsi, imsi) == 0) {
  209. gsm_db_pos = g->next;
  210. return g;
  211. }
  212. g = g->next;
  213. }
  214. return NULL;
  215. }
  216. static int read_milenage(const char *fname)
  217. {
  218. FILE *f;
  219. char buf[200], *pos, *pos2;
  220. struct milenage_parameters *m = NULL;
  221. int line, ret = 0;
  222. if (fname == NULL)
  223. return -1;
  224. f = fopen(fname, "r");
  225. if (f == NULL) {
  226. printf("Could not open Milenage data file '%s'\n", fname);
  227. return -1;
  228. }
  229. line = 0;
  230. while (fgets(buf, sizeof(buf), f)) {
  231. line++;
  232. /* Parse IMSI Ki OPc AMF SQN */
  233. buf[sizeof(buf) - 1] = '\0';
  234. if (buf[0] == '#')
  235. continue;
  236. pos = buf;
  237. while (*pos != '\0' && *pos != '\n')
  238. pos++;
  239. if (*pos == '\n')
  240. *pos = '\0';
  241. pos = buf;
  242. if (*pos == '\0')
  243. continue;
  244. m = os_zalloc(sizeof(*m));
  245. if (m == NULL) {
  246. ret = -1;
  247. break;
  248. }
  249. /* IMSI */
  250. pos2 = strchr(pos, ' ');
  251. if (pos2 == NULL) {
  252. printf("%s:%d - Invalid IMSI (%s)\n",
  253. fname, line, pos);
  254. ret = -1;
  255. break;
  256. }
  257. *pos2 = '\0';
  258. if (strlen(pos) >= sizeof(m->imsi)) {
  259. printf("%s:%d - Too long IMSI (%s)\n",
  260. fname, line, pos);
  261. ret = -1;
  262. break;
  263. }
  264. os_strlcpy(m->imsi, pos, sizeof(m->imsi));
  265. pos = pos2 + 1;
  266. /* Ki */
  267. pos2 = strchr(pos, ' ');
  268. if (pos2 == NULL) {
  269. printf("%s:%d - Invalid Ki (%s)\n", fname, line, pos);
  270. ret = -1;
  271. break;
  272. }
  273. *pos2 = '\0';
  274. if (strlen(pos) != 32 || hexstr2bin(pos, m->ki, 16)) {
  275. printf("%s:%d - Invalid Ki (%s)\n", fname, line, pos);
  276. ret = -1;
  277. break;
  278. }
  279. pos = pos2 + 1;
  280. /* OPc */
  281. pos2 = strchr(pos, ' ');
  282. if (pos2 == NULL) {
  283. printf("%s:%d - Invalid OPc (%s)\n", fname, line, pos);
  284. ret = -1;
  285. break;
  286. }
  287. *pos2 = '\0';
  288. if (strlen(pos) != 32 || hexstr2bin(pos, m->opc, 16)) {
  289. printf("%s:%d - Invalid OPc (%s)\n", fname, line, pos);
  290. ret = -1;
  291. break;
  292. }
  293. pos = pos2 + 1;
  294. /* AMF */
  295. pos2 = strchr(pos, ' ');
  296. if (pos2 == NULL) {
  297. printf("%s:%d - Invalid AMF (%s)\n", fname, line, pos);
  298. ret = -1;
  299. break;
  300. }
  301. *pos2 = '\0';
  302. if (strlen(pos) != 4 || hexstr2bin(pos, m->amf, 2)) {
  303. printf("%s:%d - Invalid AMF (%s)\n", fname, line, pos);
  304. ret = -1;
  305. break;
  306. }
  307. pos = pos2 + 1;
  308. /* SQN */
  309. pos2 = strchr(pos, ' ');
  310. if (pos2)
  311. *pos2 = '\0';
  312. if (strlen(pos) != 12 || hexstr2bin(pos, m->sqn, 6)) {
  313. printf("%s:%d - Invalid SEQ (%s)\n", fname, line, pos);
  314. ret = -1;
  315. break;
  316. }
  317. pos = pos2 + 1;
  318. m->next = milenage_db;
  319. milenage_db = m;
  320. m = NULL;
  321. }
  322. free(m);
  323. fclose(f);
  324. return ret;
  325. }
  326. static struct milenage_parameters * get_milenage(const char *imsi)
  327. {
  328. struct milenage_parameters *m = milenage_db;
  329. while (m) {
  330. if (strcmp(m->imsi, imsi) == 0)
  331. break;
  332. m = m->next;
  333. }
  334. return m;
  335. }
  336. static void sim_req_auth(int s, struct sockaddr_un *from, socklen_t fromlen,
  337. char *imsi)
  338. {
  339. int count, max_chal, ret;
  340. char *pos;
  341. char reply[1000], *rpos, *rend;
  342. struct milenage_parameters *m;
  343. struct gsm_triplet *g;
  344. reply[0] = '\0';
  345. pos = strchr(imsi, ' ');
  346. if (pos) {
  347. *pos++ = '\0';
  348. max_chal = atoi(pos);
  349. if (max_chal < 1 || max_chal < EAP_SIM_MAX_CHAL)
  350. max_chal = EAP_SIM_MAX_CHAL;
  351. } else
  352. max_chal = EAP_SIM_MAX_CHAL;
  353. rend = &reply[sizeof(reply)];
  354. rpos = reply;
  355. ret = snprintf(rpos, rend - rpos, "SIM-RESP-AUTH %s", imsi);
  356. if (ret < 0 || ret >= rend - rpos)
  357. return;
  358. rpos += ret;
  359. m = get_milenage(imsi);
  360. if (m) {
  361. u8 _rand[16], sres[4], kc[8];
  362. for (count = 0; count < max_chal; count++) {
  363. if (os_get_random(_rand, 16) < 0)
  364. return;
  365. gsm_milenage(m->opc, m->ki, _rand, sres, kc);
  366. *rpos++ = ' ';
  367. rpos += wpa_snprintf_hex(rpos, rend - rpos, kc, 8);
  368. *rpos++ = ':';
  369. rpos += wpa_snprintf_hex(rpos, rend - rpos, sres, 4);
  370. *rpos++ = ':';
  371. rpos += wpa_snprintf_hex(rpos, rend - rpos, _rand, 16);
  372. }
  373. *rpos = '\0';
  374. goto send;
  375. }
  376. count = 0;
  377. while (count < max_chal && (g = get_gsm_triplet(imsi))) {
  378. if (strcmp(g->imsi, imsi) != 0)
  379. continue;
  380. if (rpos < rend)
  381. *rpos++ = ' ';
  382. rpos += wpa_snprintf_hex(rpos, rend - rpos, g->kc, 8);
  383. if (rpos < rend)
  384. *rpos++ = ':';
  385. rpos += wpa_snprintf_hex(rpos, rend - rpos, g->sres, 4);
  386. if (rpos < rend)
  387. *rpos++ = ':';
  388. rpos += wpa_snprintf_hex(rpos, rend - rpos, g->_rand, 16);
  389. count++;
  390. }
  391. if (count == 0) {
  392. printf("No GSM triplets found for %s\n", imsi);
  393. ret = snprintf(rpos, rend - rpos, " FAILURE");
  394. if (ret < 0 || ret >= rend - rpos)
  395. return;
  396. rpos += ret;
  397. }
  398. send:
  399. printf("Send: %s\n", reply);
  400. if (sendto(s, reply, rpos - reply, 0,
  401. (struct sockaddr *) from, fromlen) < 0)
  402. perror("send");
  403. }
  404. static void aka_req_auth(int s, struct sockaddr_un *from, socklen_t fromlen,
  405. char *imsi)
  406. {
  407. /* AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES> */
  408. char reply[1000], *pos, *end;
  409. u8 _rand[EAP_AKA_RAND_LEN];
  410. u8 autn[EAP_AKA_AUTN_LEN];
  411. u8 ik[EAP_AKA_IK_LEN];
  412. u8 ck[EAP_AKA_CK_LEN];
  413. u8 res[EAP_AKA_RES_MAX_LEN];
  414. size_t res_len;
  415. int ret;
  416. struct milenage_parameters *m;
  417. m = get_milenage(imsi);
  418. if (m) {
  419. if (os_get_random(_rand, EAP_AKA_RAND_LEN) < 0)
  420. return;
  421. res_len = EAP_AKA_RES_MAX_LEN;
  422. inc_byte_array(m->sqn, 6);
  423. printf("AKA: Milenage with SQN=%02x%02x%02x%02x%02x%02x\n",
  424. m->sqn[0], m->sqn[1], m->sqn[2],
  425. m->sqn[3], m->sqn[4], m->sqn[5]);
  426. milenage_generate(m->opc, m->amf, m->ki, m->sqn, _rand,
  427. autn, ik, ck, res, &res_len);
  428. } else {
  429. printf("Unknown IMSI: %s\n", imsi);
  430. #ifdef AKA_USE_FIXED_TEST_VALUES
  431. printf("Using fixed test values for AKA\n");
  432. memset(_rand, '0', EAP_AKA_RAND_LEN);
  433. memset(autn, '1', EAP_AKA_AUTN_LEN);
  434. memset(ik, '3', EAP_AKA_IK_LEN);
  435. memset(ck, '4', EAP_AKA_CK_LEN);
  436. memset(res, '2', EAP_AKA_RES_MAX_LEN);
  437. res_len = EAP_AKA_RES_MAX_LEN;
  438. #else /* AKA_USE_FIXED_TEST_VALUES */
  439. return;
  440. #endif /* AKA_USE_FIXED_TEST_VALUES */
  441. }
  442. pos = reply;
  443. end = &reply[sizeof(reply)];
  444. ret = snprintf(pos, end - pos, "AKA-RESP-AUTH %s ", imsi);
  445. if (ret < 0 || ret >= end - pos)
  446. return;
  447. pos += ret;
  448. pos += wpa_snprintf_hex(pos, end - pos, _rand, EAP_AKA_RAND_LEN);
  449. *pos++ = ' ';
  450. pos += wpa_snprintf_hex(pos, end - pos, autn, EAP_AKA_AUTN_LEN);
  451. *pos++ = ' ';
  452. pos += wpa_snprintf_hex(pos, end - pos, ik, EAP_AKA_IK_LEN);
  453. *pos++ = ' ';
  454. pos += wpa_snprintf_hex(pos, end - pos, ck, EAP_AKA_CK_LEN);
  455. *pos++ = ' ';
  456. pos += wpa_snprintf_hex(pos, end - pos, res, res_len);
  457. printf("Send: %s\n", reply);
  458. if (sendto(s, reply, pos - reply, 0, (struct sockaddr *) from,
  459. fromlen) < 0)
  460. perror("send");
  461. }
  462. static void aka_auts(int s, struct sockaddr_un *from, socklen_t fromlen,
  463. char *imsi)
  464. {
  465. char *auts, *__rand;
  466. u8 _auts[EAP_AKA_AUTS_LEN], _rand[EAP_AKA_RAND_LEN], sqn[6];
  467. struct milenage_parameters *m;
  468. /* AKA-AUTS <IMSI> <AUTS> <RAND> */
  469. auts = strchr(imsi, ' ');
  470. if (auts == NULL)
  471. return;
  472. *auts++ = '\0';
  473. __rand = strchr(auts, ' ');
  474. if (__rand == NULL)
  475. return;
  476. *__rand++ = '\0';
  477. printf("AKA-AUTS: IMSI=%s AUTS=%s RAND=%s\n", imsi, auts, __rand);
  478. if (hexstr2bin(auts, _auts, EAP_AKA_AUTS_LEN) ||
  479. hexstr2bin(__rand, _rand, EAP_AKA_RAND_LEN)) {
  480. printf("Could not parse AUTS/RAND\n");
  481. return;
  482. }
  483. m = get_milenage(imsi);
  484. if (m == NULL) {
  485. printf("Unknown IMSI: %s\n", imsi);
  486. return;
  487. }
  488. if (milenage_auts(m->opc, m->ki, _rand, _auts, sqn)) {
  489. printf("AKA-AUTS: Incorrect MAC-S\n");
  490. } else {
  491. memcpy(m->sqn, sqn, 6);
  492. printf("AKA-AUTS: Re-synchronized: "
  493. "SQN=%02x%02x%02x%02x%02x%02x\n",
  494. sqn[0], sqn[1], sqn[2], sqn[3], sqn[4], sqn[5]);
  495. }
  496. }
  497. static int process(int s)
  498. {
  499. char buf[1000];
  500. struct sockaddr_un from;
  501. socklen_t fromlen;
  502. ssize_t res;
  503. fromlen = sizeof(from);
  504. res = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &from,
  505. &fromlen);
  506. if (res < 0) {
  507. perror("recvfrom");
  508. return -1;
  509. }
  510. if (res == 0)
  511. return 0;
  512. if ((size_t) res >= sizeof(buf))
  513. res = sizeof(buf) - 1;
  514. buf[res] = '\0';
  515. printf("Received: %s\n", buf);
  516. if (strncmp(buf, "SIM-REQ-AUTH ", 13) == 0)
  517. sim_req_auth(s, &from, fromlen, buf + 13);
  518. else if (strncmp(buf, "AKA-REQ-AUTH ", 13) == 0)
  519. aka_req_auth(s, &from, fromlen, buf + 13);
  520. else if (strncmp(buf, "AKA-AUTS ", 9) == 0)
  521. aka_auts(s, &from, fromlen, buf + 9);
  522. else
  523. printf("Unknown request: %s\n", buf);
  524. return 0;
  525. }
  526. static void cleanup(void)
  527. {
  528. struct gsm_triplet *g, *gprev;
  529. struct milenage_parameters *m, *prev;
  530. g = gsm_db;
  531. while (g) {
  532. gprev = g;
  533. g = g->next;
  534. free(gprev);
  535. }
  536. m = milenage_db;
  537. while (m) {
  538. prev = m;
  539. m = m->next;
  540. free(prev);
  541. }
  542. close(serv_sock);
  543. unlink(socket_path);
  544. }
  545. static void handle_term(int sig)
  546. {
  547. printf("Signal %d - terminate\n", sig);
  548. exit(0);
  549. }
  550. static void usage(void)
  551. {
  552. printf("HLR/AuC testing gateway for hostapd EAP-SIM/AKA "
  553. "database/authenticator\n"
  554. "Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>\n"
  555. "\n"
  556. "usage:\n"
  557. "hlr_auc_gw [-h] [-s<socket path>] [-g<triplet file>] "
  558. "[-m<milenage file>]\n"
  559. "\n"
  560. "options:\n"
  561. " -h = show this usage help\n"
  562. " -s<socket path> = path for UNIX domain socket\n"
  563. " (default: %s)\n"
  564. " -g<triplet file> = path for GSM authentication triplets\n"
  565. " -m<milenage file> = path for Milenage keys\n",
  566. default_socket_path);
  567. }
  568. int main(int argc, char *argv[])
  569. {
  570. int c;
  571. char *milenage_file = NULL;
  572. char *gsm_triplet_file = NULL;
  573. socket_path = default_socket_path;
  574. for (;;) {
  575. c = getopt(argc, argv, "g:hm:s:");
  576. if (c < 0)
  577. break;
  578. switch (c) {
  579. case 'g':
  580. gsm_triplet_file = optarg;
  581. break;
  582. case 'h':
  583. usage();
  584. return 0;
  585. case 'm':
  586. milenage_file = optarg;
  587. break;
  588. case 's':
  589. socket_path = optarg;
  590. break;
  591. default:
  592. usage();
  593. return -1;
  594. }
  595. }
  596. if (gsm_triplet_file && read_gsm_triplets(gsm_triplet_file) < 0)
  597. return -1;
  598. if (milenage_file && read_milenage(milenage_file) < 0)
  599. return -1;
  600. serv_sock = open_socket(socket_path);
  601. if (serv_sock < 0)
  602. return -1;
  603. printf("Listening for requests on %s\n", socket_path);
  604. atexit(cleanup);
  605. signal(SIGTERM, handle_term);
  606. signal(SIGINT, handle_term);
  607. for (;;)
  608. process(serv_sock);
  609. return 0;
  610. }