summaryrefslogtreecommitdiffstats
path: root/openbsc/contrib/nat/ussd_example.py
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-05-08 23:25:31 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-05-09 00:26:01 +0200
commit6950d14c5bf301fbb3061f5a4fe67f5f57b76040 (patch)
tree1ae01412e3f15a6a7358ea5ad2a63cd6862a45f8 /openbsc/contrib/nat/ussd_example.py
parentcf2ca648e9f8b9ed753b4ffb588305b0a3430208 (diff)
parentcd5e52605cdb77bdc6f36fce81a6a1bac7fbda48 (diff)
Merge branch 'master' into sysmocom/iu, with tweakssysmocom/iu_orig_history
Numerous manual adjustments are included to make sense on the sysmocom/iu branch: * gsm_04_08_gprs.h has moved to libosmocore on the master branch, but sysmocom/iu has added some entries. Until it is clear whether to move the additions to libosmocore as well, keep gsm_04_08_gprs.h on sysmocom/iu with merely the additions. * Thus, keep using the old gsm_04_08_gprs.[hc] from openbsc in the Makefiles, but only where the sysmocom/iu additions are needed. * In openbsc's gsm_04_08_gprs.h, * include the libosmocore gsm_04_08_gprs.h, * use '#pragma once' instead of #ifndef and * add a TODO comment about moving the rest to libosmocore. * Apply the addition of an osmo_auth_vector to gsm_auth_tuple: in the Iu auth vector hacks, use the gsm_auth_tuple.vec instead of a local struct. See iu_hack__get_hardcoded_auth_tuple() and gsm48_rx_gmm_att_req(). * In the si2q tests, pass NULL as ctx to gsm_network_init(). * In cscn_main.c, add a debug log that was originally added to osmo-nitb. * openbsc/.gitignore: keep only one addition of 'writtenconfig' Conflicts: openbsc/include/openbsc/gprs_sgsn.h openbsc/include/openbsc/gsm_04_08_gprs.h openbsc/src/gprs/gsm_04_08_gprs.c openbsc/src/libmsc/gsm_04_08.c openbsc/src/osmo-cscn/cscn_main.c openbsc/tests/gsm0408/Makefile.am
Diffstat (limited to 'openbsc/contrib/nat/ussd_example.py')
-rw-r--r--openbsc/contrib/nat/ussd_example.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/openbsc/contrib/nat/ussd_example.py b/openbsc/contrib/nat/ussd_example.py
new file mode 100644
index 000000000..8f7a58d3f
--- /dev/null
+++ b/openbsc/contrib/nat/ussd_example.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python2.7
+
+"""
+AGPLv3+ 2016 Copyright Holger Hans Peter Freyther
+
+Example of how to connect to the USSD side-channel and how to respond
+with a fixed message.
+"""
+
+import socket
+import struct
+
+ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ussdSocket.connect(('127.0.0.1', 5001))
+
+def send_dt1(dstref, data):
+ dlen = struct.pack('B', len(data)).encode('hex')
+ hex = '06' + dstref.encode('hex') + '00' + '01' + dlen + data.encode('hex')
+ pdata = hex.decode('hex')
+ out = struct.pack('>HB', len(pdata), 0xfd) + pdata
+ ussdSocket.send(out)
+
+def send_rel(srcref, dstref):
+ hex = '04' + dstref.encode('hex') + srcref.encode('hex') + '000100'
+ pdata = hex.decode('hex')
+ out = struct.pack('>HB', len(pdata), 0xfd) + pdata
+ ussdSocket.send(out)
+
+def recv_one():
+ plen = ussdSocket.recv(3)
+ (plen,ptype) = struct.unpack(">HB", plen)
+ data = ussdSocket.recv(plen)
+
+ return ptype, data
+
+# Assume this is the ID request
+data = ussdSocket.recv(4)
+ussdSocket.send("\x00\x08\xfe\x05\x00" + "\x05\x01" + "ussd")
+# ^len ^len of tag ... and ignore
+
+# Expect a fake message. see struct ipac_msgt_sccp_state
+ptype, data = recv_one()
+print("%d %s" % (ptype, data.encode('hex')))
+(srcref, dstref, transid, invokeid) = struct.unpack("<3s3sBB", data[1:9])
+print("New transID %d invoke %d" % (transid, invokeid))
+
+# Expect a the invocation.. todo.. extract invoke id
+ptype, data = recv_one()
+print("%d %s" % (ptype, data.encode('hex')))
+
+# Reply with BSSAP + GSM 04.08 + MAP portion
+# 00 == invoke id 0f == DCS
+res = "01002a9b2a0802e1901c22a220020100301b02013b301604010f041155e7d2f9bc3a41412894991c06a9c9a713"
+send_dt1(dstref, res.decode('hex'))
+
+clear = "000420040109"
+send_dt1(dstref, clear.decode('hex'))
+
+# should be the clear complete
+send_rel(srcref, dstref)
+
+# Give it some time to handle connection shutdown properly
+print("Gracefully sleeping")
+import time
+time.sleep(3)