diff options
author | Oliver Smith <osmith@sysmocom.de> | 2019-01-11 15:30:21 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-01-24 15:29:08 +0000 |
commit | 851814aa7c6a89faa536d5ec60d16dd37826e2d0 (patch) | |
tree | 8d1ceaeba706d82a6ae7a4c82bb42c5650fd719c | |
parent | 81db389fd489f1b7962e72105a5a2cc5f3feb3fb (diff) |
Optionally store IMEI in subscriber table
Add VTY config option "store-imei". When it is set, store the IMEI
sent from the VLR with CHECK-IMEI in the database.
Related: OS#2541
Change-Id: I09274ecbed64224f7ae305e09ede773931da2a57
-rw-r--r-- | src/hlr.c | 18 | ||||
-rw-r--r-- | src/hlr.h | 2 | ||||
-rw-r--r-- | src/hlr_vty.c | 21 | ||||
-rw-r--r-- | tests/test_nodes.vty | 4 |
4 files changed, 43 insertions, 2 deletions
@@ -419,8 +419,22 @@ static int rx_check_imei_req(struct osmo_gsup_conn *conn, const struct osmo_gsup return -1; } - /* Only print the IMEI for now, it's planned to store it here (OS#2541) */ - LOGP(DMAIN, LOGL_INFO, "%s: has IMEI: %s\n", gsup->imsi, imei); + /* Save in DB if desired */ + if (g_hlr->store_imei) { + LOGP(DAUC, LOGL_DEBUG, "IMSI='%s': storing IMEI = %s\n", gsup->imsi, imei); + if (db_subscr_update_imei_by_imsi(g_hlr->dbc, gsup->imsi, imei) < 0) { + gsup_send_err_reply(conn, gsup->imsi, gsup->message_type, GMM_CAUSE_INV_MAND_INFO); + return -1; + } + } else { + /* Check if subscriber exists and print IMEI */ + LOGP(DMAIN, LOGL_INFO, "IMSI='%s': has IMEI = %s (consider setting 'store-imei')\n", gsup->imsi, imei); + struct hlr_subscriber subscr; + if (db_subscr_get_by_imsi(g_hlr->dbc, gsup->imsi, &subscr) < 0) { + gsup_send_err_reply(conn, gsup->imsi, gsup->message_type, GMM_CAUSE_INV_MAND_INFO); + return -1; + } + } /* Accept all IMEIs */ gsup_reply.imei_result = OSMO_GSUP_IMEI_RESULT_ACK; @@ -51,6 +51,8 @@ struct hlr { struct llist_head ussd_routes; struct llist_head ss_sessions; + + bool store_imei; }; extern struct hlr *g_hlr; diff --git a/src/hlr_vty.c b/src/hlr_vty.c index 6706aa4..04e0191 100644 --- a/src/hlr_vty.c +++ b/src/hlr_vty.c @@ -71,6 +71,8 @@ DEFUN(cfg_gsup, static int config_write_hlr(struct vty *vty) { vty_out(vty, "hlr%s", VTY_NEWLINE); + if (g_hlr->store_imei) + vty_out(vty, " store-imei%s", VTY_NEWLINE); return CMD_SUCCESS; } @@ -305,6 +307,23 @@ DEFUN(cfg_ncss_guard_timeout, cfg_ncss_guard_timeout_cmd, return CMD_SUCCESS; } +DEFUN(cfg_store_imei, cfg_store_imei_cmd, + "store-imei", + "Save the IMEI in the database when receiving Check IMEI requests. Note that an MSC does not necessarily send" + " Check IMEI requests (for OsmoMSC, you may want to set 'check-imei-rqd 1').") +{ + g_hlr->store_imei = true; + return CMD_SUCCESS; +} + +DEFUN(cfg_no_store_imei, cfg_no_store_imei_cmd, + "no store-imei", + "Do not save the IMEI in the database, when receiving Check IMEI requests.") +{ + g_hlr->store_imei = false; + return CMD_SUCCESS; +} + /*********************************************************************** * Common Code ***********************************************************************/ @@ -368,6 +387,8 @@ void hlr_vty_init(const struct log_info *cat) install_element(HLR_NODE, &cfg_ussd_defaultroute_cmd); install_element(HLR_NODE, &cfg_ussd_no_defaultroute_cmd); install_element(HLR_NODE, &cfg_ncss_guard_timeout_cmd); + install_element(HLR_NODE, &cfg_store_imei_cmd); + install_element(HLR_NODE, &cfg_no_store_imei_cmd); hlr_vty_subscriber_init(); } diff --git a/tests/test_nodes.vty b/tests/test_nodes.vty index 63d3da0..6e72ed0 100644 --- a/tests/test_nodes.vty +++ b/tests/test_nodes.vty @@ -79,6 +79,8 @@ OsmoHLR(config-hlr)# list ussd default-route external EUSE no ussd default-route ncss-guard-timeout <0-255> + store-imei + no store-imei OsmoHLR(config-hlr)# gsup OsmoHLR(config-hlr-gsup)# list @@ -98,6 +100,7 @@ OsmoHLR(config-hlr)# exit OsmoHLR(config)# exit OsmoHLR# configure terminal OsmoHLR(config)# hlr +OsmoHLR(config-hlr)# store-imei OsmoHLR(config-hlr)# gsup OsmoHLR(config-hlr-gsup)# end OsmoHLR# disable @@ -116,6 +119,7 @@ log stderr logging level ss info ... hlr + store-imei gsup bind ip 127.0.0.1 ussd route prefix *#100# internal own-msisdn |