aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2018-12-17 11:34:51 +0100
committerosmith <osmith@sysmocom.de>2019-01-07 09:43:37 +0000
commit783ac81b9caa629b82b4d47dd6be704f8670dced (patch)
tree5e862c496f68df93504ab3f5b23e88c03a762ed3
parentdf8d454919e9482e5eaa823df4b495cdcc620c1d (diff)
Reply to CHECK-IMEI GSUP messages
Decode the IMEI from incoming CHECK-IMEI messages, print the IMEI to the log and always send ACK back to the VLR/MSC. In the future, we will not only log the IMEI, but store it in the HLR (OS#2541). This is not the original intention of CHECK-IMEI from the 3GPP spec, but an useful side effect. Depends: I085819df0ea7f3bfeb0cabebb5fd1942a23c6155 (libosmocore) Related: OS#3733 Change-Id: Ib240474b0c3c603ba840cf26babb38a44dfc9364
-rw-r--r--src/hlr.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/hlr.c b/src/hlr.c
index 4873a66..ce5618a 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -32,6 +32,7 @@
#include <osmocom/vty/ports.h>
#include <osmocom/ctrl/control_vty.h>
#include <osmocom/gsm/apn.h>
+#include <osmocom/gsm/gsm48_ie.h>
#include "db.h"
#include "hlr.h"
@@ -399,6 +400,38 @@ static int gsup_send_err_reply(struct osmo_gsup_conn *conn, const char *imsi,
return osmo_gsup_conn_send(conn, msg_out);
}
+static int rx_check_imei_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup)
+{
+ struct osmo_gsup_message gsup_reply = {0};
+ struct msgb *msg_out;
+ char imei[GSM23003_IMEI_NUM_DIGITS+1] = {0};
+
+ /* Encoded IMEI length check */
+ if (!gsup->imei_enc || gsup->imei_enc_len < 1 || gsup->imei_enc[0] >= sizeof(imei)) {
+ LOGP(DMAIN, LOGL_ERROR, "%s: wrong encoded IMEI length\n", gsup->imsi);
+ gsup_send_err_reply(conn, gsup->imsi, gsup->message_type, GMM_CAUSE_INV_MAND_INFO);
+ return -1;
+ }
+
+ /* Decode IMEI */
+ if (gsm48_decode_bcd_number(imei, sizeof(imei), gsup->imei_enc, 0) < 0) {
+ LOGP(DMAIN, LOGL_ERROR, "%s: failed to decode IMEI\n", gsup->imsi);
+ gsup_send_err_reply(conn, gsup->imsi, gsup->message_type, GMM_CAUSE_INV_MAND_INFO);
+ 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);
+
+ /* Accept all IMEIs */
+ gsup_reply.imei_result = OSMO_GSUP_IMEI_RESULT_ACK;
+ gsup_reply.message_type = OSMO_GSUP_MSGT_CHECK_IMEI_RESULT;
+ msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP Check_IMEI response");
+ memcpy(gsup_reply.imsi, gsup->imsi, sizeof(gsup_reply.imsi));
+ osmo_gsup_encode(msg_out, &gsup_reply);
+ return osmo_gsup_conn_send(conn, msg_out);
+}
+
static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
{
static struct osmo_gsup_message gsup;
@@ -459,6 +492,9 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
lu_op_rx_gsup(luop, &gsup);
}
break;
+ case OSMO_GSUP_MSGT_CHECK_IMEI_REQUEST:
+ rx_check_imei_req(conn, &gsup);
+ break;
default:
LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
osmo_gsup_message_type_name(gsup.message_type));