Neels Hofmeyr has uploaded this change for review. ( 
https://gerrit.osmocom.org/13479


Change subject: fix USSD routing to multiple MSC
......................................................................

fix USSD routing to multiple MSC

hlr_ussd.c so far hardcoded osmo-msc's default IPA-name and hence was only able
to negotiate USSD sessions to
- a single osmo-msc
- that has no custom IPA-name set.
Fix: correctly route USSD to any number of MSC with any custom IPA names.

Resolve the right MSC's IPA name from the USSD session's IMSI, using
hlr_subscriber->vlr_number to determine the right GSUP peer.

Add ss_session->subscr, so that if a code path already knows the subscriber
data, setting a pointer to it avoids another database lookup.

Related: OS#3710
Change-Id: I18067bfadd33a6bc59a9ee336b6937313826fce3
---
M src/hlr_ussd.c
1 file changed, 40 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/79/13479/1

diff --git a/src/hlr_ussd.c b/src/hlr_ussd.c
index cc6aa8a..906b129 100644
--- a/src/hlr_ussd.c
+++ b/src/hlr_ussd.c
@@ -166,6 +166,10 @@
                const struct hlr_iuse *iuse;
        } u;

+       /* Reference to the HLR subscriber for this session, to avoid looking 
it up in the database too often.
+        * Still, this should be refreshed in due time, e.g. once per received 
message. */
+       struct hlr_subscriber *subscr;
+
        /* we don't keep a pointer to the osmo_gsup_{route,conn} towards the 
MSC/VLR here,
         * as this might change during inter-VLR hand-over, and we simply 
look-up the serving MSC/VLR
         * every time we receive an USSD component from the EUSE */
@@ -222,6 +226,34 @@
  * handling functions for encoding SS messages + wrapping them in GSUP
  ***********************************************************************/

+/* Resolve the target MSC by ss->imsi and send GSUP message. */
+static int ss_gsup_send(struct ss_session *ss, struct osmo_gsup_server *gs, 
struct msgb *msg)
+{
+       struct hlr_subscriber _subscr = {};
+       struct hlr_subscriber *subscr = ss->subscr;
+       int rc;
+
+       /* Use subscr as looked up by the caller, or look up now. */
+       if (!subscr) {
+               rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &_subscr);
+               if (rc < 0) {
+                       LOGPSS(ss, LOGL_ERROR, "Cannot find subscriber for IMSI 
%s, cannot route GSUP message\n",
+                              ss->imsi);
+                       return -EINVAL;
+               }
+               subscr = &_subscr;
+       }
+
+       if (!subscr->vlr_number[0]) {
+               LOGP(DLGSUP, LOGL_ERROR, "Cannot send GSUP message, no VLR 
number stored for subscriber %s\n",
+                    subscr->imsi);
+               return -EINVAL;
+       }
+
+       LOGPSS(ss, LOGL_DEBUG, "Tx USSD for IMSI %s to VLR '%s'\n", 
subscr->imsi, subscr->vlr_number);
+       return osmo_gsup_addr_send(gs, (uint8_t *)subscr->vlr_number, 
strlen(subscr->vlr_number), msg);
+}
+
 static int ss_tx_to_ms(struct ss_session *ss, enum osmo_gsup_message_type 
gsup_msg_type,
                        bool final, struct msgb *ss_msg)

@@ -246,8 +278,7 @@
        osmo_gsup_encode(resp_msg, &resp);
        msgb_free(ss_msg);

-       /* FIXME: resolve this based on the database vlr_addr */
-       return osmo_gsup_addr_send(g_hlr->gs, (uint8_t 
*)"MSC-00-00-00-00-00-00", 22, resp_msg);
+       return ss_gsup_send(ss, g_hlr->gs, resp_msg);
 }

 #if 0
@@ -298,7 +329,9 @@
                        snprintf(buf, sizeof(buf), "You have no MSISDN!");
                else
                        snprintf(buf, sizeof(buf), "Your extension is %s", 
subscr.msisdn);
+               ss->subscr = &subscr;
                ss_tx_ussd_7bit(ss, true, req->invoke_id, buf);
+               ss->subscr = NULL;
                break;
        case -ENOENT:
                ss_tx_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
@@ -433,8 +466,7 @@
                OSMO_ASSERT(msg_out);
                /* Received from EUSE, Forward to VLR */
                osmo_gsup_encode(msg_out, gsup);
-               /* FIXME: resolve this based on the database vlr_addr */
-               osmo_gsup_addr_send(conn->server, (uint8_t 
*)"MSC-00-00-00-00-00-00", 22, msg_out);
+               ss_gsup_send(ss, conn->server, msg_out);
        } else {
                /* Received from VLR (MS) */
                if (ss->is_external) {
@@ -557,6 +589,10 @@
                                gsup->imsi, gsup->session_id);
                        goto out_err;
                }
+
+               /* Make sure we refresh any subscriber data */
+               ss->subscr = NULL;
+
                if (ss_op_is_ussd(req.opcode)) {
                        /* dispatch unstructured SS to routing */
                        handle_ussd(conn, ss, gsup, &req);

--
To view, visit https://gerrit.osmocom.org/13479
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I18067bfadd33a6bc59a9ee336b6937313826fce3
Gerrit-Change-Number: 13479
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <[email protected]>

Reply via email to