From f1158c7719c1b746f0fb303efabf8e6a4670646b Mon Sep 17 00:00:00 2001 From: "Mychaela N. Falconia" Date: Sat, 26 Aug 2023 01:06:57 +0000 Subject: [PATCH] SMS over GSUP: implement forwarding of MT SMS When an SMSC tries to deliver an SM to a subscriber, it will send us an MT-forwardSM.req GSUP message. We look up the subscriber by IMSI and see if they are attached to a VLR. If the subscriber is attached, we forward the message to the MSC/VLR, otherwise return an error to the SMSC. Related: OS#6135 Change-Id: Ib3551bf7839690606c677461758c5cfef5f0aa7b --- include/osmocom/hlr/hlr_sms.h | 1 + src/hlr.c | 3 +++ src/hlr_sms.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/include/osmocom/hlr/hlr_sms.h b/include/osmocom/hlr/hlr_sms.h index 6e68a858..b3beea6f 100644 --- a/include/osmocom/hlr/hlr_sms.h +++ b/include/osmocom/hlr/hlr_sms.h @@ -29,3 +29,4 @@ struct hlr_smsc_route *smsc_route_alloc(struct hlr *hlr, const char *num_addr, void smsc_route_del(struct hlr_smsc_route *rt); void forward_mo_sms(struct osmo_gsup_req *req); +void forward_mt_sms(struct osmo_gsup_req *req); diff --git a/src/hlr.c b/src/hlr.c index 501eabc9..eae9e843 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -560,6 +560,9 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg) case OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST: forward_mo_sms(req); break; + case OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST: + forward_mt_sms(req); + break; default: LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n", osmo_gsup_message_type_name(req->gsup.message_type)); diff --git a/src/hlr_sms.c b/src/hlr_sms.c index ebf40994..ac4d50d6 100644 --- a/src/hlr_sms.c +++ b/src/hlr_sms.c @@ -191,3 +191,31 @@ void forward_mo_sms(struct osmo_gsup_req *req) strlen(smsc->name) + 1); osmo_gsup_forward_to_local_peer(req->cb_data, &dest_peer, req, NULL); } + +/*********************************************************************** + * forwarding of MT SMS from SMSCs to MSC/VLR based on IMSI + ***********************************************************************/ + +void forward_mt_sms(struct osmo_gsup_req *req) +{ + struct hlr_subscriber subscr; + struct osmo_cni_peer_id dest_peer; + int rc; + + rc = db_subscr_get_by_imsi(g_hlr->dbc, req->gsup.imsi, &subscr); + if (rc < 0) { + osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN, + "IMSI unknown"); + return; + } + /* is this subscriber currently attached to a VLR? */ + if (!subscr.vlr_number[0]) { + osmo_gsup_req_respond_err(req, GMM_CAUSE_IMPL_DETACHED, + "subscriber not attached to a VLR"); + return; + } + osmo_cni_peer_id_set(&dest_peer, OSMO_CNI_PEER_ID_IPA_NAME, + (const uint8_t *) subscr.vlr_number, + strlen(subscr.vlr_number) + 1); + osmo_gsup_forward_to_local_peer(req->cb_data, &dest_peer, req, NULL); +}