[PATCH] nat/ussd: Add 'show ussd-connection' vty command

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Wed Aug 14 09:10:34 UTC 2013


This command returns the current state of the connection to the USSD
side channel provider. It shows whether a provider has been connected
and authorized or not.

Fixes: OW#953
---
 openbsc/src/osmo-bsc_nat/bsc_nat_vty.c |   15 +++++++++-
 openbsc/src/osmo-bsc_nat/bsc_ussd.c    |   19 +++++++++++++
 openbsc/tests/vty_test_runner.py       |   49 ++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index 6ab48d6..04f6f5f 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -248,7 +248,7 @@ DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
 			for (j = 0; j < 32; ++j) {
 				endp = mgcp_timeslot_to_endpoint(i, j);
 				vty_out(vty, " Endpoint 0x%x %s%s", endp,
-					con->_endpoint_status[endp] == 0 
+					con->_endpoint_status[endp] == 0
 						? "free" : "allocated",
 				VTY_NEWLINE);
 			}
@@ -1155,6 +1155,18 @@ DEFUN(cfg_pgroup_no_lac, cfg_pgroup_no_lac_cmd,
 	return CMD_SUCCESS;
 }
 
+DEFUN(show_ussd_connection,
+      show_ussd_connection_cmd,
+      "show ussd-connection",
+      SHOW_STR "USSD connection related information\n")
+{
+	vty_out(vty, "The USSD side channel provider is %sconnected and %sauthorized.%s",
+		_nat->ussd_con ? "" : "not ",
+		_nat->ussd_con && _nat->ussd_con->authorized? "" : "not ",
+		VTY_NEWLINE);
+	return CMD_SUCCESS;
+}
+
 int bsc_nat_vty_init(struct bsc_nat *nat)
 {
 	_nat = nat;
@@ -1172,6 +1184,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
 	install_element_ve(&show_acc_lst_cmd);
 	install_element_ve(&show_bar_lst_cmd);
 	install_element_ve(&show_prefix_tree_cmd);
+	install_element_ve(&show_ussd_connection_cmd);
 
 	install_element(ENABLE_NODE, &set_last_endp_cmd);
 	install_element(ENABLE_NODE, &block_new_conn_cmd);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_ussd.c b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
index f7753fb..d422f9e 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_ussd.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
@@ -69,6 +69,20 @@ static void bsc_nat_ussd_destroy(struct bsc_nat_ussd_con *con)
 	talloc_free(con);
 }
 
+static void ussd_pong(struct bsc_nat_ussd_con *conn)
+{
+	struct msgb *msg;
+
+	msg = msgb_alloc_headroom(4096, 128, "pong message");
+	if (!msg) {
+		LOGP(DNAT, LOGL_ERROR, "Failed to allocate pong msg\n");
+		return;
+	}
+
+	msgb_v_put(msg, IPAC_MSGT_PONG);
+	bsc_do_write(&conn->queue, msg, IPAC_PROTO_IPACCESS);
+}
+
 static int forward_sccp(struct bsc_nat *nat, struct msgb *msg)
 {
 	struct nat_sccp_connection *con;
@@ -133,6 +147,11 @@ static int ussd_read_cb(struct osmo_fd *bfd)
 			}
 			if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME))
 				ussd_auth_con(&tvp, conn);
+		} else if (msg->l2h[0] == IPAC_MSGT_PING) {
+			LOGP(DNAT, LOGL_DEBUG, "Got USSD ping request.\n");
+			ussd_pong(conn);
+		} else {
+			LOGP(DNAT, LOGL_NOTICE, "Got unknown IPACCESS message 0x%02x.\n", msg->l2h[0]);
 		}
 
 		msgb_free(msg);
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index 730b8ba..210bd42 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -18,6 +18,7 @@
 import os
 import time
 import unittest
+import socket
 
 import osmopy.obscvty as obscvty
 import osmopy.osmoutil as osmoutil
@@ -132,6 +133,54 @@ class TestVTYNAT(TestVTYBase):
         res = self.vty.command("show prefix-tree")
         self.assertEqual(res, "% there is now prefix tree loaded.")
 
+    def testUssdSideChannelProvider(self):
+        self.vty.command("end")
+        self.vty.enable()
+        self.vty.command("configure terminal")
+        self.vty.command("nat")
+        self.vty.command("ussd-token key")
+        self.vty.command("end")
+
+        res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
+        self.assertEqual(res, True)
+
+        ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        ussdSocket.connect(('127.0.0.1', 5001))
+        ussdSocket.settimeout(2.0)
+        print "Connected to %s:%d" % ussdSocket.getpeername()
+
+        print "Expecting ID_GET request"
+        data = ussdSocket.recv(4)
+        self.assertEqual(data, "\x00\x01\xfe\x04")
+
+        print "Going to send ID_RESP response"
+        res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79")
+        self.assertEqual(res, 10)
+
+        # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
+
+        print "Going to send PING request"
+        res = ussdSocket.send("\x00\x01\xfe\x00")
+        self.assertEqual(res, 4)
+
+        print "Expecting PONG response"
+        data = ussdSocket.recv(4)
+        self.assertEqual(data, "\x00\x01\xfe\x01")
+
+        res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
+        self.assertEqual(res, True)
+
+        print "Going to shut down connection"
+        ussdSocket.shutdown(socket.SHUT_WR)
+
+        print "Expecting EOF"
+        data = ussdSocket.recv(4)
+        self.assertEqual(data, "")
+
+        ussdSocket.close()
+
+        res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
+        self.assertEqual(res, True)
 
 def add_nat_test(suite, workdir):
     if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
-- 
1.7.9.5





More information about the OpenBSC mailing list