blob: bb6f05a82e83440299cde5595cac98688ef2232c [file] [log] [blame]
Harald Welte936f6722016-05-03 18:51:18 +02001/* (C) 2016 by Harald Welte <laforge@gnumonks.org>
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
Harald Welteaabae9e2016-04-28 12:48:14 +020020#include <signal.h>
Harald Weltee687be52016-05-03 18:49:27 +020021#include <errno.h>
Maxea8b0d42017-02-14 16:53:04 +010022#include <stdbool.h>
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +010023#include <getopt.h>
24
Harald Weltee72cf552016-04-28 07:18:49 +020025#include <osmocom/core/msgb.h>
26#include <osmocom/core/logging.h>
27#include <osmocom/core/application.h>
28#include <osmocom/gsm/gsup.h>
Max2fc63a62016-12-20 16:49:20 +010029#include <osmocom/gsm/apn.h>
Neels Hofmeyr627de842016-12-19 13:16:06 +010030#include <osmocom/gsm/gsm48_ie.h>
Neels Hofmeyr7685a782017-01-30 23:30:26 +010031#include <osmocom/vty/vty.h>
32#include <osmocom/vty/command.h>
33#include <osmocom/vty/telnet_interface.h>
34#include <osmocom/vty/ports.h>
Harald Weltee72cf552016-04-28 07:18:49 +020035
36#include "db.h"
Maxd4bebbd2017-03-02 12:00:19 +010037#include "hlr.h"
Harald Weltee72cf552016-04-28 07:18:49 +020038#include "logging.h"
39#include "gsup_server.h"
Harald Weltee687be52016-05-03 18:49:27 +020040#include "gsup_router.h"
Harald Weltee72cf552016-04-28 07:18:49 +020041#include "rand.h"
Maxea8b0d42017-02-14 16:53:04 +010042#include "luop.h"
Neels Hofmeyr7685a782017-01-30 23:30:26 +010043#include "hlr_vty.h"
Harald Weltee72cf552016-04-28 07:18:49 +020044
Maxd4bebbd2017-03-02 12:00:19 +010045static struct hlr *g_hlr;
Harald Weltee72cf552016-04-28 07:18:49 +020046
Harald Weltee687be52016-05-03 18:49:27 +020047/***********************************************************************
48 * Send Auth Info handling
49 ***********************************************************************/
50
Harald Weltee72cf552016-04-28 07:18:49 +020051/* process an incoming SAI request */
52static int rx_send_auth_info(struct osmo_gsup_conn *conn,
Maxd4bebbd2017-03-02 12:00:19 +010053 const struct osmo_gsup_message *gsup,
54 struct db_context *dbc)
Harald Weltee72cf552016-04-28 07:18:49 +020055{
56 struct osmo_gsup_message gsup_out;
57 struct msgb *msg_out;
58 int rc;
59
60 /* initialize return message structure */
61 memset(&gsup_out, 0, sizeof(gsup_out));
Harald Weltee72cf552016-04-28 07:18:49 +020062 memcpy(&gsup_out.imsi, &gsup->imsi, sizeof(gsup_out.imsi));
63
Maxd4bebbd2017-03-02 12:00:19 +010064 rc = db_get_auc(dbc, gsup->imsi, gsup_out.auth_vectors,
Harald Weltee72cf552016-04-28 07:18:49 +020065 ARRAY_SIZE(gsup_out.auth_vectors),
Harald Welte9be0d2f2016-06-10 17:34:02 +020066 gsup->rand, gsup->auts);
Harald Weltecfc752b2016-05-05 16:38:14 +020067 if (rc < 0) {
Harald Weltee72cf552016-04-28 07:18:49 +020068 gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR;
Harald Weltecfc752b2016-05-05 16:38:14 +020069 gsup_out.cause = GMM_CAUSE_NET_FAIL;
70 } else if (rc == 0) {
71 gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR;
72 gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN;
Harald Welte15db8262016-05-05 16:50:39 +020073 } else {
74 gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT;
75 gsup_out.num_auth_vectors = rc;
Harald Weltee72cf552016-04-28 07:18:49 +020076 }
77
Harald Weltee687be52016-05-03 18:49:27 +020078 msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response");
Harald Weltee72cf552016-04-28 07:18:49 +020079 osmo_gsup_encode(msg_out, &gsup_out);
80 return osmo_gsup_conn_send(conn, msg_out);
81}
82
Harald Weltee687be52016-05-03 18:49:27 +020083/***********************************************************************
84 * LU Operation State / Structure
85 ***********************************************************************/
86
87static LLIST_HEAD(g_lu_ops);
88
Harald Weltee687be52016-05-03 18:49:27 +020089/*! Receive Cancel Location Result from old VLR/SGSN */
90void lu_op_rx_cancel_old_ack(struct lu_operation *luop,
Maxea8b0d42017-02-14 16:53:04 +010091 const struct osmo_gsup_message *gsup)
Harald Weltee687be52016-05-03 18:49:27 +020092{
93 OSMO_ASSERT(luop->state == LU_S_CANCEL_SENT);
94 /* FIXME: Check for spoofing */
95
96 osmo_timer_del(&luop->timer);
97
98 /* FIXME */
99
100 lu_op_tx_insert_subscr_data(luop);
101}
102
Harald Weltee687be52016-05-03 18:49:27 +0200103/*! Receive Insert Subscriber Data Result from new VLR/SGSN */
104static void lu_op_rx_insert_subscr_data_ack(struct lu_operation *luop,
105 const struct osmo_gsup_message *gsup)
106{
107 OSMO_ASSERT(luop->state == LU_S_ISD_SENT);
108 /* FIXME: Check for spoofing */
109
110 osmo_timer_del(&luop->timer);
111
112 /* Subscriber_Present_HLR */
113 /* CS only: Check_SS_required? -> MAP-FW-CHECK_SS_IND.req */
114
115 /* Send final ACK towards inquiring VLR/SGSN */
116 lu_op_tx_ack(luop);
117}
118
119/*! Receive GSUP message for given \ref lu_operation */
120void lu_op_rx_gsup(struct lu_operation *luop,
121 const struct osmo_gsup_message *gsup)
122{
123 switch (gsup->message_type) {
124 case OSMO_GSUP_MSGT_INSERT_DATA_ERROR:
125 /* FIXME */
126 break;
127 case OSMO_GSUP_MSGT_INSERT_DATA_RESULT:
128 lu_op_rx_insert_subscr_data_ack(luop, gsup);
129 break;
130 case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR:
131 /* FIXME */
132 break;
133 case OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT:
134 lu_op_rx_cancel_old_ack(luop, gsup);
135 break;
136 default:
137 LOGP(DMAIN, LOGL_ERROR, "Unhandled GSUP msg_type 0x%02x\n",
138 gsup->message_type);
139 break;
140 }
141}
142
Harald Weltee687be52016-05-03 18:49:27 +0200143/*! Receive Update Location Request, creates new \ref lu_operation */
144static int rx_upd_loc_req(struct osmo_gsup_conn *conn,
145 const struct osmo_gsup_message *gsup)
146{
Maxea8b0d42017-02-14 16:53:04 +0100147 struct lu_operation *luop = lu_op_alloc_conn(conn);
148 if (!luop) {
Harald Weltee687be52016-05-03 18:49:27 +0200149 LOGP(DMAIN, LOGL_ERROR, "LU REQ from conn without addr?\n");
Maxea8b0d42017-02-14 16:53:04 +0100150 return -EINVAL;
Harald Weltee687be52016-05-03 18:49:27 +0200151 }
152
Harald Weltee687be52016-05-03 18:49:27 +0200153 lu_op_statechg(luop, LU_S_LU_RECEIVED);
Maxea8b0d42017-02-14 16:53:04 +0100154
Harald Weltee687be52016-05-03 18:49:27 +0200155 if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS)
156 luop->is_ps = true;
157 llist_add(&luop->list, &g_lu_ops);
158
159 /* Roughly follwing "Process Update_Location_HLR" of TS 09.02 */
160
161 /* check if subscriber is known at all */
Maxd4bebbd2017-03-02 12:00:19 +0100162 if (!lu_op_fill_subscr(luop, g_hlr->dbc, gsup->imsi)) {
Harald Weltee687be52016-05-03 18:49:27 +0200163 /* Send Error back: Subscriber Unknown in HLR */
164 strcpy(luop->subscr.imsi, gsup->imsi);
165 lu_op_tx_error(luop, GMM_CAUSE_IMSI_UNKNOWN);
166 return 0;
167 }
168
Harald Welte99909272016-05-05 18:24:15 +0200169 /* Check if subscriber is generally permitted on CS or PS
170 * service (as requested) */
Maxea8b0d42017-02-14 16:53:04 +0100171 if (!luop->is_ps && !luop->subscr.nam_cs) {
Harald Weltee687be52016-05-03 18:49:27 +0200172 lu_op_tx_error(luop, GMM_CAUSE_PLMN_NOTALLOWED);
173 return 0;
Maxea8b0d42017-02-14 16:53:04 +0100174 } else if (luop->is_ps && !luop->subscr.nam_ps) {
Harald Weltee687be52016-05-03 18:49:27 +0200175 lu_op_tx_error(luop, GMM_CAUSE_GPRS_NOTALLOWED);
176 return 0;
177 }
178
179 /* TODO: Set subscriber tracing = deactive in VLR/SGSN */
180
181#if 0
182 /* Cancel in old VLR/SGSN, if new VLR/SGSN differs from old */
183 if (luop->is_ps == false &&
184 strcmp(subscr->vlr_number, vlr_number)) {
Harald Weltee687be52016-05-03 18:49:27 +0200185 lu_op_tx_cancel_old(luop);
186 } else if (luop->is_ps == true &&
187 strcmp(subscr->sgsn_number, sgsn_number)) {
Harald Weltee687be52016-05-03 18:49:27 +0200188 lu_op_tx_cancel_old(luop);
189 } else
190#endif
191 {
192 /* TODO: Subscriber allowed to roam in PLMN? */
193 /* TODO: Update RoutingInfo */
194 /* TODO: Reset Flag MS Purged (cs/ps) */
195 /* TODO: Control_Tracing_HLR / Control_Tracing_HLR_with_SGSN */
196 lu_op_tx_insert_subscr_data(luop);
197 }
198 return 0;
199}
200
Harald Welteb18f0e02016-05-05 21:03:03 +0200201static int rx_purge_ms_req(struct osmo_gsup_conn *conn,
202 const struct osmo_gsup_message *gsup)
203{
204 struct osmo_gsup_message gsup_reply = {0};
205 struct msgb *msg_out;
206 bool is_ps = false;
207 int rc;
208
209 LOGP(DAUC, LOGL_INFO, "%s: Purge MS (%s)\n", gsup->imsi,
210 is_ps ? "PS" : "CS");
211
212 memcpy(gsup_reply.imsi, gsup->imsi, sizeof(gsup_reply.imsi));
213
214 if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS)
215 is_ps = true;
216
217 /* FIXME: check if the VLR that sends the purge is the same that
218 * we have on record. Only update if yes */
219
220 /* Perform the actual update of the DB */
Maxd4bebbd2017-03-02 12:00:19 +0100221 rc = db_subscr_purge(g_hlr->dbc, gsup->imsi, is_ps);
Harald Welteb18f0e02016-05-05 21:03:03 +0200222
223 if (rc == 1)
224 gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT;
225 else if (rc == 0) {
226 gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR;
227 gsup_reply.cause = GMM_CAUSE_IMSI_UNKNOWN;
228 } else {
229 gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR;
230 gsup_reply.cause = GMM_CAUSE_NET_FAIL;
231 }
232
233 msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response");
234 osmo_gsup_encode(msg_out, &gsup_reply);
235 return osmo_gsup_conn_send(conn, msg_out);
236}
237
Harald Weltee72cf552016-04-28 07:18:49 +0200238static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
239{
240 static struct osmo_gsup_message gsup;
241 int rc;
242
Harald Weltee687be52016-05-03 18:49:27 +0200243 rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup);
Harald Weltee72cf552016-04-28 07:18:49 +0200244 if (rc < 0) {
245 LOGP(DMAIN, LOGL_ERROR, "error in GSUP decode: %d\n", rc);
246 return rc;
247 }
248
249 switch (gsup.message_type) {
250 /* requests sent to us */
251 case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
Maxd4bebbd2017-03-02 12:00:19 +0100252 rx_send_auth_info(conn, &gsup, g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +0200253 break;
254 case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
Harald Weltee687be52016-05-03 18:49:27 +0200255 rx_upd_loc_req(conn, &gsup);
Harald Weltee72cf552016-04-28 07:18:49 +0200256 break;
Harald Welteb18f0e02016-05-05 21:03:03 +0200257 case OSMO_GSUP_MSGT_PURGE_MS_REQUEST:
258 rx_purge_ms_req(conn, &gsup);
259 break;
Harald Weltee72cf552016-04-28 07:18:49 +0200260 /* responses to requests sent by us */
261 case OSMO_GSUP_MSGT_INSERT_DATA_ERROR:
Harald Weltee72cf552016-04-28 07:18:49 +0200262 case OSMO_GSUP_MSGT_INSERT_DATA_RESULT:
Harald Weltee687be52016-05-03 18:49:27 +0200263 case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR:
264 case OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT:
265 {
Maxea8b0d42017-02-14 16:53:04 +0100266 struct lu_operation *luop = lu_op_by_imsi(gsup.imsi,
267 &g_lu_ops);
Harald Weltee687be52016-05-03 18:49:27 +0200268 if (!luop) {
Maxaa0fefd2017-02-16 12:25:22 +0100269 LOGP(DMAIN, LOGL_ERROR, "GSUP message %s for "
270 "unknown IMSI %s\n",
271 osmo_gsup_message_type_name(gsup.message_type),
Harald Weltee687be52016-05-03 18:49:27 +0200272 gsup.imsi);
273 break;
274 }
275 lu_op_rx_gsup(luop, &gsup);
276 }
Harald Weltee72cf552016-04-28 07:18:49 +0200277 break;
278 default:
Maxaa0fefd2017-02-16 12:25:22 +0100279 LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
280 osmo_gsup_message_type_name(gsup.message_type));
Harald Weltee72cf552016-04-28 07:18:49 +0200281 break;
282 }
Harald Welte5341b5d2016-04-28 12:48:39 +0200283 msgb_free(msg);
Harald Weltee72cf552016-04-28 07:18:49 +0200284 return 0;
285}
286
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100287static void print_usage()
288{
289 printf("Usage: osmo-hlr\n");
290}
291
292static void print_help()
293{
294 printf(" -h --help This text.\n");
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100295 printf(" -c --config-file filename The config file to use.\n");
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100296 printf(" -l --database db-name The database to use.\n");
297 printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM Enable debugging.\n");
298 printf(" -D --daemonize Fork the process into a background daemon.\n");
299 printf(" -s --disable-color Do not print ANSI colors in the log\n");
300 printf(" -T --timestamp Prefix every log line with a timestamp.\n");
301 printf(" -e --log-level number Set a global loglevel.\n");
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100302 printf(" -V --version Print the version of OsmoHLR.\n");
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100303}
304
305static struct {
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100306 const char *config_file;
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100307 const char *db_file;
308 bool daemonize;
309} cmdline_opts = {
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100310 .config_file = "osmo-hlr.cfg",
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100311 .db_file = "hlr.db",
312 .daemonize = false,
313};
314
315static void handle_options(int argc, char **argv)
316{
317 while (1) {
318 int option_index = 0, c;
319 static struct option long_options[] = {
320 {"help", 0, 0, 'h'},
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100321 {"config-file", 1, 0, 'c'},
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100322 {"database", 1, 0, 'l'},
323 {"debug", 1, 0, 'd'},
324 {"daemonize", 0, 0, 'D'},
325 {"disable-color", 0, 0, 's'},
326 {"log-level", 1, 0, 'e'},
327 {"timestamp", 0, 0, 'T'},
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100328 {"version", 0, 0, 'V' },
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100329 {0, 0, 0, 0}
330 };
331
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100332 c = getopt_long(argc, argv, "hc:l:d:Dse:TV",
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100333 long_options, &option_index);
334 if (c == -1)
335 break;
336
337 switch (c) {
338 case 'h':
339 print_usage();
340 print_help();
341 exit(0);
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100342 case 'c':
343 cmdline_opts.config_file = optarg;
344 break;
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100345 case 'l':
346 cmdline_opts.db_file = optarg;
347 break;
348 case 'd':
349 log_parse_category_mask(osmo_stderr_target, optarg);
350 break;
351 case 'D':
352 cmdline_opts.daemonize = 1;
353 break;
354 case 's':
355 log_set_use_color(osmo_stderr_target, 0);
356 break;
357 case 'e':
358 log_set_log_level(osmo_stderr_target, atoi(optarg));
359 break;
360 case 'T':
361 log_set_print_timestamp(osmo_stderr_target, 1);
362 break;
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100363 case 'V':
364 print_version(1);
365 exit(0);
366 break;
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100367 default:
368 /* catch unknown options *as well as* missing arguments. */
369 fprintf(stderr, "Error in command line options. Exiting.\n");
370 exit(-1);
371 break;
372 }
373 }
374}
375
Neels Hofmeyrca43e302017-01-30 13:18:23 +0100376static void *hlr_ctx = NULL;
Harald Welteaabae9e2016-04-28 12:48:14 +0200377
378static void signal_hdlr(int signal)
379{
380 switch (signal) {
381 case SIGINT:
382 LOGP(DMAIN, LOGL_NOTICE, "Terminating due to SIGINT\n");
Maxd4bebbd2017-03-02 12:00:19 +0100383 osmo_gsup_server_destroy(g_hlr->gs);
384 db_close(g_hlr->dbc);
Harald Welteaabae9e2016-04-28 12:48:14 +0200385 log_fini();
Neels Hofmeyrca43e302017-01-30 13:18:23 +0100386 talloc_report_full(hlr_ctx, stderr);
Harald Welteaabae9e2016-04-28 12:48:14 +0200387 exit(0);
388 break;
389 case SIGUSR1:
390 LOGP(DMAIN, LOGL_DEBUG, "Talloc Report due to SIGUSR1\n");
Neels Hofmeyrca43e302017-01-30 13:18:23 +0100391 talloc_report_full(hlr_ctx, stderr);
Harald Welteaabae9e2016-04-28 12:48:14 +0200392 break;
393 }
394}
Harald Weltee72cf552016-04-28 07:18:49 +0200395
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100396static struct vty_app_info vty_info = {
397 .name = "OsmoHLR",
398 .version = PACKAGE_VERSION,
399 .is_config_node = hlr_vty_is_config_node,
400};
401
Harald Weltee72cf552016-04-28 07:18:49 +0200402int main(int argc, char **argv)
403{
Harald Weltee72cf552016-04-28 07:18:49 +0200404 int rc;
405
Neels Hofmeyrca43e302017-01-30 13:18:23 +0100406 hlr_ctx = talloc_named_const(NULL, 1, "OsmoHLR");
407 msgb_talloc_ctx_init(hlr_ctx, 0);
Harald Welteaabae9e2016-04-28 12:48:14 +0200408
Maxd4bebbd2017-03-02 12:00:19 +0100409 g_hlr = talloc_zero(hlr_ctx, struct hlr);
410
Harald Weltee72cf552016-04-28 07:18:49 +0200411 rc = osmo_init_logging(&hlr_log_info);
412 if (rc < 0) {
413 fprintf(stderr, "Error initializing logging\n");
414 exit(1);
415 }
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100416
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100417 vty_init(&vty_info);
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100418 handle_options(argc, argv);
Neels Hofmeyr7685a782017-01-30 23:30:26 +0100419 hlr_vty_init(&hlr_log_info);
420
421 rc = vty_read_config_file(cmdline_opts.config_file, NULL);
422 if (rc < 0) {
423 LOGP(DMAIN, LOGL_FATAL,
424 "Failed to parse the config file: '%s'\n",
425 cmdline_opts.config_file);
426 return rc;
427 }
428
429 /* start telnet after reading config for vty_get_bind_addr() */
430 rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(),
431 OSMO_VTY_PORT_HLR);
432 if (rc < 0)
433 return rc;
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100434
Harald Weltee72cf552016-04-28 07:18:49 +0200435 LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n");
436
437 rc = rand_init();
438 if (rc < 0) {
439 LOGP(DMAIN, LOGL_FATAL, "Error initializing random source\n");
440 exit(1);
441 }
442
Maxd4bebbd2017-03-02 12:00:19 +0100443 g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file);
444 if (!g_hlr->dbc) {
Harald Weltee72cf552016-04-28 07:18:49 +0200445 LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
446 exit(1);
447 }
448
Maxd4bebbd2017-03-02 12:00:19 +0100449 g_hlr->gs = osmo_gsup_server_create(hlr_ctx, NULL, 2222, read_cb);
450 if (!g_hlr->gs) {
Harald Weltee72cf552016-04-28 07:18:49 +0200451 LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n");
452 exit(1);
453 }
454
Harald Welteaabae9e2016-04-28 12:48:14 +0200455 osmo_init_ignore_signals();
456 signal(SIGINT, &signal_hdlr);
457 signal(SIGUSR1, &signal_hdlr);
458
Neels Hofmeyr7f9491f2017-01-30 13:30:47 +0100459 if (cmdline_opts.daemonize) {
460 rc = osmo_daemonize();
461 if (rc < 0) {
462 perror("Error during daemonize");
463 exit(1);
464 }
465 }
Harald Welteaabae9e2016-04-28 12:48:14 +0200466
Harald Weltee72cf552016-04-28 07:18:49 +0200467 while (1) {
468 osmo_select_main(0);
469 }
470
Maxd4bebbd2017-03-02 12:00:19 +0100471 db_close(g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +0200472
473 log_fini();
474
475 exit(0);
476}