mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr.git
synced 2025-11-02 05:03:31 +00:00
Compare commits
131 Commits
35c3
...
neels/dgsm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1971b6731a | ||
|
|
b3c1726fb9 | ||
|
|
81ac78dfac | ||
|
|
dd73ccfc99 | ||
|
|
40d3a96f9d | ||
|
|
1e635ab550 | ||
|
|
43d5cfc13b | ||
|
|
61917ed51d | ||
|
|
43de5efb3d | ||
|
|
c992d85068 | ||
|
|
d29b2f236f | ||
|
|
647c106d1c | ||
|
|
a75d1c2c94 | ||
|
|
32cc07ad06 | ||
|
|
bf8b614c0e | ||
|
|
bcb5dca1c9 | ||
|
|
f6c8f04c79 | ||
|
|
82112ea835 | ||
|
|
0d28d85168 | ||
|
|
b2553ebb4a | ||
|
|
0c27a4c2d1 | ||
|
|
08358b2752 | ||
|
|
5424dcb879 | ||
|
|
f0e90e6bd5 | ||
|
|
15ad7bef5f | ||
|
|
74e7072f63 | ||
|
|
4fa9653733 | ||
|
|
5e5ce4aef2 | ||
|
|
9e533f666d | ||
|
|
544b15d3fa | ||
|
|
89afb7f78b | ||
|
|
b1775162ea | ||
|
|
f55f605931 | ||
|
|
fbe4929543 | ||
|
|
e53a34a7e1 | ||
|
|
52ef60fe96 | ||
|
|
3a9f267983 | ||
|
|
5436c77a96 | ||
|
|
110a49f69f | ||
|
|
41fe362591 | ||
|
|
0bb8fce2f1 | ||
|
|
637bbfcd92 | ||
|
|
f10463c5fc | ||
|
|
bf7deda0fc | ||
|
|
81b92bbe69 | ||
|
|
3a66698d87 | ||
|
|
276c5a7719 | ||
|
|
80dc9ae4be | ||
|
|
a377c41bd4 | ||
|
|
06f5af22c8 | ||
|
|
07e1602d2d | ||
|
|
abdfdb8a4a | ||
|
|
7355d0ddfe | ||
|
|
6b305b4c30 | ||
|
|
a7d0f87eb7 | ||
|
|
981e126686 | ||
|
|
7143f3a0cb | ||
|
|
f0968798a2 | ||
|
|
2f75803e5d | ||
|
|
7f4dd11682 | ||
|
|
a8045daeef | ||
|
|
4359b885d4 | ||
|
|
5b65461d68 | ||
|
|
f8ad67e7fc | ||
|
|
c3d40326ec | ||
|
|
a9f8a4bdce | ||
|
|
f5459de2e2 | ||
|
|
7d2843df4c | ||
|
|
2b0bf31183 | ||
|
|
28f0774e34 | ||
|
|
b07f33df41 | ||
|
|
8b860e54be | ||
|
|
9cf0030b6a | ||
|
|
b9b224c7bd | ||
|
|
e49391bfc4 | ||
|
|
fbd736ef37 | ||
|
|
dc30154fdf | ||
|
|
37642177f9 | ||
|
|
6401b90574 | ||
|
|
5b5cac7e94 | ||
|
|
937f583a7e | ||
|
|
4ca7f6a17e | ||
|
|
b64cb27003 | ||
|
|
3b33b01fb0 | ||
|
|
78abea6a0e | ||
|
|
9ac494f486 | ||
|
|
d62d401d07 | ||
|
|
103c11bd24 | ||
|
|
63de00cfc1 | ||
|
|
1a1398ed54 | ||
|
|
a8253a54ba | ||
|
|
29f371fddf | ||
|
|
2e403d6c3f | ||
|
|
c41572330d | ||
|
|
c7f1787c18 | ||
|
|
c13599dc69 | ||
|
|
6b73fd9678 | ||
|
|
cd2af5ead7 | ||
|
|
e21b45aecd | ||
|
|
5857c595b3 | ||
|
|
d9724f4298 | ||
|
|
c69a18bb3d | ||
|
|
8625cdaf2a | ||
|
|
609978d0ab | ||
|
|
28f0af872e | ||
|
|
9f6e558215 | ||
|
|
633fe291f5 | ||
|
|
7d53ae1db8 | ||
|
|
95abc2be17 | ||
|
|
f1fe94c8ca | ||
|
|
f7d3251d9a | ||
|
|
3cf87fe22c | ||
|
|
ee7c0cb8d9 | ||
|
|
c5044cfd80 | ||
|
|
20ddfdbc53 | ||
|
|
227834b6bc | ||
|
|
44a2180009 | ||
|
|
f9cf180ebe | ||
|
|
02078b7d91 | ||
|
|
ef64b231dc | ||
|
|
851814aa7c | ||
|
|
81db389fd4 | ||
|
|
7943e26938 | ||
|
|
e0c6fe5921 | ||
|
|
f58f44543f | ||
|
|
15f624ec53 | ||
|
|
d4e0e4d503 | ||
|
|
2dc7d960a1 | ||
|
|
52c4aa09b2 | ||
|
|
66106c0992 | ||
|
|
783ac81b9c |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -2,6 +2,8 @@
|
||||
*.lo
|
||||
*.la
|
||||
*.db
|
||||
*.db-shm
|
||||
*.db-wal
|
||||
*.pyc
|
||||
.*.sw?
|
||||
.version
|
||||
@@ -34,10 +36,12 @@ src/osmo-hlr
|
||||
src/osmo-hlr-db-tool
|
||||
src/osmo-euse-demo
|
||||
src/gsupclient/gsup-test-client
|
||||
src/mslookup/osmo-mslookup-client
|
||||
|
||||
tests/atconfig
|
||||
tests/testsuite
|
||||
tests/testsuite.log
|
||||
tests/testsuite.dir
|
||||
|
||||
tests/auc/auc_3g_test
|
||||
tests/auc/auc_ts_55_205_test_sets.c
|
||||
@@ -46,6 +50,12 @@ tests/auc/auc_test
|
||||
tests/gsup_server/gsup_server_test
|
||||
tests/gsup/gsup_test
|
||||
tests/db/db_test
|
||||
tests/hlr_vty_test.db*
|
||||
tests/db_upgrade/*.dump
|
||||
tests/mslookup/mdns_test
|
||||
tests/mslookup/mslookup_client_mdns_test
|
||||
tests/mslookup/mslookup_client_test
|
||||
tests/mslookup/mslookup_test
|
||||
|
||||
# manuals
|
||||
doc/manuals/*.html
|
||||
|
||||
@@ -17,7 +17,8 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libosmo-gsup-client.pc
|
||||
pkgconfig_DATA = libosmo-gsup-client.pc \
|
||||
libosmo-mslookup.pc
|
||||
|
||||
@RELMAKE@
|
||||
|
||||
|
||||
48
configure.ac
48
configure.ac
@@ -25,6 +25,11 @@ AC_PROG_MKDIR_P
|
||||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
|
||||
dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang
|
||||
AS_CASE(["$LD"],[*clang*],
|
||||
[AS_CASE(["${host_os}"],
|
||||
[*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])])
|
||||
|
||||
dnl check for pkg-config (explained in detail in libosmocore/configure.ac)
|
||||
AC_PATH_PROG(PKG_CONFIG_INSTALLED, pkg-config, no)
|
||||
if test "x$PKG_CONFIG_INSTALLED" = "xno"; then
|
||||
@@ -34,11 +39,11 @@ PKG_PROG_PKG_CONFIG([0.20])
|
||||
|
||||
PKG_CHECK_MODULES(TALLOC, [talloc >= 2.0.1])
|
||||
|
||||
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.11.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 0.11.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.11.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 0.11.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.5.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.3.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.3.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.3.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.3.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.6.0)
|
||||
|
||||
PKG_CHECK_MODULES(SQLITE3, sqlite3)
|
||||
|
||||
@@ -59,6 +64,21 @@ then
|
||||
CPPFLAGS="$CPPFLAGS -fsanitize=address -fsanitize=undefined"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([sqlite_talloc],
|
||||
AC_HELP_STRING([--enable-sqlite-talloc],
|
||||
[Configure SQLite3 to use talloc memory allocator [default=no]]),
|
||||
[sqlite_talloc="$enableval"],[sqlite_talloc="no"])
|
||||
if test "x$sqlite_talloc" = "xyes" ; then
|
||||
# Older versions of SQLite3 (at least 3.8.2) become unstable with talloc.
|
||||
# Feel free to relax to 3.24.0 > VER > 3.8.2 if it works for you.
|
||||
# FIXME: PKG_CHECK_MODULES() may return cached result here!
|
||||
PKG_CHECK_MODULES(SQLITE3, sqlite3 >= 3.24.0)
|
||||
AC_DEFINE([SQLITE_USE_TALLOC], 1, [Use talloc for SQLite3])
|
||||
fi
|
||||
AC_MSG_CHECKING([whether to use talloc for SQLite3])
|
||||
AC_MSG_RESULT([$sqlite_talloc])
|
||||
AM_CONDITIONAL([DB_SQLITE_DEBUG], [test "x$sqlite_talloc" = "xyes"])
|
||||
|
||||
AC_ARG_ENABLE(werror,
|
||||
[AS_HELP_STRING(
|
||||
[--enable-werror],
|
||||
@@ -92,6 +112,15 @@ AC_MSG_CHECKING([whether to enable VTY/CTRL tests])
|
||||
AC_MSG_RESULT([$enable_ext_tests])
|
||||
AM_CONDITIONAL(ENABLE_EXT_TESTS, test "x$enable_ext_tests" = "xyes")
|
||||
|
||||
# mslookup_client_mdns_test (OS#4385: does not work everywhere)
|
||||
AC_ARG_ENABLE([mslookup_client_mdns_test],
|
||||
AC_HELP_STRING([--enable-mslookup-client-mdns-test],
|
||||
[Include the mslookup_client_mdns_test in make check [default=no]]),
|
||||
[enable_mslookup_client_mdns_test="$enableval"],[enable_mslookup_client_mdns_test="no"])
|
||||
AC_MSG_CHECKING([whether to enable mslookup_client_mdns_test])
|
||||
AC_MSG_RESULT([$enable_mslookup_client_mdns_test])
|
||||
AM_CONDITIONAL(ENABLE_MSLOOKUP_CLIENT_MDNS_TEST, test "x$enable_mslookup_client_mdns_test" = "xyes")
|
||||
|
||||
# Generate manuals
|
||||
AC_ARG_ENABLE(manuals,
|
||||
[AS_HELP_STRING(
|
||||
@@ -157,18 +186,27 @@ AC_OUTPUT(
|
||||
Makefile
|
||||
doc/Makefile
|
||||
doc/examples/Makefile
|
||||
doc/sequence_charts/Makefile
|
||||
src/Makefile
|
||||
src/gsupclient/Makefile
|
||||
src/mslookup/Makefile
|
||||
include/Makefile
|
||||
include/osmocom/Makefile
|
||||
include/osmocom/hlr/Makefile
|
||||
include/osmocom/mslookup/Makefile
|
||||
libosmo-gsup-client.pc
|
||||
libosmo-mslookup.pc
|
||||
sql/Makefile
|
||||
doc/manuals/Makefile
|
||||
contrib/Makefile
|
||||
contrib/systemd/Makefile
|
||||
contrib/dgsm/Makefile
|
||||
tests/Makefile
|
||||
tests/auc/Makefile
|
||||
tests/auc/gen_ts_55_205_test_sets/Makefile
|
||||
tests/gsup_server/Makefile
|
||||
tests/gsup/Makefile
|
||||
tests/db/Makefile
|
||||
tests/db_upgrade/Makefile
|
||||
tests/mslookup/Makefile
|
||||
)
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
SUBDIRS = systemd
|
||||
SUBDIRS = \
|
||||
systemd \
|
||||
dgsm \
|
||||
$(NULL)
|
||||
|
||||
6
contrib/dgsm/Makefile.am
Normal file
6
contrib/dgsm/Makefile.am
Normal file
@@ -0,0 +1,6 @@
|
||||
EXTRA_DIST = \
|
||||
esme_dgsm.py \
|
||||
freeswitch_dialplan_dgsm.py \
|
||||
osmo-mslookup-pipe.py \
|
||||
osmo-mslookup-socket.py \
|
||||
$(NULL)
|
||||
184
contrib/dgsm/esme_dgsm.py
Executable file
184
contrib/dgsm/esme_dgsm.py
Executable file
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright 2019 sysmocom s.f.m.c GmbH <info@sysmocom.de>
|
||||
|
||||
WARNING: this is just a proof-of-concept implementation, it blocks for every
|
||||
received SMPP request and is not suitable for servicing more than one request
|
||||
at a time.
|
||||
|
||||
Based on esme.py from RCCN (license changed with permission from author):
|
||||
https://github.com/Rhizomatica/rccn/blob/master/rccn/esme.py
|
||||
Copyright 2017 keith <keith@rhizomatica.org>
|
||||
|
||||
Forward SMS to the receiver's SMSC, as determined with mslookup.
|
||||
Requires smpplip (pip3 install --user smpplib) and osmo-mslookup-client.
|
||||
|
||||
Example SMPP configuration for osmo-msc.cfg:
|
||||
smpp
|
||||
local-tcp-ip 127.0.0.1 2775
|
||||
policy closed
|
||||
smpp-first
|
||||
# outgoing to esme_dgsm.py
|
||||
esme OSMPP
|
||||
no alert-notifications
|
||||
password foo
|
||||
default-route
|
||||
# incoming from esme_dgsm.py
|
||||
esme ISMPP
|
||||
no alert-notifications
|
||||
password foo
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import smpplib
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
def can_handle_pdu(pdu):
|
||||
if not isinstance(pdu, smpplib.command.DeliverSM):
|
||||
logging.info('PDU is not a DeliverSM, ignoring')
|
||||
return False
|
||||
|
||||
if int(pdu.dest_addr_ton) == smpplib.consts.SMPP_TON_INTL:
|
||||
logging.info("Unable to handle SMS for %s: SMPP_TON_INTL" %
|
||||
(pdu.destination_addr))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def query_mslookup(service_type, id, id_type='msisdn'):
|
||||
query_str = '%s.%s.%s' % (service_type, id, id_type)
|
||||
logging.info('mslookup: ' + query_str)
|
||||
|
||||
result_line = subprocess.check_output(['osmo-mslookup-client', query_str,
|
||||
'-f', 'json'])
|
||||
if isinstance(result_line, bytes):
|
||||
result_line = result_line.decode('ascii')
|
||||
|
||||
logging.info('mslookup result: ' + result_line.rstrip())
|
||||
return json.loads(result_line)
|
||||
|
||||
|
||||
def tx_sms(dst_host, dst_port, source, destination, registered_delivery,
|
||||
unicode_text):
|
||||
smpp_client = smpplib.client.Client(dst_host, dst_port, 90)
|
||||
smpp_client.connect()
|
||||
smpp_client.bind_transceiver(system_id=args.dst_id, password=args.dst_pass)
|
||||
logging.info('Connected to destination SMSC (%s@%s:%s)' % (args.dst_id,
|
||||
dst_host, dst_port))
|
||||
|
||||
pdu = smpp_client.send_message(
|
||||
source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,
|
||||
source_addr_npi=smpplib.consts.SMPP_NPI_UNK,
|
||||
source_addr=source.decode(),
|
||||
dest_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
|
||||
dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
|
||||
destination_addr=destination.decode(),
|
||||
short_message=unicode_text,
|
||||
registered_delivery=registered_delivery,
|
||||
)
|
||||
|
||||
smpp_client.unbind()
|
||||
smpp_client.disconnect()
|
||||
del pdu
|
||||
del smpp_client
|
||||
|
||||
|
||||
def rx_deliver_sm(pdu):
|
||||
if not can_handle_pdu(pdu):
|
||||
return smpplib.consts.SMPP_ESME_RSYSERR
|
||||
|
||||
msisdn = pdu.destination_addr.decode()
|
||||
logging.info("Incoming SMS for: " + msisdn)
|
||||
|
||||
if args.sleep:
|
||||
logging.info("Sleeping for %i seconds" % (args.sleep))
|
||||
time.sleep(args.sleep)
|
||||
logging.info("Sleep done")
|
||||
|
||||
if args.always_fail is not None:
|
||||
return args.always_fail
|
||||
|
||||
result = query_mslookup("smpp.sms", msisdn)
|
||||
if 'v4' not in result or not result['v4']:
|
||||
logging.info('No IPv4 result from mslookup! This example only'
|
||||
' makes use of IPv4, dropping.')
|
||||
return smpplib.consts.SMPP_ESME_RSYSERR
|
||||
|
||||
dst_host, dst_port = result['v4']
|
||||
tx_sms(dst_host, dst_port, pdu.source_addr,
|
||||
pdu.destination_addr, int(pdu.registered_delivery),
|
||||
pdu.short_message)
|
||||
|
||||
return smpplib.consts.SMPP_ESME_ROK
|
||||
|
||||
|
||||
def smpp_bind():
|
||||
client = smpplib.client.Client(args.src_host, args.src_port, 90)
|
||||
client.set_message_received_handler(rx_deliver_sm)
|
||||
client.connect()
|
||||
client.bind_transceiver(system_id=args.src_id, password=args.src_pass)
|
||||
logging.info('Connected to source SMSC (%s@%s:%s)' % (args.src_id,
|
||||
args.src_host, args.src_port))
|
||||
logging.info('Waiting for SMS...')
|
||||
client.listen()
|
||||
|
||||
|
||||
def main():
|
||||
global args
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--src-host', default='127.0.0.1',
|
||||
help='source SMSC (OsmoMSC) host (default: 127.0.0.1)')
|
||||
parser.add_argument('--src-port', default=2775, type=int,
|
||||
help='source SMSC (OsmoMSC) port (default: 2775)')
|
||||
parser.add_argument('--src-id', default='OSMPP',
|
||||
help='source system id, as configured in osmo-msc.cfg'
|
||||
' (default: OSMPP)')
|
||||
parser.add_argument('--src-pass', default='foo',
|
||||
help='source system password, as configured in'
|
||||
' osmo-msc.cfg (default: foo)')
|
||||
parser.add_argument('--dst-id', default='ISMPP',
|
||||
help='destination system id, as configured in'
|
||||
' osmo-msc.cfg (default: ISMPP)')
|
||||
parser.add_argument('--dst-pass', default='foo',
|
||||
help='destination system password, as configured in'
|
||||
' osmo-msc.cfg (default: foo)')
|
||||
parser.add_argument('--sleep', default=0, type=float,
|
||||
help='sleep time in seconds before forwarding an SMS,'
|
||||
' to test multithreading (default: 0)')
|
||||
parser.add_argument('--always-fail', default=None, metavar='SMPP_ESME_ERRCODE',
|
||||
help='test delivery failure: always return an error code on Deliver-SM,'
|
||||
' pass an smpplib error code name like RDELIVERYFAILURE (see smpplib/consts.py),'
|
||||
' or an SMPP error code in hex digits')
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='[%(asctime)s]'
|
||||
' (%(threadName)s) %(message)s', datefmt="%H:%M:%S")
|
||||
|
||||
if args.always_fail:
|
||||
resolved = None
|
||||
name = 'SMPP_ESME_' + args.always_fail
|
||||
if hasattr(smpplib.consts, name):
|
||||
resolved = getattr(smpplib.consts, name)
|
||||
if resolved is None:
|
||||
try:
|
||||
resolved = int(args.always_fail, 16)
|
||||
except ValueError:
|
||||
resolved = None
|
||||
if resolved is None:
|
||||
print('Invalid argument for --always-fail: %r' % args.always_fail)
|
||||
exit(1)
|
||||
args.always_fail = resolved
|
||||
logging.info('--always-fail: returning error code %s to all Deliver-SM' % hex(args.always_fail))
|
||||
|
||||
smpp_bind()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim: expandtab tabstop=4 shiftwidth=4
|
||||
77
contrib/dgsm/freeswitch_dialplan_dgsm.py
Executable file
77
contrib/dgsm/freeswitch_dialplan_dgsm.py
Executable file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright 2019 sysmocom s.f.m.c GmbH <info@sysmocom.de>
|
||||
|
||||
This is a freeswitch dialplan implementation, see:
|
||||
https://freeswitch.org/confluence/display/FREESWITCH/mod_python
|
||||
|
||||
Find the right SIP server with mslookup (depending on the destination number)
|
||||
and bridge calls accordingly.
|
||||
"""
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
|
||||
def query_mslookup(service_type, id, id_type='msisdn'):
|
||||
query_str = '%s.%s.%s' % (service_type, id, id_type)
|
||||
print('[dialplan-dgsm] mslookup: ' + query_str)
|
||||
|
||||
result_line = subprocess.check_output([
|
||||
'osmo-mslookup-client', query_str, '-f', 'json'])
|
||||
if isinstance(result_line, bytes):
|
||||
result_line = result_line.decode('ascii')
|
||||
|
||||
print('[dialplan-dgsm] mslookup result: ' + result_line)
|
||||
return json.loads(result_line)
|
||||
|
||||
|
||||
def handler(session, args):
|
||||
""" Handle calls: bridge to the SIP server found with mslookup. """
|
||||
print('[dialplan-dgsm] call handler')
|
||||
msisdn = session.getVariable('destination_number')
|
||||
|
||||
# Run osmo-mslookup-client binary. We have also tried to directly call the
|
||||
# C functions with ctypes but this has lead to hard-to-debug segfaults.
|
||||
try:
|
||||
result = query_mslookup("sip.voice", msisdn)
|
||||
|
||||
# This example only makes use of IPv4
|
||||
if not result['v4']:
|
||||
print('[dialplan-dgsm] no IPv4 result from mslookup')
|
||||
session.hangup('UNALLOCATED_NUMBER')
|
||||
return
|
||||
|
||||
sip_ip, sip_port = result['v4']
|
||||
dial_str = 'sofia/internal/sip:{}@{}:{}'.format(
|
||||
msisdn, sip_ip, sip_port)
|
||||
print('[dialplan-dgsm] dial_str: ' + str(dial_str))
|
||||
|
||||
session.execute('bridge', dial_str)
|
||||
except:
|
||||
print('[dialplan-dgsm]: exception during call handler')
|
||||
session.hangup('UNALLOCATED_NUMBER')
|
||||
|
||||
|
||||
def fsapi(session, stream, env, args):
|
||||
""" Freeswitch refuses to load the module without this. """
|
||||
stream.write(env.serialize())
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('id', type=int)
|
||||
parser.add_argument('-i', '--id-type', default='msisdn',
|
||||
help='default: "msisdn"')
|
||||
parser.add_argument('-s', '--service', default='sip.voice',
|
||||
help='default: "sip.voice"')
|
||||
args = parser.parse_args()
|
||||
|
||||
result = query_mslookup(args.service, args.id, args.id_type)
|
||||
print(json.dumps(result))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
24
contrib/dgsm/osmo-mslookup-pipe.py
Executable file
24
contrib/dgsm/osmo-mslookup-pipe.py
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: shiftwidth=4 tabstop=4 expandtab
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
def query_mslookup(query_str):
|
||||
result = {'result': 'not-found'}
|
||||
proc = subprocess.Popen(('osmo-mslookup-client', '-f', 'json', query_str),
|
||||
stdout=subprocess.PIPE)
|
||||
for line in iter(proc.stdout.readline,''):
|
||||
if not line:
|
||||
break
|
||||
response = json.loads(line)
|
||||
if response.get('result') == 'result':
|
||||
result = response
|
||||
print('Response: %r' % response)
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
query_str = '1000-5000@sip.voice.12345.msisdn'
|
||||
if len(sys.argv) > 1:
|
||||
query_str = sys.argv[1]
|
||||
print('Final result: %r' % query_mslookup(query_str))
|
||||
35
contrib/dgsm/osmo-mslookup-socket.py
Executable file
35
contrib/dgsm/osmo-mslookup-socket.py
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: shiftwidth=4 tabstop=4 expandtab
|
||||
import socket
|
||||
import time
|
||||
|
||||
MSLOOKUP_SOCKET_PATH = '/tmp/mslookup'
|
||||
|
||||
def query_mslookup_socket(query_str, socket_path=MSLOOKUP_SOCKET_PATH):
|
||||
mslookup_socket = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
mslookup_socket.setblocking(True)
|
||||
mslookup_socket.connect(socket_path)
|
||||
result = {'result': 'not-found'}
|
||||
column_names = mslookup_socket.recv(1024).decode('ascii')
|
||||
if not column_names:
|
||||
return result
|
||||
column_names = column_names.split('\t')
|
||||
mslookup_socket.sendall(query_str.encode('ascii'))
|
||||
while True:
|
||||
csv = mslookup_socket.recv(1024).decode('ascii')
|
||||
if not csv:
|
||||
break
|
||||
response = dict(zip(column_names, csv.split('\t')))
|
||||
if response.get('result') == 'result':
|
||||
result = response
|
||||
print('Response: %r' % response)
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
print(
|
||||
'\nPlease run separately: osmo-mslookup-client --socket /tmp/mslookup -d\n')
|
||||
query_str = '1000-5000@sip.voice.12345.msisdn'
|
||||
if len(sys.argv) > 1:
|
||||
query_str = sys.argv[1]
|
||||
print('Final result: %r' % query_mslookup_socket(query_str))
|
||||
@@ -49,7 +49,12 @@ set -x
|
||||
|
||||
cd "$base"
|
||||
autoreconf --install --force
|
||||
./configure --enable-sanitize --enable-external-tests --enable-werror $CONFIG
|
||||
./configure \
|
||||
--enable-sanitize \
|
||||
--enable-external-tests \
|
||||
--enable-mslookup-client-mdns-test \
|
||||
--enable-werror \
|
||||
$CONFIG
|
||||
$MAKE $PARALLEL_MAKE
|
||||
$MAKE check || cat-testlogs.sh
|
||||
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE distcheck || cat-testlogs.sh
|
||||
@@ -58,4 +63,5 @@ if [ "$WITH_MANUALS" = "1" ] && [ "$PUBLISH" = "1" ]; then
|
||||
make -C "$base/doc/manuals" publish
|
||||
fi
|
||||
|
||||
$MAKE maintainer-clean
|
||||
osmo-clean-workspace.sh
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[Unit]
|
||||
Description=Osmocom Home Location Register (OsmoHLR)
|
||||
Documentation=https://osmocom.org/projects/osmo-hlr/wiki/OsmoHLR
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
||||
180
debian/changelog
vendored
180
debian/changelog
vendored
@@ -1,3 +1,183 @@
|
||||
osmo-hlr (1.2.0) unstable; urgency=medium
|
||||
|
||||
[ Ruben Undheim ]
|
||||
* Fix test for return codes on mipsel and alpha archs
|
||||
|
||||
[ Thorsten Alteholz ]
|
||||
* fix spelling errors detected by lintian
|
||||
|
||||
[ Pau Espin Pedrol ]
|
||||
* tests: Fix db_test err file to expect error code name instead of value
|
||||
|
||||
[ Oliver Smith ]
|
||||
* tests/test_nodes.vty: check less libosmocore cmds
|
||||
* tests/db_upgrade: disable for old sqlite versions
|
||||
* gitignore: add tests/db_upgrade/*.dump
|
||||
* gsup_client.h: fix license header: GPLv2+
|
||||
* tests/auc: change back to python3
|
||||
|
||||
[ Neels Hofmeyr ]
|
||||
* fix double free in osmo_gsup_client_enc_send()
|
||||
* db upgrade to v2: log version 2, not 1
|
||||
* fix upgrade to version 2: imei column default value
|
||||
* add --db-check option
|
||||
* hlr.sql: move comment
|
||||
* add db_upgrade test
|
||||
* hlr db schema 3: hlr_number -> msc_number
|
||||
* db.c: code dup: add db_run_statements() for arrays of statements
|
||||
* move headers to include/osmocom/hlr
|
||||
* fix upgrade test in presence of ~/.sqliterc
|
||||
* db upgrade: remove some code dup
|
||||
* add osmo_gsup_msgb_alloc()
|
||||
* Makefile convenience: add VTY_TEST var to run only one test
|
||||
* remove gsup_test
|
||||
* test_nodes.vty: tweak: add some '?' checks
|
||||
* db v4: add column last_lu_seen_ps
|
||||
|
||||
[ Harald Welte ]
|
||||
* AUC: Add support for setting the AMF separation bit to '1' for EUTRAN
|
||||
* hlr: exit(2) on unsupported positional arguments on command line
|
||||
|
||||
-- Pau Espin Pedrol <pespin@sysmocom.de> Fri, 03 Jan 2020 12:37:35 +0100
|
||||
|
||||
osmo-hlr (1.1.0) unstable; urgency=medium
|
||||
|
||||
[ Oliver Smith ]
|
||||
* docs: running: document --db-upgrade
|
||||
* Add IMEI column to subscriber table
|
||||
* Optionally store IMEI in subscriber table
|
||||
* VTY tests: fill DB before running test
|
||||
* VTY: integrate IMEI
|
||||
* hlr.c: replace deprecated osmo_gsup_get_err_msg_type()
|
||||
* hlr.c: move hlr_ctx to the top
|
||||
* tests: use -no-install libtool flag to avoid ./lt-* scripts
|
||||
* Cosmetic: gsup_route_find: comment addr, addrlen
|
||||
* USSD: save MO USSD's originating MSC's vlr_number
|
||||
* USSD: don't use gsm0480_msgb_alloc_name()
|
||||
* hlr.c: forward GSUP messages between clients
|
||||
* db_hlr.c: db_subscr_create(): add flags argument
|
||||
* db_hlr.c: add db_subscr_exists_by_imsi()
|
||||
* Create subscribers on demand
|
||||
* Document subscribers create on demand feature
|
||||
* debian: create -doc subpackage with pdf manuals
|
||||
* db_test: set timezone to work around mktime bug
|
||||
* db_hlr: zero-initialize "struct tm"
|
||||
* rx_check_imei_req(): fix IMEI bounds checking
|
||||
* contrib/jenkins.sh: run "make maintainer-clean"
|
||||
* VTY: add subscriber update network-access-mode
|
||||
* manuals: improve subscribers create on demand
|
||||
* gitignore: ignore everything generated in db_test
|
||||
* db_auc.c: verify hex key sizes read from DB
|
||||
|
||||
[ Max ]
|
||||
* Log ip:port when adding GSUP routes
|
||||
* Add link to project wiki to .service file
|
||||
* Enable statsd support
|
||||
|
||||
[ Vadim Yanitskiy ]
|
||||
* hlr.c: properly terminate the process on SIGTERM
|
||||
* hlr.c: fix: also store the session state in read_cb_forward()
|
||||
* hlr.c: fix: properly print the original message type in read_cb_forward()
|
||||
* hlr.c: check the presence of msgb->l2h in read_cb()
|
||||
* hlr.c: fix possible msgb memleaks in read_cb()
|
||||
* db_hlr.c: add db_subscr_exists_by_msisdn()
|
||||
* src/db.h: use GSM23003_MSISDN_MAX_DIGITS for MSISDN buffer size
|
||||
* src/hlr.c: fix deprecation warning: use gsm48_decode_bcd_number2()
|
||||
* hlr_ussd.c: fix: properly pass invokeID in handle_ussd_own_msisdn()
|
||||
* hlr_ussd.c: rx_proc_ss_req(): fix NULL pointer dereference
|
||||
* build: fix mess with 'db_test_SOURCES' and 'db_test_LDADD'
|
||||
* tests/db_test: close the database when test is finished
|
||||
* src/db.c: integrate SQLite3 with talloc allocator
|
||||
|
||||
[ Neels Hofmeyr ]
|
||||
* USSD: fix routing to multiple MSC
|
||||
* fix error logging for GSUP route
|
||||
* add missing error log: invalid IMSI
|
||||
* osmo-hlr: allow configuring db path from cfg file
|
||||
* use new OSMO_IMSI_BUF_SIZE
|
||||
|
||||
[ Daniel Willmann ]
|
||||
* manuals: Add script to update vty/counter documentation from docker
|
||||
* manuals: Update vty documentation
|
||||
|
||||
[ Pau Espin Pedrol ]
|
||||
* Remove undefined param passed to logging_vty_add_cmds
|
||||
* configure.ac: Require libosmocore 1.2.0
|
||||
|
||||
-- Pau Espin Pedrol <pespin@sysmocom.de> Wed, 07 Aug 2019 16:14:23 +0200
|
||||
|
||||
osmo-hlr (1.0.0) unstable; urgency=medium
|
||||
|
||||
[ Stefan Sperling ]
|
||||
* move creation of insert subscriber data messages to a common function
|
||||
|
||||
[ Harald Welte ]
|
||||
* Return proper GSUP error in case of too short IMSI
|
||||
* disable blind subscriber insertion into every VLR/SGSN
|
||||
* gsup_server: Add "priv" pointer and make it point to 'struct hlr'
|
||||
* move osmo_gsup_addr_send() declaration from luop.h to gsup_router.h
|
||||
* gsup_router: Use "#pragma once" and add missing #includes
|
||||
* Add "show gsup-connections" VTY command
|
||||
* import gsup_client.c as new libosmo-gsup-client
|
||||
* gsup_client: rename gsup_client_* to osmo_gsup_client_*
|
||||
* GSUP: Log GSUP route add/remove
|
||||
* hlr: Export + Declare global g_hlr symbol
|
||||
* USSD: Add Core USSD handling + VTY routing config to HLR
|
||||
* USSD: Add basic dispatch + decode of GSUP-encapsulated SS/USSD
|
||||
* hlr_ussd: Introduce LOGPSS() macro
|
||||
* USSD: Send ReturnError component if USSD Code unknown / EUSE disconnected
|
||||
* USSD: Further unification of log output; Use LOGPSS when possible
|
||||
* osmo-hlr.cfg: Don't enable DEBUG logging by default
|
||||
* USSD: Add new "DSS" logging category and use it appropriately
|
||||
* USSD: fix null-pointer deref in "default-route" vty/config cmd
|
||||
* Add osmo-euse-demo as minimalistic test of a External USSD (EUSE) handler
|
||||
* USSD: Add support for internal USSD handlers
|
||||
* debian: Add sub-package for libosmo-gsup-client
|
||||
* pkg-config: Fix libosmo-gsup-client pkg-config file
|
||||
* gitignore: Add .tarball-version
|
||||
* debian: Make libosmo-gsup-client-dev depend on libosmo-gsup-client0
|
||||
* USSD: Fix "ussd default-route"
|
||||
* libosmo-gsup-client: License is GPLv2-or-later
|
||||
* osmo-hlr.cfg: Ensure well-formed config file example
|
||||
* test_nodes.vty: Since libosmocore 1.0.0, we only have one space
|
||||
|
||||
[ Martin Hauke ]
|
||||
* sql/Makefile.am: Make docsdir completely configurable
|
||||
* debian: Fix typo in package description
|
||||
|
||||
[ Pau Espin Pedrol ]
|
||||
* debian: Avoid installing duplicate cfg file in /etc
|
||||
* sql/Makefile: Install hlr_data.sql as example together with hlr.sql
|
||||
* sql/Makefile: Install sql files under doc/.../sql subdir
|
||||
* sql/Makefile: Create empty /var/lib/osmocom directory at install time
|
||||
* Install systemd services with autotools
|
||||
* Move doc/Makefile.am to doc/examples/Makefile.am
|
||||
* Install sample cfg file to /etc/osmocom
|
||||
|
||||
[ Vadim Yanitskiy ]
|
||||
* hlr.c: move deinitialization code from SIGINT handler
|
||||
* hlr.c: free root talloc context on exit
|
||||
* hlr.c: track the use of talloc NULL memory contexts
|
||||
* src/db.c: fix: make sure the database is properly closed
|
||||
* src/db.c: don't ignore the result of db_bootstrap()
|
||||
* hlr_vty_subscr.c: fix subscriber creation command help
|
||||
* Update .gitignore: add missing build products
|
||||
* tests/Makefile.am: also remove temporary sqlite files
|
||||
* hlr_ussd.h: add #pragma once include guard
|
||||
* hlr_ussd.h: use proper libc headers
|
||||
* Update .gitignore: ignore osmo-euse-demo
|
||||
* hlr_ussd.h: drop meaningless forward declaration
|
||||
* USSD/hlr_vty.c: print error if EUSE is not found
|
||||
* hlr_ussd.c: fix: properly print a EUSE / IUSE name
|
||||
* hlr_ussd.c: avoid using CR and NL in IUSE responses
|
||||
|
||||
[ Neels Hofmeyr ]
|
||||
* fix build: adjust test_nodes.vty to logging change
|
||||
* tweak example config
|
||||
* make: always allow running python tests manually
|
||||
|
||||
-- Harald Welte <laforge@gnumonks.org> Sun, 20 Jan 2019 19:29:58 +0100
|
||||
|
||||
osmo-hlr (0.2.1) unstable; urgency=medium
|
||||
|
||||
[ Neels Hofmeyr ]
|
||||
|
||||
36
debian/control
vendored
36
debian/control
vendored
@@ -7,12 +7,13 @@ Build-Depends: debhelper (>= 9),
|
||||
dh-autoreconf,
|
||||
dh-systemd (>= 1.5),
|
||||
autotools-dev,
|
||||
python-minimal,
|
||||
python3-minimal,
|
||||
libosmocore-dev,
|
||||
libosmo-abis-dev,
|
||||
libosmo-netif-dev,
|
||||
libsqlite3-dev,
|
||||
sqlite3
|
||||
sqlite3,
|
||||
osmo-gsm-manuals-dev
|
||||
Standards-Version: 3.9.6
|
||||
Vcs-Browser: http://cgit.osmocom.org/osmo-hlr
|
||||
Vcs-Git: git://git.osmocom.org/osmo-hlr
|
||||
@@ -57,3 +58,34 @@ Description: Development headers of Osmocom GSUP client library
|
||||
and External USSD Entities (EUSEs) using this library to implement clients.
|
||||
.
|
||||
This package contains the development headers.
|
||||
|
||||
Package: libosmo-mslookup0
|
||||
Section: libs
|
||||
Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends}
|
||||
Pre-Depends: ${misc:Pre-Depends}
|
||||
Description: Osmocom MS lookup library
|
||||
This shared library contains routines for looking up mobile subscribers.
|
||||
|
||||
Package: libosmo-mslookup-dev
|
||||
Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends: ${misc:Depends},
|
||||
libosmo-mslookup0 (= ${binary:Version}),
|
||||
libosmocore-dev
|
||||
Pre-Depends: ${misc:Pre-Depends}
|
||||
Description: Development headers of Osmocom MS lookup library
|
||||
This shared library contains routines for looking up mobile subscribers.
|
||||
.
|
||||
This package contains the development headers.
|
||||
|
||||
Package: osmo-hlr-doc
|
||||
Architecture: all
|
||||
Section: doc
|
||||
Priority: optional
|
||||
Depends: ${misc:Depends}
|
||||
Description: ${misc:Package} PDF documentation
|
||||
Various manuals: user manual, VTY reference manual and/or
|
||||
protocol/interface manuals.
|
||||
|
||||
5
debian/libosmo-mslookup-dev.install
vendored
Normal file
5
debian/libosmo-mslookup-dev.install
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
usr/include/osmocom/mslookup
|
||||
usr/lib/*/libosmo-mslookup*.a
|
||||
usr/lib/*/libosmo-mslookup*.so
|
||||
usr/lib/*/libosmo-mslookup*.la
|
||||
usr/lib/*/pkgconfig/libosmo-mslookup.pc
|
||||
1
debian/libosmo-mslookup0.install
vendored
Normal file
1
debian/libosmo-mslookup0.install
vendored
Normal file
@@ -0,0 +1 @@
|
||||
usr/lib/*/libosmo-mslookup*.so.*
|
||||
1
debian/osmo-hlr-doc.install
vendored
Normal file
1
debian/osmo-hlr-doc.install
vendored
Normal file
@@ -0,0 +1 @@
|
||||
usr/share/doc/osmo-hlr-doc/*.pdf
|
||||
6
debian/rules
vendored
6
debian/rules
vendored
@@ -17,4 +17,8 @@ override_dh_auto_test:
|
||||
dh_auto_test || (find . -name testsuite.log -exec cat {} \; ; false)
|
||||
|
||||
override_dh_auto_configure:
|
||||
dh_auto_configure -- --with-systemdsystemunitdir=/lib/systemd/system
|
||||
dh_auto_configure -- --with-systemdsystemunitdir=/lib/systemd/system --enable-manuals
|
||||
|
||||
# Don't create .pdf.gz files (barely saves space and they can't be opened directly by most pdf readers)
|
||||
override_dh_compress:
|
||||
dh_compress -X.pdf
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
SUBDIRS = \
|
||||
examples \
|
||||
manuals \
|
||||
sequence_charts \
|
||||
$(NULL)
|
||||
|
||||
22
doc/examples/osmo-hlr-dgsm.cfg
Normal file
22
doc/examples/osmo-hlr-dgsm.cfg
Normal file
@@ -0,0 +1,22 @@
|
||||
# OsmoHLR example configuration for Distributed GSM (mslookup)
|
||||
hlr
|
||||
gsup
|
||||
# For D-GSM roaming, osmo-hlr's GSUP must listen on a public IP:
|
||||
bind ip 10.9.8.7
|
||||
# Each HLR should identify with a distinct name
|
||||
ipa-name hlr-23
|
||||
mslookup
|
||||
# Bind mslookup mDNS server and client on default multicast address and port:
|
||||
# 239.192.23.42 port 4266
|
||||
mdns bind
|
||||
# Tell the mslookup server in osmo-hlr which IP+ports to return when a
|
||||
# remote voice call or SMS wants to deliver to a local subscriber:
|
||||
server
|
||||
# local osmo-sip-connector SIP port
|
||||
service sip.voice at 10.9.8.7 5060
|
||||
# local osmo-msc SMPP port
|
||||
service smpp.sms at 10.9.8.7 2775
|
||||
# experimental: SMS-over-GSUP: this HLR's GSUP port
|
||||
service gsup.sms at 10.9.8.7 4222
|
||||
# only required if different from above 'gsup'/'bind ip':
|
||||
#service gsup.hlr at 10.9.8.7 4222
|
||||
@@ -4,17 +4,24 @@ EXTRA_DIST = example_subscriber_add_update_delete.vty \
|
||||
osmohlr-usermanual.adoc \
|
||||
osmohlr-usermanual-docinfo.xml \
|
||||
osmohlr-vty-reference.xml \
|
||||
chapters/proxy_cache_attach.msc \
|
||||
chapters/proxy_cache_more_tuples.msc \
|
||||
chapters/proxy_cache_periodic_lu.msc \
|
||||
chapters/proxy_cache_tuple_cache_dry.msc \
|
||||
chapters/proxy_cache_umts_aka_resync.msc \
|
||||
regen_doc.sh \
|
||||
chapters \
|
||||
vty
|
||||
|
||||
if BUILD_MANUALS
|
||||
ASCIIDOC = osmohlr-usermanual.adoc
|
||||
ASCIIDOC_DEPS = $(srcdir)/chapters/*.adoc $(srcdir)/*.vty $(srcdir)/*.ctrl
|
||||
ASCIIDOC_DEPS = $(srcdir)/chapters/*.adoc $(srcdir)/*.vty $(srcdir)/*.ctrl $(srcdir)/chapters/*.msc
|
||||
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.asciidoc.inc
|
||||
|
||||
VTY_REFERENCE = osmohlr-vty-reference.xml
|
||||
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.vty-reference.inc
|
||||
|
||||
OSMO_REPOSITORY = osmo-hlr
|
||||
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.common.inc
|
||||
endif
|
||||
|
||||
|
||||
20
doc/manuals/chapters/Makefile
Normal file
20
doc/manuals/chapters/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
all: \
|
||||
proxy_cache_attach.msc \
|
||||
proxy_cache_more_tuples.msc \
|
||||
proxy_cache_tuple_cache_dry.msc \
|
||||
proxy_cache_periodic_lu.msc \
|
||||
proxy_cache_umts_aka_resync.msc \
|
||||
$(NULL)
|
||||
|
||||
png: \
|
||||
proxy_cache.png \
|
||||
proxy_cache_unused.png \
|
||||
lu_attach_and_periodic.png \
|
||||
$(NULL)
|
||||
|
||||
%.png: %.msc
|
||||
mscgen -T png -o $@ $<
|
||||
|
||||
%.msc: %.ladder
|
||||
@which ladder_to_msc.py || (echo 'PLEASE POINT YOUR $$PATH AT libosmocore/contrib/ladder_to_msc.py' && false)
|
||||
ladder_to_msc.py -i $< -o $@
|
||||
491
doc/manuals/chapters/dgsm.adoc
Normal file
491
doc/manuals/chapters/dgsm.adoc
Normal file
@@ -0,0 +1,491 @@
|
||||
== Distributed GSM / Multicast MS Lookup
|
||||
|
||||
Distributed GSM (D-GSM) allows independent mobile core network stacks to provide voice, SMS and Roaming services to each
|
||||
other, without the need for centralised entities or administration authority, and in a way that is resilient against
|
||||
unstable network links between sites.
|
||||
|
||||
D-GSM aims at communal networks, where several independent sites, let's call them villages, each have a full mobile core
|
||||
network infrastructure. It elegantly provides ad-hoc service for subscribers moving across villages, and allows villages
|
||||
to dynamically join or leave the cooperative network without the need for configuration changes at other sites.
|
||||
|
||||
A challenge for linking separate sites is to find the current location of a subscriber. Typically, in mobile networks, a
|
||||
centralized entity keeps track of where to Page for subscribers. Running several fully independent sites with unreliable
|
||||
links between them makes it hard to provide such centralisation.
|
||||
|
||||
D-GSM finds subscribers by mslookup, a service provided by OsmoHLR, typically using multicast DNS queries. This allows
|
||||
routing Location Updating requests, calls, and SMS to the right site without administrative delay nor the need for a
|
||||
reliable link to a central database.
|
||||
|
||||
D-GSM is highly resilient against single sites or links becoming temporarily unavailable. Service between still
|
||||
reachable sites simply continues; Service to a disconnected site resumes as soon as it becomes reachable again.
|
||||
|
||||
This brings an entirely new paradigm to mobile core network infrastructure: as sites become reachable on the IP network
|
||||
and join the common IP multicast group, services between them become available immediately. Basically, the only premise
|
||||
is that IP routing and multicast works across sites, and that each site uses unique IPA names in the GSUP config.
|
||||
|
||||
This chapter describes how D-GSM and mslookup work, and how to configure sites to use D-GSM, using Osmocom core network
|
||||
infrastructure.
|
||||
|
||||
=== Finding Subscribers: mslookup Clients
|
||||
|
||||
There are two fundamentally distinct subscriber lookups provided by the mslookup service.
|
||||
|
||||
==== Find the Current Location of an MSISDN
|
||||
|
||||
[[fig_dgsm_connect]]
|
||||
.mslookup for connecting subscribers: Alice is visiting village C; a phone call gets routed directly to her current location independently from her resident village infrastructure
|
||||
[graphviz]
|
||||
----
|
||||
digraph G {
|
||||
rankdir=LR
|
||||
|
||||
subgraph cluster_village_b {
|
||||
label="Village B"
|
||||
ms_bob [label="Bob\n(from village B)",shape=box]
|
||||
pbx_b [label="SIP B"]
|
||||
}
|
||||
|
||||
subgraph cluster_village_c {
|
||||
label="Village C"
|
||||
ms_alice [label="Alice\n(from village A)",shape=box]
|
||||
msc_c [label="MSC C"]
|
||||
hlr_c [label="HLR C"]
|
||||
sip_c [label="SIP C"]
|
||||
}
|
||||
|
||||
ms_alice -> msc_c [style=dashed,arrowhead=none]
|
||||
msc_c -> hlr_c [label="attached",style=dashed,arrowhead=none]
|
||||
ms_bob -> pbx_b [label="call Alice"]
|
||||
pbx_b -> hlr_c [label="mslookup by MSISDN",style=dotted,dir=both]
|
||||
pbx_b -> sip_c -> msc_c -> ms_alice [label="call"]
|
||||
}
|
||||
----
|
||||
|
||||
For example, if a subscriber is currently visiting another village, establish a phone call / send SMS towards that
|
||||
village.
|
||||
|
||||
- To deliver a phone call, a SIP agent integrates an mslookup client to request the SIP service of an MSISDN's current
|
||||
location (example: <<dgsm_conf_dialplan>>). It receives an IP address and port to send the SIP Invite to.
|
||||
|
||||
- To deliver an SMS, an ESME integrates an mslookup client to request the SMPP service of an MSISDN's current location
|
||||
(example: <<dgsm_conf_esme_smpp>>).
|
||||
|
||||
The current location of a subscriber may change at any time, and, when moving across locations, a subscriber may
|
||||
suddenly lose reception to the previous location without explicitly detaching. Hence an mslookup request for the current
|
||||
location of an MSISDN may get numerous responses. To find the currently valid location, mslookup includes the age of the
|
||||
subscriber record, i.e. how long ago the subscriber was last reached. The one response with the youngest age reflects
|
||||
the current location.
|
||||
|
||||
In order to evaluate several responses, mslookup always waits for a fixed amount of time (1 second), and then evaluates
|
||||
the available responses.
|
||||
|
||||
Services are not limited to SIP and SMPP, arbitrarily named services can be added to the mslookup configuration.
|
||||
|
||||
.Message sequence for locating an MSISDN to deliver a voice call
|
||||
["mscgen"]
|
||||
----
|
||||
msc {
|
||||
hscale="2";
|
||||
moms[label="MS,BSS\nvillage A"],momsc[label="MSC,MGW\nvillage A"],mosipcon[label="osmo-sip-connector\nvillage A"],mopbx[label="PBX\nvillage A"],mthlr[label="OsmoHLR\nvillage B"],mtsipcon[label="osmo-sip-connector\nvillage B"],mtmsc[label="MGW,MSC\nvillage B"],mtms[label="RAN,MS\nvillage B"];
|
||||
|
||||
moms =>> momsc [label="CC Setup"];
|
||||
momsc =>> mosipcon [label="MNCC_SETUP_IND"];
|
||||
mosipcon =>> mopbx [label="SIP INVITE"];
|
||||
mopbx rbox mopbx [label="dialplan: launch mslookup by MSISDN"];
|
||||
--- [label="multicast-DNS query to all connected sites"];
|
||||
...;
|
||||
mopbx <<= mthlr [label="mDNS response\n(age)"];
|
||||
mopbx rbox mopbx [label="wait ~ 1s for more mDNS responses"];
|
||||
...;
|
||||
mopbx =>> mtsipcon [label="SIP INVITE (MT)"];
|
||||
mtmsc <<= mtsipcon [label="MNCC_SETUP_REQ"];
|
||||
mtms <<= mtmsc [label="Paging (CC)"];
|
||||
moms rbox mtms [label="voice call commences"];
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
==== Find the Home HLR for an IMSI
|
||||
|
||||
[[fig_dgsm_roaming]]
|
||||
.mslookup for Roaming: Alice visits village B; she can attach to the local mobile network, which proxies HLR administration to her home village.
|
||||
[graphviz]
|
||||
----
|
||||
digraph G {
|
||||
rankdir=LR
|
||||
|
||||
subgraph cluster_village_b {
|
||||
label="Village B"
|
||||
|
||||
ms_alice [label="Alice\n(from village A)",shape=box]
|
||||
msc_b [label="MSC B"]
|
||||
hlr_b [label="HLR B"]
|
||||
}
|
||||
|
||||
subgraph cluster_village_a {
|
||||
label="Village A"
|
||||
hlr_alice [label="Alice's home HLR"]
|
||||
}
|
||||
|
||||
ms_alice -> msc_b -> hlr_b [label="Location\nUpdating"]
|
||||
hlr_b -> hlr_alice [label="mslookup by IMSI",style=dotted,dir=both]
|
||||
hlr_b -> hlr_alice [label="GSUP proxy forwarding"]
|
||||
}
|
||||
----
|
||||
|
||||
For example, when attaching to a local network, a local resident gets serviced directly by the local village's HLR,
|
||||
while a visitor from another village gets serviced by the remote village's HLR (Roaming).
|
||||
|
||||
A home HLR typically stays the same for a given IMSI. If the home site is reachable, there should be exactly one
|
||||
response to an mslookup request asking for it. The age of such a home-HLR response is always sent as zero.
|
||||
|
||||
If a response's age is zero, mslookup does not wait for further responses and immediately uses the result.
|
||||
|
||||
If there were more than one HLR accepting service for an IMSI, the one with the shortest response latency is used.
|
||||
|
||||
=== mslookup Configuration
|
||||
|
||||
OsmoHLR the main mslookup agent. It provides the responses for both current location services as well as for locating
|
||||
the fixed home-HLR. But naturally, depending on the mslookup request's purpose, different OsmoHLR instances will respond
|
||||
for a given subscriber.
|
||||
|
||||
- When querying the home HLR, it is always the (typically single) home HLR instance that sends the mslookup response. As
|
||||
soon as it finds the queried IMSI in the local HLR database, an OsmoHLR will respond to home-HLR requests.
|
||||
In <<fig_dgsm_roaming>>, Alice's home HLR responds to the Roaming request ("where is the home HLR?").
|
||||
|
||||
- When querying the location of an MSISDN, it is always the HLR proxy nearest to the servicing MSC that sends the
|
||||
mslookup response. Even though the home HLR keeps the Location Updating record also for Roaming cases, it will only
|
||||
respond to an mslookup service request if the subscriber has attached at a directly connected MSC. If attached at a
|
||||
remote MSC, that MSC's remote HLR will be the GSUP proxy for the home HLR, and the remote HLR is responsible for
|
||||
responding to service requests.
|
||||
In <<fig_dgsm_roaming>>, HLR B is the nearest proxy and will answer all service requests ("where is this MSISDN?").
|
||||
Alice's home HLR will not answer service requests, because it detects that the servicing MSC is connected via another
|
||||
HLR proxy.
|
||||
|
||||
[[dgsm_example_config]]
|
||||
==== Example
|
||||
|
||||
Here is an osmo-hlr.cfg mslookup configuration example for one site, which is explained in subsequent chapters.
|
||||
|
||||
hlr
|
||||
gsup
|
||||
bind ip 10.9.8.7
|
||||
ipa-name hlr-23
|
||||
mslookup
|
||||
mdns bind
|
||||
server
|
||||
service sip.voice at 10.9.8.7 5060
|
||||
service smpp.sms at 10.9.8.7 2775
|
||||
|
||||
OsmoHLR has both an mslookup server and a client.
|
||||
|
||||
- The server responds to incoming service and home-HLR requests, when the local HLR is responsible.
|
||||
- The client is used as GSUP proxy to a remote home HLR (found by mslookup upon a locally unknown IMSI).
|
||||
- The client may also be used for forwarding SMS-over-GSUP.
|
||||
|
||||
The mslookup service can be implemented by various methods.
|
||||
At the time of writing, the only method implemented is mDNS.
|
||||
|
||||
==== mDNS
|
||||
|
||||
The stock mslookup method is mDNS, multicast DNS. It consists of standard DNS encoding according to <<ietf-rfc1035>> and
|
||||
<<ietf-rfc3596>>, but sent and received on IP multicast. In the response, standard A and AAAA records return the
|
||||
service's IP address, while additional TXT records provide the service's port number and the MS attach age.
|
||||
|
||||
TIP: To watch D-GSM mDNS conversations in wireshark, select "udp.port == 4266" (the default mslookup mDNS port
|
||||
number), right click on the packet to "Decode as...", and select "DNS".
|
||||
|
||||
In OsmoHLR, the mDNS server and client are typically both enabled at the same time:
|
||||
|
||||
mslookup
|
||||
mdns bind
|
||||
|
||||
Server and client can also be enabled/disabled individually:
|
||||
|
||||
mslookup
|
||||
server
|
||||
mdns bind
|
||||
client
|
||||
mdns bind
|
||||
|
||||
These examples use the default mslookup multicast IP address and port. It is possible to configure custom IP address and
|
||||
port, but beware that the IP address must be from a multicast range, see <<ietf-rfc5771>>:
|
||||
|
||||
mslookup
|
||||
mdns bind 239.192.23.42 4266
|
||||
|
||||
Domain names generated from mslookup queries (e.g. "sip.voice.123.msisdn") should not collide with IANA permitted
|
||||
domains. Therefore we add the "mdns.osmocom.org" suffix. It can be overridden as follows:
|
||||
|
||||
mslookup
|
||||
mdns domain-suffix mdns.osmocom.org
|
||||
|
||||
==== Server: Site Services
|
||||
|
||||
The mslookup server requires a list of service addresses provided at the local site, in order to respond to service
|
||||
requests matching locally attached subscribers.
|
||||
|
||||
mslookup
|
||||
server
|
||||
service sip.voice at 10.9.8.7 5060
|
||||
service smpp.sms at 10.9.8.7 2775
|
||||
|
||||
In this example:
|
||||
|
||||
- "10.9.8.7 5060" are the IP address and port on which the local site's osmo-sip-connector is bound to receive SIP
|
||||
Invite requests.
|
||||
- "10.9.8.7 2775" are the local site's OsmoMSC SMPP bind address and port.
|
||||
|
||||
Obviously, these IP addresses must be routable back to this site from all other sites. Using link-local or "ANY"
|
||||
addresses, like 127.0.0.1 or 0.0.0.0, will not work here. Instead, each service config requires a public IP address that
|
||||
all remote requestors are able to reach (not necessarily on the host that osmo-hlr is running on).
|
||||
|
||||
If a site has more than one MSC, services can also be configured for each MSC individually, keyed by the IPA unit name
|
||||
that each MSC sends on the GSUP link:
|
||||
|
||||
mslookup
|
||||
server
|
||||
msc ipa-name msc-262-42-0
|
||||
service sip.voice at 10.11.12.13 5060
|
||||
service smpp.sms at 10.11.12.13 2775
|
||||
msc ipa-name msc-901-70-0
|
||||
service sip.voice at 10.9.8.7 5060
|
||||
service smpp.sms at 10.9.8.7 2775
|
||||
|
||||
Here, "msc-262-42-0" is the IPA name of a local OsmoMSC instance. To configure an OsmoMSC's IPA name on the GSUP link,
|
||||
see osmo-msc.cfg, setting `hlr` / `ipa-name`.
|
||||
|
||||
For mslookup service responses, only Location Updatings in the Circuit Switched domain are relevant. OsmoHLR does manage
|
||||
IMSIs attaching in the Packet Switched domain (via an SGSN) similarly to Circuit Switched (via an MSC), but mslookup
|
||||
completely ignores the Packet Switched attach status.
|
||||
|
||||
==== Server: Own GSUP Address
|
||||
|
||||
When responding to home-HLR requests, OsmoHLR implicitly by default responds with its locally configured GSUP bind
|
||||
address (setting `hlr` / `gsup` / `bind ip`). If required, an explicit local GSUP address and port can be configured,
|
||||
for example:
|
||||
|
||||
hlr
|
||||
gsup
|
||||
bind ip 0.0.0.0
|
||||
ipa-name hlr-23
|
||||
mslookup
|
||||
server
|
||||
# osmo-hlr's own GSUP address to send in mslookup responses:
|
||||
service gsup.hlr at 10.9.8.7 4222
|
||||
|
||||
The gsup.hlr service can only be configured globally (because requests come from arbitrary mDNS clients, before a
|
||||
Location Updating has associated the IMSI with the requesting MSC).
|
||||
|
||||
==== Client IPA Naming
|
||||
|
||||
For reliable GSUP proxy routing to a remote HLR (Roaming), it is important that each GSUP client, i.e. each HLR, MSC and
|
||||
SGSN instance, has a unique IPA name.
|
||||
|
||||
Example for configuring an OsmoHLR instance's IPA name:
|
||||
|
||||
hlr
|
||||
gsup
|
||||
ipa-name hlr-23
|
||||
|
||||
Here, "hlr-23" is the unique identification of this OsmoHLR instance across all potentially connected D-GSM sites.
|
||||
|
||||
Furthermore, each MSC and SGSN must have a uniquely distinct IPA name across all sites (here "msc-262-42-0" and
|
||||
"msc-901-70-0" are used as example IPA names for local MSCs).
|
||||
|
||||
When this OsmoHLR connects to a remote HLR, be it for GSUP proxying or SMS-over-GSUP, it communicates its own IPA name
|
||||
(on GSUP link-up) as well as the IPA name of the requesting client MSC/SGSN (as Source Name in each message) to the
|
||||
remote OsmoHLR GSUP server. These names are used to route GSUP responses back to the respective requesting peer.
|
||||
|
||||
If two MSCs were accidentally configured with identical names, a problem will occur as soon as both MSCs attempt to
|
||||
attach to the same OsmoHLR (either directly or via GSUP proxying). The MSC that shows up first will work normally, but
|
||||
any duplicate that shows up later will be rejected, since a route for its name already exists.
|
||||
|
||||
=== Queries
|
||||
|
||||
In URL notation, typical mslookup queries look like:
|
||||
|
||||
gsup.hlr.123456789.imsi
|
||||
sip.voice.123.msisdn
|
||||
smpp.sms.123.msisdn
|
||||
|
||||
A query consists of
|
||||
|
||||
- a service name ("gsup.hlr"),
|
||||
- an id ("123456789"),
|
||||
- the id type ("imsi").
|
||||
|
||||
The calling client also defines a timeout to wait for responses.
|
||||
|
||||
The mslookup ID types are fixed, while service names can be chosen arbitrarily.
|
||||
|
||||
.mslookup ID types, no other ID types are understood by mslookup
|
||||
[options="header",width="100%",cols="20%,80%"]
|
||||
|===
|
||||
|ID Type|Description
|
||||
|imsi|An IMSI as existing in an OsmoHLR subscriber database
|
||||
|msisdn|A phone number as configured in an OsmoHLR subscriber database
|
||||
|===
|
||||
|
||||
.mslookup service name conventions, arbitrary service names can be added as required
|
||||
[options="header",width="100%",cols="20%,20%,60%"]
|
||||
|===
|
||||
|Service Name|Protocol|Description
|
||||
|gsup.hlr | GSUP | Home HLR's GSUP server, to handle Location Updating related procedures
|
||||
|sip.voice | SIP | OsmoSIPConnector, to receive a SIP Invite (MT side of a call)
|
||||
|smpp.sms | SMPP | Destination OsmoMSC (or other SMPP server) to deliver an SMS to the recipient
|
||||
|gsup.sms | GSUP | GSUP peer to deliver an SMS to the recipient using SMS-over-GSUP
|
||||
|===
|
||||
|
||||
Arbitrarily named services can be added to the mslookup configuration and queried by mslookup clients; as soon as a
|
||||
service name is present in osmo-hlr.cfg, it can be queried from any mslookup client.
|
||||
|
||||
Service names should consist of a protocol name (like "sip", "gsup", "english") and an intended action/entity (like
|
||||
"voice", "hlr", "greeting").
|
||||
|
||||
=== Service Client Implementation
|
||||
|
||||
In principle, arbitrary services could query target addresses via mslookup, leaving it up to any and all kinds of
|
||||
clients to find their respective destination addresses. But of course, mslookup was designed with specific services in
|
||||
mind, namely:
|
||||
|
||||
- SIP call agents and
|
||||
- SMS delivery (an ESME or SMSC)
|
||||
|
||||
The following chapters describe examples of setting up a working distributed core network providing SIP voice calls and
|
||||
SMS forwarding across sites.
|
||||
|
||||
==== mslookup Library
|
||||
|
||||
The OsmoHLR provides an mslookup client C library, libosmo-mslookup. Service lookups can be integrated directly
|
||||
in client programs using this library. However, its mDNS implementation requires the libosmocore select() loop, which
|
||||
can be challenging to integrate in practice. An alternative solution is the osmo-mslookup-client tool.
|
||||
|
||||
[[dgsm_osmo_mslookup_client]]
|
||||
==== osmo-mslookup-client
|
||||
|
||||
The mslookup C library is available, but often, a simpler approach for client implementations is desirable:
|
||||
|
||||
- When querying for a service address, the client is typically interested in the single final best result (youngest age
|
||||
/ first responding home HLR).
|
||||
- Voice call and SMS clients typically would block until an mslookup result is known. For example, the FreeSwitch
|
||||
dialplan integration expects a result synchronously, i.e. without waiting for mslookup responses via a select() loop.
|
||||
- Integrating the libosmocore select() loop required for mDNS can break the already existing socket handling in the
|
||||
client program.
|
||||
|
||||
The osmo-mslookup-client cmdline tool provides a trivial way to synchronously acquire the single result for an mslookup
|
||||
request. The service client can invoke an osmo-mslookup-client process per request and read the result from stdout.
|
||||
|
||||
Each invocation obviously spawns a separate process and opens a multicast socket for mDNS. For better scalability,
|
||||
osmo-mslookup-client can also be run as a daemon, providing results via a unix domain socket. Using synchronous write()
|
||||
and recv() allows blocking until a result is received without interfering with the client program's select() setup.
|
||||
|
||||
By itself, osmo-mslookup-client is also helpful as a diagnostic tool:
|
||||
|
||||
----
|
||||
$ osmo-mslookup-client sip.voice.1001.msisdn
|
||||
sip.voice.1001.msisdn ok 10.9.8.7 5060
|
||||
|
||||
$ osmo-mslookup-client gsup.hlr.901700000014701.imsi
|
||||
gsup.hlr.901700000014701.imsi ok 10.9.8.7 4222
|
||||
|
||||
$ osmo-mslookup-client gsup.hlr.111111.imsi
|
||||
gsup.hlr.111111.imsi not-found
|
||||
|
||||
$ osmo-mslookup-client gsup.hlr.1001.msisdn sip.voice.1001.msisdn smpp.sms.1001.msisdn foo.1001.msisdn
|
||||
gsup.hlr.1001.msisdn ok 10.9.8.7 4222
|
||||
foo.1001.msisdn not-found
|
||||
smpp.sms.1001.msisdn ok 10.9.8.7 2775
|
||||
sip.voice.1001.msisdn ok 10.9.8.7 5060
|
||||
|
||||
$ osmo-mslookup-client --csv-headers gsup.hlr.901700000014701.imsi
|
||||
QUERY RESULT V4_IP V4_PORT V6_IP V6_PORT
|
||||
gsup.hlr.901700000014701.imsi ok 10.9.8.7 4222
|
||||
|
||||
$ osmo-mslookup-client -f json gsup.hlr.901700000014701.imsi
|
||||
{"query": "gsup.hlr.901700000014701.imsi", "result": "ok", "v4": ["10.9.8.7", "4222"]}
|
||||
----
|
||||
|
||||
For full help including example client invocations in Python, see the output of:
|
||||
|
||||
osmo-mslookup-client -h
|
||||
|
||||
==== SIP Service Client
|
||||
|
||||
[[dgsm_conf_dialplan]]
|
||||
===== FreeSwitch dialplan.py
|
||||
|
||||
The FreeSWITCH PBX software <<freeswitch_pbx>> offers a Python integration to determine a SIP call recipient by a custom
|
||||
dialplan implementation. An example dialplan implementation for FreeSWITCH that uses D-GSM mslookup is provided in the
|
||||
osmo-hlr source tree under `contrib`, called `freeswitch_dialplan_dgsm.py`.
|
||||
|
||||
To integrate it with your FREESWITCH setup, add a new `extension` block to your `dialplan/public.xml`:
|
||||
|
||||
----
|
||||
<extension name="outbound">
|
||||
<condition field="destination_number" expression=".*">
|
||||
<action application="set" data="hangup_after_bridge=true"/>
|
||||
<action application="set" data="session_in_hangup_hook=true"/>
|
||||
<action application="set" data="ringback=%(2000, 4000, 440.0, 480.0)"/>
|
||||
<action application="python" data="freeswitch_dialplan_dgsm"/>
|
||||
</condition>
|
||||
</extension>
|
||||
----
|
||||
|
||||
Make sure that the dir containing `freeswitch_dialplan_dgsm.py` is in your `PYTHONPATH` environment variable, and start
|
||||
the server:
|
||||
|
||||
----
|
||||
$ export PYTHONPATH="$PYTHONPATH:/home/user/code/osmo-hlr/contrib/dgsm"
|
||||
$ freeswitch -nf -nonat -nonatmap -nocal -nort -c
|
||||
----
|
||||
|
||||
==== SMS Service Client
|
||||
|
||||
[[dgsm_conf_esme_smpp]]
|
||||
===== SMS via SMPP Port
|
||||
|
||||
An example ESME using D-GSM mslookup, `esme_dgsm.py`, is provided in the osmo-hlr source tree under `contrib`. It
|
||||
attaches to OsmoMSC's SMPP port to send SMS to recipients determined by mslookup.
|
||||
|
||||
OsmoMSC should be configured as "smpp-first", so that all SMS routing is determined by mslookup. If configured without
|
||||
smpp-first, OsmoMSC may try to deliver an SMS locally, even though the recipient has recently moved to a different site.
|
||||
|
||||
An example OsmoMSC configuration to work with esme_dgsm.py:
|
||||
|
||||
----
|
||||
smpp
|
||||
local-tcp-ip 127.0.0.1 2775
|
||||
system-id test-msc
|
||||
policy closed
|
||||
smpp-first
|
||||
# outgoing to esme_dgsm.py
|
||||
esme OSMPP
|
||||
no alert-notifications
|
||||
password foo
|
||||
default-route
|
||||
# incoming from esme_dgsm.py
|
||||
esme ISMPP
|
||||
no alert-notifications
|
||||
password foo
|
||||
----
|
||||
|
||||
Launch esme_dgsm.py alongside OsmoMSC:
|
||||
|
||||
----
|
||||
./esme_dgsm.py --src-host 127.0.0.1
|
||||
----
|
||||
|
||||
esme_dgsm.py will be notified via SMPP for each SMS to be delivered, and will forward them either to a remote
|
||||
recipient, or back to the same OsmoMSC, depending on the mslookup result. If the MSISDN is not reachable (or
|
||||
esme_dgsm.py can't handle the message for other reasons), it returns the RSYSERR code back to OsmoMSC.
|
||||
|
||||
Note that the esme_dgsm.py is a proof of concept and should not be used in production. It has several limitations, such
|
||||
as not supporting multipart SMS messages.
|
||||
|
||||
===== SMS-Over-GSUP
|
||||
|
||||
The GSUP protocol defines SMS delivery messages. When OsmoMSC is configured to deliver SMS via GSUP, MO SMS are directly
|
||||
forwarded to the HLR, which will determine where to forward the SMS-over-GSUP messages using its mslookup client.
|
||||
|
||||
FIXME implement this
|
||||
333
doc/manuals/chapters/proxy_cache.adoc
Normal file
333
doc/manuals/chapters/proxy_cache.adoc
Normal file
@@ -0,0 +1,333 @@
|
||||
== Distributed GSM / GSUP Proxy Cache: Remedy Temporary Link Failure to Home HLR
|
||||
|
||||
The aim of the Proxy Cache is to still provide service to roaming subscribers even if the GSUP link to the home HLR is
|
||||
temporarily down or unresponsive.
|
||||
|
||||
If a subscriber from a remote site is currently roaming at this local site, and the link to the subscriber's home HLR
|
||||
has succeeded before, the GSUP proxy cache can try to bridge the time of temporary link failure to that home HLR.
|
||||
|
||||
Tasks to take over from an unreachable home HLR:
|
||||
|
||||
- Cache and send auth tuples on Send Auth Info Request.
|
||||
- Acknowledge periodic Location Updating.
|
||||
- ...?
|
||||
|
||||
=== Design Considerations
|
||||
|
||||
==== Authentication
|
||||
|
||||
The most critical role of the home HLR is providing the Authentication and Key Agreement (AKA) tuples. If the home HLR
|
||||
is not reachable, the lack of fresh authentication challenges would normally cause the subscriber to be rejected. To
|
||||
avoid that, a proxying HLR needs to be able to provide AKA tuples on behalf of the home HLR.
|
||||
|
||||
In short, the strategy of the D-GSM proxy cache is:
|
||||
|
||||
- Try to keep a certain number of unused full UMTS AKA tuples in the proxy cache at all times.
|
||||
- When the MSC requests more tuples, dispense some from the cache, and fill it back up later on, as soon as a good link
|
||||
is available.
|
||||
- When the tuple cache in the proxy HLR runs dry, 3G RAN becomes unusable. But 2G RAN may fall back to GSM AKA, if the
|
||||
proxy HLR configuration permits it: resend previously used GSM AKA auth tuples to the MSC, omitting UMTS AKA items
|
||||
from the Send Auth Info Result, to force the MSC to send a GSM AKA challenge on 2G.
|
||||
|
||||
The remaining part of this section provides detailed reasoning for this strategy.
|
||||
|
||||
The aim is to attach a subscriber without immediate access to the authentication key data.
|
||||
|
||||
Completely switching off authentication would be an option on GERAN (2G), but this would mean complete lack of
|
||||
encryption on the air interface, and is not recommended. On 3G and later, authentication is always mandatory.
|
||||
|
||||
The key data is known only to the USIM and the home HLR. The HLR generates distinct authentication tuples, each
|
||||
containing a cryptographic challenge (RAND, AUTN) and its expected response (SRES, XRES). The MSC consumes one tuple
|
||||
per authentication: it sends the challenge to the subscriber, and compares the response received.
|
||||
|
||||
The proxy could generate fresh tuples if the cryptographic key data (Ki,K,OP/OPC) from the home HLR was shared with the
|
||||
proxy HLR. Distributed GSM does not do this, because:
|
||||
|
||||
- The key data is cryptographically very valuable. If it were leaked, any and all authentication challenges would be
|
||||
fully compromised.
|
||||
|
||||
- In D-GSM, each home site shall retain exclusive authority over the user data. It should not be necessary to share the
|
||||
secret keys with any remote site.
|
||||
|
||||
So, how about resending already used auth tuples to the MSC when no fresh ones are available? Resending identical
|
||||
authentication challenges makes the system vulnerable to relatively trivial replay-attacks, but this may be an
|
||||
acceptable fallback in situations of failing links, if it means being able to provide reliable roaming.
|
||||
|
||||
But, even if a proxying HLR is willing to compromise cryptographic security to improve service, this can only work with
|
||||
GSM AKA:
|
||||
|
||||
- In GSM AKA (so-called 2G auth), tuples may be re-used any amount of times without a strict need to generate more
|
||||
authentication challenges. The SIM will merely calculate the (same) SRES response again, and authentication will
|
||||
succeed. It is bad security to do so, but it is a choice the core network is free to make.
|
||||
|
||||
- UMTS AKA (Milenage or so-called 3G auth, but also used on 2G GERAN) adds mutual authentication, i.e. the core network
|
||||
must prove that it is authentic. Specifically to thwart replay-attacks that would spoof a core network, UMTS AKA
|
||||
contains an ongoing sequence number (SQN) that is woven into the authentication challenge. An SQN may skip forward by
|
||||
a certain number of counts, but it can never move backwards. If a USIM detects a stale SQN, it will request an
|
||||
authentication re-synchronisation (by passing AUTS in an Authentication Failure message), after which a freshly
|
||||
generated UMTS AKA challenge is strictly required -- not possible with an unresponsive home HLR.
|
||||
|
||||
Post-R99 (1999) 2G GERAN networks are capable of UMTS AKA, so, not only 3G, but also the vast majority of 2G networks
|
||||
today use UMTS AKA -- and so does Osmocom, typically. Hence it is desirable to fully support UMTS AKA in D-GSM.
|
||||
|
||||
[options="header"]
|
||||
|===
|
||||
| RAN | authentication is... 2+| available AKA types
|
||||
| GERAN (2G) | optional | GSM AKA | UMTS AKA
|
||||
| UTRAN (3G) | mandatory | - | UMTS AKA
|
||||
|===
|
||||
|
||||
UMTS AKA will not allow re-sending previously used authentication tuples. But a UMTS capable SIM will fall back to GSM
|
||||
AKA if the network sent only a GSM AKA challenge. If the proxy HLR sends only GSM AKA tuples, then the MSC will request
|
||||
GSM authentication, and re-sending old tuples is again possible. However, a USIM will only fall back to GSM AKA if the
|
||||
phone is attaching on a 2G network. For 3G RAN and later, UMTS AKA is mandatory. So, as soon as a site uses 3G or newer
|
||||
RAN technology, there is simply no way to resend previously used authentication tuples.
|
||||
|
||||
The only way to have unused UMTS AKA tuples in the proxy HLR is to already have them stored from an earlier time. The
|
||||
idea is to request more auth tuples in advance whenever the link is available, and cache them in the proxy. When the MSC
|
||||
uses up some tuples from the proxy HLR, the proxy cache can fill up again in its own time, by requesting more tuples
|
||||
from the home HLR at a time of good link. Then, the next time the subscriber needs immediate action, it does not matter
|
||||
whether the home HLR is directly reachable or not.
|
||||
|
||||
In an aside, since OsmoMSC already caches a number of authentication tuples, one option would be to implement this in
|
||||
OsmoMSC, and not in the proxy HLR: the MSC could request new tuples long before its tuple cache runs dry. However, the
|
||||
OsmoMSC VLR state is volatile, and a power cycle of the system would lose the tuple cache; if the home HLR is
|
||||
unreachable at the same time of the power cycle, roaming service would be interrupted. The proxy cache in the HLR is
|
||||
persistent, so roaming can continue immediately after a power cycle, even if the home HLR link is down.
|
||||
|
||||
==== Location Updating
|
||||
|
||||
Any attached subscriber periodically repeats a Location Updating procedure, typically every 15 minutes. If a home HLR is
|
||||
unreachable at the time of the periodic Location Updating, a roaming subscriber would assume that it is detached from
|
||||
the network, even though the local site it is roaming at is still fully operational.
|
||||
|
||||
The aim of D-GSM is to keep subscribers attached even if the remote home HLR is temporarily unreachable. The simplest
|
||||
way to achieve that is by directly responding with a Update Location Result to the MSC.
|
||||
|
||||
In addition to accepting an Update Location, a proxy HLR should also start an Insert Subscriber Data procedure, as a
|
||||
home HLR would do. For a periodic Location Updating, the MSC should already know all of the information that an Insert
|
||||
Subscriber Data would convey (i.e. the MSISDN), and there would be no strict need to resend this data. But if a
|
||||
subscriber quickly detaches and re-attaches (e.g. the device rebooted), the MSC has discarded the subscriber info from
|
||||
the VLR, and hence the proxy HLR should also always perform an Insert Subscriber Data. (On the GSUP wire, a periodic LU
|
||||
is indistinguishable from an IMSI-Attach LU.)
|
||||
|
||||
Furthermore, the longer the proxy HLR's cache keeps a roaming subscriber's data after an IMSI Detach, the longer it is
|
||||
possible for the subscriber to immediately re-attach despite the home HLR being temporarily unreachable.
|
||||
|
||||
If a subscriber has carried out a GSUP Update Location with the proxy HLR while the home HLR was unreachable, it is not
|
||||
strictly necessary to repeat that Update Location message to the home HLR later. The home HLR does keep a timestamped
|
||||
record of an Update Location from a proxy HLR if seen, but that has no visible effect on serving the subscriber:
|
||||
|
||||
- If the home HLR still thinks that the subscriber is currently attached at the home site, it will respond to mslookup
|
||||
requests. But the actual site the subscriber is roaming at will have a younger age, and its mslookup responses will
|
||||
win.
|
||||
|
||||
- If the home HLR has no record of the subscriber being attached recently, or has a record of being attached at another
|
||||
remote site, it does not respond to mslookup requests for that subscriber. If it records the new proxy LU, it still
|
||||
does not respond to mslookup requests since the subscriber is attached remotely, i.e. there is no difference.
|
||||
|
||||
It is thinkable to always handle an Update Location in the proxy HLR, and never even attempt to involve the home HLR in
|
||||
case the proxy cache already has data for a given subscriber, but then the proxy HLR would never notice a changed MSISDN
|
||||
or authorization status for this subscriber. It is best practice to involve the home HLR whenever possible.
|
||||
|
||||
==== IMSI Detach
|
||||
|
||||
If a GSUP client reports a detaching IMSI when the home HLR is not reachable, simply respond with an ack.
|
||||
|
||||
It is not required to signal the home HLR with a detach once the link is back up. A home HLR anyway flags a remotely
|
||||
roaming subscriber as attached-at-a-proxy, and there is literally no difference between telling a home HLR about a
|
||||
detach or not.
|
||||
|
||||
(TODO: is there even a GSUP message that a VLR should send on IMSI Detach? see OS#4374)
|
||||
|
||||
[[proxy_cache_umts_aka_resync]]
|
||||
==== UMTS AKA Resync
|
||||
|
||||
When the SQN between USIM and AUC (subscriber and home HLR) have diverged, the Send Authentication Info Request from the
|
||||
MSC contains an AUTS IE. This means that a resynchronization between USIM and AUC (the home HLR) is necessary. All of
|
||||
the UMTS AKA tuples in the proxy cache are now unusable, and the home HLR must respond with fresh tuples after doing a
|
||||
resync. This also means that either the home HLR must be reachable immediately, or GSM AKA fallback must be allowed for
|
||||
the subscriber to remain in roaming service.
|
||||
|
||||
In short:
|
||||
|
||||
- A UMTS AKA resync is handled similarly to the attaching of a so far unknown subscriber.
|
||||
- With the exception that previous GSM AKA tuples may be available to try a fallback to re-using older tuples.
|
||||
|
||||
Needless to say that avoiding the need for UMTS AKA resynchronization is an important aspect of D-GSM's resilience
|
||||
against unreliable links.
|
||||
|
||||
In UMTS AKA, there is not one single SQN, but there are a number SQN slots, called IND slots or IND buckets. The IND
|
||||
bitlen configured on the USIM determines the amount of slots available. The IND bitlen is usually 5, i.e. 2^5^ = 32
|
||||
slots. Monotonously rising SQN are only strictly enforced within each slot, so that each site should maintain a
|
||||
different IND slot. OsmoHLR determines distinct IND slots based on the IPA unit name. As soon as more than 16 sites
|
||||
(with an MSC and SGSN each) are maintained, IND slots may be shared between distinct sites, and administrative care
|
||||
should be taken to choose wisely which sites share the same slots: those that least share a common user group.
|
||||
|
||||
On 2G RAN, it may be possible to fall back to GSM AKA after a UMTS AKA resync request.
|
||||
TODO: test this
|
||||
|
||||
Either way, the AUTS that was received from the MSC definitely needs to find its way to the home HLR, and, ideally, the
|
||||
immediately returned auth tuples from the home HLR should be used to attach the subscriber.
|
||||
|
||||
=== CS and PS
|
||||
|
||||
Each subscriber may have multiple HLR subscriptions from distinct CN Domain VLRs at any time: Circuit Switched (MSC) and
|
||||
Packet Switched (SGSN) attach separately and perform Update Location Requests that are completely orthogonal, as far as
|
||||
the HLR is concerned.
|
||||
|
||||
Particularly the UMTS AKA tuples, which use distinct IND slots per VLR, need to be cached separately per CN Domain.
|
||||
|
||||
Hence it is not enough to maintain one cache per subscriber. A separate auth tuple cache and Mobility Management state
|
||||
has to be kept for each VLR that is requesting roaming service for a given subscriber.
|
||||
|
||||
=== Intercepting GSUP Conversations
|
||||
|
||||
Taking over GSUP conversations in the proxy HLR is not as trivial as it may sound. Here are potential problems and how
|
||||
to fix them.
|
||||
|
||||
[[proxy_cache_gsup_mm_messages]]
|
||||
==== Which GSUP Conversations to Intercept
|
||||
|
||||
For the purpose of providing highly available roaming despite unreliable links to the home HLR, it suffices to intercept
|
||||
Mobility Management (MM) related GSUP messages, only:
|
||||
|
||||
- Send Auth Info Request / Result
|
||||
- Update Location Request / Result
|
||||
- Insert Subscriber Data Request / Result
|
||||
- PurgeMS Request / Result (?)
|
||||
|
||||
An interesting feature would be to also intercept specific USSD requests, like returning the own MSISDN or IMSI more
|
||||
reliably, or handling services that only make sense when served by the local site. At the time of writing, this is seen
|
||||
as a future extension of D-GSM and not considered for implementation.
|
||||
|
||||
==== Determining Whether a Home HLR is Responsive
|
||||
|
||||
Normally, all GSUP messages are merely routed via the proxy HLR and are handled by the home HLR. The idea is that the
|
||||
proxy HLR jumps in and saves a GSUP conversation when the home HLR is not answering properly.
|
||||
|
||||
The simplest method to decide whether a home HLR is currently connected would be to look at the GSUP client state.
|
||||
However, a local flag that indicates an established GSUP connection does not necessarily mean a reliable link.
|
||||
There are keep-alive messages on the GSUP/IPA link, and a lost connection should reflect in the client state, so that a
|
||||
lost GSUP link definitely indicates an unresponsive home HLR. But for various reasons (e.g. packet loss), the link might
|
||||
look intact, but still a given GSUP message fails to get a response from the home HLR.
|
||||
|
||||
A more resilient method to decide whether a home HLR is responsive is to keep track of every MM related GSUP
|
||||
conversation for each subscriber, and to jump in and take over the GSUP conversation as soon as the response is taking
|
||||
too long to arrive. However, choosing an inadequate timeout period would either mean responding after the MSC has
|
||||
already timed out (too slow), or completely cutting off all responses from a high-latency home HLR (too fast).
|
||||
|
||||
Also, if the proxy HLR has already responded to the MSC, but a slow home HLR's response arrives shortly after,
|
||||
forwarding this late message to the MSC on top of the earlier response to the same request would confuse the GSUP
|
||||
conversation.
|
||||
|
||||
So, the proxy HLR just jumping into the GSUP conversation when a specific delay has passed is fairly complex and error
|
||||
prone. A better idea is to always intercept MM related GSUP conversations:
|
||||
|
||||
[[proxy_cache_gsup_conversations]]
|
||||
==== Solution: Distinct GSUP Conversations
|
||||
|
||||
A solution that avoids all of the above problems is to *always* take over *all* MM related conversations (see
|
||||
<<proxy_cache_gsup_mm_messages>>), as soon as the proxy has sufficient data to service them by itself; at the same time,
|
||||
the proxy HLR should also relay the same requests to the home HLR, and acknowledge its responses, after the fact.
|
||||
|
||||
If the proxy cache already has a complete record of a subscriber, the proxy HLR can always directly accept an Update
|
||||
Location Request, including an Insert Subscriber Data. A prompt response ensures that the MSC does not timeout its GSUP
|
||||
request, and reduces waiting time for the subscriber.
|
||||
|
||||
To ensure that the proxy HLR's data on the subscriber doesn't become stale and diverge from the home HLR, the proxy
|
||||
asynchronously also forwards an Update Location Request to the home HLR. In most normal cases, there will be no
|
||||
surprises, and the home HLR will continue with an Insert Subscriber Data Request containing already known data, and an
|
||||
Update Location Result accepting the LU.
|
||||
|
||||
If the home HLR does not respond, the proxy HLR ignores that fact -- the home HLR is not reachable, and the aim is to
|
||||
continue to service the subscriber for the time being.
|
||||
|
||||
But, should the home HLR's Insert Subscriber Data Request send different data than the proxy cache sees on record, the
|
||||
proxy HLR can trigger another Insert Subscriber Data Request to the MSC, to correct the stale data sent before.
|
||||
|
||||
Similarly, if the home HLR rejects the Update Location Request completely, the proxy HLR can tell the MSC to detach the
|
||||
subscriber with a Cancel Location Request message, as soon as it notices the rejection.
|
||||
|
||||
Note that a UMTS AKA resynchronization request invalidates the entire auth tuple cache and needs to either be sent to
|
||||
the home HLR immediately, if available, or the AUTS from the USIM must later reach the home HLR to obtain fresh UMTS AKA
|
||||
tuples for the cache. See <<proxy_cache_umts_aka_resync>>.
|
||||
|
||||
=== Message Sequences
|
||||
|
||||
==== Normal Roaming Attach
|
||||
|
||||
On first attaching via a proxy HLR, when there is no proxy state for the subscriber yet, the home HLR must be reachable.
|
||||
|
||||
The normal procedure takes place without modification, except that he proxy HLR keeps a copy of the first auth tuples it
|
||||
forwards from the home HLR back to the MSC (marked as used) (1). This is to have auth tuples available for resending
|
||||
already used tuples in a fallback to GSM AKA, in case this is enabled in the proxy HLR config.
|
||||
|
||||
After the Location Updating has completed successfully, the proxy HLR fills up its auth tuple cache by additional Send
|
||||
Auth Info Requests (2). As soon as unused auth tuples become available, the proxy HLR can discard already used tuples
|
||||
from (1).
|
||||
|
||||
.Normal attaching of a subscriber that is roaming here
|
||||
["mscgen"]
|
||||
----
|
||||
include::proxy_cache_attach.msc[]
|
||||
----
|
||||
|
||||
==== MSC Requests More Auth Tuples
|
||||
|
||||
As soon as the MSC has run out of fresh auth tuples, it will ask the HLR proxy for more. Without proxy caching, this
|
||||
request would be directly forwarded to the home HLR. Instead, the proxy HLR finds unused auth tuples in the cache and
|
||||
directly sends those (3). Even if there is a reliable link, the home HLR is not contacted at this point.
|
||||
|
||||
Directly after completing the Send Auth Info Result, the proxy HLR finds that less tuples than requested by the D-GSM
|
||||
configuration are cached, and asks the home HLR for more tuples, to fill up the cache (4). If there currently is no
|
||||
reliable link, this will fail, and the proxy HLR will retry periodically (5) / upon GSUP reconnect.
|
||||
|
||||
.When the MSC has used up all of its auth tuples, but the proxy HLR still has unused auth tuples in the cache
|
||||
["mscgen"]
|
||||
----
|
||||
include::proxy_cache_more_tuples.msc[]
|
||||
----
|
||||
|
||||
==== Running Out of Auth Tuples
|
||||
|
||||
When all fresh tuples from the proxy HLR have been used up, and the home HLR remains unreachable, the proxy HLR normally
|
||||
fails and rejects the subscriber (default configuration).
|
||||
|
||||
If explicitly enabled in the configuration, the proxy HLR will attempt to fall back to GSM AKA and resend already spent
|
||||
tuples, deliberately omitting UMTS AKA parts (6).
|
||||
|
||||
Note that an attempt to refill the tuple cache in the proxy HLR always happens asynchronously. If there are no tuples,
|
||||
that means the link to the home HLR is currently broken, and there is no point in trying to contact it now. Tuples will
|
||||
be obtained as soon as the link is established again.
|
||||
|
||||
.When the MSC has used up all of its auth tuples and the proxy HLR tuple cache is dry
|
||||
["mscgen"]
|
||||
----
|
||||
include::proxy_cache_tuple_cache_dry.msc[]
|
||||
----
|
||||
|
||||
==== Periodic Location Updating
|
||||
|
||||
Each subscriber performs periodic Location Updating to ensure that it is not implicitly detached from the network. When
|
||||
the proxy HLR already has a proxy cache for this subscriber, all information to complete the periodic Location Updating
|
||||
is already known in the proxy HLR. If the link to the home HLR is unresponsive, the proxy HLR mimicks the Insert
|
||||
Subscriber Data Request that the home HLR would normally send, using the cached MSISDN, and then sends the Update
|
||||
Location Result. The subscriber remains attached without a responsive link to the home HLR being required.
|
||||
|
||||
.Periodic Location Updating when the MSC still has unused auth tuples
|
||||
["mscgen"]
|
||||
----
|
||||
include::proxy_cache_periodic_lu.msc[]
|
||||
----
|
||||
|
||||
==== UMTS AKA Resync
|
||||
|
||||
The AUTS from a UMTS AKA resync needs to reach the home HLR sooner or later, and a resync renders all UMTS AKA tuples in
|
||||
the cache stale.
|
||||
|
||||
.Cached tuples become unusable from a UMTS AKA resynchronisation request from the USIM.
|
||||
["mscgen"]
|
||||
----
|
||||
include::proxy_cache_umts_aka_resync.msc[]
|
||||
----
|
||||
39
doc/manuals/chapters/proxy_cache_attach.ladder
Normal file
39
doc/manuals/chapters/proxy_cache_attach.ladder
Normal file
@@ -0,0 +1,39 @@
|
||||
{hscale=2}
|
||||
ms = MS,BSS
|
||||
msc = MSC
|
||||
hlr = HLR proxy
|
||||
home = Home HLR
|
||||
|
||||
ms -> msc Location Updating Request (IMSI Attach)
|
||||
msc -> hlr Send Auth Info Request
|
||||
hlr <> hlr No proxy cache data available for this subscriber
|
||||
hlr () home mslookup finds the home HLR
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <- home Send Auth Info Result
|
||||
with 5 auth tuples
|
||||
hlr () . (1) Keep a copy of the auth tuples
|
||||
msc <- hlr Send Auth Info Result
|
||||
msc () . MSC stores 5 auth tuples,
|
||||
uses the first one now,
|
||||
and keeps the rest for later requests
|
||||
ms () msc Authentication
|
||||
msc -> hlr Update Location Request
|
||||
hlr -> home Update Location Request
|
||||
hlr <- home Insert Subscriber Data Request
|
||||
(with subscriber's MSISDN)
|
||||
hlr () . proxy HLR caches the MSISDN
|
||||
msc <- hlr Insert Subscriber Data Request
|
||||
msc -> hlr Insert Subscriber Data Result
|
||||
hlr -> home Insert Subscriber Data Result
|
||||
hlr <- home Update Location Result
|
||||
msc <- hlr Update Location Result
|
||||
ms <- msc Location Updating Accept
|
||||
hlr <> . After successful Update Location, check the cache
|
||||
hlr () . (2) Ask for more auth tuples to cache
|
||||
(amount of tuples configurable)
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <- home Send Auth Info Result
|
||||
hlr () . store 5 more tuples
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <- home Send Auth Info Result
|
||||
hlr () . store yet 5 more tuples
|
||||
33
doc/manuals/chapters/proxy_cache_attach.msc
Normal file
33
doc/manuals/chapters/proxy_cache_attach.msc
Normal file
@@ -0,0 +1,33 @@
|
||||
msc {
|
||||
hscale="2";
|
||||
ms[label="MS,BSS"],__msc[label="MSC"],hlr[label="HLR proxy"],home[label="Home HLR"];
|
||||
|
||||
ms => __msc [label="Location Updating Request (IMSI Attach)"];
|
||||
__msc => hlr [label="Send Auth Info Request"];
|
||||
hlr abox hlr [label="No proxy cache data available for this subscriber"];
|
||||
hlr rbox home [label="mslookup finds the home HLR"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr <= home [label="Send Auth Info Result\nwith 5 auth tuples"];
|
||||
hlr rbox hlr [label="(1) Keep a copy of the auth tuples"];
|
||||
__msc <= hlr [label="Send Auth Info Result"];
|
||||
__msc rbox __msc [label="MSC stores 5 auth tuples,\nuses the first one now,\nand keeps the rest for later requests"];
|
||||
ms rbox __msc [label="Authentication"];
|
||||
__msc => hlr [label="Update Location Request"];
|
||||
hlr => home [label="Update Location Request"];
|
||||
hlr <= home [label="Insert Subscriber Data Request\n(with subscriber's MSISDN)"];
|
||||
hlr rbox hlr [label="proxy HLR caches the MSISDN"];
|
||||
__msc <= hlr [label="Insert Subscriber Data Request"];
|
||||
__msc => hlr [label="Insert Subscriber Data Result"];
|
||||
hlr => home [label="Insert Subscriber Data Result"];
|
||||
hlr <= home [label="Update Location Result"];
|
||||
__msc <= hlr [label="Update Location Result"];
|
||||
ms <= __msc [label="Location Updating Accept"];
|
||||
hlr abox hlr [label="After successful Update Location, check the cache"];
|
||||
hlr rbox hlr [label="(2) Ask for more auth tuples to cache\n(amount of tuples configurable)"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr <= home [label="Send Auth Info Result"];
|
||||
hlr rbox hlr [label="store 5 more tuples"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr <= home [label="Send Auth Info Result"];
|
||||
hlr rbox hlr [label="store yet 5 more tuples"];
|
||||
}
|
||||
31
doc/manuals/chapters/proxy_cache_more_tuples.ladder
Normal file
31
doc/manuals/chapters/proxy_cache_more_tuples.ladder
Normal file
@@ -0,0 +1,31 @@
|
||||
{hscale=2}
|
||||
ms = MS,BSS
|
||||
msc = MSC
|
||||
hlr = HLR proxy
|
||||
home = Home HLR
|
||||
|
||||
ms -> msc CM Service Request / Paging Response
|
||||
msc -> hlr Send Auth Info Request
|
||||
hlr () . Use already set up proxy path
|
||||
hlr <> . there still are unsent auth tuples
|
||||
in the cache
|
||||
hlr () . (3) Send cached, fresh tuples
|
||||
msc <- hlr Send Auth Info Result
|
||||
containing auth tuples
|
||||
from the proxy cache
|
||||
ms () msc Authentication
|
||||
ms () msc Continue the CM Service / Paging action
|
||||
hlr <> . Note that there are no/few unused tuples in the cache, fill up again
|
||||
hlr () . (4) Ask for more auth tuples to cache
|
||||
hlr -> home Send Auth Info Request
|
||||
--- If the home HLR link is not working
|
||||
hlr <> . no link
|
||||
or
|
||||
response timeout
|
||||
hlr () . (5) Set up a timer to retry SAI
|
||||
(a few minutes?)
|
||||
hlr <> . Timer triggers
|
||||
hlr -> home Send Auth Info Request
|
||||
--- If the home HLR link is functional
|
||||
hlr <- home Send Auth Info Result
|
||||
hlr () . store 5 more tuples
|
||||
24
doc/manuals/chapters/proxy_cache_more_tuples.msc
Normal file
24
doc/manuals/chapters/proxy_cache_more_tuples.msc
Normal file
@@ -0,0 +1,24 @@
|
||||
msc {
|
||||
hscale="2";
|
||||
ms[label="MS,BSS"],__msc[label="MSC"],hlr[label="HLR proxy"],home[label="Home HLR"];
|
||||
|
||||
ms => __msc [label="CM Service Request / Paging Response"];
|
||||
__msc => hlr [label="Send Auth Info Request"];
|
||||
hlr rbox hlr [label="Use already set up proxy path"];
|
||||
hlr abox hlr [label="there still are unsent auth tuples\nin the cache"];
|
||||
hlr rbox hlr [label="(3) Send cached, fresh tuples"];
|
||||
__msc <= hlr [label="Send Auth Info Result\ncontaining auth tuples\nfrom the proxy cache"];
|
||||
ms rbox __msc [label="Authentication"];
|
||||
ms rbox __msc [label="Continue the CM Service / Paging action"];
|
||||
hlr abox hlr [label="Note that there are no/few unused tuples in the cache, fill up again"];
|
||||
hlr rbox hlr [label="(4) Ask for more auth tuples to cache"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
--- [label="If the home HLR link is not working"];
|
||||
hlr abox hlr [label="no link\nor\nresponse timeout"];
|
||||
hlr rbox hlr [label="(5) Set up a timer to retry SAI\n(a few minutes?)"];
|
||||
hlr abox hlr [label="Timer triggers"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
--- [label="If the home HLR link is functional"];
|
||||
hlr <= home [label="Send Auth Info Result"];
|
||||
hlr rbox hlr [label="store 5 more tuples"];
|
||||
}
|
||||
47
doc/manuals/chapters/proxy_cache_periodic_lu.ladder
Normal file
47
doc/manuals/chapters/proxy_cache_periodic_lu.ladder
Normal file
@@ -0,0 +1,47 @@
|
||||
{hscale=2}
|
||||
ms = MS,BSS
|
||||
msc = MSC
|
||||
hlr = HLR proxy
|
||||
home = Home HLR
|
||||
|
||||
ms -> msc Location Updating Request (Periodic)
|
||||
ms () msc Authentication,
|
||||
using the next of 5 auth tuples the MSC has stored
|
||||
msc -> hlr Update Location Request
|
||||
hlr () . Use already set up proxy path
|
||||
hlr <> . (8) proxy cache already has all information to answer
|
||||
msc <- hlr Insert Subscriber Data Request
|
||||
msc -> hlr Insert Subscriber Data Result
|
||||
msc <- hlr Update Location Result
|
||||
ms <- msc Location Updating Accept
|
||||
hlr () . (9) Verify Update Location with home HLR
|
||||
|||
|
||||
--- if the home HLR has no changes and accepts
|
||||
hlr -> home Update Location Request
|
||||
hlr <- home Insert Subscriber Data Request
|
||||
hlr -> home Insert Subscriber Data Result
|
||||
hlr <> . Notice identical MSISDN
|
||||
hlr <- home Update Location Result
|
||||
|||
|
||||
--- if the home HLR is unreachable
|
||||
hlr -> home Update Location Request
|
||||
hlr <> . no link
|
||||
or
|
||||
response timeout
|
||||
hlr () . Don't care, carry on
|
||||
|||
|
||||
--- if the home HLR has a modified MSISDN, and accepts
|
||||
hlr -> home Update Location Request
|
||||
hlr <- home Insert Subscriber Data Request
|
||||
hlr -> home Insert Subscriber Data Result
|
||||
hlr <> . Notice changed MSISDN
|
||||
msc <- hlr Insert Subscriber Data Request
|
||||
msc -> hlr Insert Subscriber Data Result
|
||||
hlr <- home Update Location Result
|
||||
|||
|
||||
--- if the home HLR rejects
|
||||
hlr -> home Update Location Request
|
||||
hlr <- home Update Location Error
|
||||
msc <- hlr Cancel Location Request
|
||||
msc -> hlr Cancel Location Result
|
||||
hlr () . Clear subscriber cache
|
||||
43
doc/manuals/chapters/proxy_cache_periodic_lu.msc
Normal file
43
doc/manuals/chapters/proxy_cache_periodic_lu.msc
Normal file
@@ -0,0 +1,43 @@
|
||||
msc {
|
||||
hscale="2";
|
||||
ms[label="MS,BSS"],__msc[label="MSC"],hlr[label="HLR proxy"],home[label="Home HLR"];
|
||||
|
||||
ms => __msc [label="Location Updating Request (Periodic)"];
|
||||
ms rbox __msc [label="Authentication,\nusing the next of 5 auth tuples the MSC has stored"];
|
||||
__msc => hlr [label="Update Location Request"];
|
||||
hlr rbox hlr [label="Use already set up proxy path"];
|
||||
hlr abox hlr [label="(8) proxy cache already has all information to answer"];
|
||||
__msc <= hlr [label="Insert Subscriber Data Request"];
|
||||
__msc => hlr [label="Insert Subscriber Data Result"];
|
||||
__msc <= hlr [label="Update Location Result"];
|
||||
ms <= __msc [label="Location Updating Accept"];
|
||||
hlr rbox hlr [label="(9) Verify Update Location with home HLR"];
|
||||
|||;
|
||||
--- [label="if the home HLR has no changes and accepts"];
|
||||
hlr => home [label="Update Location Request"];
|
||||
hlr <= home [label="Insert Subscriber Data Request"];
|
||||
hlr => home [label="Insert Subscriber Data Result"];
|
||||
hlr abox hlr [label="Notice identical MSISDN"];
|
||||
hlr <= home [label="Update Location Result"];
|
||||
|||;
|
||||
--- [label="if the home HLR is unreachable"];
|
||||
hlr => home [label="Update Location Request"];
|
||||
hlr abox hlr [label="no link\nor\nresponse timeout"];
|
||||
hlr rbox hlr [label="Don't care, carry on"];
|
||||
|||;
|
||||
--- [label="if the home HLR has a modified MSISDN, and accepts"];
|
||||
hlr => home [label="Update Location Request"];
|
||||
hlr <= home [label="Insert Subscriber Data Request"];
|
||||
hlr => home [label="Insert Subscriber Data Result"];
|
||||
hlr abox hlr [label="Notice changed MSISDN"];
|
||||
__msc <= hlr [label="Insert Subscriber Data Request"];
|
||||
__msc => hlr [label="Insert Subscriber Data Result"];
|
||||
hlr <= home [label="Update Location Result"];
|
||||
|||;
|
||||
--- [label="if the home HLR rejects"];
|
||||
hlr => home [label="Update Location Request"];
|
||||
hlr <= home [label="Update Location Error"];
|
||||
__msc <= hlr [label="Cancel Location Request"];
|
||||
__msc => hlr [label="Cancel Location Result"];
|
||||
hlr rbox hlr [label="Clear subscriber cache"];
|
||||
}
|
||||
21
doc/manuals/chapters/proxy_cache_tuple_cache_dry.ladder
Normal file
21
doc/manuals/chapters/proxy_cache_tuple_cache_dry.ladder
Normal file
@@ -0,0 +1,21 @@
|
||||
{hscale=2}
|
||||
ms = MS,BSS
|
||||
msc = MSC
|
||||
hlr = HLR proxy
|
||||
home = Home HLR
|
||||
|
||||
ms -> msc CM Service Request / Paging Response
|
||||
msc -> hlr Send Auth Info Request
|
||||
hlr () . Use already set up proxy path
|
||||
hlr <> . All cached auth tuples have been sent to the MSC before
|
||||
--- If no GSM AKA fallback is allowed
|
||||
msc <- hlr Send Auth Info Error
|
||||
ms () msc Detach
|
||||
--- If GSM AKA fallback is allowed
|
||||
hlr () . (6) Resend only GSM AKA tuples, already sent earlier
|
||||
msc <- hlr Send Auth Info Result
|
||||
containing GSM AKA auth tuples
|
||||
from the proxy cache
|
||||
ms () msc 2G: Authentication
|
||||
3G: Detach
|
||||
ms () msc Continue the CM Service / Paging action
|
||||
17
doc/manuals/chapters/proxy_cache_tuple_cache_dry.msc
Normal file
17
doc/manuals/chapters/proxy_cache_tuple_cache_dry.msc
Normal file
@@ -0,0 +1,17 @@
|
||||
msc {
|
||||
hscale="2";
|
||||
ms[label="MS,BSS"],__msc[label="MSC"],hlr[label="HLR proxy"],home[label="Home HLR"];
|
||||
|
||||
ms => __msc [label="CM Service Request / Paging Response"];
|
||||
__msc => hlr [label="Send Auth Info Request"];
|
||||
hlr rbox hlr [label="Use already set up proxy path"];
|
||||
hlr abox hlr [label="All cached auth tuples have been sent to the MSC before"];
|
||||
--- [label="If no GSM AKA fallback is allowed"];
|
||||
__msc <= hlr [label="Send Auth Info Error"];
|
||||
ms rbox __msc [label="Detach"];
|
||||
--- [label="If GSM AKA fallback is allowed"];
|
||||
hlr rbox hlr [label="(6) Resend only GSM AKA tuples, already sent earlier"];
|
||||
__msc <= hlr [label="Send Auth Info Result\ncontaining GSM AKA auth tuples\nfrom the proxy cache"];
|
||||
ms rbox __msc [label="2G: Authentication\n3G: Detach"];
|
||||
ms rbox __msc [label="Continue the CM Service / Paging action"];
|
||||
}
|
||||
55
doc/manuals/chapters/proxy_cache_umts_aka_resync.ladder
Normal file
55
doc/manuals/chapters/proxy_cache_umts_aka_resync.ladder
Normal file
@@ -0,0 +1,55 @@
|
||||
{hscale=2}
|
||||
ms = MS,BSS
|
||||
msc = MSC
|
||||
hlr = HLR proxy
|
||||
home = Home HLR
|
||||
|
||||
ms -> msc CM Service Request / Paging Response
|
||||
msc -> hlr Send Auth Info Request
|
||||
hlr <> . there still are unsent auth tuples
|
||||
in the cache
|
||||
hlr () . Send cached, fresh tuples
|
||||
msc <- hlr Send Auth Info Result
|
||||
containing auth tuples
|
||||
from the proxy cache
|
||||
ms <- msc Authentication Request
|
||||
ms -> msc USIM requests UMTS AKA resync
|
||||
Auth Failure with AUTS
|
||||
msc -> hlr Send Auth Info Request
|
||||
containing AUTS IE
|
||||
hlr () . Mark all UMTS AKA tuples as stale
|
||||
--- If the home HLR responds in time
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <- home Send Auth Info Result
|
||||
with 5 auth tuples
|
||||
hlr () . clear tuple cache, store new tuples
|
||||
msc <- hlr Send Auth Info Result
|
||||
ms () msc Authentication
|
||||
hlr () . fill up the tuple cache as necessary
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <- home Send Auth Info Result
|
||||
...
|
||||
--- If the home HLR is unreachable
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <> . no link
|
||||
or
|
||||
response timeout
|
||||
hlr () . Store the AUTS received earlier,
|
||||
and set up a timer to retry SAI
|
||||
(a few minutes?)
|
||||
--- If no GSM AKA fallback is allowed
|
||||
msc <- hlr Send Auth Info Error
|
||||
ms () msc Detach
|
||||
--- If GSM AKA fallback is allowed
|
||||
hlr () . Resend only GSM AKA tuples, already sent earlier
|
||||
msc <- hlr Send Auth Info Result
|
||||
containing GSM AKA auth tuples
|
||||
from the proxy cache
|
||||
ms () msc 2G: Authentication
|
||||
3G: Detach
|
||||
---
|
||||
hlr <> . AUTS timer triggers
|
||||
hlr -> home Send Auth Info Request
|
||||
hlr <- home Send Auth Info Result
|
||||
hlr () . clear tuple cache, store new tuples
|
||||
hlr () . continue to fill up the cache as necessary
|
||||
41
doc/manuals/chapters/proxy_cache_umts_aka_resync.msc
Normal file
41
doc/manuals/chapters/proxy_cache_umts_aka_resync.msc
Normal file
@@ -0,0 +1,41 @@
|
||||
msc {
|
||||
hscale="2";
|
||||
ms[label="MS,BSS"],__msc[label="MSC"],hlr[label="HLR proxy"],home[label="Home HLR"];
|
||||
|
||||
ms => __msc [label="CM Service Request / Paging Response"];
|
||||
__msc => hlr [label="Send Auth Info Request"];
|
||||
hlr abox hlr [label="there still are unsent auth tuples\nin the cache"];
|
||||
hlr rbox hlr [label="Send cached, fresh tuples"];
|
||||
__msc <= hlr [label="Send Auth Info Result\ncontaining auth tuples\nfrom the proxy cache"];
|
||||
ms <= __msc [label="Authentication Request"];
|
||||
ms => __msc [label="USIM requests UMTS AKA resync\nAuth Failure with AUTS"];
|
||||
__msc => hlr [label="Send Auth Info Request\ncontaining AUTS IE"];
|
||||
hlr rbox hlr [label="Mark all UMTS AKA tuples as stale"];
|
||||
--- [label="If the home HLR responds in time"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr <= home [label="Send Auth Info Result\nwith 5 auth tuples"];
|
||||
hlr rbox hlr [label="clear tuple cache, store new tuples"];
|
||||
__msc <= hlr [label="Send Auth Info Result"];
|
||||
ms rbox __msc [label="Authentication"];
|
||||
hlr rbox hlr [label="fill up the tuple cache as necessary"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr <= home [label="Send Auth Info Result"];
|
||||
...;
|
||||
--- [label="If the home HLR is unreachable"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr abox hlr [label="no link\nor\nresponse timeout"];
|
||||
hlr rbox hlr [label="Store the AUTS received earlier,\nand set up a timer to retry SAI\n(a few minutes?)"];
|
||||
--- [label="If no GSM AKA fallback is allowed"];
|
||||
__msc <= hlr [label="Send Auth Info Error"];
|
||||
ms rbox __msc [label="Detach"];
|
||||
--- [label="If GSM AKA fallback is allowed"];
|
||||
hlr rbox hlr [label="Resend only GSM AKA tuples, already sent earlier"];
|
||||
__msc <= hlr [label="Send Auth Info Result\ncontaining GSM AKA auth tuples\nfrom the proxy cache"];
|
||||
ms rbox __msc [label="2G: Authentication\n3G: Detach"];
|
||||
---;
|
||||
hlr abox hlr [label="AUTS timer triggers"];
|
||||
hlr => home [label="Send Auth Info Request"];
|
||||
hlr <= home [label="Send Auth Info Result"];
|
||||
hlr rbox hlr [label="clear tuple cache, store new tuples"];
|
||||
hlr rbox hlr [label="continue to fill up the cache as necessary"];
|
||||
}
|
||||
@@ -5,24 +5,27 @@ arguments:
|
||||
|
||||
=== SYNOPSIS
|
||||
|
||||
*osmo-hlr* [-h|-V] [-d 'DBGMASK'] [-D] [-c 'CONFIGFILE'] [-s] [-T] [-e 'LOGLEVEL'] [-l 'DATABASE']
|
||||
*osmo-hlr* [-h] [-c 'CONFIGFILE'] [-l 'DATABASE'] [-d 'DBGMASK'] [-D] [-s] [-T] [-e 'LOGLEVEL'] [-U] [-V]
|
||||
|
||||
=== OPTIONS
|
||||
|
||||
// Keep the order the same as in osmo-hlr --help!
|
||||
|
||||
*-h, --help*::
|
||||
Print a short help message about the supported options
|
||||
*-V, --version*::
|
||||
Print the compile-time version number of the OsmoBTS program
|
||||
*-c, --config-file 'CONFIGFILE'*::
|
||||
Specify the file and path name of the configuration file to be
|
||||
used. If none is specified, use `osmo-hlr.cfg` in the current
|
||||
working directory.
|
||||
*-l, --database 'DATABASE'*::
|
||||
Specify the file name of the SQLite3 database to use as HLR/AUC
|
||||
storage
|
||||
*-d, --debug 'DBGMASK','DBGLEVELS'*::
|
||||
Set the log subsystems and levels for logging to stderr. This
|
||||
has mostly been superseded by VTY-based logging configuration,
|
||||
see <<logging>> for further information.
|
||||
*-D, --daemonize*::
|
||||
Fork the process as a daemon into background.
|
||||
*-c, --config-file 'CONFIGFILE'*::
|
||||
Specify the file and path name of the configuration file to be
|
||||
used. If none is specified, use `osmo-hlr.cfg` in the current
|
||||
working directory.
|
||||
*-s, --disable-color*::
|
||||
Disable colors for logging to stderr. This has mostly been
|
||||
deprecated by VTY based logging configuration, see <<logging>>
|
||||
@@ -35,9 +38,13 @@ arguments:
|
||||
Set the global log level for logging to stderr. This has mostly
|
||||
been deprecated by VTY based logging configuration, see
|
||||
<<logging>> for more information.
|
||||
*-l, --database 'DATABASE'*::
|
||||
Specify the file name of the SQLite3 database to use as HLR/AUC
|
||||
storage
|
||||
*-U, --db-upgrade*::
|
||||
Allow HLR database schema upgrades. If OsmoHLR was updated and
|
||||
requires a newer database schema, it will refuse to start unless
|
||||
this option is specified. The updated database can not be
|
||||
downgraded, make backups as necessary.
|
||||
*-V, --version*::
|
||||
Print the compile-time version number of the OsmoHLR program
|
||||
|
||||
=== Bootstrap the Database
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ transceiving only RAND and SRES, may be applicable. (See 3GPP TS 33.102, chapter
|
||||
|aud3g.ind_bitlen|5|Nr of index bits at lower SQN end
|
||||
|apn||
|
||||
|vlr_number||3GPP TS 23.008 chapter 2.4.5
|
||||
|hlr_number||3GPP TS 23.008 chapter 2.4.6
|
||||
|msc_number||3GPP TS 23.008 chapter 2.4.6
|
||||
|sgsn_number||3GPP TS 23.008 chapter 2.4.8.1
|
||||
|sgsn_address||3GPP TS 23.008 chapter 2.13.10
|
||||
|ggsn_number||3GPP TS 23.008 chapter 2.4.8.2
|
||||
@@ -67,3 +67,63 @@ transceiving only RAND and SRES, may be applicable. (See 3GPP TS 33.102, chapter
|
||||
|ms_purged_ps|1|3GPP TS 23.008 chapter 2.7.6
|
||||
|===
|
||||
|
||||
=== Configuring the Subscribers Create on Demand Feature
|
||||
|
||||
Usually a HLR will only allow mobile equipment (ME) on the network, if the HLR
|
||||
has a subscriber entry with the ME's IMSI. But OsmoHLR can also be configured to
|
||||
automatically create new entries for new IMSIs, with the
|
||||
`subscriber-create-on-demand` VTY option. The obvious use case is creating the
|
||||
new subscriber entry and then allowing the ME to use both the CS
|
||||
(Circuit Switched) and PS (Packet Switched) NAM (Network Access Mode).
|
||||
|
||||
.osmo-hlr.cfg
|
||||
----
|
||||
hlr
|
||||
subscriber-create-on-demand 5 cs+ps
|
||||
----
|
||||
|
||||
On the other hand, operators might only want to give network access to IMSIs, of
|
||||
which they know the owner. In order to do that, one can set the default NAM to
|
||||
`none` and manually approve new subscribers by changing the NAM (e.g. over the
|
||||
VTY, see the example below).
|
||||
|
||||
Oftentimes it is hard to know, which IMSI belongs to which ME, but the IMEI is
|
||||
readily available. If you configure your MSC to send IMEI checking requests to
|
||||
the HLR, before sending location update requests, the subscribers created on
|
||||
demand can also have the IMEI stored in the HLR database. With OsmoMSC, this
|
||||
is done by writing `check-imei-rqd early` in the `msc` section of osmo-msc.cfg.
|
||||
Then enable storing the IMEI when receiving check IMEI requests with
|
||||
`store-imei` in the OsmoHLR configuration.
|
||||
|
||||
.osmo-msc.cfg
|
||||
----
|
||||
msc
|
||||
check-imei-rqd early
|
||||
----
|
||||
|
||||
.osmo-hlr.cfg
|
||||
----
|
||||
hlr
|
||||
subscriber-create-on-demand 5 none
|
||||
store-imei
|
||||
----
|
||||
|
||||
.Example: Enabling CS and PS NAM via VTY for a known IMEI
|
||||
----
|
||||
OsmoHLR> enable
|
||||
OsmoHLR# subscriber imei 35761300444848 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: 58192 <1>
|
||||
IMEI: 35761300444848
|
||||
CS disabled <2>
|
||||
PS disabled <2>
|
||||
OsmoHLR# subscriber imei 35761300444848 update network-access-mode cs+ps
|
||||
OsmoHLR# subscriber imei 35761300444848 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: 58192
|
||||
IMEI: 35761300444848
|
||||
----
|
||||
<1> Randomly generated 5 digit MSISDN
|
||||
<2> Disabled CS and PS NAM prevent the subscriber from accessing the network
|
||||
|
||||
@@ -24,6 +24,10 @@ include::{srcdir}/chapters/control.adoc[]
|
||||
|
||||
include::./common/chapters/control_if.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/dgsm.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/proxy_cache.adoc[]
|
||||
|
||||
include::./common/chapters/gsup.adoc[]
|
||||
|
||||
include::./common/chapters/port_numbers.adoc[]
|
||||
|
||||
17
doc/manuals/regen_doc.sh
Executable file
17
doc/manuals/regen_doc.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
if [ -z "$DOCKER_PLAYGROUND" ]; then
|
||||
echo "You need to set DOCKER_PLAYGROUND"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT=$(realpath "$0")
|
||||
MANUAL_DIR=$(dirname "$SCRIPT")
|
||||
|
||||
COMMIT=${COMMIT:-$(git log -1 --format=format:%H)}
|
||||
|
||||
cd "$DOCKER_PLAYGROUND/scripts" || exit 1
|
||||
|
||||
OSMO_HLR_BRANCH=$COMMIT ./regen_doc.sh osmo-hlr 4258 \
|
||||
"$MANUAL_DIR/chapters/counters_generated.adoc" \
|
||||
"$MANUAL_DIR/vty/hlr_vty_reference.xml"
|
||||
@@ -187,7 +187,7 @@
|
||||
<param name='MASK' doc='List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific application, refer to the 'logging level' command. Optionally add individual log levels like 'abc,1:mno,3:xyz,5', where the level numbers are LOGL_DEBUG=1 LOGL_INFO=3 LOGL_NOTICE=5 LOGL_ERROR=7 LOGL_FATAL=8' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='logging level (main|db|auc|ss|lglobal|llapd|linp|lmux|lmi|lmib|lsms|lctrl|lgtp|lstats|lgsup|loap|lss7|lsccp|lsua|lm3ua|lmgcp|ljibuf) (debug|info|notice|error|fatal)'>
|
||||
<command id='logging level (main|db|auc|ss|lglobal|llapd|linp|lmux|lmi|lmib|lsms|lctrl|lgtp|lstats|lgsup|loap|lss7|lsccp|lsua|lm3ua|lmgcp|ljibuf|lrspro) (debug|info|notice|error|fatal)'>
|
||||
<params>
|
||||
<param name='logging' doc='Configure logging' />
|
||||
<param name='level' doc='Set the log level for a specified category' />
|
||||
@@ -213,6 +213,7 @@
|
||||
<param name='lm3ua' doc='libosmo-sigtran MTP3 User Adaptation' />
|
||||
<param name='lmgcp' doc='libosmo-mgcp Media Gateway Control Protocol' />
|
||||
<param name='ljibuf' doc='libosmo-netif Jitter Buffer' />
|
||||
<param name='lrspro' doc='Remote SIM protocol' />
|
||||
<param name='debug' doc='Log debug messages and higher levels' />
|
||||
<param name='info' doc='Log informational messages and higher levels' />
|
||||
<param name='notice' doc='Log noticeable messages and higher levels' />
|
||||
@@ -302,22 +303,63 @@
|
||||
<param name='REGEXP' doc='Regular expression' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show stats'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='stats' doc='Show statistical values' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show stats level (global|peer|subscriber)'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='stats' doc='Show statistical values' />
|
||||
<param name='level' doc='Set the maximum group level' />
|
||||
<param name='global' doc='Show global groups only' />
|
||||
<param name='peer' doc='Show global and network peer related groups' />
|
||||
<param name='subscriber' doc='Show global, peer, and subscriber groups' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show asciidoc counters'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='asciidoc' doc='Asciidoc generation' />
|
||||
<param name='counters' doc='Generate table of all registered counters' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show rate-counters'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='rate-counters' doc='Show all rate counters' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show gsup-connections'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='gsup-connections' doc='GSUP Connections from VLRs, SGSNs, EUSEs' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT show'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT show'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='show' doc='Show subscriber information' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show subscriber (imsi|msisdn|id|imei) IDENT'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
</params>
|
||||
</command>
|
||||
</node>
|
||||
<node id='enable'>
|
||||
<name>enable</name>
|
||||
@@ -486,7 +528,7 @@
|
||||
<param name='MASK' doc='List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific application, refer to the 'logging level' command. Optionally add individual log levels like 'abc,1:mno,3:xyz,5', where the level numbers are LOGL_DEBUG=1 LOGL_INFO=3 LOGL_NOTICE=5 LOGL_ERROR=7 LOGL_FATAL=8' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='logging level (main|db|auc|ss|lglobal|llapd|linp|lmux|lmi|lmib|lsms|lctrl|lgtp|lstats|lgsup|loap|lss7|lsccp|lsua|lm3ua|lmgcp|ljibuf) (debug|info|notice|error|fatal)'>
|
||||
<command id='logging level (main|db|auc|ss|lglobal|llapd|linp|lmux|lmi|lmib|lsms|lctrl|lgtp|lstats|lgsup|loap|lss7|lsccp|lsua|lm3ua|lmgcp|ljibuf|lrspro) (debug|info|notice|error|fatal)'>
|
||||
<params>
|
||||
<param name='logging' doc='Configure logging' />
|
||||
<param name='level' doc='Set the log level for a specified category' />
|
||||
@@ -512,6 +554,7 @@
|
||||
<param name='lm3ua' doc='libosmo-sigtran MTP3 User Adaptation' />
|
||||
<param name='lmgcp' doc='libosmo-mgcp Media Gateway Control Protocol' />
|
||||
<param name='ljibuf' doc='libosmo-netif Jitter Buffer' />
|
||||
<param name='lrspro' doc='Remote SIM protocol' />
|
||||
<param name='debug' doc='Log debug messages and higher levels' />
|
||||
<param name='info' doc='Log informational messages and higher levels' />
|
||||
<param name='notice' doc='Log noticeable messages and higher levels' />
|
||||
@@ -521,8 +564,7 @@
|
||||
</command>
|
||||
<command id='logging level set-all (debug|info|notice|error|fatal)'>
|
||||
<params>
|
||||
<param name='logging' doc='Configure logging' />
|
||||
<param name='level' doc='Set the log level for a specified category' />
|
||||
<param name='logging' doc='Configure logging' /> <param name='level' doc='Set the log level for a specified category' />
|
||||
<param name='set-all' doc='Once-off set all categories to the given log level. There is no single command to take back these changes -- each category is set to the given level, period.' />
|
||||
<param name='debug' doc='Log debug messages and higher levels' />
|
||||
<param name='info' doc='Log informational messages and higher levels' />
|
||||
@@ -601,22 +643,63 @@
|
||||
<param name='REGEXP' doc='Regular expression' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show stats'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='stats' doc='Show statistical values' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show stats level (global|peer|subscriber)'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='stats' doc='Show statistical values' />
|
||||
<param name='level' doc='Set the maximum group level' />
|
||||
<param name='global' doc='Show global groups only' />
|
||||
<param name='peer' doc='Show global and network peer related groups' />
|
||||
<param name='subscriber' doc='Show global, peer, and subscriber groups' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show asciidoc counters'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='asciidoc' doc='Asciidoc generation' />
|
||||
<param name='counters' doc='Generate table of all registered counters' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show rate-counters'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='rate-counters' doc='Show all rate counters' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show gsup-connections'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='gsup-connections' doc='GSUP Connections from VLRs, SGSNs, EUSEs' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT show'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT show'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='show' doc='Show subscriber information' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='show subscriber (imsi|msisdn|id|imei) IDENT'>
|
||||
<params>
|
||||
<param name='show' doc='Show running system information' />
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber imsi IDENT create'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
@@ -625,47 +708,52 @@
|
||||
<param name='create' doc='Create subscriber by IMSI' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT delete'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT delete'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='delete' doc='Delete subscriber from database' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT update msisdn MSISDN'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update msisdn (none|MSISDN)'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='msisdn' doc='Set MSISDN (phone number) of the subscriber' />
|
||||
<param name='none' doc='Remove MSISDN (phone number)' />
|
||||
<param name='MSISDN' doc='New MSISDN (phone number)' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT update aud2g none'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update aud2g none'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='aud2g' doc='Set 2G authentication data' />
|
||||
<param name='none' doc='Delete 2G authentication data' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT update aud2g (comp128v1|comp128v2|comp128v3|xor) ki KI'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update aud2g (comp128v1|comp128v2|comp128v3|xor) ki KI'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='aud2g' doc='Set 2G authentication data' />
|
||||
<param name='comp128v1' doc='Use COMP128v1 algorithm' />
|
||||
@@ -676,25 +764,27 @@
|
||||
<param name='KI' doc='Ki as 32 hexadecimal characters' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT update aud3g none'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update aud3g none'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='aud3g' doc='Set UMTS authentication data (3G, and 2G with UMTS AKA)' />
|
||||
<param name='none' doc='Delete 3G authentication data' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id) IDENT update aud3g milenage k K (op|opc) OP_C [ind-bitlen] [<0-28>]'>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update aud3g milenage k K (op|opc) OP_C [ind-bitlen] [<0-28>]'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID of the subscriber' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='aud3g' doc='Set UMTS authentication data (3G, and 2G with UMTS AKA)' />
|
||||
<param name='milenage' doc='Use Milenage algorithm' />
|
||||
@@ -707,6 +797,36 @@
|
||||
<param name='[<0-28>]' doc='IND bit length value (default: 5)' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update imei (none|IMEI)'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='imei' doc='Set IMEI of the subscriber (normally populated from MSC, no need to set this manually)' />
|
||||
<param name='none' doc='Forget IMEI' />
|
||||
<param name='IMEI' doc='Set IMEI (use for debug only!)' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber (imsi|msisdn|id|imei) IDENT update network-access-mode (none|cs|ps|cs+ps)'>
|
||||
<params>
|
||||
<param name='subscriber' doc='Subscriber management commands' />
|
||||
<param name='imsi' doc='Identify subscriber by IMSI' />
|
||||
<param name='msisdn' doc='Identify subscriber by MSISDN (phone number)' />
|
||||
<param name='id' doc='Identify subscriber by database ID' />
|
||||
<param name='imei' doc='Identify subscriber by IMEI' />
|
||||
<param name='IDENT' doc='IMSI/MSISDN/ID/IMEI of the subscriber' />
|
||||
<param name='update' doc='Set or update subscriber data' />
|
||||
<param name='network-access-mode' doc='Set Network Access Mode (NAM) of the subscriber' />
|
||||
<param name='none' doc='Do not allow access to circuit switched or packet switched services' />
|
||||
<param name='cs' doc='Allow access to circuit switched services only' />
|
||||
<param name='ps' doc='Allow access to packet switched services only' />
|
||||
<param name='cs+ps' doc='Allow access to both circuit and packet switched services' />
|
||||
</params>
|
||||
</command>
|
||||
</node>
|
||||
<node id='config'>
|
||||
<name>config</name>
|
||||
@@ -883,7 +1003,8 @@
|
||||
<param name='user' doc='Generic facility' />
|
||||
<param name='uucp' doc='UUCP facility' />
|
||||
</params>
|
||||
</command> <command id='log syslog local <0-7>'>
|
||||
</command>
|
||||
<command id='log syslog local <0-7>'>
|
||||
<params>
|
||||
<param name='log' doc='Configure logging sub-system' />
|
||||
<param name='syslog' doc='Logging via syslog' />
|
||||
@@ -905,6 +1026,43 @@
|
||||
<param name='[HOSTNAME]' doc='Host name to send the GSMTAP logging to (UDP port 4729)' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='stats reporter statsd'>
|
||||
<params>
|
||||
<param name='stats' doc='Configure stats sub-system' />
|
||||
<param name='reporter' doc='Configure a stats reporter' />
|
||||
<param name='statsd' doc='Report to a STATSD server' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no stats reporter statsd'>
|
||||
<params>
|
||||
<param name='no' doc='Negate a command or set its defaults' />
|
||||
<param name='stats' doc='Configure stats sub-system' />
|
||||
<param name='reporter' doc='Configure a stats reporter' />
|
||||
<param name='statsd' doc='Report to a STATSD server' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='stats reporter log'>
|
||||
<params>
|
||||
<param name='stats' doc='Configure stats sub-system' />
|
||||
<param name='reporter' doc='Configure a stats reporter' />
|
||||
<param name='log' doc='Report to the logger' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no stats reporter log'>
|
||||
<params>
|
||||
<param name='no' doc='Negate a command or set its defaults' />
|
||||
<param name='stats' doc='Configure stats sub-system' />
|
||||
<param name='reporter' doc='Configure a stats reporter' />
|
||||
<param name='log' doc='Report to the logger' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='stats interval <1-65535>'>
|
||||
<params>
|
||||
<param name='stats' doc='Configure stats sub-system' />
|
||||
<param name='interval' doc='Set the reporting interval' />
|
||||
<param name='<1-65535>' doc='Interval in seconds' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='hlr'>
|
||||
<params>
|
||||
<param name='hlr' doc='Configure the HLR' />
|
||||
@@ -985,7 +1143,7 @@
|
||||
<param name='[last]' doc='Log source file info at the end of a log line. If omitted, log source file info just before the log text.' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='logging level (main|db|auc|ss|lglobal|llapd|linp|lmux|lmi|lmib|lsms|lctrl|lgtp|lstats|lgsup|loap|lss7|lsccp|lsua|lm3ua|lmgcp|ljibuf) (debug|info|notice|error|fatal)'>
|
||||
<command id='logging level (main|db|auc|ss|lglobal|llapd|linp|lmux|lmi|lmib|lsms|lctrl|lgtp|lstats|lgsup|loap|lss7|lsccp|lsua|lm3ua|lmgcp|ljibuf|lrspro) (debug|info|notice|error|fatal)'>
|
||||
<params>
|
||||
<param name='logging' doc='Configure logging' />
|
||||
<param name='level' doc='Set the log level for a specified category' />
|
||||
@@ -1011,6 +1169,7 @@
|
||||
<param name='lm3ua' doc='libosmo-sigtran MTP3 User Adaptation' />
|
||||
<param name='lmgcp' doc='libosmo-mgcp Media Gateway Control Protocol' />
|
||||
<param name='ljibuf' doc='libosmo-netif Jitter Buffer' />
|
||||
<param name='lrspro' doc='Remote SIM protocol' />
|
||||
<param name='debug' doc='Log debug messages and higher levels' />
|
||||
<param name='info' doc='Log informational messages and higher levels' />
|
||||
<param name='notice' doc='Log noticeable messages and higher levels' />
|
||||
@@ -1051,6 +1210,75 @@
|
||||
</params>
|
||||
</command>
|
||||
</node>
|
||||
<node id='config-stats'>
|
||||
<name>config-stats</name>
|
||||
<command id='local-ip ADDR'>
|
||||
<params>
|
||||
<param name='local-ip' doc='Set the IP address to which we bind locally' />
|
||||
<param name='ADDR' doc='IP Address' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no local-ip'>
|
||||
<params>
|
||||
<param name='no' doc='Negate a command or set its defaults' />
|
||||
<param name='local-ip' doc='Set the IP address to which we bind locally' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='remote-ip ADDR'>
|
||||
<params>
|
||||
<param name='remote-ip' doc='Set the remote IP address to which we connect' />
|
||||
<param name='ADDR' doc='IP Address' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='remote-port <1-65535>'>
|
||||
<params>
|
||||
<param name='remote-port' doc='Set the remote port to which we connect' />
|
||||
<param name='<1-65535>' doc='Remote port number' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='mtu <100-65535>'>
|
||||
<params>
|
||||
<param name='mtu' doc='Set the maximum packet size' />
|
||||
<param name='<100-65535>' doc='Size in byte' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no mtu'>
|
||||
<params>
|
||||
<param name='no' doc='Negate a command or set its defaults' />
|
||||
<param name='mtu' doc='Set the maximum packet size' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='prefix PREFIX'>
|
||||
<params>
|
||||
<param name='prefix' doc='Set the item name prefix' />
|
||||
<param name='PREFIX' doc='The prefix string' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no prefix'>
|
||||
<params>
|
||||
<param name='no' doc='Negate a command or set its defaults' />
|
||||
<param name='prefix' doc='Set the item name prefix' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='level (global|peer|subscriber)'>
|
||||
<params>
|
||||
<param name='level' doc='Set the maximum group level' />
|
||||
<param name='global' doc='Report global groups only' />
|
||||
<param name='peer' doc='Report global and network peer related groups' />
|
||||
<param name='subscriber' doc='Report global, peer, and subscriber groups' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='enable'>
|
||||
<params>
|
||||
<param name='enable' doc='Enable the reporter' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='disable'>
|
||||
<params>
|
||||
<param name='disable' doc='Disable the reporter' />
|
||||
</params>
|
||||
</command>
|
||||
</node>
|
||||
<node id='config-line'>
|
||||
<name>config-line</name>
|
||||
<command id='login'>
|
||||
@@ -1064,10 +1292,11 @@
|
||||
<param name='login' doc='Enable password checking' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='bind A.B.C.D'>
|
||||
<command id='bind A.B.C.D [<0-65535>]'>
|
||||
<params>
|
||||
<param name='bind' doc='Accept VTY telnet connections on local interface' />
|
||||
<param name='A.B.C.D' doc='Local interface IP address (default: 127.0.0.1)' />
|
||||
<param name='[<0-65535>]' doc='Local TCP port number' />
|
||||
</params>
|
||||
</command>
|
||||
</node>
|
||||
@@ -1087,6 +1316,12 @@
|
||||
<param name='gsup' doc='Configure GSUP options' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='database PATH'>
|
||||
<params>
|
||||
<param name='database' doc='Set the path to the HLR database file' />
|
||||
<param name='PATH' doc='Relative or absolute file system path to the database file (default is 'hlr.db')' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='euse NAME'>
|
||||
<params>
|
||||
<param name='euse' doc='Configure a particular External USSD Entity' />
|
||||
@@ -1145,6 +1380,40 @@
|
||||
<param name='default-route' doc='Remove the default-route for all USSD to unknown destinations' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='ncss-guard-timeout <0-255>'>
|
||||
<params>
|
||||
<param name='ncss-guard-timeout' doc='Set guard timer for NCSS (call independent SS) session activity' />
|
||||
<param name='<0-255>' doc='Guard timer value (sec.), or 0 to disable' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='store-imei'>
|
||||
<params>
|
||||
<param name='store-imei' doc='Save the IMEI in the database when receiving Check IMEI requests. Note that an MSC does not necessarily send Check IMEI requests (for OsmoMSC, you may want to set 'check-imei-rqd 1').' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no store-imei'>
|
||||
<params>
|
||||
<param name='no' doc='Do not save the IMEI in the database, when receiving Check IMEI requests.' />
|
||||
<param name='store-imei' doc='(null)' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='subscriber-create-on-demand (no-msisdn|<3-15>) (none|cs|ps|cs+ps)'>
|
||||
<params>
|
||||
<param name='subscriber-create-on-demand' doc='Make a new record when a subscriber is first seen.' />
|
||||
<param name='no-msisdn' doc='Do not automatically assign MSISDN.' />
|
||||
<param name='<3-15>' doc='Length of an automatically assigned MSISDN.' />
|
||||
<param name='none' doc='Do not allow any NAM (Network Access Mode) by default.' />
|
||||
<param name='cs' doc='Allow access to circuit switched NAM by default.' />
|
||||
<param name='ps' doc='Allow access to packet switched NAM by default.' />
|
||||
<param name='cs+ps' doc='Allow access to circuit and packet switched NAM by default.' />
|
||||
</params>
|
||||
</command>
|
||||
<command id='no subscriber-create-on-demand'>
|
||||
<params>
|
||||
<param name='no' doc='Do not make a new record when a subscriber is first seen.' />
|
||||
<param name='subscriber-create-on-demand' doc='(null)' />
|
||||
</params>
|
||||
</command>
|
||||
</node>
|
||||
<node id='config-hlr-gsup'>
|
||||
<name>config-hlr-gsup</name>
|
||||
|
||||
39
doc/sequence_charts/Makefile.am
Normal file
39
doc/sequence_charts/Makefile.am
Normal file
@@ -0,0 +1,39 @@
|
||||
all:
|
||||
echo "built only on manual invocation, needs mscgen and dot (graphviz) programs: invoke 'make charts'"
|
||||
|
||||
charts: msc dot
|
||||
|
||||
EXTRA_DIST = \
|
||||
proxy_cache.dot \
|
||||
proxy_cache__mm_fsm.dot \
|
||||
proxy_cache__to_home_hlr_fsm.dot \
|
||||
$(NULL)
|
||||
|
||||
CLEANFILES = \
|
||||
proxy_cache.png \
|
||||
proxy_cache__mm_fsm.png \
|
||||
proxy_cache__to_home_hlr_fsm.png \
|
||||
$(NULL)
|
||||
|
||||
msc: \
|
||||
$(NULL)
|
||||
|
||||
dot: \
|
||||
$(builddir)/proxy_cache.png \
|
||||
$(builddir)/proxy_cache__mm_fsm.png \
|
||||
$(builddir)/proxy_cache__to_home_hlr_fsm.png \
|
||||
$(NULL)
|
||||
|
||||
$(builddir)/%.png: %.msc
|
||||
mscgen -T png -o $@ $<
|
||||
|
||||
$(builddir)/%.msc: $(srcdir)/%.ladder
|
||||
@which ladder_to_msc.py || (echo 'PLEASE POINT YOUR $$PATH AT libosmocore/contrib/ladder_to_msc.py' && false)
|
||||
ladder_to_msc.py -i $< -o $@
|
||||
|
||||
$(builddir)/%.png: $(srcdir)/%.dot
|
||||
dot -Tpng $< > $@
|
||||
|
||||
.PHONY: poll
|
||||
poll:
|
||||
while true; do $(MAKE) msc dot; sleep 1; done
|
||||
19
doc/sequence_charts/proxy_cache.dot
Normal file
19
doc/sequence_charts/proxy_cache.dot
Normal file
@@ -0,0 +1,19 @@
|
||||
digraph G {
|
||||
rankdir=LR
|
||||
labelloc=t;
|
||||
|
||||
msc [label="MS/BSS/MSC"]
|
||||
subgraph cluster_proxy {
|
||||
label="HLR Proxy"
|
||||
proxy_mm [label="Proxy Mobility Management FSM",shape=box3d]
|
||||
proxy_home [label="Proxy to Home HLR FSM",shape=box3d]
|
||||
proxy [label="GSUP Proxy"]
|
||||
proxy_mm -> proxy_home [constraint=false,dir=both,label="(FSM events)"]
|
||||
}
|
||||
hlr [label="Home HLR"]
|
||||
|
||||
msc -> proxy_mm [dir=both,label="MM related GSUP\n (immediate response\n if possible)"]
|
||||
proxy_home -> hlr [dir=both,label="MM related GSUP\n (delayed)"]
|
||||
|
||||
msc -> proxy -> hlr [dir=both,label="non-MM GSUP",style=dashed]
|
||||
}
|
||||
78
doc/sequence_charts/proxy_cache__mm_fsm.dot
Normal file
78
doc/sequence_charts/proxy_cache__mm_fsm.dot
Normal file
@@ -0,0 +1,78 @@
|
||||
digraph G {
|
||||
rankdir=TB
|
||||
labelloc=t; label="HLR Proxy MM FSM"
|
||||
|
||||
top,top2,top3[shape=invtriangle,label="(1)"]
|
||||
|
||||
top -> READY
|
||||
|
||||
new [label="proxy_cache_subscr_new()\n/ proxy_cache_subscr_from_db()",shape=box]
|
||||
READY [style=bold]
|
||||
HIBERNATE [shape=note,label="Hibernate\n (keep in DB)"]
|
||||
CLEAR [shape=box,label="Clear DB entry\n (discard completely)"]
|
||||
WAIT_AUTH_TUPLES [style=bold]
|
||||
WAIT_SUBSCR_DATA [style=bold]
|
||||
WAIT_GSUP_ISD_RESULT [style=bold]
|
||||
|
||||
home_fsm [label="Proxy to Home HLR FSM",shape=box3d]
|
||||
{rank=same;READY,home_fsm}
|
||||
|
||||
|
||||
new -> {READY,home_fsm}
|
||||
|
||||
READY -> {event_lu_req,event_auth_info_req} [arrowhead=none]
|
||||
|
||||
event_auth_info_req [shape=rarrow,label="Rx GSUP\nSend Auth Info Request\nfrom MSC"]
|
||||
event_auth_info_req -> junction_send_auth_info_req
|
||||
junction_send_auth_info_req [shape=diamond,label="Unused\nauth tuples\navailable?"]
|
||||
junction_send_auth_info_req -> action_send_auth_info [label="yes"]
|
||||
junction_send_auth_info_req -> emit_need_tuples [label="no"]
|
||||
emit_need_tuples [shape=lpromoter,label="emit\n HOME_EV_CHECK_TUPLES\n to Home FSM"]
|
||||
emit_need_tuples->WAIT_AUTH_TUPLES
|
||||
WAIT_AUTH_TUPLES -> rx_ev_rx_auth_tuples [arrowhead=none]
|
||||
rx_ev_rx_auth_tuples [shape=rpromoter,label="receive\n MM_EV_RX_AUTH_TUPLES"]
|
||||
rx_ev_rx_auth_tuples -> action_send_auth_info
|
||||
action_send_auth_info [shape=larrow,label="Tx GSUP\nSend Auth Info Result\nwith fresh auth tuples\n to MSC"]
|
||||
action_send_auth_info -> emit_check_tuples
|
||||
emit_check_tuples [shape=lpromoter,label="emit\n HOME_EV_CHECK_TUPLES\n to Home FSM"]
|
||||
emit_check_tuples -> top2
|
||||
WAIT_AUTH_TUPLES -> junction_check_auth_fallback [label="Timeout",style=dashed]
|
||||
junction_check_auth_fallback -> action_do_auth_fallback [label="yes",style=dashed]
|
||||
action_do_auth_fallback [shape=larrow,label="Tx GSUP\nSend Auth Info Result\nwith recycled auth tuple\n(GSM AKA only)"]
|
||||
junction_check_auth_fallback [shape=diamond,label="Re-usable\nauth tuples\navailable?"]
|
||||
junction_check_auth_fallback -> action_fail_auth [label="no",style=dashed]
|
||||
action_fail_auth [shape=larrow,label="Tx GSUP\nSend Auth Info Error\npending re-connection to\nthe home HLR"]
|
||||
{action_do_auth_fallback,action_fail_auth} -> top2 [style=dashed]
|
||||
|
||||
event_lu_req [shape=rarrow,label="Rx GSUP\nUpdate Location Request\nfrom MSC"]
|
||||
event_lu_req -> emit_lu_req
|
||||
emit_lu_req [shape=lpromoter,label="emit\n HOME_EV_CONFIRM_LU"];
|
||||
emit_lu_req -> junction_check_subscriber_data
|
||||
junction_check_subscriber_data [shape=diamond,label="Subscriber\nData\nknown?"]
|
||||
junction_check_subscriber_data -> WAIT_SUBSCR_DATA [label=no]
|
||||
WAIT_SUBSCR_DATA -> rx_ev_subscr_data [arrowhead=none]
|
||||
rx_ev_subscr_data [shape=rpromoter,label="receive\n MM_EV_RX_SUBSCR_DATA"];
|
||||
rx_ev_subscr_data -> action_subscr_data_req
|
||||
junction_check_subscriber_data -> action_subscr_data_req [label="yes"]
|
||||
action_subscr_data_req [shape=larrow,label="Tx GSUP\n Insert Subscriber Data\n Request to MSC"]
|
||||
action_subscr_data_req -> WAIT_GSUP_ISD_RESULT
|
||||
WAIT_GSUP_ISD_RESULT -> tx_gsup_isd_res [arrowhead=none]
|
||||
tx_gsup_isd_res [shape=rarrow,label="Rx GSUP\n Insert Subscriber Data Result\nfrom MSC"]
|
||||
tx_gsup_isd_res -> top3
|
||||
|
||||
{WAIT_GSUP_ISD_RESULT,WAIT_SUBSCR_DATA} -> action_lu_reject [label="Timeout",style=dashed]
|
||||
action_lu_reject [shape=larrow,label="Tx GSUP\nUpdate Location Error\nto MSC\npending reconnect of home HLR"]
|
||||
action_lu_reject -> top3 [style=dashed]
|
||||
|
||||
READY -> HIBERNATE [label="Timeout"]
|
||||
READY -> rx_ev_subscr_invalid [arrowhead=none]
|
||||
rx_ev_subscr_invalid[shape=rpromoter,label="receive\n MM_EV_SUBSCR_INVALID"]
|
||||
rx_ev_subscr_invalid -> tx_purge_req
|
||||
tx_purge_req [shape=larrow,label="Tx GSUP\nPurge MS Request"]
|
||||
tx_purge_req -> note_purge [style=dotted]
|
||||
note_purge [shape=note,label="Don't care about\nPurge MS Result"]
|
||||
tx_purge_req -> CLEAR
|
||||
{CLEAR,HIBERNATE} -> TERM
|
||||
TERM[shape=octagon][style=bold]
|
||||
|
||||
}
|
||||
97
doc/sequence_charts/proxy_cache__to_home_hlr_fsm.dot
Normal file
97
doc/sequence_charts/proxy_cache__to_home_hlr_fsm.dot
Normal file
@@ -0,0 +1,97 @@
|
||||
digraph G {
|
||||
rankdir=TB
|
||||
labelloc=t; label="HLR Proxy to Home HLR FSM"
|
||||
|
||||
top,to_top1,to_top2,to_top3,to_top4,to_top5[shape=invtriangle,label="(A)"]
|
||||
top->junction_resolve_home_hlr
|
||||
|
||||
at_clear,to_clear1,to_clear2 [shape=invtriangle,label="(X)"]
|
||||
|
||||
mm_fsm [shape=box3d,label="Proxy MM FSM"]
|
||||
mm_fsm -> junction_resolve_home_hlr [style=invisible,arrowhead=none]
|
||||
|
||||
WAIT_HOME_HLR_RESOLVED [style=bold]
|
||||
WAIT_UPDATE_LOCATION_RESULT [style=bold]
|
||||
WAIT_SEND_AUTH_INFO_RESULT [style=bold]
|
||||
IDLE [style=bold]
|
||||
CLEAR [style=bold]
|
||||
|
||||
new [label="proxy_cache_subscr_new()\n/ proxy_cache_subscr_from_db()",shape=box]
|
||||
{
|
||||
rank=same;
|
||||
junction_resolve_home_hlr [shape=diamond,label="Home HLR\n known?"]
|
||||
junction_confirm_home_hlr [shape=diamond,label="mslookup\n for home HLR\n very old?"]
|
||||
junction_update_location [shape=diamond,label="Did MM FSM emit another\n HOME_EV_CONFIRM_LU?"]
|
||||
junction_auth_info [shape=diamond,label="Auth tuple\ncache full of\nfresh tuples?"]
|
||||
}
|
||||
|
||||
new -> {junction_resolve_home_hlr, mm_fsm}
|
||||
|
||||
junction_resolve_home_hlr -> junction_confirm_home_hlr [label="known"]
|
||||
junction_resolve_home_hlr -> action_mslookup [label="wat"]
|
||||
action_mslookup [shape=larrow,label="start mslookup"]
|
||||
action_mslookup -> WAIT_HOME_HLR_RESOLVED
|
||||
WAIT_HOME_HLR_RESOLVED -> rx_mslookup_res [arrowhead=none]
|
||||
rx_mslookup_res [shape=rarrow,label="home HLR\n resolved"]
|
||||
rx_mslookup_res -> to_top1
|
||||
WAIT_HOME_HLR_RESOLVED -> CLEAR [style=dashed,label=Timeout]
|
||||
|
||||
junction_update_location -> action_lu_req [label="need data\n/\nneed to confirm LU"]
|
||||
action_lu_req [shape=larrow,label="Tx GSUP Update Location Req\nto home HLR"]
|
||||
action_lu_req -> WAIT_UPDATE_LOCATION_RESULT
|
||||
WAIT_UPDATE_LOCATION_RESULT->rx_isd [arrowhead=none]
|
||||
rx_isd [shape=rarrow,label="Rx GSUP\n Insert Subscriber\n Data Request\nfrom home HLR"]
|
||||
rx_isd -> emit_rx_subscr_data
|
||||
emit_rx_subscr_data [shape=lpromoter,label="emit\n MM_EV_RX_SUBSCR_DATA"]
|
||||
emit_rx_subscr_data->action_tx_isd_res
|
||||
action_tx_isd_res -> WAIT_UPDATE_LOCATION_RESULT
|
||||
action_tx_isd_res [shape=larrow,label="Tx GSUP Insert Subscriber Data Result\nto home HLR"]
|
||||
WAIT_UPDATE_LOCATION_RESULT -> rx_lu_res [arrowhead=none]
|
||||
rx_lu_res [shape=rarrow,label="Rx GSUP Update\n Location Result\nfrom home HLR"]
|
||||
rx_lu_res -> to_top2
|
||||
junction_update_location -> junction_auth_info [label="data known,\nLU confirmed"]
|
||||
WAIT_UPDATE_LOCATION_RESULT->junction_lu_failed [label="Timeout "]
|
||||
junction_lu_failed [shape=diamond,label="has home HLR\never confirmed\na LU before?"];
|
||||
junction_lu_failed -> to_clear2 [label="never\nconfirmed",style=dashed]
|
||||
junction_lu_failed -> note_lu_failed [label="has\nconfirmed\nbefore"]
|
||||
note_lu_failed [shape=note,label="Home HLR is\ntemporarily unreachable,\n just carry on."]
|
||||
note_lu_failed -> to_top3
|
||||
|
||||
junction_confirm_home_hlr -> action_mslookup_confirm [label="very old"]
|
||||
junction_confirm_home_hlr -> junction_update_location [label="fair enough"]
|
||||
action_mslookup_confirm [shape=larrow,label="start mslookup"]
|
||||
note_mslookup_confirm [shape=note,label="Result evaluated in IDLE state.\nIf no mslookup result comes\n back, the home HLR is\ntemporarily unreachable:\ncontinue anyway.\nThis is sanity checking for\na *modified* home HLR"]
|
||||
action_mslookup_confirm -> note_mslookup_confirm [arrowhead=none,style=dotted]
|
||||
action_mslookup_confirm -> junction_update_location
|
||||
|
||||
junction_auth_info -> action_sai_req [label="need more tuples"]
|
||||
junction_auth_info -> set_idle_timeout [label="cache is fresh"]
|
||||
action_sai_req [shape=larrow,label="Tx GSUP\n Send Auth Info Request\n to home HLR"]
|
||||
action_sai_req -> WAIT_SEND_AUTH_INFO_RESULT
|
||||
WAIT_SEND_AUTH_INFO_RESULT->rx_sai_res[arrowhead=none]
|
||||
rx_sai_res[shape=rarrow,label="Rx GSUP\n Send Auth Info\n Result\nfrom home HLR"]
|
||||
rx_sai_res -> emit_rx_tuples
|
||||
emit_rx_tuples [shape=lpromoter,label="emit\n MM_EV_RX_AUTH_TUPLES"]
|
||||
emit_rx_tuples -> to_top4
|
||||
WAIT_SEND_AUTH_INFO_RESULT->set_idle_timeout[label="Timeout",style=dashed]
|
||||
set_idle_timeout [shape=diamond,label="Select IDLE\n timeout:\nmin(\nretry tuples,\n confirm mslookup)"]
|
||||
set_idle_timeout -> IDLE
|
||||
|
||||
IDLE -> rx_mslookup_confirm_res [arrowhead=none]
|
||||
rx_mslookup_confirm_res [shape=rarrow,label="Rx mslookup result"]
|
||||
rx_mslookup_confirm_res -> junction_compare_home_hlr
|
||||
junction_compare_home_hlr [shape=diamond,label="mslookup result\n matches home HLR\n on record?"]
|
||||
junction_compare_home_hlr -> set_idle_timeout [label="matches"]
|
||||
junction_compare_home_hlr -> to_clear1 [label="mismatch",style=dashed]
|
||||
|
||||
IDLE -> to_top5 [label="Timeout"]
|
||||
IDLE -> {rx_ev_check_tuples,rx_ev_confirm_lu} [arrowhead=none]
|
||||
rx_ev_check_tuples [shape=rpromoter,label="receive\n HOME_EV_CHECK_TUPLES"]
|
||||
rx_ev_confirm_lu [shape=rpromoter,label="receive\n HOME_EV_CONFIRM_LU"]
|
||||
{rx_ev_check_tuples,rx_ev_confirm_lu} -> to_top5
|
||||
|
||||
at_clear -> CLEAR
|
||||
CLEAR -> emit_subscr_invalid -> TERM
|
||||
emit_subscr_invalid [shape=lpromoter,label="emit\n MM_EV_SUBSCR_INVALID"]
|
||||
TERM[shape=octagon][style=bold]
|
||||
}
|
||||
@@ -1,2 +1,13 @@
|
||||
nobase_include_HEADERS = osmocom/gsupclient/gsup_client.h
|
||||
SUBDIRS = osmocom
|
||||
|
||||
nobase_include_HEADERS = \
|
||||
osmocom/gsupclient/gsup_peer_id.h \
|
||||
osmocom/gsupclient/gsup_client.h \
|
||||
osmocom/gsupclient/gsup_req.h \
|
||||
osmocom/mslookup/mdns.h \
|
||||
osmocom/mslookup/mdns_sock.h \
|
||||
osmocom/mslookup/mslookup_client_fake.h \
|
||||
osmocom/mslookup/mslookup_client.h \
|
||||
osmocom/mslookup/mslookup_client_mdns.h \
|
||||
osmocom/mslookup/mslookup.h \
|
||||
$(NULL)
|
||||
|
||||
4
include/osmocom/Makefile.am
Normal file
4
include/osmocom/Makefile.am
Normal file
@@ -0,0 +1,4 @@
|
||||
SUBDIRS = \
|
||||
hlr \
|
||||
mslookup \
|
||||
$(NULL)
|
||||
@@ -6,18 +6,17 @@
|
||||
* Author: Jacob Erlbeck
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@@ -39,6 +38,8 @@ struct osmo_gsup_client;
|
||||
/* Expects message in msg->l2h */
|
||||
typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct msgb *msg);
|
||||
|
||||
typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up);
|
||||
|
||||
struct osmo_gsup_client {
|
||||
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
|
||||
|
||||
@@ -54,8 +55,31 @@ struct osmo_gsup_client {
|
||||
int got_ipa_pong;
|
||||
|
||||
struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */
|
||||
|
||||
osmo_gsup_client_up_down_cb_t up_down_cb;
|
||||
};
|
||||
|
||||
struct osmo_gsup_client_config {
|
||||
/*! IP access unit which contains client identification information; must be allocated in talloc_ctx as well to
|
||||
* ensure it lives throughout the lifetime of the connection. */
|
||||
struct ipaccess_unit *ipa_dev;
|
||||
/*! GSUP server IP address to connect to. */
|
||||
const char *ip_addr;
|
||||
/*! GSUP server TCP port to connect to. */
|
||||
unsigned int tcp_port;
|
||||
/*! OPA client configuration, or NULL. */
|
||||
struct osmo_oap_client_config *oapc_config;
|
||||
/*! callback for reading from the GSUP connection. */
|
||||
osmo_gsup_client_read_cb_t read_cb;
|
||||
/*! Invoked when the GSUP link is ready for communication, and when the link drops. */
|
||||
osmo_gsup_client_up_down_cb_t up_down_cb;
|
||||
/*! User data stored in the returned gsupc->data, as context for the callbacks. */
|
||||
void *data;
|
||||
/*! Marker for future extension, always pass this as false. */
|
||||
bool more;
|
||||
};
|
||||
struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx, struct osmo_gsup_client_config *config);
|
||||
|
||||
struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
|
||||
struct ipaccess_unit *ipa_dev,
|
||||
const char *ip_addr,
|
||||
|
||||
66
include/osmocom/gsupclient/gsup_peer_id.h
Normal file
66
include/osmocom/gsupclient/gsup_peer_id.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
|
||||
/*! IPA Name: Arbitrary length blob, not necessarily zero-terminated.
|
||||
* In osmo-hlr, struct hlr_subscriber is mostly used as static reference and cannot serve as talloc context, which is
|
||||
* why this is also implemented as a fixed-maximum-size buffer instead of a talloc'd arbitrary sized buffer.
|
||||
* NOTE: The length of val may be extended in the future if it becomes necessary.
|
||||
* At the time of writing, this holds IPA unit name strings of very limited length.
|
||||
*/
|
||||
struct osmo_ipa_name {
|
||||
size_t len;
|
||||
uint8_t val[128];
|
||||
};
|
||||
|
||||
bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name);
|
||||
int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len);
|
||||
int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...);
|
||||
int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b);
|
||||
const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_name);
|
||||
const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name);
|
||||
|
||||
enum osmo_gsup_peer_id_type {
|
||||
OSMO_GSUP_PEER_ID_EMPTY=0,
|
||||
OSMO_GSUP_PEER_ID_IPA_NAME,
|
||||
/* OSMO_GSUP_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */
|
||||
};
|
||||
|
||||
extern const struct value_string osmo_gsup_peer_id_type_names[];
|
||||
static inline const char *osmo_gsup_peer_id_type_name(enum osmo_gsup_peer_id_type val)
|
||||
{ return get_value_string(osmo_gsup_peer_id_type_names, val); }
|
||||
|
||||
struct osmo_gsup_peer_id {
|
||||
enum osmo_gsup_peer_id_type type;
|
||||
union {
|
||||
struct osmo_ipa_name ipa_name;
|
||||
};
|
||||
};
|
||||
|
||||
bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id);
|
||||
int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
|
||||
const uint8_t *val, size_t len);
|
||||
int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
|
||||
const char *str_fmt, ...);
|
||||
int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b);
|
||||
const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gsup_peer_id);
|
||||
const char *osmo_gsup_peer_id_to_str_c(void *ctx, const struct osmo_gsup_peer_id *gsup_peer_id);
|
||||
115
include/osmocom/gsupclient/gsup_req.h
Normal file
115
include/osmocom/gsupclient/gsup_req.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
|
||||
struct osmo_gsup_req;
|
||||
|
||||
#define LOG_GSUP_REQ_CAT_SRC(req, subsys, level, file, line, fmt, args...) \
|
||||
LOGPSRC(subsys, level, file, line, "GSUP %u: %s: IMSI-%s %s: " fmt, \
|
||||
(req) ? (req)->nr : 0, \
|
||||
(req) ? osmo_gsup_peer_id_to_str(&(req)->source_name) : "NULL", \
|
||||
(req) ? (req)->gsup.imsi : "NULL", \
|
||||
(req) ? osmo_gsup_message_type_name((req)->gsup.message_type) : "NULL", \
|
||||
##args)
|
||||
#define LOG_GSUP_REQ_CAT(req, subsys, level, fmt, args...) \
|
||||
LOG_GSUP_REQ_CAT_SRC(req, subsys, level, __FILE__, __LINE__, fmt, ##args)
|
||||
|
||||
#define LOG_GSUP_REQ_SRC(req, level, file, line, fmt, args...) \
|
||||
LOG_GSUP_REQ_CAT_SRC(req, DLGSUP, level, file, line, fmt, ##args)
|
||||
|
||||
#define LOG_GSUP_REQ(req, level, fmt, args...) \
|
||||
LOG_GSUP_REQ_SRC(req, level, __FILE__, __LINE__, fmt, ##args)
|
||||
|
||||
typedef void (*osmo_gsup_req_send_response_t)(struct osmo_gsup_req *req, struct osmo_gsup_message *response);
|
||||
|
||||
/* Keep track of an incoming request, to route back a response when it is ready.
|
||||
* Particularly, a GSUP response to a request must contain various bits of information that need to be copied from the
|
||||
* request for proxy/routing to work and for session states to remain valid. That is the main reason why (almost) all
|
||||
* GSUP request/response should go through an osmo_gsup_req, even if it is handled synchronously.
|
||||
*/
|
||||
struct osmo_gsup_req {
|
||||
/* The incoming GSUP message in decoded form. */
|
||||
const struct osmo_gsup_message gsup;
|
||||
|
||||
/* Decoding result code. If decoding failed, this will be != 0. */
|
||||
int decode_rc;
|
||||
|
||||
/* The ultimate source of this message: the source_name form the GSUP message, or, if not present, then the
|
||||
* immediate GSUP peer. GSUP messages going via a proxy reflect the initial source in the source_name.
|
||||
* This source_name is implicitly added to the routes for the conn the message was received on. */
|
||||
struct osmo_gsup_peer_id source_name;
|
||||
|
||||
/* If the source_name is not an immediate GSUP peer, this is set to the closest intermediate peer between here
|
||||
* and source_name. */
|
||||
struct osmo_gsup_peer_id via_proxy;
|
||||
|
||||
/* Identify this request by number, for logging. */
|
||||
unsigned int nr;
|
||||
|
||||
/* osmo_gsup_req can be used by both gsup_server and gsup_client. The individual method of actually sending a
|
||||
* GSUP message is provided by this callback. */
|
||||
osmo_gsup_req_send_response_t send_response_cb;
|
||||
|
||||
/* User supplied data pointer, may be used to provide context to send_response_cb(). */
|
||||
void *cb_data;
|
||||
|
||||
/* List entry that can be used to keep a list of osmo_gsup_req instances; not used directly by osmo_gsup_req.c,
|
||||
* it is up to using implementations to keep a list. If this is non-NULL, osmo_gsup_req_free() calls
|
||||
* llist_del() on this. */
|
||||
struct llist_head entry;
|
||||
|
||||
/* A decoded GSUP message still points into the received msgb. For a decoded osmo_gsup_message to remain valid,
|
||||
* we also need to keep the msgb. */
|
||||
struct msgb *msg;
|
||||
};
|
||||
|
||||
struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_id *from_peer, struct msgb *msg,
|
||||
osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
|
||||
struct llist_head *add_to_list);
|
||||
void osmo_gsup_req_free(struct osmo_gsup_req *req);
|
||||
|
||||
/*! Call _osmo_gsup_req_respond() to convey the sender's source file and line in the logs. */
|
||||
#define osmo_gsup_req_respond(REQ, RESPONSE, ERROR, FINAL_RESPONSE) \
|
||||
_osmo_gsup_req_respond(REQ, RESPONSE, ERROR, FINAL_RESPONSE, __FILE__, __LINE__)
|
||||
int _osmo_gsup_req_respond(struct osmo_gsup_req *req, struct osmo_gsup_message *response,
|
||||
bool error, bool final_response, const char *file, int line);
|
||||
|
||||
/*! Call _osmo_gsup_req_respond_msgt() to convey the sender's source file and line in the logs. */
|
||||
#define osmo_gsup_req_respond_msgt(REQ, MESSAGE_TYPE, FINAL_RESPONSE) \
|
||||
_osmo_gsup_req_respond_msgt(REQ, MESSAGE_TYPE, FINAL_RESPONSE, __FILE__, __LINE__)
|
||||
int _osmo_gsup_req_respond_msgt(struct osmo_gsup_req *req, enum osmo_gsup_message_type message_type,
|
||||
bool final_response, const char *file, int line);
|
||||
|
||||
/*! Log an error message, and call _osmo_gsup_req_respond() to convey the sender's source file and line in the logs. */
|
||||
#define osmo_gsup_req_respond_err(REQ, CAUSE, FMT, args...) do { \
|
||||
LOG_GSUP_REQ(REQ, LOGL_ERROR, "%s: " FMT "\n", \
|
||||
get_value_string(gsm48_gmm_cause_names, CAUSE), ##args); \
|
||||
_osmo_gsup_req_respond_err(REQ, CAUSE, __FILE__, __LINE__); \
|
||||
} while(0)
|
||||
void _osmo_gsup_req_respond_err(struct osmo_gsup_req *req, enum gsm48_gmm_cause cause,
|
||||
const char *file, int line);
|
||||
|
||||
int osmo_gsup_make_response(struct osmo_gsup_message *reply,
|
||||
const struct osmo_gsup_message *rx, bool error, bool final_response);
|
||||
|
||||
size_t osmo_gsup_message_to_str_buf(char *buf, size_t bufsize, const struct osmo_gsup_message *msg);
|
||||
char *osmo_gsup_message_to_str_c(void *ctx, const struct osmo_gsup_message *msg);
|
||||
22
include/osmocom/hlr/Makefile.am
Normal file
22
include/osmocom/hlr/Makefile.am
Normal file
@@ -0,0 +1,22 @@
|
||||
noinst_HEADERS = \
|
||||
auc.h \
|
||||
ctrl.h \
|
||||
db.h \
|
||||
dgsm.h \
|
||||
gsup_router.h \
|
||||
gsup_server.h \
|
||||
hlr.h \
|
||||
hlr_ussd.h \
|
||||
hlr_vty.h \
|
||||
hlr_vty_subscr.h \
|
||||
logging.h \
|
||||
lu_fsm.h \
|
||||
mslookup_server.h \
|
||||
mslookup_server_mdns.h \
|
||||
proxy.h \
|
||||
proxy_mm.h \
|
||||
proxy_db.h \
|
||||
rand.h \
|
||||
remote_hlr.h \
|
||||
timestamp.h \
|
||||
$(NULL)
|
||||
@@ -3,14 +3,19 @@
|
||||
#include <stdbool.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
struct hlr;
|
||||
|
||||
enum stmt_idx {
|
||||
DB_STMT_SEL_BY_IMSI,
|
||||
DB_STMT_SEL_BY_MSISDN,
|
||||
DB_STMT_SEL_BY_ID,
|
||||
DB_STMT_SEL_BY_IMEI,
|
||||
DB_STMT_UPD_VLR_BY_ID,
|
||||
DB_STMT_UPD_SGSN_BY_ID,
|
||||
DB_STMT_UPD_IMEI_BY_IMSI,
|
||||
DB_STMT_AUC_BY_IMSI,
|
||||
DB_STMT_AUC_UPD_SQN,
|
||||
DB_STMT_UPD_PURGE_CS_BY_IMSI,
|
||||
@@ -26,6 +31,12 @@ enum stmt_idx {
|
||||
DB_STMT_AUC_3G_INSERT,
|
||||
DB_STMT_AUC_3G_DELETE,
|
||||
DB_STMT_SET_LAST_LU_SEEN,
|
||||
DB_STMT_SET_LAST_LU_SEEN_PS,
|
||||
DB_STMT_EXISTS_BY_IMSI,
|
||||
DB_STMT_EXISTS_BY_MSISDN,
|
||||
DB_STMT_IND_ADD,
|
||||
DB_STMT_IND_SELECT,
|
||||
DB_STMT_IND_DEL,
|
||||
_NUM_DB_STMT
|
||||
};
|
||||
|
||||
@@ -35,10 +46,16 @@ struct db_context {
|
||||
sqlite3_stmt *stmt[_NUM_DB_STMT];
|
||||
};
|
||||
|
||||
/* Optional feature to make SQLite3 using talloc */
|
||||
#ifdef SQLITE_USE_TALLOC
|
||||
int db_sqlite3_use_talloc(void *ctx);
|
||||
#endif
|
||||
|
||||
void db_remove_reset(sqlite3_stmt *stmt);
|
||||
bool db_bind_text(sqlite3_stmt *stmt, const char *param_name, const char *text);
|
||||
bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
|
||||
bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
|
||||
bool db_bind_null(sqlite3_stmt *stmt, const char *param_name);
|
||||
void db_close(struct db_context *dbc);
|
||||
struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite3_logging, bool allow_upgrades);
|
||||
|
||||
@@ -56,7 +73,7 @@ int db_update_sqn(struct db_context *dbc, int64_t id,
|
||||
int db_get_auc(struct db_context *dbc, const char *imsi,
|
||||
unsigned int auc_3g_ind, struct osmo_auth_vector *vec,
|
||||
unsigned int num_vec, const uint8_t *rand_auts,
|
||||
const uint8_t *auts);
|
||||
const uint8_t *auts, bool separation_bit);
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/gsm/protocol/gsm_23_003.h>
|
||||
@@ -69,8 +86,9 @@ struct hlr_subscriber {
|
||||
|
||||
int64_t id;
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
|
||||
char msisdn[GT_MAX_DIGITS+1];
|
||||
char msisdn[GSM23003_MSISDN_MAX_DIGITS+1];
|
||||
/* imeisv? */
|
||||
char imei[GSM23003_IMEI_NUM_DIGITS+1];
|
||||
char vlr_number[32];
|
||||
char sgsn_number[32];
|
||||
char sgsn_address[GT_MAX_DIGITS+1];
|
||||
@@ -85,6 +103,10 @@ struct hlr_subscriber {
|
||||
bool ms_purged_cs;
|
||||
bool ms_purged_ps;
|
||||
time_t last_lu_seen;
|
||||
time_t last_lu_seen_ps;
|
||||
/* talloc'd IPA unit name */
|
||||
struct osmo_ipa_name vlr_via_proxy;
|
||||
struct osmo_ipa_name sgsn_via_proxy;
|
||||
};
|
||||
|
||||
/* A format string for use with strptime(3). This format string is
|
||||
@@ -115,13 +137,20 @@ struct sub_auth_data_str {
|
||||
} u;
|
||||
};
|
||||
|
||||
int db_subscr_create(struct db_context *dbc, const char *imsi);
|
||||
#define DB_SUBSCR_FLAG_NAM_CS (1 << 1)
|
||||
#define DB_SUBSCR_FLAG_NAM_PS (1 << 2)
|
||||
|
||||
int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags);
|
||||
int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id);
|
||||
|
||||
int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi,
|
||||
const char *msisdn);
|
||||
int db_subscr_update_aud_by_id(struct db_context *dbc, int64_t subscr_id,
|
||||
const struct sub_auth_data_str *aud);
|
||||
int db_subscr_update_imei_by_imsi(struct db_context *dbc, const char* imsi, const char *imei);
|
||||
|
||||
int db_subscr_exists_by_imsi(struct db_context *dbc, const char *imsi);
|
||||
int db_subscr_exists_by_msisdn(struct db_context *dbc, const char *msisdn);
|
||||
|
||||
int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
|
||||
struct hlr_subscriber *subscr);
|
||||
@@ -129,14 +158,17 @@ int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
|
||||
struct hlr_subscriber *subscr);
|
||||
int db_subscr_get_by_id(struct db_context *dbc, int64_t id,
|
||||
struct hlr_subscriber *subscr);
|
||||
int db_subscr_get_by_imei(struct db_context *dbc, const char *imei, struct hlr_subscriber *subscr);
|
||||
int db_subscr_nam(struct db_context *dbc, const char *imsi, bool nam_val, bool is_ps);
|
||||
int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
const char *vlr_or_sgsn_number, bool is_ps);
|
||||
const struct osmo_ipa_name *vlr_name, bool is_ps,
|
||||
const struct osmo_ipa_name *via_proxy);
|
||||
|
||||
int db_subscr_purge(struct db_context *dbc, const char *by_imsi,
|
||||
bool purge_val, bool is_ps);
|
||||
|
||||
int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val, bool is_ps);
|
||||
int db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr, unsigned int *ind);
|
||||
int db_ind_del(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr);
|
||||
|
||||
/*! Call sqlite3_column_text() and copy result to a char[].
|
||||
* \param[out] buf A char[] used as sizeof() arg(!) and osmo_strlcpy() target.
|
||||
@@ -148,3 +180,14 @@ int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val,
|
||||
const char *_txt = (const char *) sqlite3_column_text(stmt, idx); \
|
||||
osmo_strlcpy(buf, _txt, sizeof(buf)); \
|
||||
} while (0)
|
||||
|
||||
/*! Call sqlite3_column_text() and copy result to a struct osmo_ipa_name.
|
||||
* \param[out] ipa_name A struct osmo_ipa_name* to write to.
|
||||
* \param[in] stmt An sqlite3_stmt*.
|
||||
* \param[in] idx Index in stmt's returned columns.
|
||||
*/
|
||||
#define copy_sqlite3_text_to_ipa_name(ipa_name, stmt, idx) \
|
||||
do { \
|
||||
const char *_txt = (const char *) sqlite3_column_text(stmt, idx); \
|
||||
osmo_ipa_name_set_str(ipa_name, _txt); \
|
||||
} while (0)
|
||||
46
include/osmocom/hlr/dgsm.h
Normal file
46
include/osmocom/hlr/dgsm.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/mslookup/mslookup.h>
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/gsupclient/gsup_req.h>
|
||||
|
||||
#define LOG_DGSM(imsi, level, fmt, args...) \
|
||||
LOGP(DDGSM, level, "(IMSI-%s) " fmt, imsi, ##args)
|
||||
|
||||
struct vty;
|
||||
struct remote_hlr;
|
||||
struct hlr_subscriber;
|
||||
|
||||
extern void *dgsm_ctx;
|
||||
|
||||
void dgsm_init(void *ctx);
|
||||
void dgsm_start(void *ctx);
|
||||
void dgsm_stop();
|
||||
|
||||
bool dgsm_check_forward_gsup_msg(struct osmo_gsup_req *req);
|
||||
|
||||
void dgsm_vty_init();
|
||||
void dgsm_mdns_client_config_apply(void);
|
||||
|
||||
bool hlr_subscr_lu_age(const struct hlr_subscriber *subscr, uint32_t *age_p);
|
||||
33
include/osmocom/hlr/gsup_router.h
Normal file
33
include/osmocom/hlr/gsup_router.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
|
||||
struct osmo_ipa_name;
|
||||
|
||||
struct gsup_route {
|
||||
struct llist_head list;
|
||||
|
||||
uint8_t *addr;
|
||||
struct osmo_gsup_conn *conn;
|
||||
};
|
||||
|
||||
struct osmo_gsup_conn *gsup_route_find(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen);
|
||||
struct osmo_gsup_conn *gsup_route_find_by_ipa_name(struct osmo_gsup_server *gs, const struct osmo_ipa_name *ipa_name);
|
||||
|
||||
struct gsup_route *gsup_route_find_by_conn(const struct osmo_gsup_conn *conn);
|
||||
|
||||
/* add a new route for the given address to the given conn */
|
||||
int gsup_route_add_ipa_name(struct osmo_gsup_conn *conn, const struct osmo_ipa_name *ipa_name);
|
||||
int gsup_route_add(struct osmo_gsup_conn *conn, const uint8_t *addr, size_t addrlen);
|
||||
|
||||
/* delete all routes for the given connection */
|
||||
int gsup_route_del_conn(struct osmo_gsup_conn *conn);
|
||||
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg);
|
||||
int osmo_gsup_send_to_ipa_name(struct osmo_gsup_server *gs, const struct osmo_ipa_name *ipa_name, struct msgb *msg);
|
||||
int osmo_gsup_enc_send_to_ipa_name(struct osmo_gsup_server *gs, const struct osmo_ipa_name *ipa_name,
|
||||
const struct osmo_gsup_message *gsup);
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <osmocom/abis/ipa.h>
|
||||
#include <osmocom/abis/ipaccess.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/gsupclient/gsup_req.h>
|
||||
|
||||
#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN
|
||||
#define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN 43 /* TS 24.008 10.5.4.7 */
|
||||
@@ -22,12 +24,12 @@ struct osmo_gsup_server {
|
||||
/* list of osmo_gsup_conn */
|
||||
struct llist_head clients;
|
||||
|
||||
/* lu_operations list */
|
||||
struct llist_head *luop;
|
||||
|
||||
struct ipa_server_link *link;
|
||||
osmo_gsup_read_cb_t read_cb;
|
||||
struct llist_head routes;
|
||||
|
||||
/* Proxy requests from this server's clients to remote GSUP servers. */
|
||||
struct proxy *proxy;
|
||||
};
|
||||
|
||||
|
||||
@@ -45,9 +47,15 @@ struct osmo_gsup_conn {
|
||||
/* Set when Location Update is received: */
|
||||
bool supports_cs; /* client supports OSMO_GSUP_CN_DOMAIN_CS */
|
||||
bool supports_ps; /* client supports OSMO_GSUP_CN_DOMAIN_PS */
|
||||
|
||||
/* The IPA unit name received on this link. Routes with more unit names serviced by this link may exist in
|
||||
* osmo_gsup_server->routes, but this is the name the immediate peer identified as in the IPA handshake. */
|
||||
struct osmo_ipa_name peer_name;
|
||||
};
|
||||
|
||||
struct msgb *osmo_gsup_msgb_alloc(const char *label);
|
||||
|
||||
struct osmo_gsup_req *osmo_gsup_conn_rx(struct osmo_gsup_conn *conn, struct msgb *msg);
|
||||
int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg);
|
||||
int osmo_gsup_conn_ccm_get(const struct osmo_gsup_conn *clnt, uint8_t **addr,
|
||||
uint8_t tag);
|
||||
@@ -56,7 +64,6 @@ struct osmo_gsup_server *osmo_gsup_server_create(void *ctx,
|
||||
const char *ip_addr,
|
||||
uint16_t tcp_port,
|
||||
osmo_gsup_read_cb_t read_cb,
|
||||
struct llist_head *lu_op_lst,
|
||||
void *priv);
|
||||
|
||||
void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups);
|
||||
@@ -67,3 +74,5 @@ int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup,
|
||||
uint8_t *msisdn_enc, size_t msisdn_enc_size,
|
||||
uint8_t *apn_buf, size_t apn_buf_size,
|
||||
enum osmo_gsup_cn_domain cn_domain);
|
||||
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_gsup_peer_id *to_peer,
|
||||
struct osmo_gsup_req *req, struct osmo_gsup_message *modified_gsup);
|
||||
121
include/osmocom/hlr/hlr.h
Normal file
121
include/osmocom/hlr/hlr.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/* OsmoHLR generic header */
|
||||
|
||||
/* (C) 2017 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* Author: Max Suraev <msuraev@sysmocom.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/gsm/ipa.h>
|
||||
#include <osmocom/core/tdef.h>
|
||||
#include <osmocom/core/sockaddr_str.h>
|
||||
|
||||
#include <osmocom/hlr/dgsm.h>
|
||||
|
||||
#define HLR_DEFAULT_DB_FILE_PATH "hlr.db"
|
||||
|
||||
struct hlr_euse;
|
||||
struct osmo_gsup_conn;
|
||||
enum osmo_gsup_message_type;
|
||||
|
||||
extern struct osmo_tdef g_hlr_tdefs[];
|
||||
|
||||
struct hlr {
|
||||
/* GSUP server pointer */
|
||||
struct osmo_gsup_server *gs;
|
||||
|
||||
/* DB context */
|
||||
char *db_file_path;
|
||||
struct db_context *dbc;
|
||||
|
||||
/* Control Interface */
|
||||
struct ctrl_handle *ctrl;
|
||||
const char *ctrl_bind_addr;
|
||||
|
||||
/* Local bind addr */
|
||||
char *gsup_bind_addr;
|
||||
struct ipaccess_unit gsup_unit_name;
|
||||
|
||||
struct llist_head euse_list;
|
||||
struct hlr_euse *euse_default;
|
||||
|
||||
/* NCSS (call independent) session guard timeout value */
|
||||
int ncss_guard_timeout;
|
||||
|
||||
struct llist_head ussd_routes;
|
||||
|
||||
struct llist_head ss_sessions;
|
||||
|
||||
bool store_imei;
|
||||
|
||||
bool subscr_create_on_demand;
|
||||
/* Bitmask of DB_SUBSCR_FLAG_* */
|
||||
uint8_t subscr_create_on_demand_flags;
|
||||
unsigned int subscr_create_on_demand_rand_msisdn_len;
|
||||
|
||||
struct {
|
||||
bool allow_startup;
|
||||
struct {
|
||||
/* Whether the mslookup server should be active in general (all lookup methods) */
|
||||
bool enable;
|
||||
uint32_t local_attach_max_age;
|
||||
struct llist_head local_site_services;
|
||||
struct {
|
||||
/* Whether the mDNS method of the mslookup server should be active. */
|
||||
bool enable;
|
||||
/* The mDNS bind address and domain suffix as set by the VTY, not necessarily in use. */
|
||||
struct osmo_sockaddr_str bind_addr;
|
||||
char *domain_suffix;
|
||||
struct osmo_mslookup_server_mdns *running;
|
||||
} mdns;
|
||||
} server;
|
||||
|
||||
/* The mslookup client in osmo-hlr is used to find out which remote HLRs service a locally unknown IMSI.
|
||||
* (It may also be used to resolve recipients for SMS-over-GSUP in the future.) */
|
||||
struct {
|
||||
/* Whether to proxy/forward to remote HLRs */
|
||||
bool enable;
|
||||
|
||||
/* If this is set, all GSUP for unknown IMSIs is forwarded directly to this GSUP address,
|
||||
* unconditionally. */
|
||||
struct osmo_sockaddr_str gsup_gateway_proxy;
|
||||
|
||||
/* mslookup client request handling */
|
||||
unsigned int result_timeout_milliseconds;
|
||||
|
||||
struct osmo_mslookup_client *client;
|
||||
struct {
|
||||
/* Whether to use mDNS for IMSI MS Lookup */
|
||||
bool enable;
|
||||
struct osmo_sockaddr_str query_addr;
|
||||
char *domain_suffix;
|
||||
struct osmo_mslookup_client_method *running;
|
||||
} mdns;
|
||||
} client;
|
||||
} mslookup;
|
||||
};
|
||||
|
||||
extern struct hlr *g_hlr;
|
||||
|
||||
struct hlr_subscriber;
|
||||
|
||||
void osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr);
|
||||
int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val, bool is_ps);
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
#include "gsup_server.h"
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
|
||||
#define NCSS_GUARD_TIMEOUT_DEFAULT 30
|
||||
|
||||
@@ -46,8 +46,8 @@ struct hlr_ussd_route *ussd_route_prefix_alloc_ext(struct hlr *hlr, const char *
|
||||
struct hlr_euse *euse);
|
||||
void ussd_route_del(struct hlr_ussd_route *rt);
|
||||
|
||||
int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup);
|
||||
int rx_proc_ss_error(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup);
|
||||
void rx_proc_ss_req(struct osmo_gsup_req *req);
|
||||
void rx_proc_ss_error(struct osmo_gsup_req *req);
|
||||
|
||||
struct ss_session;
|
||||
struct ss_request;
|
||||
@@ -56,6 +56,5 @@ struct ss_request;
|
||||
struct hlr_iuse {
|
||||
const char *name;
|
||||
/* call-back to be called for any incoming USSD messages for this IUSE */
|
||||
int (*handle_ussd)(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
const struct osmo_gsup_message *gsup, const struct ss_request *req);
|
||||
int (*handle_ussd)(struct ss_session *ss, const struct osmo_gsup_message *gsup, const struct ss_request *req);
|
||||
};
|
||||
@@ -25,14 +25,19 @@
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/vty/vty.h>
|
||||
#include <osmocom/vty/command.h>
|
||||
#include "hlr.h"
|
||||
#include <osmocom/hlr/hlr.h>
|
||||
|
||||
enum hlr_vty_node {
|
||||
HLR_NODE = _LAST_OSMOVTY_NODE + 1,
|
||||
GSUP_NODE,
|
||||
EUSE_NODE,
|
||||
MSLOOKUP_NODE,
|
||||
MSLOOKUP_SERVER_NODE,
|
||||
MSLOOKUP_SERVER_MSC_NODE,
|
||||
MSLOOKUP_CLIENT_NODE,
|
||||
};
|
||||
|
||||
int hlr_vty_is_config_node(struct vty *vty, int node);
|
||||
int hlr_vty_go_parent(struct vty *vty);
|
||||
void hlr_vty_init(const struct log_info *cat);
|
||||
void hlr_vty_init(void);
|
||||
void dgsm_vty_init(void);
|
||||
@@ -8,6 +8,9 @@ enum {
|
||||
DGSUP,
|
||||
DAUC,
|
||||
DSS,
|
||||
DMSLOOKUP,
|
||||
DLU,
|
||||
DDGSM,
|
||||
};
|
||||
|
||||
extern const struct log_info hlr_log_info;
|
||||
22
include/osmocom/hlr/lu_fsm.h
Normal file
22
include/osmocom/hlr/lu_fsm.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void lu_rx_gsup(struct osmo_gsup_req *req);
|
||||
72
include/osmocom/hlr/mslookup_server.h
Normal file
72
include/osmocom/hlr/mslookup_server.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/mslookup/mslookup.h>
|
||||
|
||||
struct osmo_mslookup_query;
|
||||
struct osmo_mslookup_result;
|
||||
|
||||
/*! mslookup service name used for roaming/proxying between osmo-hlr instances. */
|
||||
#define OSMO_MSLOOKUP_SERVICE_HLR_GSUP "gsup.hlr"
|
||||
|
||||
/*! What addresses to return to mslookup queries when a subscriber is attached at the local site.
|
||||
* Mapping of service name to IP address and port. This corresponds to the VTY config for
|
||||
* 'mslookup' / 'server' [/ 'msc MSC-1-2-3'] / 'service sip.voice at 1.2.3.4 1234'.
|
||||
*/
|
||||
struct mslookup_service_host {
|
||||
struct llist_head entry;
|
||||
char service[OSMO_MSLOOKUP_SERVICE_MAXLEN+1];
|
||||
struct osmo_sockaddr_str host_v4;
|
||||
struct osmo_sockaddr_str host_v6;
|
||||
};
|
||||
|
||||
/*! Sets of mslookup_service_host per connected MSC.
|
||||
* When there are more than one MSC connected to this osmo-hlr, this allows keeping separate sets of service addresses
|
||||
* for each MSC. The entry with mslookup_server_msc_wildcard as MSC name is used for all MSCs (if no match for that
|
||||
* particular MSC is found). This corresponds to the VTY config for
|
||||
* 'mslookup' / 'server' / 'msc MSC-1-2-3'.
|
||||
*/
|
||||
struct mslookup_server_msc_cfg {
|
||||
struct llist_head entry;
|
||||
struct osmo_ipa_name name;
|
||||
struct llist_head service_hosts;
|
||||
};
|
||||
|
||||
struct mslookup_service_host *mslookup_server_service_get(const struct osmo_ipa_name *msc_name, const char *service);
|
||||
|
||||
struct mslookup_service_host *mslookup_server_msc_service_get(struct mslookup_server_msc_cfg *msc, const char *service,
|
||||
bool create);
|
||||
int mslookup_server_msc_service_set(struct mslookup_server_msc_cfg *msc, const char *service,
|
||||
const struct osmo_sockaddr_str *addr);
|
||||
int mslookup_server_msc_service_del(struct mslookup_server_msc_cfg *msc, const char *service,
|
||||
const struct osmo_sockaddr_str *addr);
|
||||
|
||||
extern const struct osmo_ipa_name mslookup_server_msc_wildcard;
|
||||
struct mslookup_server_msc_cfg *mslookup_server_msc_get(const struct osmo_ipa_name *msc_name, bool create);
|
||||
|
||||
const struct mslookup_service_host *mslookup_server_get_local_gsup_addr();
|
||||
void mslookup_server_rx(const struct osmo_mslookup_query *query,
|
||||
struct osmo_mslookup_result *result);
|
||||
|
||||
bool subscriber_has_done_lu_here(const struct osmo_mslookup_query *query,
|
||||
uint32_t *lu_age_p, struct osmo_ipa_name *local_msc_name,
|
||||
char *ret_imsi, size_t ret_imsi_len);
|
||||
36
include/osmocom/hlr/mslookup_server_mdns.h
Normal file
36
include/osmocom/hlr/mslookup_server_mdns.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <osmocom/core/sockaddr_str.h>
|
||||
#include <osmocom/mslookup/mdns_sock.h>
|
||||
|
||||
struct osmo_mslookup_server_mdns {
|
||||
struct osmo_mslookup_server *mslookup;
|
||||
struct osmo_sockaddr_str bind_addr;
|
||||
char *domain_suffix;
|
||||
struct osmo_mdns_sock *sock;
|
||||
};
|
||||
|
||||
struct osmo_mslookup_server_mdns *osmo_mslookup_server_mdns_start(void *ctx, const struct osmo_sockaddr_str *bind_addr,
|
||||
const char *domain_suffix);
|
||||
void osmo_mslookup_server_mdns_stop(struct osmo_mslookup_server_mdns *server);
|
||||
void mslookup_server_mdns_config_apply();
|
||||
100
include/osmocom/hlr/proxy.h
Normal file
100
include/osmocom/hlr/proxy.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
#include <osmocom/core/sockaddr_str.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/timer.h>
|
||||
#include <osmocom/gsm/protocol/gsm_23_003.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/hlr/timestamp.h>
|
||||
|
||||
struct osmo_gsup_req;
|
||||
struct remote_hlr;
|
||||
|
||||
struct proxy {
|
||||
struct llist_head subscr_list;
|
||||
struct llist_head pending_gsup_reqs;
|
||||
|
||||
/* When messages arrive back from a remote HLR that this is the proxy for, reach the VLR to forward the response
|
||||
* to via this osmo_gsup_server. */
|
||||
struct osmo_gsup_server *gsup_server_to_vlr;
|
||||
|
||||
/* How long to keep proxy entries without a refresh, in seconds. */
|
||||
uint32_t fresh_time;
|
||||
|
||||
/* How often to garbage collect the proxy cache, period in seconds.
|
||||
* To change this and take effect immediately, rather use proxy_set_gc_period(). */
|
||||
uint32_t gc_period;
|
||||
|
||||
struct osmo_timer_list gc_timer;
|
||||
};
|
||||
|
||||
struct proxy_subscr_domain_state {
|
||||
struct osmo_ipa_name vlr_name;
|
||||
timestamp_t last_lu;
|
||||
|
||||
/* The name from which an Update Location Request was received. Copied to vlr_name as soon as the LU is
|
||||
* completed successfully. */
|
||||
struct osmo_ipa_name vlr_name_preliminary;
|
||||
|
||||
/* Set if this is a middle proxy, i.e. a proxy behind another proxy.
|
||||
* That is mostly to know whether the MS is attached at a local MSC/SGSN or further away.
|
||||
* It could be a boolean, but store the full name for logging. Set only at successful LU acceptance. */
|
||||
struct osmo_ipa_name vlr_via_proxy;
|
||||
};
|
||||
|
||||
struct proxy_subscr {
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
|
||||
char msisdn[GSM23003_MSISDN_MAX_DIGITS+1];
|
||||
struct osmo_sockaddr_str remote_hlr_addr;
|
||||
struct proxy_subscr_domain_state cs, ps;
|
||||
struct osmo_fsm_inst *mm_fi;
|
||||
struct osmo_fsm_inst *to_home_fi;
|
||||
};
|
||||
|
||||
void proxy_init(struct osmo_gsup_server *gsup_server_to_vlr);
|
||||
void proxy_del(struct proxy *proxy);
|
||||
void proxy_set_gc_period(struct proxy *proxy, uint32_t gc_period);
|
||||
|
||||
/* The API to access / modify proxy entries keeps the implementation opaque, to make sure that we can easily move proxy
|
||||
* storage to SQLite db. */
|
||||
int proxy_subscr_get_by_imsi(struct proxy_subscr *dst, struct proxy *proxy, const char *imsi);
|
||||
int proxy_subscr_get_by_msisdn(struct proxy_subscr *dst, struct proxy *proxy, const char *msisdn);
|
||||
void proxy_subscrs_get_by_remote_hlr(struct proxy *proxy, const struct osmo_sockaddr_str *remote_hlr_addr,
|
||||
bool (*yield)(struct proxy *proxy, const struct proxy_subscr *subscr, void *data),
|
||||
void *data);
|
||||
int proxy_subscr_create_or_update(struct proxy *proxy, const struct proxy_subscr *proxy_subscr);
|
||||
int proxy_subscr_del(struct proxy *proxy, const char *imsi);
|
||||
|
||||
int proxy_subscr_forward_to_remote_hlr(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
|
||||
struct osmo_gsup_req *req);
|
||||
void proxy_subscr_forward_to_remote_hlr_resolved(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
|
||||
struct remote_hlr *remote_hlr, struct osmo_gsup_req *req);
|
||||
|
||||
int proxy_subscr_forward_to_vlr(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
|
||||
const struct osmo_gsup_message *gsup, struct remote_hlr *from_remote_hlr);
|
||||
|
||||
void proxy_subscr_remote_hlr_resolved(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
|
||||
const struct osmo_sockaddr_str *remote_hlr_addr);
|
||||
void proxy_subscr_remote_hlr_up(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
|
||||
struct remote_hlr *remote_hlr);
|
||||
37
include/osmocom/hlr/proxy_broken_link_cache.h
Normal file
37
include/osmocom/hlr/proxy_broken_link_cache.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* Author: Neels Hofmeyr <neels@hofmeyr.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* If a subscriber from a remote site has successfully attached at this local site, and the link to the subscriber's
|
||||
* home HLR has succeeded, this will try to bridge the time of temporary link failure to that home HLR.
|
||||
* Tasks to take over from the unreachable home HLR:
|
||||
* - Resend known auth tuples on OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST.
|
||||
* - ...?
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* Data stored per subscriber */
|
||||
struct proxy_broken_link_cache {
|
||||
struct osmo_auth_vector auth_vectors[OSMO_GSUP_MAX_NUM_AUTH_INFO];
|
||||
size_t num_auth_vectors;
|
||||
|
||||
timestamp_t last_update;
|
||||
};
|
||||
54
include/osmocom/hlr/proxy_mm.h
Normal file
54
include/osmocom/hlr/proxy_mm.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/hlr/proxy.h>
|
||||
|
||||
enum proxy_mm_fsm_event {
|
||||
PROXY_MM_EV_SUBSCR_INVALID,
|
||||
PROXY_MM_EV_RX_GSUP_LU,
|
||||
PROXY_MM_EV_RX_GSUP_SAI,
|
||||
PROXY_MM_EV_RX_SUBSCR_DATA,
|
||||
PROXY_MM_EV_RX_GSUP_ISD_RESULT,
|
||||
PROXY_MM_EV_RX_AUTH_TUPLES,
|
||||
};
|
||||
|
||||
enum proxy_to_home_fsm_event {
|
||||
PROXY_TO_HOME_EV_HOME_HLR_RESOLVED,
|
||||
PROXY_TO_HOME_EV_RX_INSERT_SUBSCRIBER_DATA_REQ,
|
||||
PROXY_TO_HOME_EV_RX_UPDATE_LOCATION_RESULT,
|
||||
PROXY_TO_HOME_EV_RX_SEND_AUTH_INFO_RESULT,
|
||||
PROXY_TO_HOME_EV_CHECK_TUPLES,
|
||||
PROXY_TO_HOME_EV_CONFIRM_LU,
|
||||
};
|
||||
|
||||
extern struct llist_head proxy_mm_list;
|
||||
|
||||
struct proxy_mm_auth_cache {
|
||||
struct llist_head entry;
|
||||
uint64_t db_id;
|
||||
struct osmo_auth_vector auth_vectors[OSMO_GSUP_MAX_NUM_AUTH_INFO];
|
||||
size_t num_auth_vectors;
|
||||
unsigned int sent_to_vlr_count;
|
||||
};
|
||||
|
||||
struct proxy_mm {
|
||||
struct llist_head entry;
|
||||
struct osmo_gsup_peer_id vlr_name;
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
|
||||
bool is_ps;
|
||||
struct osmo_fsm_inst *mm_fi;
|
||||
struct osmo_fsm_inst *to_home_fi;
|
||||
struct llist_head auth_cache;
|
||||
};
|
||||
|
||||
struct proxy_mm *proxy_mm_alloc(const struct osmo_gsup_peer_id *vlr_name,
|
||||
bool is_ps,
|
||||
const char *imsi);
|
||||
|
||||
void proxy_mm_add_auth_vectors(struct proxy_mm *proxy_mm,
|
||||
const struct osmo_auth_vector *auth_vectors, size_t num_auth_vectors);
|
||||
struct proxy_mm_auth_cache *proxy_mm_get_auth_vectors(struct proxy_mm *proxy_mm);
|
||||
void proxy_mm_use_auth_vectors(struct proxy_mm *proxy_mm, struct proxy_mm_auth_cache *ac);
|
||||
void proxy_mm_discard_auth_vectors(struct proxy_mm *proxy_mm, struct proxy_mm_auth_cache *ac);
|
||||
|
||||
bool proxy_mm_subscriber_data_known(const struct proxy_mm *proxy_mm);
|
||||
59
include/osmocom/hlr/remote_hlr.h
Normal file
59
include/osmocom/hlr/remote_hlr.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/sockaddr_str.h>
|
||||
|
||||
struct osmo_gsup_client;
|
||||
struct osmo_gsup_message;
|
||||
struct osmo_gsup_req;
|
||||
struct msgb;
|
||||
|
||||
#define LOG_REMOTE_HLR(remote_hlr, level, fmt, args...) \
|
||||
LOGP(DDGSM, level, "(Proxy HLR-" OSMO_SOCKADDR_STR_FMT ") " fmt, \
|
||||
OSMO_SOCKADDR_STR_FMT_ARGS((remote_hlr) ? &(remote_hlr)->addr : NULL), ##args)
|
||||
|
||||
#define LOG_REMOTE_HLR_MSG(remote_hlr, gsup_msg, level, fmt, args...) \
|
||||
LOG_REMOTE_HLR(remote_hlr, level, "%s: " fmt, osmo_gsup_message_type_name((gsup_msg)->message_type), ##args)
|
||||
|
||||
/* GSUP client link for proxying to a remote HLR. */
|
||||
struct remote_hlr {
|
||||
struct llist_head entry;
|
||||
struct osmo_sockaddr_str addr;
|
||||
struct osmo_gsup_client *gsupc;
|
||||
struct llist_head pending_up_callbacks;
|
||||
};
|
||||
|
||||
/*! Receive a remote_hlr address when connecting succeeded, or remote_hlr == NULL on error.
|
||||
* \param addr GSUP IP address and port for which the connection was requested.
|
||||
* \param remote_hlr The connected remote_hlr ready for sending, or NULL if connecting failed.
|
||||
* \param data Same a passed to remote_hlr_get_or_connect(). */
|
||||
typedef void (*remote_hlr_connect_result_cb_t)(const struct osmo_sockaddr_str *addr, struct remote_hlr *remote_hlr, void *data);
|
||||
|
||||
struct remote_hlr *remote_hlr_get_or_connect(const struct osmo_sockaddr_str *addr, bool connect,
|
||||
remote_hlr_connect_result_cb_t connect_result_cb, void *data);
|
||||
void remote_hlr_destroy(struct remote_hlr *remote_hlr);
|
||||
int remote_hlr_msgb_send(struct remote_hlr *remote_hlr, struct msgb *msg);
|
||||
void remote_hlr_gsup_forward_to_remote_hlr(struct remote_hlr *remote_hlr, struct osmo_gsup_req *req,
|
||||
struct osmo_gsup_message *modified_gsup);
|
||||
|
||||
bool remote_hlr_is_up(struct remote_hlr *remote_hlr);
|
||||
28
include/osmocom/hlr/timestamp.h
Normal file
28
include/osmocom/hlr/timestamp.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef time_t timestamp_t;
|
||||
void timestamp_update(timestamp_t *timestamp);
|
||||
bool timestamp_age(const timestamp_t *timestamp, uint32_t *age);
|
||||
6
include/osmocom/mslookup/Makefile.am
Normal file
6
include/osmocom/mslookup/Makefile.am
Normal file
@@ -0,0 +1,6 @@
|
||||
# most headers here are installed, see /include/Makefile.am
|
||||
|
||||
noinst_HEADERS = \
|
||||
mdns_msg.h \
|
||||
mdns_rfc.h \
|
||||
$(NULL)
|
||||
39
include/osmocom/mslookup/mdns.h
Normal file
39
include/osmocom/mslookup/mdns.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! \file mdns.h */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/mslookup/mslookup.h>
|
||||
|
||||
#define OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT "mdns.osmocom.org"
|
||||
|
||||
struct msgb *osmo_mdns_query_encode(void *ctx, uint16_t packet_id, const struct osmo_mslookup_query *query,
|
||||
const char *domain_suffix);
|
||||
|
||||
struct osmo_mslookup_query *osmo_mdns_query_decode(void *ctx, const uint8_t *data, size_t data_len,
|
||||
uint16_t *packet_id, const char *domain_suffix);
|
||||
|
||||
struct msgb *osmo_mdns_result_encode(void *ctx, uint16_t packet_id, const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_result *result, const char *domain_suffix);
|
||||
|
||||
int osmo_mdns_result_decode(void *ctx, const uint8_t *data, size_t data_len, uint16_t *packet_id,
|
||||
struct osmo_mslookup_query *query, struct osmo_mslookup_result *result,
|
||||
const char *domain_suffix);
|
||||
54
include/osmocom/mslookup/mdns_msg.h
Normal file
54
include/osmocom/mslookup/mdns_msg.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mdns_rfc.h"
|
||||
|
||||
struct osmo_mdns_record {
|
||||
struct llist_head list;
|
||||
enum osmo_mdns_rfc_record_type type;
|
||||
uint16_t length;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
struct osmo_mdns_msg_request {
|
||||
uint16_t id;
|
||||
char *domain;
|
||||
enum osmo_mdns_rfc_record_type type;
|
||||
};
|
||||
|
||||
struct osmo_mdns_msg_answer {
|
||||
uint16_t id;
|
||||
char *domain;
|
||||
/*! list of osmo_mdns_record. */
|
||||
struct llist_head records;
|
||||
};
|
||||
|
||||
int osmo_mdns_msg_request_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_msg_request *req);
|
||||
struct osmo_mdns_msg_request *osmo_mdns_msg_request_decode(void *ctx, const uint8_t *data, size_t data_len);
|
||||
|
||||
void osmo_mdns_msg_answer_init(struct osmo_mdns_msg_answer *answer);
|
||||
int osmo_mdns_msg_answer_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_msg_answer *ans);
|
||||
struct osmo_mdns_msg_answer *osmo_mdns_msg_answer_decode(void *ctx, const uint8_t *data, size_t data_len);
|
||||
int osmo_mdns_result_from_answer(struct osmo_mslookup_result *result, const struct osmo_mdns_msg_answer *ans);
|
||||
|
||||
struct osmo_mdns_record *osmo_mdns_record_txt_keyval_encode(void *ctx, const char *key, const char *value_fmt, ...);
|
||||
int osmo_mdns_record_txt_keyval_decode(const struct osmo_mdns_record *rec,
|
||||
char *key_buf, size_t key_size, char *value_buf, size_t value_size);
|
||||
113
include/osmocom/mslookup/mdns_rfc.h
Normal file
113
include/osmocom/mslookup/mdns_rfc.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/endian.h>
|
||||
#include <osmocom/mslookup/mdns.h>
|
||||
|
||||
/* RFC 1035 2.3.4 */
|
||||
#define OSMO_MDNS_RFC_MAX_NAME_LEN 255
|
||||
|
||||
/* RFC 1035 3.3 <character-string> */
|
||||
#define OSMO_MDNS_RFC_MAX_CHARACTER_STRING_LEN 256
|
||||
|
||||
enum osmo_mdns_rfc_record_type {
|
||||
OSMO_MDNS_RFC_RECORD_TYPE_UNKNOWN = 0,
|
||||
|
||||
/* RFC 1035 3.2.2 */
|
||||
OSMO_MDNS_RFC_RECORD_TYPE_A = 1, /* IPv4 address */
|
||||
OSMO_MDNS_RFC_RECORD_TYPE_TXT = 16, /* Text strings */
|
||||
|
||||
/* RFC 3596 2.1 */
|
||||
OSMO_MDNS_RFC_RECORD_TYPE_AAAA = 28, /* IPv6 address */
|
||||
|
||||
/* RFC 1035 3.2.3 */
|
||||
OSMO_MDNS_RFC_RECORD_TYPE_ALL = 255, /* Request only: ask for all */
|
||||
};
|
||||
|
||||
enum osmo_mdns_rfc_class {
|
||||
OSMO_MDNS_RFC_CLASS_UNKNOWN = 0,
|
||||
|
||||
/* RFC 1035 3.2.4 */
|
||||
OSMO_MDNS_RFC_CLASS_IN = 1, /* Internet and IP networks */
|
||||
|
||||
/* RFC 1035 3.2.5 */
|
||||
OSMO_MDNS_RFC_CLASS_ALL = 255, /* Request only: ask for all */
|
||||
};
|
||||
|
||||
/* RFC 1035 4.1.1 */
|
||||
struct osmo_mdns_rfc_header {
|
||||
#if OSMO_IS_LITTLE_ENDIAN
|
||||
uint16_t id;
|
||||
uint8_t rd:1,
|
||||
tc:1,
|
||||
aa:1,
|
||||
opcode:4,
|
||||
qr:1; /* QR (0: query, 1: response) */
|
||||
uint8_t rcode:4,
|
||||
z:3,
|
||||
ra:1;
|
||||
uint16_t qdcount; /* Number of questions */
|
||||
uint16_t ancount; /* Number of answers */
|
||||
uint16_t nscount; /* Number of authority records */
|
||||
uint16_t arcount; /* Number of additional records */
|
||||
#elif OSMO_IS_BIG_ENDIAN
|
||||
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
|
||||
uint16_t id;
|
||||
uint8_t qr:1, opcode:4, aa:1, tc:1, rd:1;
|
||||
uint8_t ra:1, z:3, rcode:4;
|
||||
uint16_t qdcount;
|
||||
uint16_t ancount;
|
||||
uint16_t nscount;
|
||||
uint16_t arcount;
|
||||
#endif
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* RFC 1035 4.1.2 */
|
||||
struct osmo_mdns_rfc_question {
|
||||
char *domain; /* Domain to be encoded as qname (e.g. "gsup.hlr.1234567.imsi") */
|
||||
enum osmo_mdns_rfc_record_type qtype;
|
||||
enum osmo_mdns_rfc_class qclass;
|
||||
};
|
||||
|
||||
/* RFC 1035 4.1.3 */
|
||||
struct osmo_mdns_rfc_record {
|
||||
char *domain; /* Domain to be encoded as name (e.g. "gsup.hlr.1234567.imsi") */
|
||||
enum osmo_mdns_rfc_record_type type;
|
||||
enum osmo_mdns_rfc_class class;
|
||||
uint32_t ttl;
|
||||
uint16_t rdlength;
|
||||
uint8_t *rdata;
|
||||
};
|
||||
|
||||
char *osmo_mdns_rfc_qname_encode(void *ctx, const char *domain);
|
||||
char *osmo_mdns_rfc_qname_decode(void *ctx, const char *qname, size_t qname_len);
|
||||
|
||||
void osmo_mdns_rfc_header_encode(struct msgb *msg, const struct osmo_mdns_rfc_header *hdr);
|
||||
int osmo_mdns_rfc_header_decode(const uint8_t *data, size_t data_len, struct osmo_mdns_rfc_header *hdr);
|
||||
|
||||
int osmo_mdns_rfc_question_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_question *qst);
|
||||
struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const uint8_t *data, size_t data_len);
|
||||
|
||||
int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_record *rec);
|
||||
struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_t *data, size_t data_len,
|
||||
size_t *record_len);
|
||||
33
include/osmocom/mslookup/mdns_sock.h
Normal file
33
include/osmocom/mslookup/mdns_sock.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <netdb.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/select.h>
|
||||
|
||||
struct osmo_mdns_sock {
|
||||
struct osmo_fd osmo_fd;
|
||||
struct addrinfo *ai;
|
||||
};
|
||||
|
||||
struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned int port,
|
||||
int (*cb)(struct osmo_fd *fd, unsigned int what),
|
||||
void *data, unsigned int priv_nr);
|
||||
int osmo_mdns_sock_send(const struct osmo_mdns_sock *mdns_sock, struct msgb *msg);
|
||||
void osmo_mdns_sock_cleanup(struct osmo_mdns_sock *mdns_sock);
|
||||
121
include/osmocom/mslookup/mslookup.h
Normal file
121
include/osmocom/mslookup/mslookup.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! \defgroup mslookup Distributed GSM: finding subscribers
|
||||
* @{
|
||||
* \file mslookup.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/sockaddr_str.h>
|
||||
#include <osmocom/gsm/protocol/gsm_23_003.h>
|
||||
|
||||
#define OSMO_MSLOOKUP_SERVICE_MAXLEN 64
|
||||
|
||||
bool osmo_mslookup_service_valid(const char *service);
|
||||
|
||||
enum osmo_mslookup_id_type {
|
||||
OSMO_MSLOOKUP_ID_NONE = 0,
|
||||
OSMO_MSLOOKUP_ID_IMSI,
|
||||
OSMO_MSLOOKUP_ID_MSISDN,
|
||||
};
|
||||
|
||||
extern const struct value_string osmo_mslookup_id_type_names[];
|
||||
static inline const char *osmo_mslookup_id_type_name(enum osmo_mslookup_id_type val)
|
||||
{ return get_value_string(osmo_mslookup_id_type_names, val); }
|
||||
|
||||
struct osmo_mslookup_id {
|
||||
enum osmo_mslookup_id_type type;
|
||||
union {
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
|
||||
char msisdn[GSM23003_MSISDN_MAX_DIGITS+1];
|
||||
};
|
||||
};
|
||||
|
||||
int osmo_mslookup_id_cmp(const struct osmo_mslookup_id *a, const struct osmo_mslookup_id *b);
|
||||
bool osmo_mslookup_id_valid(const struct osmo_mslookup_id *id);
|
||||
|
||||
enum osmo_mslookup_result_code {
|
||||
OSMO_MSLOOKUP_RC_NONE = 0,
|
||||
/*! An intermediate valid result. The request is still open for more results. */
|
||||
OSMO_MSLOOKUP_RC_RESULT,
|
||||
/*! Returned when the final request timeout has elapsed without results. */
|
||||
OSMO_MSLOOKUP_RC_NOT_FOUND,
|
||||
};
|
||||
|
||||
extern const struct value_string osmo_mslookup_result_code_names[];
|
||||
static inline const char *osmo_mslookup_result_code_name(enum osmo_mslookup_result_code val)
|
||||
{ return get_value_string(osmo_mslookup_result_code_names, val); }
|
||||
|
||||
/*! Information to request from a lookup. */
|
||||
struct osmo_mslookup_query {
|
||||
/*! Which service to request, by freely invented names. For service name conventions (for voice, SMS, HLR,...),
|
||||
* refer to the OsmoHLR user's manual http://ftp.osmocom.org/docs/latest/osmohlr-usermanual.pdf */
|
||||
char service[OSMO_MSLOOKUP_SERVICE_MAXLEN + 1];
|
||||
/*! IMSI or MSISDN to look up. */
|
||||
struct osmo_mslookup_id id;
|
||||
|
||||
/*! Caller provided private data, if desired. */
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/*! Result data as passed back to a lookup client that invoked an osmo_mslookup_client_request. */
|
||||
struct osmo_mslookup_result {
|
||||
/*! Outcome of the request. */
|
||||
enum osmo_mslookup_result_code rc;
|
||||
|
||||
/*! IP address and port to reach the given service via IPv4, if any. */
|
||||
struct osmo_sockaddr_str host_v4;
|
||||
|
||||
/*! IP address and port to reach the given service via IPv6, if any. */
|
||||
struct osmo_sockaddr_str host_v6;
|
||||
|
||||
/*! How long ago the service last verified presence of the subscriber, in seconds, or zero if the presence is
|
||||
* invariable (like the home HLR record for an IMSI).
|
||||
* If a subscriber has recently moved to a different location, we get multiple replies and want to choose the
|
||||
* most recent one. If this were a timestamp, firstly the time zones would need to be taken care of.
|
||||
* Even if we choose UTC, a service provider with an inaccurate date/time would end up affecting the result.
|
||||
* The least susceptible to configuration errors or difference in local and remote clock is a value that
|
||||
* indicates the actual age of the record in seconds. The time that the lookup query took to be answered should
|
||||
* be neglectable here, since we would typically wait one second (or very few seconds) for lookup replies,
|
||||
* while typical Location Updating periods are in the range of 15 minutes. */
|
||||
uint32_t age;
|
||||
|
||||
/*! Whether this is the last result returned for this request. */
|
||||
bool last;
|
||||
};
|
||||
|
||||
int osmo_mslookup_query_init_from_domain_str(struct osmo_mslookup_query *q, const char *domain);
|
||||
|
||||
size_t osmo_mslookup_id_name_buf(char *buf, size_t buflen, const struct osmo_mslookup_id *id);
|
||||
char *osmo_mslookup_id_name_c(void *ctx, const struct osmo_mslookup_id *id);
|
||||
char *osmo_mslookup_id_name_b(char *buf, size_t buflen, const struct osmo_mslookup_id *id);
|
||||
|
||||
size_t osmo_mslookup_result_to_str_buf(char *buf, size_t buflen,
|
||||
const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_result *result);
|
||||
char *osmo_mslookup_result_name_c(void *ctx,
|
||||
const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_result *result);
|
||||
char *osmo_mslookup_result_name_b(char *buf, size_t buflen,
|
||||
const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_result *result);
|
||||
|
||||
/*! @} */
|
||||
132
include/osmocom/mslookup/mslookup_client.h
Normal file
132
include/osmocom/mslookup/mslookup_client.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/timer.h>
|
||||
#include <osmocom/core/sockaddr_str.h>
|
||||
#include <osmocom/mslookup/mslookup.h>
|
||||
|
||||
struct osmo_mslookup_client;
|
||||
struct osmo_mslookup_result;
|
||||
|
||||
typedef void (*osmo_mslookup_cb_t)(struct osmo_mslookup_client *client,
|
||||
uint32_t request_handle,
|
||||
const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_result *result);
|
||||
|
||||
/*! This handling information is passed along with a lookup request.
|
||||
* It tells the osmo_mslookup_client layer how to handle responses received from various mslookup methods (at the time
|
||||
* of writing only mDNS exists as a method, but the intention is to easily allow adding other methods in the future).
|
||||
* This query handling info is not seen by the individual method implementations, to clarify that it is the
|
||||
* osmo_mslookup_client layer that takes care of these details. */
|
||||
struct osmo_mslookup_query_handling {
|
||||
/*! Wait at least this long before returning any results.
|
||||
*
|
||||
* If nonzero, result_cb will be called as soon as this delay has elapsed, either with the so far youngest age
|
||||
* result, or with a "not found yet" result. After this delay has elapsed, receiving results will continue
|
||||
* until result_timeout_milliseconds has elapsed.
|
||||
*
|
||||
* If zero, responses are fed to the result_cb right from the start, every time a younger aged result than
|
||||
* before comes in.
|
||||
*
|
||||
* If a result with age == 0 is received, min_wait_milliseconds is ignored, the result is returned immediately
|
||||
* and listening for responses ends.
|
||||
*
|
||||
* Rationale: If a subscriber has recently moved between sites, multiple results will arrive, and the youngest
|
||||
* age wins. It can make sense to wait a minimum time for responses before determining the winning result.
|
||||
*
|
||||
* However, if no result or no valid result has arrived within a short period, the subscriber may be at a site
|
||||
* that is far away or that is currently experiencing high latency. It is thus a good safety net to still
|
||||
* receive results for an extended period of time.
|
||||
*
|
||||
* For some services, it is possible to establish links to every received result, and whichever link succeeds
|
||||
* will be used (for example for SIP calls: first to pick up the call gets connected, the others are dropped
|
||||
* silently).
|
||||
*/
|
||||
uint32_t min_wait_milliseconds;
|
||||
|
||||
/*! Total time in milliseconds to listen for lookup responses.
|
||||
*
|
||||
* When this timeout elapses, osmo_mslookup_client_request_cancel() is called implicitly; Manually invoking
|
||||
* osmo_mslookup_client_request_cancel() after result_timeout_milliseconds has elapsed is not necessary, but is
|
||||
* still safe to do anyway.
|
||||
*
|
||||
* If zero, min_wait_milliseconds is also used as result_timeout_milliseconds; if that is also zero, a default
|
||||
* timeout value is used.
|
||||
*
|
||||
* If result_timeout_milliseconds <= min_wait_milliseconds, then min_wait_milliseconds is used as
|
||||
* result_timeout_milliseconds, i.e. the timeout triggers as soon as min_wait_milliseconds hits.
|
||||
*
|
||||
* osmo_mslookup_client_request_cancel() can be called any time to end the request.
|
||||
*/
|
||||
uint32_t result_timeout_milliseconds;
|
||||
|
||||
/*! Invoked every time a result with a younger age than the previous result has arrived.
|
||||
* To stop receiving results before result_timeout_milliseconds has elapsed, call
|
||||
* osmo_mslookup_client_request_cancel().
|
||||
*/
|
||||
osmo_mslookup_cb_t result_cb;
|
||||
};
|
||||
|
||||
uint32_t osmo_mslookup_client_request(struct osmo_mslookup_client *client,
|
||||
const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_query_handling *handling);
|
||||
|
||||
void osmo_mslookup_client_request_cancel(struct osmo_mslookup_client *client, uint32_t request_handle);
|
||||
|
||||
struct osmo_mslookup_client *osmo_mslookup_client_new(void *ctx);
|
||||
bool osmo_mslookup_client_active(struct osmo_mslookup_client *client);
|
||||
void osmo_mslookup_client_free(struct osmo_mslookup_client *client);
|
||||
|
||||
/*! Describe a specific mslookup client method implementation. This struct is only useful for a lookup method
|
||||
* implementation to add itself to an osmo_mslookup_client, see for example osmo_mslookup_client_add_mdns(). */
|
||||
struct osmo_mslookup_client_method {
|
||||
struct llist_head entry;
|
||||
|
||||
/*! Human readable name of this lookup method. */
|
||||
const char *name;
|
||||
|
||||
/*! Private data for the lookup method implementation. */
|
||||
void *priv;
|
||||
|
||||
/*! Backpointer to the client this method is added to. */
|
||||
struct osmo_mslookup_client *client;
|
||||
|
||||
/*! Launch a lookup query. Called from osmo_mslookup_client_request().
|
||||
* The implementation returns results by calling osmo_mslookup_client_rx_result(). */
|
||||
void (*request)(struct osmo_mslookup_client_method *method,
|
||||
const struct osmo_mslookup_query *query,
|
||||
uint32_t request_handle);
|
||||
/*! End a lookup query. Called from osmo_mslookup_client_request_cancel(). It is guaranteed to be called
|
||||
* exactly once per above request() invocation. (The API user is required to invoke
|
||||
* osmo_mslookup_client_request_cancel() exactly once per osmo_mslookup_client_request().) */
|
||||
void (*request_cleanup)(struct osmo_mslookup_client_method *method,
|
||||
uint32_t request_handle);
|
||||
|
||||
/*! The mslookup_client is removing this method, clean up all open requests, lists and allocations. */
|
||||
void (*destruct)(struct osmo_mslookup_client_method *method);
|
||||
};
|
||||
|
||||
void osmo_mslookup_client_method_add(struct osmo_mslookup_client *client,
|
||||
struct osmo_mslookup_client_method *method);
|
||||
bool osmo_mslookup_client_method_del(struct osmo_mslookup_client *client,
|
||||
struct osmo_mslookup_client_method *method);
|
||||
void osmo_mslookup_client_rx_result(struct osmo_mslookup_client *client, uint32_t request_handle,
|
||||
const struct osmo_mslookup_result *result);
|
||||
34
include/osmocom/mslookup/mslookup_client_fake.h
Normal file
34
include/osmocom/mslookup/mslookup_client_fake.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*! MS lookup fake API for testing purposes. */
|
||||
#include <osmocom/mslookup/mslookup_client.h>
|
||||
|
||||
struct osmo_mslookup_fake_response {
|
||||
struct timeval time_to_reply;
|
||||
struct osmo_mslookup_id for_id;
|
||||
const char *for_service;
|
||||
struct osmo_mslookup_result result;
|
||||
bool sent;
|
||||
};
|
||||
|
||||
struct osmo_mslookup_client_method *osmo_mslookup_client_add_fake(struct osmo_mslookup_client *client,
|
||||
struct osmo_mslookup_fake_response *responses,
|
||||
size_t responses_len);
|
||||
38
include/osmocom/mslookup/mslookup_client_mdns.h
Normal file
38
include/osmocom/mslookup/mslookup_client_mdns.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct osmo_mslookup_client;
|
||||
struct osmo_mslookup_client_method;
|
||||
|
||||
/*! MS Lookup mDNS server bind default IP. Taken from the Administratevly Scoped block, particularly the Organizational
|
||||
* Scoped range, https://tools.ietf.org/html/rfc2365 . */
|
||||
#define OSMO_MSLOOKUP_MDNS_IP4 "239.192.23.42"
|
||||
#define OSMO_MSLOOKUP_MDNS_IP6 "ff08::23:42" // <-- TODO: sane?
|
||||
#define OSMO_MSLOOKUP_MDNS_PORT 4266
|
||||
|
||||
struct osmo_mslookup_client_method *osmo_mslookup_client_add_mdns(struct osmo_mslookup_client *client, const char *ip,
|
||||
uint16_t port, int initial_packet_id,
|
||||
const char *domain_suffix);
|
||||
|
||||
const struct osmo_sockaddr_str *osmo_mslookup_client_method_mdns_get_bind_addr(struct osmo_mslookup_client_method *dns_method);
|
||||
|
||||
const char *osmo_mslookup_client_method_mdns_get_domain_suffix(struct osmo_mslookup_client_method *dns_method);
|
||||
11
libosmo-mslookup.pc.in
Normal file
11
libosmo-mslookup.pc.in
Normal file
@@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: Osmocom MS Lookup Library
|
||||
Description: C Utility Library
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} @TALLOC_LIBS@ -losmogsm -losmo-mslookup -losmocore
|
||||
Cflags: -I${includedir}/
|
||||
|
||||
48
sql/hlr.sql
48
sql/hlr.sql
@@ -5,12 +5,14 @@ CREATE TABLE subscriber (
|
||||
imsi VARCHAR(15) UNIQUE NOT NULL,
|
||||
-- Chapter 2.1.2
|
||||
msisdn VARCHAR(15) UNIQUE,
|
||||
-- Chapter 2.2.3: Most recent / current IMEI
|
||||
-- Chapter 2.2.3: Most recent / current IMEISV
|
||||
imeisv VARCHAR,
|
||||
-- Chapter 2.1.9: Most recent / current IMEI
|
||||
imei VARCHAR(14),
|
||||
-- Chapter 2.4.5
|
||||
vlr_number VARCHAR(15),
|
||||
-- Chapter 2.4.6
|
||||
hlr_number VARCHAR(15),
|
||||
msc_number VARCHAR(15),
|
||||
-- Chapter 2.4.8.1
|
||||
sgsn_number VARCHAR(15),
|
||||
-- Chapter 2.13.10
|
||||
@@ -40,7 +42,13 @@ CREATE TABLE subscriber (
|
||||
|
||||
-- Timestamp of last location update seen from subscriber
|
||||
-- The value is a string which encodes a UTC timestamp in granularity of seconds.
|
||||
last_lu_seen TIMESTAMP default NULL
|
||||
last_lu_seen TIMESTAMP default NULL,
|
||||
last_lu_seen_ps TIMESTAMP default NULL,
|
||||
|
||||
-- When a LU was received via a proxy, that proxy's hlr_number is stored here,
|
||||
-- while vlr_number reflects the MSC on the far side of that proxy.
|
||||
vlr_via_proxy VARCHAR,
|
||||
sgsn_via_proxy VARCHAR
|
||||
);
|
||||
|
||||
CREATE TABLE subscriber_apn (
|
||||
@@ -67,11 +75,41 @@ CREATE TABLE auc_3g (
|
||||
op VARCHAR(32), -- hex string: operator's secret key (128bit)
|
||||
opc VARCHAR(32), -- hex string: derived from OP and K (128bit)
|
||||
sqn INTEGER NOT NULL DEFAULT 0, -- sequence number of key usage
|
||||
ind_bitlen INTEGER NOT NULL DEFAULT 5 -- nr of index bits at lower SQN end
|
||||
-- nr of index bits at lower SQN end
|
||||
ind_bitlen INTEGER NOT NULL DEFAULT 5
|
||||
);
|
||||
|
||||
CREATE TABLE ind (
|
||||
-- 3G auth IND pool to be used for this VLR
|
||||
ind INTEGER PRIMARY KEY,
|
||||
-- VLR identification, usually the GSUP source_name
|
||||
vlr TEXT NOT NULL,
|
||||
UNIQUE (vlr)
|
||||
);
|
||||
|
||||
CREATE TABLE proxy_auth_cache {
|
||||
id INTEGER PRIMARY KEY,
|
||||
vlr TEXT NOT NULL,
|
||||
imsi TEXT NOT NULL,
|
||||
sent_count INTEGER
|
||||
};
|
||||
|
||||
CREATE TABLE proxy_auth_cache_vector {
|
||||
-- belongs to this proxy_auth_cache entry
|
||||
proxy_auth_cache_id INTEGER,
|
||||
rand VARCHAR(32),
|
||||
autn VARCHAR(32),
|
||||
ck VARCHAR(32),
|
||||
ik VARCHAR(32),
|
||||
res VARCHAR(32),
|
||||
kc[8] VARCHAR(16),
|
||||
sres[4] VARCHAR(8),
|
||||
-- enum osmo_sub_auth_type bitmask
|
||||
auth_types INTEGER
|
||||
};
|
||||
|
||||
CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi);
|
||||
|
||||
-- Set HLR database schema version number
|
||||
-- Note: This constant is currently duplicated in src/db.c and must be kept in sync!
|
||||
PRAGMA user_version = 1;
|
||||
PRAGMA user_version = 6;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
SUBDIRS = gsupclient
|
||||
SUBDIRS = \
|
||||
gsupclient \
|
||||
mslookup \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
-Wall \
|
||||
@@ -6,11 +9,13 @@ AM_CFLAGS = \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(LIBOSMOVTY_CFLAGS) \
|
||||
$(LIBOSMOCTRL_CFLAGS) \
|
||||
$(LIBOSMOMSLOOKUP_CFLAGS) \
|
||||
$(LIBOSMOABIS_CFLAGS) \
|
||||
$(SQLITE3_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/include \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
@@ -24,18 +29,6 @@ BUILT_SOURCES = \
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
noinst_HEADERS = \
|
||||
auc.h \
|
||||
db.h \
|
||||
hlr.h \
|
||||
luop.h \
|
||||
gsup_router.h \
|
||||
gsup_server.h \
|
||||
logging.h \
|
||||
rand.h \
|
||||
ctrl.h \
|
||||
hlr_vty.h \
|
||||
hlr_vty_subscr.h \
|
||||
hlr_ussd.h \
|
||||
db_bootstrap.h \
|
||||
$(NULL)
|
||||
|
||||
@@ -49,7 +42,6 @@ osmo_hlr_SOURCES = \
|
||||
auc.c \
|
||||
ctrl.c \
|
||||
db.c \
|
||||
luop.c \
|
||||
db_auc.c \
|
||||
db_hlr.c \
|
||||
gsup_router.c \
|
||||
@@ -61,13 +53,27 @@ osmo_hlr_SOURCES = \
|
||||
hlr_vty_subscr.c \
|
||||
gsup_send.c \
|
||||
hlr_ussd.c \
|
||||
proxy.c \
|
||||
proxy_mm.c \
|
||||
proxy_to_home.c \
|
||||
proxy_db.c \
|
||||
dgsm.c \
|
||||
remote_hlr.c \
|
||||
lu_fsm.c \
|
||||
timestamp.c \
|
||||
mslookup_server.c \
|
||||
mslookup_server_mdns.c \
|
||||
dgsm_vty.c \
|
||||
$(NULL)
|
||||
|
||||
osmo_hlr_LDADD = \
|
||||
$(top_builddir)/src/gsupclient/libosmo-gsup-client.la \
|
||||
$(top_builddir)/src/mslookup/libosmo-mslookup.la \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(LIBOSMOVTY_LIBS) \
|
||||
$(LIBOSMOCTRL_LIBS) \
|
||||
$(LIBOSMOMSLOOKUP_LIBS) \
|
||||
$(LIBOSMOABIS_LIBS) \
|
||||
$(SQLITE3_LIBS) \
|
||||
$(NULL)
|
||||
@@ -79,6 +85,7 @@ osmo_hlr_db_tool_SOURCES = \
|
||||
logging.c \
|
||||
rand_urandom.c \
|
||||
dbd_decode_binary.c \
|
||||
$(srcdir)/gsupclient/gsup_peer_id.c \
|
||||
$(NULL)
|
||||
|
||||
osmo_hlr_db_tool_LDADD = \
|
||||
@@ -87,21 +94,6 @@ osmo_hlr_db_tool_LDADD = \
|
||||
$(SQLITE3_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
db_test_SOURCES = \
|
||||
auc.c \
|
||||
db.c \
|
||||
db_auc.c \
|
||||
db_test.c \
|
||||
logging.c \
|
||||
rand_fake.c \
|
||||
$(NULL)
|
||||
|
||||
db_test_LDADD = \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(SQLITE3_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
osmo_euse_demo_SOURCES = \
|
||||
osmo-euse-demo.c \
|
||||
$(NULL)
|
||||
@@ -112,6 +104,11 @@ osmo_euse_demo_LDADD = \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
if DB_SQLITE_DEBUG
|
||||
osmo_hlr_SOURCES += db_debug.c
|
||||
osmo_hlr_db_tool_SOURCES += db_debug.c
|
||||
endif
|
||||
|
||||
BOOTSTRAP_SQL = $(top_srcdir)/sql/hlr.sql
|
||||
|
||||
db_bootstrap.h: $(BOOTSTRAP_SQL) $(srcdir)/db_sql2c.sed
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/crypt/auth.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "rand.h"
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/rand.h>
|
||||
|
||||
#define hexb(buf) osmo_hexdump_nospc((void*)buf, sizeof(buf))
|
||||
#define hex(buf,sz) osmo_hexdump_nospc((void*)buf, sz)
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
#include <osmocom/ctrl/ports.h>
|
||||
|
||||
#include "hlr.h"
|
||||
#include "ctrl.h"
|
||||
#include "db.h"
|
||||
#include <osmocom/hlr/hlr.h>
|
||||
#include <osmocom/hlr/ctrl.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
|
||||
#define SEL_BY "by-"
|
||||
#define SEL_BY_IMSI SEL_BY "imsi-"
|
||||
@@ -95,7 +95,7 @@ static bool get_subscriber(struct db_context *dbc,
|
||||
cmd->reply = "No such subscriber.";
|
||||
return false;
|
||||
default:
|
||||
cmd->reply = "An unknown error has occured during get_subscriber().";
|
||||
cmd->reply = "An unknown error has occurred during get_subscriber().";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
343
src/db.c
343
src/db.c
@@ -23,17 +23,18 @@
|
||||
#include <sqlite3.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "db.h"
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
#include "db_bootstrap.h"
|
||||
|
||||
/* This constant is currently duplicated in sql/hlr.sql and must be kept in sync! */
|
||||
#define CURRENT_SCHEMA_VERSION 1
|
||||
#define CURRENT_SCHEMA_VERSION 6
|
||||
|
||||
#define SEL_COLUMNS \
|
||||
"id," \
|
||||
"imsi," \
|
||||
"msisdn," \
|
||||
"imei," \
|
||||
"vlr_number," \
|
||||
"sgsn_number," \
|
||||
"sgsn_address," \
|
||||
@@ -44,14 +45,19 @@
|
||||
"lmsi," \
|
||||
"ms_purged_cs," \
|
||||
"ms_purged_ps," \
|
||||
"last_lu_seen"
|
||||
"last_lu_seen," \
|
||||
"last_lu_seen_ps," \
|
||||
"vlr_via_proxy," \
|
||||
"sgsn_via_proxy"
|
||||
|
||||
static const char *stmt_sql[] = {
|
||||
[DB_STMT_SEL_BY_IMSI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imsi = ?",
|
||||
[DB_STMT_SEL_BY_MSISDN] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE msisdn = ?",
|
||||
[DB_STMT_SEL_BY_ID] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE id = ?",
|
||||
[DB_STMT_UPD_VLR_BY_ID] = "UPDATE subscriber SET vlr_number = $number WHERE id = $subscriber_id",
|
||||
[DB_STMT_UPD_SGSN_BY_ID] = "UPDATE subscriber SET sgsn_number = $number WHERE id = $subscriber_id",
|
||||
[DB_STMT_SEL_BY_IMEI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imei = ?",
|
||||
[DB_STMT_UPD_VLR_BY_ID] = "UPDATE subscriber SET vlr_number = $number, vlr_via_proxy = $proxy WHERE id = $subscriber_id",
|
||||
[DB_STMT_UPD_SGSN_BY_ID] = "UPDATE subscriber SET sgsn_number = $number, sgsn_via_proxy = $proxy WHERE id = $subscriber_id",
|
||||
[DB_STMT_UPD_IMEI_BY_IMSI] = "UPDATE subscriber SET imei = $imei WHERE imsi = $imsi",
|
||||
[DB_STMT_AUC_BY_IMSI] =
|
||||
"SELECT id, algo_id_2g, ki, algo_id_3g, k, op, opc, sqn, ind_bitlen"
|
||||
" FROM subscriber"
|
||||
@@ -63,7 +69,7 @@ static const char *stmt_sql[] = {
|
||||
[DB_STMT_UPD_PURGE_PS_BY_IMSI] = "UPDATE subscriber SET ms_purged_ps = $val WHERE imsi = $imsi",
|
||||
[DB_STMT_UPD_NAM_CS_BY_IMSI] = "UPDATE subscriber SET nam_cs = $val WHERE imsi = $imsi",
|
||||
[DB_STMT_UPD_NAM_PS_BY_IMSI] = "UPDATE subscriber SET nam_ps = $val WHERE imsi = $imsi",
|
||||
[DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi) VALUES ($imsi)",
|
||||
[DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi, nam_cs, nam_ps) VALUES ($imsi, $nam_cs, $nam_ps)",
|
||||
[DB_STMT_DEL_BY_ID] = "DELETE FROM subscriber WHERE id = $subscriber_id",
|
||||
[DB_STMT_SET_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = $msisdn WHERE imsi = $imsi",
|
||||
[DB_STMT_DELETE_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = NULL WHERE imsi = $imsi",
|
||||
@@ -76,6 +82,12 @@ static const char *stmt_sql[] = {
|
||||
" VALUES($subscriber_id, $algo_id_3g, $k, $op, $opc, $ind_bitlen)",
|
||||
[DB_STMT_AUC_3G_DELETE] = "DELETE FROM auc_3g WHERE subscriber_id = $subscriber_id",
|
||||
[DB_STMT_SET_LAST_LU_SEEN] = "UPDATE subscriber SET last_lu_seen = datetime($val, 'unixepoch') WHERE id = $subscriber_id",
|
||||
[DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch') WHERE id = $subscriber_id",
|
||||
[DB_STMT_EXISTS_BY_IMSI] = "SELECT 1 FROM subscriber WHERE imsi = $imsi",
|
||||
[DB_STMT_EXISTS_BY_MSISDN] = "SELECT 1 FROM subscriber WHERE msisdn = $msisdn",
|
||||
[DB_STMT_IND_ADD] = "INSERT INTO ind (vlr) VALUES ($vlr)",
|
||||
[DB_STMT_IND_SELECT] = "SELECT ind FROM ind WHERE vlr = $vlr",
|
||||
[DB_STMT_IND_DEL] = "DELETE FROM ind WHERE vlr = $vlr",
|
||||
};
|
||||
|
||||
static void sql3_error_log_cb(void *arg, int err_code, const char *msg)
|
||||
@@ -176,6 +188,25 @@ bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool db_bind_null(sqlite3_stmt *stmt, const char *param_name)
|
||||
{
|
||||
int rc;
|
||||
int idx = param_name ? sqlite3_bind_parameter_index(stmt, param_name) : 1;
|
||||
if (idx < 1) {
|
||||
LOGP(DDB, LOGL_ERROR, "Error composing SQL, cannot bind parameter '%s'\n",
|
||||
param_name);
|
||||
return false;
|
||||
}
|
||||
rc = sqlite3_bind_null(stmt, idx);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Error binding NULL to SQL parameter %s: %d\n",
|
||||
param_name ? param_name : "#1", rc);
|
||||
db_remove_reset(stmt);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void db_close(struct db_context *dbc)
|
||||
{
|
||||
unsigned int i;
|
||||
@@ -196,28 +227,38 @@ void db_close(struct db_context *dbc)
|
||||
talloc_free(dbc);
|
||||
}
|
||||
|
||||
static int db_bootstrap(struct db_context *dbc)
|
||||
static int db_run_statements(struct db_context *dbc, const char **statements, size_t statements_count)
|
||||
{
|
||||
int rc;
|
||||
int i;
|
||||
for (i = 0; i < ARRAY_SIZE(stmt_bootstrap_sql); i++) {
|
||||
int rc;
|
||||
for (i = 0; i < statements_count; i++) {
|
||||
const char *stmt_str = statements[i];
|
||||
sqlite3_stmt *stmt;
|
||||
rc = sqlite3_prepare_v2(dbc->db, stmt_bootstrap_sql[i], -1, &stmt, NULL);
|
||||
|
||||
rc = sqlite3_prepare_v2(dbc->db, stmt_str, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", stmt_bootstrap_sql[i]);
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", stmt_str);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
db_remove_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Cannot bootstrap database: SQL error: (%d) %s,"
|
||||
" during stmt '%s'",
|
||||
rc, sqlite3_errmsg(dbc->db), stmt_bootstrap_sql[i]);
|
||||
LOGP(DDB, LOGL_ERROR, "SQL error: (%d) %s, during stmt '%s'",
|
||||
rc, sqlite3_errmsg(dbc->db), stmt_str);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int db_bootstrap(struct db_context *dbc)
|
||||
{
|
||||
int rc = db_run_statements(dbc, stmt_bootstrap_sql, ARRAY_SIZE(stmt_bootstrap_sql));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Cannot bootstrap database\n");
|
||||
return rc;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -258,38 +299,222 @@ static bool db_is_bootstrapped_v0(struct db_context *dbc)
|
||||
static int
|
||||
db_upgrade_v1(struct db_context *dbc)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
int rc;
|
||||
const char *update_stmt_sql = "ALTER TABLE subscriber ADD COLUMN last_lu_seen TIMESTAMP default NULL";
|
||||
const char *set_schema_version_sql = "PRAGMA user_version = 1";
|
||||
const char *statements[] = {
|
||||
"ALTER TABLE subscriber ADD COLUMN last_lu_seen TIMESTAMP default NULL",
|
||||
"PRAGMA user_version = 1",
|
||||
};
|
||||
|
||||
rc = sqlite3_prepare_v2(dbc->db, update_stmt_sql, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", update_stmt_sql);
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3_step(stmt);
|
||||
db_remove_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version %d\n", 1);
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 1\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(dbc->db, set_schema_version_sql, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", set_schema_version_sql);
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE)
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version %d\n", 1);
|
||||
|
||||
db_remove_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int db_upgrade_v2(struct db_context *dbc)
|
||||
{
|
||||
int rc;
|
||||
const char *statements[] = {
|
||||
"ALTER TABLE subscriber ADD COLUMN imei VARCHAR(14)",
|
||||
"PRAGMA user_version = 2",
|
||||
};
|
||||
|
||||
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 2\n");
|
||||
return rc;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int db_upgrade_v3(struct db_context *dbc)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* A newer SQLite version would allow simply 'ATLER TABLE subscriber RENAME COLUMN hlr_number TO msc_number'.
|
||||
* This is a really expensive workaround for that in order to cover earlier SQLite versions as well:
|
||||
* Create a new table with the new column name and copy the data over (https://www.sqlite.org/faq.html#q11).
|
||||
*/
|
||||
#define SUBSCR_V3_CREATE \
|
||||
"(\n" \
|
||||
"-- OsmoHLR's DB scheme is modelled roughly after TS 23.008 version 13.3.0\n" \
|
||||
" id INTEGER PRIMARY KEY,\n" \
|
||||
" -- Chapter 2.1.1.1\n" \
|
||||
" imsi VARCHAR(15) UNIQUE NOT NULL,\n" \
|
||||
" -- Chapter 2.1.2\n" \
|
||||
" msisdn VARCHAR(15) UNIQUE,\n" \
|
||||
" -- Chapter 2.2.3: Most recent / current IMEISV\n" \
|
||||
" imeisv VARCHAR,\n" \
|
||||
" -- Chapter 2.1.9: Most recent / current IMEI\n" \
|
||||
" imei VARCHAR(14),\n" \
|
||||
" -- Chapter 2.4.5\n" \
|
||||
" vlr_number VARCHAR(15),\n" \
|
||||
" -- Chapter 2.4.6\n" \
|
||||
" msc_number VARCHAR(15),\n" \
|
||||
" -- Chapter 2.4.8.1\n" \
|
||||
" sgsn_number VARCHAR(15),\n" \
|
||||
" -- Chapter 2.13.10\n" \
|
||||
" sgsn_address VARCHAR,\n" \
|
||||
" -- Chapter 2.4.8.2\n" \
|
||||
" ggsn_number VARCHAR(15),\n" \
|
||||
" -- Chapter 2.4.9.2\n" \
|
||||
" gmlc_number VARCHAR(15),\n" \
|
||||
" -- Chapter 2.4.23\n" \
|
||||
" smsc_number VARCHAR(15),\n" \
|
||||
" -- Chapter 2.4.24\n" \
|
||||
" periodic_lu_tmr INTEGER,\n" \
|
||||
" -- Chapter 2.13.115\n" \
|
||||
" periodic_rau_tau_tmr INTEGER,\n" \
|
||||
" -- Chapter 2.1.1.2: network access mode\n" \
|
||||
" nam_cs BOOLEAN NOT NULL DEFAULT 1,\n" \
|
||||
" nam_ps BOOLEAN NOT NULL DEFAULT 1,\n" \
|
||||
" -- Chapter 2.1.8\n" \
|
||||
" lmsi INTEGER,\n" \
|
||||
\
|
||||
" -- The below purged flags might not even be stored non-volatile,\n" \
|
||||
" -- refer to TS 23.012 Chapter 3.6.1.4\n" \
|
||||
" -- Chapter 2.7.5\n" \
|
||||
" ms_purged_cs BOOLEAN NOT NULL DEFAULT 0,\n" \
|
||||
" -- Chapter 2.7.6\n" \
|
||||
" ms_purged_ps BOOLEAN NOT NULL DEFAULT 0,\n" \
|
||||
\
|
||||
" -- Timestamp of last location update seen from subscriber\n" \
|
||||
" -- The value is a string which encodes a UTC timestamp in granularity of seconds.\n" \
|
||||
" last_lu_seen TIMESTAMP default NULL\n" \
|
||||
")\n"
|
||||
|
||||
#define SUBSCR_V2_COLUMN_NAMES \
|
||||
"id," \
|
||||
"imsi," \
|
||||
"msisdn," \
|
||||
"imeisv," \
|
||||
"imei," \
|
||||
"vlr_number," \
|
||||
"hlr_number," \
|
||||
"sgsn_number," \
|
||||
"sgsn_address," \
|
||||
"ggsn_number," \
|
||||
"gmlc_number," \
|
||||
"smsc_number," \
|
||||
"periodic_lu_tmr," \
|
||||
"periodic_rau_tau_tmr," \
|
||||
"nam_cs," \
|
||||
"nam_ps," \
|
||||
"lmsi," \
|
||||
"ms_purged_cs," \
|
||||
"ms_purged_ps," \
|
||||
"last_lu_seen"
|
||||
|
||||
#define SUBSCR_V3_COLUMN_NAMES \
|
||||
"id," \
|
||||
"imsi," \
|
||||
"msisdn," \
|
||||
"imeisv," \
|
||||
"imei," \
|
||||
"vlr_number," \
|
||||
"msc_number," \
|
||||
"sgsn_number," \
|
||||
"sgsn_address," \
|
||||
"ggsn_number," \
|
||||
"gmlc_number," \
|
||||
"smsc_number," \
|
||||
"periodic_lu_tmr," \
|
||||
"periodic_rau_tau_tmr," \
|
||||
"nam_cs," \
|
||||
"nam_ps," \
|
||||
"lmsi," \
|
||||
"ms_purged_cs," \
|
||||
"ms_purged_ps," \
|
||||
"last_lu_seen"
|
||||
|
||||
const char *statements[] = {
|
||||
"BEGIN TRANSACTION",
|
||||
"CREATE TEMPORARY TABLE subscriber_backup" SUBSCR_V3_CREATE,
|
||||
"INSERT INTO subscriber_backup SELECT " SUBSCR_V2_COLUMN_NAMES " FROM subscriber",
|
||||
"DROP TABLE subscriber",
|
||||
"CREATE TABLE subscriber" SUBSCR_V3_CREATE,
|
||||
"INSERT INTO subscriber SELECT " SUBSCR_V3_COLUMN_NAMES " FROM subscriber_backup",
|
||||
"DROP TABLE subscriber_backup",
|
||||
"COMMIT",
|
||||
"PRAGMA user_version = 3",
|
||||
};
|
||||
|
||||
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 3\n");
|
||||
return rc;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int db_upgrade_v4(struct db_context *dbc)
|
||||
{
|
||||
int rc;
|
||||
const char *statements[] = {
|
||||
"ALTER TABLE subscriber ADD COLUMN last_lu_seen_ps TIMESTAMP default NULL",
|
||||
"PRAGMA user_version = 4",
|
||||
};
|
||||
|
||||
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 4\n");
|
||||
return rc;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int db_upgrade_v5(struct db_context *dbc)
|
||||
{
|
||||
int rc;
|
||||
const char *statements[] = {
|
||||
"ALTER TABLE subscriber ADD COLUMN vlr_via_proxy VARCHAR",
|
||||
"ALTER TABLE subscriber ADD COLUMN sgsn_via_proxy VARCHAR",
|
||||
"PRAGMA user_version = 5",
|
||||
};
|
||||
|
||||
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 5\n");
|
||||
return rc;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int db_upgrade_v6(struct db_context *dbc)
|
||||
{
|
||||
int rc;
|
||||
const char *statements[] = {
|
||||
"CREATE TABLE ind (\n"
|
||||
" -- 3G auth IND pool to be used for this VLR\n"
|
||||
" ind INTEGER PRIMARY KEY,\n"
|
||||
" -- VLR identification, usually the GSUP source_name\n"
|
||||
" vlr TEXT NOT NULL,\n"
|
||||
" UNIQUE (vlr)\n"
|
||||
")"
|
||||
,
|
||||
"PRAGMA user_version = 6",
|
||||
};
|
||||
|
||||
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 6\n");
|
||||
return rc;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
typedef int (*db_upgrade_func_t)(struct db_context *dbc);
|
||||
static db_upgrade_func_t db_upgrade_path[] = {
|
||||
db_upgrade_v1,
|
||||
db_upgrade_v2,
|
||||
db_upgrade_v3,
|
||||
db_upgrade_v4,
|
||||
db_upgrade_v5,
|
||||
db_upgrade_v6,
|
||||
};
|
||||
|
||||
static int db_get_user_version(struct db_context *dbc)
|
||||
{
|
||||
const char *user_version_sql = "PRAGMA user_version";
|
||||
@@ -326,6 +551,17 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
LOGP(DDB, LOGL_INFO, "Compiled against SQLite3 lib version %s\n", SQLITE_VERSION);
|
||||
LOGP(DDB, LOGL_INFO, "Running with SQLite3 lib version %s\n", sqlite3_libversion());
|
||||
|
||||
#ifdef SQLITE_USE_TALLOC
|
||||
/* Configure SQLite3 to use talloc memory allocator */
|
||||
rc = db_sqlite3_use_talloc(ctx);
|
||||
if (rc == SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_NOTICE, "SQLite3 is configured to use talloc\n");
|
||||
} else {
|
||||
LOGP(DDB, LOGL_ERROR, "Failed to configure SQLite3 "
|
||||
"to use talloc, using default memory allocator\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
dbc->fname = talloc_strdup(dbc, fname);
|
||||
|
||||
for (i = 0; i < 0xfffff; i++) {
|
||||
@@ -365,9 +601,11 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
|
||||
char *err_msg;
|
||||
rc = sqlite3_exec(dbc->db, "PRAGMA journal_mode=WAL; PRAGMA synchonous = NORMAL;", 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK)
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to set Write-Ahead Logging: %s\n",
|
||||
err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
}
|
||||
|
||||
version = db_get_user_version(dbc);
|
||||
if (version < 0) {
|
||||
@@ -389,23 +627,16 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
|
||||
LOGP(DDB, LOGL_NOTICE, "Database '%s' has HLR DB schema version %d\n", dbc->fname, version);
|
||||
|
||||
if (version < CURRENT_SCHEMA_VERSION && allow_upgrade) {
|
||||
switch (version) {
|
||||
case 0:
|
||||
rc = db_upgrade_v1(dbc);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Failed to upgrade HLR DB schema to version 1: (rc=%d) %s\n",
|
||||
rc, sqlite3_errmsg(dbc->db));
|
||||
goto out_free;
|
||||
}
|
||||
version = 1;
|
||||
/* fall through */
|
||||
/* case N: ... */
|
||||
default:
|
||||
break;
|
||||
for (; allow_upgrade && (version < ARRAY_SIZE(db_upgrade_path)); version++) {
|
||||
db_upgrade_func_t upgrade_func = db_upgrade_path[version];
|
||||
rc = upgrade_func(dbc);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Failed to upgrade HLR DB schema to version %d: (rc=%d) %s\n",
|
||||
version+1, rc, sqlite3_errmsg(dbc->db));
|
||||
goto out_free;
|
||||
}
|
||||
LOGP(DDB, LOGL_NOTICE, "Database '%s' has been upgraded to HLR DB schema version %d\n",
|
||||
dbc->fname, version);
|
||||
dbc->fname, version+1);
|
||||
}
|
||||
|
||||
if (version != CURRENT_SCHEMA_VERSION) {
|
||||
|
||||
102
src/db_auc.c
102
src/db_auc.c
@@ -26,10 +26,10 @@
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "db.h"
|
||||
#include "auc.h"
|
||||
#include "rand.h"
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
#include <osmocom/hlr/auc.h>
|
||||
#include <osmocom/hlr/rand.h>
|
||||
|
||||
#define LOGAUC(imsi, level, fmt, args ...) LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args)
|
||||
|
||||
@@ -73,6 +73,32 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* hexparse a specific column of a sqlite prepared statement into dst (with length check)
|
||||
* returns 0 for success, -EIO on error */
|
||||
static int hexparse_stmt(uint8_t *dst, size_t dst_len, sqlite3_stmt *stmt, int col, const char *col_name,
|
||||
const char *imsi)
|
||||
{
|
||||
const uint8_t *text;
|
||||
size_t col_len;
|
||||
|
||||
/* Bytes are stored as hex strings in database, hence divide length by two */
|
||||
col_len = sqlite3_column_bytes(stmt, col) / 2;
|
||||
|
||||
if (col_len != dst_len) {
|
||||
LOGAUC(imsi, LOGL_ERROR, "Error reading %s, expected length %lu but has length %lu\n", col_name,
|
||||
dst_len, col_len);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
text = sqlite3_column_text(stmt, col);
|
||||
if (!text) {
|
||||
LOGAUC(imsi, LOGL_ERROR, "Error reading %s\n", col_name);
|
||||
return -EIO;
|
||||
}
|
||||
osmo_hexparse((void *)text, dst, dst_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* obtain the authentication data for a given imsi
|
||||
* returns 0 for success, negative value on error:
|
||||
* -ENOENT if the IMSI is not known, -ENOKEY if the IMSI is known but has no auth data,
|
||||
@@ -113,49 +139,34 @@ int db_get_auth_data(struct db_context *dbc, const char *imsi,
|
||||
/* obtain result values using sqlite3_column_*() */
|
||||
if (sqlite3_column_type(stmt, 1) == SQLITE_INTEGER) {
|
||||
/* we do have some 2G authentication data */
|
||||
const uint8_t *ki;
|
||||
|
||||
aud2g->algo = sqlite3_column_int(stmt, 1);
|
||||
ki = sqlite3_column_text(stmt, 2);
|
||||
#if 0
|
||||
if (sqlite3_column_bytes(stmt, 2) != sizeof(aud2g->u.gsm.ki)) {
|
||||
LOGAUC(imsi, LOGL_ERROR, "Error reading Ki: %d\n", rc);
|
||||
if (hexparse_stmt(aud2g->u.gsm.ki, sizeof(aud2g->u.gsm.ki), stmt, 2, "Ki", imsi))
|
||||
goto end_2g;
|
||||
}
|
||||
#endif
|
||||
osmo_hexparse((void*)ki, (void*)&aud2g->u.gsm.ki, sizeof(aud2g->u.gsm.ki));
|
||||
aud2g->algo = sqlite3_column_int(stmt, 1);
|
||||
aud2g->type = OSMO_AUTH_TYPE_GSM;
|
||||
} else
|
||||
LOGAUC(imsi, LOGL_DEBUG, "No 2G Auth Data\n");
|
||||
//end_2g:
|
||||
end_2g:
|
||||
if (sqlite3_column_type(stmt, 3) == SQLITE_INTEGER) {
|
||||
/* we do have some 3G authentication data */
|
||||
const uint8_t *k, *op, *opc;
|
||||
|
||||
aud3g->algo = sqlite3_column_int(stmt, 3);
|
||||
k = sqlite3_column_text(stmt, 4);
|
||||
if (!k) {
|
||||
LOGAUC(imsi, LOGL_ERROR, "Error reading K: %d\n", rc);
|
||||
if (hexparse_stmt(aud3g->u.umts.k, sizeof(aud3g->u.umts.k), stmt, 4, "K", imsi)) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
osmo_hexparse((void*)k, (void*)&aud3g->u.umts.k, sizeof(aud3g->u.umts.k));
|
||||
aud3g->algo = sqlite3_column_int(stmt, 3);
|
||||
|
||||
/* UMTS Subscribers can have either OP or OPC */
|
||||
op = sqlite3_column_text(stmt, 5);
|
||||
if (!op) {
|
||||
opc = sqlite3_column_text(stmt, 6);
|
||||
if (!opc) {
|
||||
LOGAUC(imsi, LOGL_ERROR, "Error reading OPC: %d\n", rc);
|
||||
if (sqlite3_column_text(stmt, 5)) {
|
||||
if (hexparse_stmt(aud3g->u.umts.opc, sizeof(aud3g->u.umts.opc), stmt, 5, "OP", imsi)) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
osmo_hexparse((void*)opc, (void*)&aud3g->u.umts.opc,
|
||||
sizeof(aud3g->u.umts.opc));
|
||||
aud3g->u.umts.opc_is_op = 0;
|
||||
} else {
|
||||
osmo_hexparse((void*)op, (void*)&aud3g->u.umts.opc,
|
||||
sizeof(aud3g->u.umts.opc));
|
||||
aud3g->u.umts.opc_is_op = 1;
|
||||
} else {
|
||||
if (hexparse_stmt(aud3g->u.umts.opc, sizeof(aud3g->u.umts.opc), stmt, 6, "OPC", imsi)) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
aud3g->u.umts.opc_is_op = 0;
|
||||
}
|
||||
aud3g->u.umts.sqn = sqlite3_column_int64(stmt, 7);
|
||||
aud3g->u.umts.ind_bitlen = sqlite3_column_int(stmt, 8);
|
||||
@@ -178,7 +189,7 @@ out:
|
||||
int db_get_auc(struct db_context *dbc, const char *imsi,
|
||||
unsigned int auc_3g_ind, struct osmo_auth_vector *vec,
|
||||
unsigned int num_vec, const uint8_t *rand_auts,
|
||||
const uint8_t *auts)
|
||||
const uint8_t *auts, bool separation_bit)
|
||||
{
|
||||
struct osmo_sub_auth_data aud2g, aud3g;
|
||||
int64_t subscr_id;
|
||||
@@ -189,15 +200,22 @@ int db_get_auc(struct db_context *dbc, const char *imsi,
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
/* modulo by the IND bitlen value range. For example, ind_bitlen == 5 would modulo 32:
|
||||
* 1 << 5 == 0b0100000 == 32
|
||||
* - 1 == 0b0011111 == bitmask of 5 lowest bits
|
||||
* x &= 0b0011111 == modulo 32
|
||||
* Why do this? osmo-hlr cannot possibly choose individual VLR INDs always matching all subscribers' IND_bitlen,
|
||||
* which might vary wildly. Instead, let hlr.c pass in an arbitrarily high number here, and the modulo does a
|
||||
* round-robin if the IND pools that this subscriber has available. */
|
||||
auc_3g_ind &= (1U << aud3g.u.umts.ind_bitlen) - 1;
|
||||
aud3g.u.umts.ind = auc_3g_ind;
|
||||
if (aud3g.type == OSMO_AUTH_TYPE_UMTS
|
||||
&& aud3g.u.umts.ind >= (1U << aud3g.u.umts.ind_bitlen)) {
|
||||
LOGAUC(imsi, LOGL_NOTICE, "3G auth: SQN's IND bitlen %u is"
|
||||
" too small to hold an index of %u. Truncating. This"
|
||||
" may cause numerous additional AUTS resyncing.\n",
|
||||
aud3g.u.umts.ind_bitlen, aud3g.u.umts.ind);
|
||||
aud3g.u.umts.ind &= (1U << aud3g.u.umts.ind_bitlen) - 1;
|
||||
}
|
||||
|
||||
/* the first bit (bit0) cannot be used as AMF anymore, but has been
|
||||
* re-appropriated as the separation bit. See 3GPP TS 33.102 Annex H
|
||||
* together with 3GPP TS 33.401 / 33.402 / 33.501 */
|
||||
aud3g.u.umts.amf[0] = aud3g.u.umts.amf[0] & 0x7f;
|
||||
if (separation_bit)
|
||||
aud3g.u.umts.amf[0] |= 0x80;
|
||||
|
||||
LOGAUC(imsi, LOGL_DEBUG, "Calling to generate %u vectors\n", num_vec);
|
||||
rc = auc_compute_vectors(vec, num_vec, &aud2g, &aud3g, rand_auts, auts);
|
||||
|
||||
86
src/db_debug.c
Normal file
86
src/db_debug.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* libtalloc based memory allocator for SQLite3.
|
||||
*
|
||||
* (C) 2019 by Vadim Yanitskiy <axilirator@gmail.com>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <talloc.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Dedicated talloc context for SQLite */
|
||||
static void *db_sqlite_ctx = NULL;
|
||||
|
||||
static void *tall_xMalloc(int size)
|
||||
{
|
||||
return talloc_size(db_sqlite_ctx, size);
|
||||
}
|
||||
|
||||
static void tall_xFree(void *ptr)
|
||||
{
|
||||
talloc_free(ptr);
|
||||
}
|
||||
|
||||
static void *tall_xRealloc(void *ptr, int size)
|
||||
{
|
||||
return talloc_realloc_fn(db_sqlite_ctx, ptr, size);
|
||||
}
|
||||
|
||||
static int tall_xSize(void *ptr)
|
||||
{
|
||||
return talloc_total_size(ptr);
|
||||
}
|
||||
|
||||
/* DUMMY: talloc doesn't round up the allocation size */
|
||||
static int tall_xRoundup(int size) { return size; }
|
||||
|
||||
/* DUMMY: nothing to initialize */
|
||||
static int tall_xInit(void *data) { return 0; }
|
||||
|
||||
/* DUMMY: nothing to deinitialize */
|
||||
static void tall_xShutdown(void *data) { }
|
||||
|
||||
/* Interface between SQLite and talloc memory allocator */
|
||||
static const struct sqlite3_mem_methods tall_sqlite_if = {
|
||||
/* Memory allocation function */
|
||||
.xMalloc = &tall_xMalloc,
|
||||
/* Free a prior allocation */
|
||||
.xFree = &tall_xFree,
|
||||
/* Resize an allocation */
|
||||
.xRealloc = &tall_xRealloc,
|
||||
/* Return the size of an allocation */
|
||||
.xSize = &tall_xSize,
|
||||
/* Round up request size to allocation size */
|
||||
.xRoundup = &tall_xRoundup,
|
||||
/* Initialize the memory allocator */
|
||||
.xInit = &tall_xInit,
|
||||
/* Deinitialize the memory allocator */
|
||||
.xShutdown = &tall_xShutdown,
|
||||
/* Argument to xInit() and xShutdown() */
|
||||
.pAppData = NULL,
|
||||
};
|
||||
|
||||
int db_sqlite3_use_talloc(void *ctx)
|
||||
{
|
||||
if (db_sqlite_ctx != NULL)
|
||||
return -EEXIST;
|
||||
|
||||
db_sqlite_ctx = talloc_named_const(ctx, 0, "SQLite3");
|
||||
return sqlite3_config(SQLITE_CONFIG_MALLOC, &tall_sqlite_if);
|
||||
}
|
||||
363
src/db_hlr.c
363
src/db_hlr.c
@@ -28,25 +28,26 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/timer.h>
|
||||
#include <osmocom/crypt/auth.h>
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "hlr.h"
|
||||
#include "db.h"
|
||||
#include "gsup_server.h"
|
||||
#include "luop.h"
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/hlr.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
|
||||
#define LOGHLR(imsi, level, fmt, args ...) LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args)
|
||||
|
||||
/*! Add new subscriber record to the HLR database.
|
||||
* \param[in,out] dbc database context.
|
||||
* \param[in] imsi ASCII string of IMSI digits, is validated.
|
||||
* \param[in] flags Bitmask of DB_SUBSCR_FLAG_*.
|
||||
* \returns 0 on success, -EINVAL on invalid IMSI, -EIO on database error.
|
||||
*/
|
||||
int db_subscr_create(struct db_context *dbc, const char *imsi)
|
||||
int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
int rc;
|
||||
@@ -61,6 +62,10 @@ int db_subscr_create(struct db_context *dbc, const char *imsi)
|
||||
|
||||
if (!db_bind_text(stmt, "$imsi", imsi))
|
||||
return -EIO;
|
||||
if (!db_bind_int(stmt, "$nam_cs", (flags & DB_SUBSCR_FLAG_NAM_CS) != 0))
|
||||
return -EIO;
|
||||
if (!db_bind_int(stmt, "$nam_ps", (flags & DB_SUBSCR_FLAG_NAM_PS) != 0))
|
||||
return -EIO;
|
||||
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
@@ -141,8 +146,8 @@ int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id)
|
||||
|
||||
/*! Set a subscriber's MSISDN in the HLR database.
|
||||
* \param[in,out] dbc database context.
|
||||
* \param[in] imsi ASCII string of IMSI digits, or NULL to remove the MSISDN.
|
||||
* \param[in] msisdn ASCII string of MSISDN digits.
|
||||
* \param[in] imsi ASCII string of IMSI digits
|
||||
* \param[in] msisdn ASCII string of MSISDN digits, or NULL to remove the MSISDN.
|
||||
* \returns 0 on success, -EINVAL in case of invalid MSISDN string, -EIO on
|
||||
* database failure, -ENOENT if no such subscriber exists.
|
||||
*/
|
||||
@@ -386,14 +391,83 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*! Set a subscriber's IMEI in the HLR database.
|
||||
* \param[in,out] dbc database context.
|
||||
* \param[in] imsi ASCII string of IMSI digits
|
||||
* \param[in] imei ASCII string of identifier digits, or NULL to remove the IMEI.
|
||||
* \returns 0 on success, -ENOENT when the given subscriber does not exist,
|
||||
* -EIO on database errors.
|
||||
*/
|
||||
int db_subscr_update_imei_by_imsi(struct db_context *dbc, const char* imsi, const char *imei)
|
||||
{
|
||||
int rc, ret = 0;
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_UPD_IMEI_BY_IMSI];
|
||||
|
||||
if (imei && !osmo_imei_str_valid(imei, false)) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update subscriber IMSI='%s': invalid IMEI: '%s'\n", imsi, imei);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!db_bind_text(stmt, "$imsi", imsi))
|
||||
return -EIO;
|
||||
if (imei && !db_bind_text(stmt, "$imei", imei))
|
||||
return -EIO;
|
||||
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Update IMEI for subscriber IMSI='%s': SQL Error: %s\n", imsi,
|
||||
sqlite3_errmsg(dbc->db));
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* verify execution result */
|
||||
rc = sqlite3_changes(dbc->db);
|
||||
if (!rc) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update IMEI for subscriber IMSI='%s': no such subscriber\n", imsi);
|
||||
ret = -ENOENT;
|
||||
} else if (rc != 1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Update IMEI for subscriber IMSI='%s': SQL modified %d rows (expected 1)\n",
|
||||
imsi, rc);
|
||||
ret = -EIO;
|
||||
}
|
||||
|
||||
out:
|
||||
db_remove_reset(stmt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void parse_last_lu_seen(time_t *dst, const char *last_lu_seen_str, const char *imsi, const char *label)
|
||||
{
|
||||
struct tm tm = {0};
|
||||
time_t val;
|
||||
if (!last_lu_seen_str || last_lu_seen_str[0] == '\0')
|
||||
return;
|
||||
|
||||
if (strptime(last_lu_seen_str, DB_LAST_LU_SEEN_FMT, &tm) == NULL) {
|
||||
LOGP(DAUC, LOGL_ERROR, "IMSI-%s: Last LU Seen %s: Cannot parse timestamp '%s'\n",
|
||||
imsi, label, last_lu_seen_str);
|
||||
return;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
val = mktime(&tm);
|
||||
if (val == -1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "IMSI-%s: Last LU Seen %s: Cannot convert timestamp '%s' to time_t: %s\n",
|
||||
imsi, label, last_lu_seen_str, strerror(errno));
|
||||
val = 0;
|
||||
}
|
||||
|
||||
*dst = val;
|
||||
}
|
||||
|
||||
/* Common code for db_subscr_get_by_*() functions. */
|
||||
static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscriber *subscr,
|
||||
const char **err)
|
||||
{
|
||||
int rc;
|
||||
int ret = 0;
|
||||
const char *last_lu_seen_str;
|
||||
struct tm tm;
|
||||
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
@@ -415,31 +489,24 @@ static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscri
|
||||
subscr->id = sqlite3_column_int64(stmt, 0);
|
||||
copy_sqlite3_text_to_buf(subscr->imsi, stmt, 1);
|
||||
copy_sqlite3_text_to_buf(subscr->msisdn, stmt, 2);
|
||||
copy_sqlite3_text_to_buf(subscr->imei, stmt, 3);
|
||||
/* FIXME: These should all be BLOBs as they might contain NUL */
|
||||
copy_sqlite3_text_to_buf(subscr->vlr_number, stmt, 3);
|
||||
copy_sqlite3_text_to_buf(subscr->sgsn_number, stmt, 4);
|
||||
copy_sqlite3_text_to_buf(subscr->sgsn_address, stmt, 5);
|
||||
subscr->periodic_lu_timer = sqlite3_column_int(stmt, 6);
|
||||
subscr->periodic_rau_tau_timer = sqlite3_column_int(stmt, 7);
|
||||
subscr->nam_cs = sqlite3_column_int(stmt, 8);
|
||||
subscr->nam_ps = sqlite3_column_int(stmt, 9);
|
||||
subscr->lmsi = sqlite3_column_int(stmt, 10);
|
||||
subscr->ms_purged_cs = sqlite3_column_int(stmt, 11);
|
||||
subscr->ms_purged_ps = sqlite3_column_int(stmt, 12);
|
||||
last_lu_seen_str = (const char *)sqlite3_column_text(stmt, 13);
|
||||
if (last_lu_seen_str && last_lu_seen_str[0] != '\0') {
|
||||
if (strptime(last_lu_seen_str, DB_LAST_LU_SEEN_FMT, &tm) == NULL) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot parse last LU timestamp '%s' of subscriber with IMSI='%s': %s\n",
|
||||
last_lu_seen_str, subscr->imsi, strerror(errno));
|
||||
} else {
|
||||
subscr->last_lu_seen = mktime(&tm);
|
||||
if (subscr->last_lu_seen == -1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot convert LU timestamp '%s' to time_t: %s\n",
|
||||
last_lu_seen_str, strerror(errno));
|
||||
subscr->last_lu_seen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
copy_sqlite3_text_to_buf(subscr->vlr_number, stmt, 4);
|
||||
copy_sqlite3_text_to_buf(subscr->sgsn_number, stmt, 5);
|
||||
copy_sqlite3_text_to_buf(subscr->sgsn_address, stmt, 6);
|
||||
subscr->periodic_lu_timer = sqlite3_column_int(stmt, 7);
|
||||
subscr->periodic_rau_tau_timer = sqlite3_column_int(stmt, 8);
|
||||
subscr->nam_cs = sqlite3_column_int(stmt, 9);
|
||||
subscr->nam_ps = sqlite3_column_int(stmt, 10);
|
||||
subscr->lmsi = sqlite3_column_int(stmt, 11);
|
||||
subscr->ms_purged_cs = sqlite3_column_int(stmt, 12);
|
||||
subscr->ms_purged_ps = sqlite3_column_int(stmt, 13);
|
||||
parse_last_lu_seen(&subscr->last_lu_seen, (const char *)sqlite3_column_text(stmt, 14),
|
||||
subscr->imsi, "CS");
|
||||
parse_last_lu_seen(&subscr->last_lu_seen_ps, (const char *)sqlite3_column_text(stmt, 15),
|
||||
subscr->imsi, "PS");
|
||||
copy_sqlite3_text_to_ipa_name(&subscr->vlr_via_proxy, stmt, 16);
|
||||
copy_sqlite3_text_to_ipa_name(&subscr->sgsn_via_proxy, stmt, 17);
|
||||
|
||||
out:
|
||||
db_remove_reset(stmt);
|
||||
@@ -458,6 +525,31 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*! Check if a subscriber exists in the HLR database.
|
||||
* \param[in, out] dbc database context.
|
||||
* \param[in] imsi ASCII string of IMSI digits.
|
||||
* \returns 0 if it exists, -ENOENT if it does not exist, -EIO on database error.
|
||||
*/
|
||||
int db_subscr_exists_by_imsi(struct db_context *dbc, const char *imsi) {
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_EXISTS_BY_IMSI];
|
||||
const char *err;
|
||||
int rc;
|
||||
|
||||
if (!db_bind_text(stmt, NULL, imsi))
|
||||
return -EIO;
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
db_remove_reset(stmt);
|
||||
if (rc == SQLITE_ROW)
|
||||
return 0; /* exists */
|
||||
if (rc == SQLITE_DONE)
|
||||
return -ENOENT; /* does not exist */
|
||||
|
||||
err = sqlite3_errmsg(dbc->db);
|
||||
LOGP(DAUC, LOGL_ERROR, "Failed to check if subscriber exists by IMSI='%s': %s\n", imsi, err);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*! Retrieve subscriber data from the HLR database.
|
||||
* \param[in,out] dbc database context.
|
||||
* \param[in] imsi ASCII string of IMSI digits.
|
||||
@@ -476,12 +568,39 @@ int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
|
||||
return -EIO;
|
||||
|
||||
rc = db_sel(dbc, stmt, subscr, &err);
|
||||
if (rc)
|
||||
if (rc && rc != -ENOENT)
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot read subscriber from db: IMSI='%s': %s\n",
|
||||
imsi, err);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*! Check if a subscriber exists in the HLR database.
|
||||
* \param[in, out] dbc database context.
|
||||
* \param[in] msisdn ASCII string of MSISDN digits.
|
||||
* \returns 0 if it exists, -ENOENT if it does not exist, -EIO on database error.
|
||||
*/
|
||||
int db_subscr_exists_by_msisdn(struct db_context *dbc, const char *msisdn)
|
||||
{
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_EXISTS_BY_MSISDN];
|
||||
const char *err;
|
||||
int rc;
|
||||
|
||||
if (!db_bind_text(stmt, NULL, msisdn))
|
||||
return -EIO;
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
db_remove_reset(stmt);
|
||||
if (rc == SQLITE_ROW)
|
||||
return 0; /* exists */
|
||||
if (rc == SQLITE_DONE)
|
||||
return -ENOENT; /* does not exist */
|
||||
|
||||
err = sqlite3_errmsg(dbc->db);
|
||||
LOGP(DAUC, LOGL_ERROR, "Failed to check if subscriber exists "
|
||||
"by MSISDN='%s': %s\n", msisdn, err);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*! Retrieve subscriber data from the HLR database.
|
||||
* \param[in,out] dbc database context.
|
||||
* \param[in] msisdn ASCII string of MSISDN digits.
|
||||
@@ -500,7 +619,7 @@ int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
|
||||
return -EIO;
|
||||
|
||||
rc = db_sel(dbc, stmt, subscr, &err);
|
||||
if (rc)
|
||||
if (rc && rc != -ENOENT)
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot read subscriber from db: MSISDN='%s': %s\n",
|
||||
msisdn, err);
|
||||
return rc;
|
||||
@@ -524,12 +643,34 @@ int db_subscr_get_by_id(struct db_context *dbc, int64_t id,
|
||||
return -EIO;
|
||||
|
||||
rc = db_sel(dbc, stmt, subscr, &err);
|
||||
if (rc)
|
||||
if (rc && rc != -ENOENT)
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot read subscriber from db: ID=%" PRId64 ": %s\n",
|
||||
id, err);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*! Retrieve subscriber data from the HLR database.
|
||||
* \param[in,out] dbc database context.
|
||||
* \param[in] imei ASCII string of identifier digits
|
||||
* \param[out] subscr place retrieved data in this struct.
|
||||
* \returns 0 on success, -ENOENT if no such subscriber was found, -EIO on
|
||||
* database error.
|
||||
*/
|
||||
int db_subscr_get_by_imei(struct db_context *dbc, const char *imei, struct hlr_subscriber *subscr)
|
||||
{
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_SEL_BY_IMEI];
|
||||
const char *err;
|
||||
int rc;
|
||||
|
||||
if (!db_bind_text(stmt, NULL, imei))
|
||||
return -EIO;
|
||||
|
||||
rc = db_sel(dbc, stmt, subscr, &err);
|
||||
if (rc && rc != -ENOENT)
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot read subscriber from db: IMEI=%s: %s\n", imei, err);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*! You should use hlr_subscr_nam() instead; enable or disable PS or CS for a
|
||||
* subscriber without notifying GSUP clients.
|
||||
* \param[in,out] dbc database context.
|
||||
@@ -595,7 +736,8 @@ out:
|
||||
* -EIO on database errors.
|
||||
*/
|
||||
int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
const char *vlr_or_sgsn_number, bool is_ps)
|
||||
const struct osmo_ipa_name *vlr_name, bool is_ps,
|
||||
const struct osmo_ipa_name *via_proxy)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
int rc, ret = 0;
|
||||
@@ -607,9 +749,17 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
if (!db_bind_int64(stmt, "$subscriber_id", subscr_id))
|
||||
return -EIO;
|
||||
|
||||
if (!db_bind_text(stmt, "$number", vlr_or_sgsn_number))
|
||||
if (!db_bind_text(stmt, "$number", (char*)vlr_name->val))
|
||||
return -EIO;
|
||||
|
||||
if (via_proxy && via_proxy->len) {
|
||||
if (!db_bind_text(stmt, "$proxy", (char*)via_proxy->val))
|
||||
return -EIO;
|
||||
} else {
|
||||
if (!db_bind_null(stmt, "$proxy"))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
@@ -643,7 +793,7 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
goto out;
|
||||
}
|
||||
|
||||
stmt = dbc->stmt[DB_STMT_SET_LAST_LU_SEEN];
|
||||
stmt = dbc->stmt[is_ps? DB_STMT_SET_LAST_LU_SEEN_PS : DB_STMT_SET_LAST_LU_SEEN];
|
||||
|
||||
if (!db_bind_int64(stmt, "$subscriber_id", subscr_id))
|
||||
return -EIO;
|
||||
@@ -735,50 +885,105 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*! Update nam_cs/nam_ps in the db and trigger notifications to GSUP clients.
|
||||
* \param[in,out] hlr Global hlr context.
|
||||
* \param[in] subscr Subscriber from a fresh db_subscr_get_by_*() call.
|
||||
* \param[in] nam_val True to enable CS/PS, false to disable.
|
||||
* \param[in] is_ps True to enable/disable PS, false for CS.
|
||||
* \returns 0 on success, ENOEXEC if there is no need to change, a negative
|
||||
* value on error.
|
||||
*/
|
||||
int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val, bool is_ps)
|
||||
static int _db_ind_run(struct db_context *dbc, sqlite3_stmt *stmt, const char *vlr, bool reset)
|
||||
{
|
||||
int rc;
|
||||
struct lu_operation *luop;
|
||||
struct osmo_gsup_conn *co;
|
||||
bool is_val = is_ps? subscr->nam_ps : subscr->nam_cs;
|
||||
|
||||
if (is_val == nam_val) {
|
||||
LOGHLR(subscr->imsi, LOGL_DEBUG, "Already has the requested value when asked to %s %s\n",
|
||||
nam_val ? "enable" : "disable", is_ps ? "PS" : "CS");
|
||||
return ENOEXEC;
|
||||
}
|
||||
if (!db_bind_text(stmt, "$vlr", vlr))
|
||||
return -EIO;
|
||||
|
||||
rc = db_subscr_nam(hlr->dbc, subscr->imsi, nam_val, is_ps);
|
||||
if (rc)
|
||||
return rc > 0? -rc : rc;
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
if (reset)
|
||||
db_remove_reset(stmt);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* If we're disabling, send a notice out to the GSUP client that is
|
||||
* responsible. Otherwise no need. */
|
||||
if (nam_val)
|
||||
return 0;
|
||||
|
||||
/* FIXME: only send to single SGSN where latest update for IMSI came from */
|
||||
llist_for_each_entry(co, &hlr->gs->clients, list) {
|
||||
luop = lu_op_alloc_conn(co);
|
||||
if (!luop) {
|
||||
LOGHLR(subscr->imsi, LOGL_ERROR,
|
||||
"Cannot notify GSUP client, cannot allocate lu_operation,"
|
||||
" for %s:%u\n",
|
||||
co && co->conn && co->conn->server? co->conn->server->addr : "unset",
|
||||
co && co->conn && co->conn->server? co->conn->server->port : 0);
|
||||
continue;
|
||||
}
|
||||
luop->subscr = *subscr;
|
||||
lu_op_tx_del_subscr_data(luop);
|
||||
lu_op_free(luop);
|
||||
static int _db_ind_add(struct db_context *dbc, const char *vlr)
|
||||
{
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_ADD];
|
||||
if (_db_ind_run(dbc, stmt, vlr, true) != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Cannot create IND entry for %s\n", osmo_quote_str_c(OTC_SELECT, vlr, -1));
|
||||
return -EIO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _db_ind_del(struct db_context *dbc, const char *vlr)
|
||||
{
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_DEL];
|
||||
_db_ind_run(dbc, stmt, vlr, true);
|
||||
/* We don't really care about the result. If it didn't exist, then that was the goal anyway. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _db_ind_get(struct db_context *dbc, const char *vlr, unsigned int *ind)
|
||||
{
|
||||
int ret = 0;
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_SELECT];
|
||||
int rc = _db_ind_run(dbc, stmt, vlr, false);
|
||||
if (rc == SQLITE_DONE) {
|
||||
/* Does not exist yet */
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
} else if (rc != SQLITE_ROW) {
|
||||
LOGP(DDB, LOGL_ERROR, "Error executing SQL: %d\n", rc);
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
OSMO_ASSERT(ind);
|
||||
*ind = sqlite3_column_int64(stmt, 0);
|
||||
out:
|
||||
db_remove_reset(stmt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr,
|
||||
unsigned int *ind, bool del)
|
||||
{
|
||||
const char *vlr_name = NULL;
|
||||
int rc;
|
||||
|
||||
switch (vlr->type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
if (vlr->ipa_name.len < 2 || vlr->ipa_name.val[vlr->ipa_name.len - 1] != '\0') {
|
||||
LOGP(DDB, LOGL_ERROR, "Expecting VLR ipa_name to be zero terminated; found %s\n",
|
||||
osmo_ipa_name_to_str(&vlr->ipa_name));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
vlr_name = (const char*)vlr->ipa_name.val;
|
||||
break;
|
||||
default:
|
||||
LOGP(DDB, LOGL_ERROR, "Unsupported osmo_gsup_peer_id type: %s\n",
|
||||
osmo_gsup_peer_id_type_name(vlr->type));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (del)
|
||||
return _db_ind_del(dbc, vlr_name);
|
||||
|
||||
rc = _db_ind_get(dbc, vlr_name, ind);
|
||||
if (!rc)
|
||||
return 0;
|
||||
|
||||
/* Does not exist yet, create. */
|
||||
rc = _db_ind_add(dbc, vlr_name);
|
||||
if (rc) {
|
||||
LOGP(DDB, LOGL_ERROR, "Error creating IND entry for %s\n", osmo_quote_str_c(OTC_SELECT, vlr_name, -1));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* To be sure, query again from scratch. */
|
||||
return _db_ind_get(dbc, vlr_name, ind);
|
||||
}
|
||||
|
||||
int db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr, unsigned int *ind)
|
||||
{
|
||||
return _db_ind(dbc, vlr, ind, false);
|
||||
}
|
||||
|
||||
int db_ind_del(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr)
|
||||
{
|
||||
return _db_ind(dbc, vlr, NULL, true);
|
||||
}
|
||||
|
||||
247
src/dgsm.c
Normal file
247
src/dgsm.c
Normal file
@@ -0,0 +1,247 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/mslookup/mslookup_client.h>
|
||||
#include <osmocom/mslookup/mslookup_client_mdns.h>
|
||||
#include <osmocom/gsupclient/gsup_client.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/hlr.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
#include <osmocom/hlr/gsup_router.h>
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/dgsm.h>
|
||||
#include <osmocom/hlr/proxy.h>
|
||||
#include <osmocom/hlr/remote_hlr.h>
|
||||
#include <osmocom/hlr/mslookup_server.h>
|
||||
#include <osmocom/hlr/mslookup_server_mdns.h>
|
||||
#include <osmocom/hlr/dgsm.h>
|
||||
|
||||
void *dgsm_ctx = NULL;
|
||||
|
||||
static void resolve_hlr_result_cb(struct osmo_mslookup_client *client,
|
||||
uint32_t request_handle,
|
||||
const struct osmo_mslookup_query *query,
|
||||
const struct osmo_mslookup_result *result)
|
||||
{
|
||||
struct proxy *proxy = g_hlr->gs->proxy;
|
||||
struct proxy_subscr proxy_subscr;
|
||||
const struct osmo_sockaddr_str *remote_hlr_addr;
|
||||
|
||||
/* A remote HLR is answering back, indicating that it is the home HLR for a given IMSI.
|
||||
* There should be a mostly empty proxy entry for that IMSI.
|
||||
* Add the remote address data in the proxy. */
|
||||
if (query->id.type != OSMO_MSLOOKUP_ID_IMSI) {
|
||||
LOGP(DDGSM, LOGL_ERROR, "Expected IMSI ID type in mslookup query+result: %s\n",
|
||||
osmo_mslookup_result_name_c(OTC_SELECT, query, result));
|
||||
return;
|
||||
}
|
||||
|
||||
if (result->rc != OSMO_MSLOOKUP_RC_RESULT) {
|
||||
LOG_DGSM(query->id.imsi, LOGL_ERROR, "Failed to resolve remote HLR: %s\n",
|
||||
osmo_mslookup_result_name_c(OTC_SELECT, query, result));
|
||||
proxy_subscr_del(proxy, query->id.imsi);
|
||||
return;
|
||||
}
|
||||
|
||||
if (osmo_sockaddr_str_is_nonzero(&result->host_v4))
|
||||
remote_hlr_addr = &result->host_v4;
|
||||
else if (osmo_sockaddr_str_is_nonzero(&result->host_v6))
|
||||
remote_hlr_addr = &result->host_v6;
|
||||
else {
|
||||
LOG_DGSM(query->id.imsi, LOGL_ERROR, "Invalid address for remote HLR: %s\n",
|
||||
osmo_mslookup_result_name_c(OTC_SELECT, query, result));
|
||||
proxy_subscr_del(proxy, query->id.imsi);
|
||||
return;
|
||||
}
|
||||
|
||||
if (proxy_subscr_get_by_imsi(&proxy_subscr, proxy, query->id.imsi)) {
|
||||
LOG_DGSM(query->id.imsi, LOGL_ERROR, "No proxy entry for mslookup result: %s\n",
|
||||
osmo_mslookup_result_name_c(OTC_SELECT, query, result));
|
||||
return;
|
||||
}
|
||||
|
||||
proxy_subscr_remote_hlr_resolved(proxy, &proxy_subscr, remote_hlr_addr);
|
||||
}
|
||||
|
||||
/* Return true when the message has been handled by D-GSM. */
|
||||
bool dgsm_check_forward_gsup_msg(struct osmo_gsup_req *req)
|
||||
{
|
||||
struct proxy_subscr proxy_subscr;
|
||||
struct proxy *proxy = g_hlr->gs->proxy;
|
||||
struct osmo_mslookup_query query;
|
||||
struct osmo_mslookup_query_handling handling;
|
||||
uint32_t request_handle;
|
||||
|
||||
/* If the IMSI is known in the local HLR, then we won't proxy. */
|
||||
if (db_subscr_exists_by_imsi(g_hlr->dbc, req->gsup.imsi) == 0)
|
||||
return false;
|
||||
|
||||
/* Are we already forwarding this IMSI to a remote HLR? */
|
||||
if (proxy_subscr_get_by_imsi(&proxy_subscr, proxy, req->gsup.imsi) == 0) {
|
||||
proxy_subscr_forward_to_remote_hlr(proxy, &proxy_subscr, req);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* The IMSI is not known locally, so we want to proxy to a remote HLR, but no proxy entry exists yet. We need to
|
||||
* look up the subscriber in remote HLRs via D-GSM mslookup, forward GSUP and reply once a result is back from
|
||||
* there. Defer message and kick off MS lookup. */
|
||||
|
||||
/* Add a proxy entry without a remote address to indicate that we are busy querying for a remote HLR. */
|
||||
proxy_subscr = (struct proxy_subscr){};
|
||||
OSMO_STRLCPY_ARRAY(proxy_subscr.imsi, req->gsup.imsi);
|
||||
if (proxy_subscr_create_or_update(proxy, &proxy_subscr)) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Failed to create proxy entry\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Is a fixed gateway proxy configured? */
|
||||
if (osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.client.gsup_gateway_proxy)) {
|
||||
proxy_subscr_remote_hlr_resolved(proxy, &proxy_subscr, &g_hlr->mslookup.client.gsup_gateway_proxy);
|
||||
|
||||
/* Proxy database modified, update info */
|
||||
if (proxy_subscr_get_by_imsi(&proxy_subscr, proxy, req->gsup.imsi)) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Internal proxy error\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
proxy_subscr_forward_to_remote_hlr(proxy, &proxy_subscr, req);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Kick off an mslookup for the remote HLR? This check could be up first on the top, but do it only now so that
|
||||
* if the mslookup client disconnected, we still continue to service open proxy entries. */
|
||||
if (!osmo_mslookup_client_active(g_hlr->mslookup.client.client)) {
|
||||
LOG_GSUP_REQ(req, LOGL_DEBUG, "mslookup client not running, cannot query remote home HLR\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* First spool message, then kick off mslookup. If the proxy denies this message type, then don't do anything. */
|
||||
if (proxy_subscr_forward_to_remote_hlr(proxy, &proxy_subscr, req)) {
|
||||
/* If the proxy denied forwarding, an error response was already generated. */
|
||||
return true;
|
||||
}
|
||||
|
||||
query = (struct osmo_mslookup_query){
|
||||
.id = {
|
||||
.type = OSMO_MSLOOKUP_ID_IMSI,
|
||||
},
|
||||
};
|
||||
OSMO_STRLCPY_ARRAY(query.id.imsi, req->gsup.imsi);
|
||||
OSMO_STRLCPY_ARRAY(query.service, OSMO_MSLOOKUP_SERVICE_HLR_GSUP);
|
||||
handling = (struct osmo_mslookup_query_handling){
|
||||
.min_wait_milliseconds = g_hlr->mslookup.client.result_timeout_milliseconds,
|
||||
.result_cb = resolve_hlr_result_cb,
|
||||
};
|
||||
request_handle = osmo_mslookup_client_request(g_hlr->mslookup.client.client, &query, &handling);
|
||||
if (!request_handle) {
|
||||
LOG_DGSM(req->gsup.imsi, LOGL_ERROR, "Error dispatching mslookup query for home HLR: %s\n",
|
||||
osmo_mslookup_result_name_c(OTC_SELECT, &query, NULL));
|
||||
proxy_subscr_del(proxy, req->gsup.imsi);
|
||||
/* mslookup seems to not be working. Try handling it locally. */
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dgsm_init(void *ctx)
|
||||
{
|
||||
dgsm_ctx = talloc_named_const(ctx, 0, "dgsm");
|
||||
INIT_LLIST_HEAD(&g_hlr->mslookup.server.local_site_services);
|
||||
|
||||
g_hlr->mslookup.server.local_attach_max_age = 60 * 60;
|
||||
|
||||
g_hlr->mslookup.client.result_timeout_milliseconds = 2000;
|
||||
|
||||
g_hlr->gsup_unit_name.unit_name = "HLR";
|
||||
g_hlr->gsup_unit_name.serno = "unnamed-HLR";
|
||||
g_hlr->gsup_unit_name.swversion = PACKAGE_NAME "-" PACKAGE_VERSION;
|
||||
|
||||
osmo_sockaddr_str_from_str(&g_hlr->mslookup.server.mdns.bind_addr,
|
||||
OSMO_MSLOOKUP_MDNS_IP4, OSMO_MSLOOKUP_MDNS_PORT);
|
||||
osmo_sockaddr_str_from_str(&g_hlr->mslookup.client.mdns.query_addr,
|
||||
OSMO_MSLOOKUP_MDNS_IP4, OSMO_MSLOOKUP_MDNS_PORT);
|
||||
}
|
||||
|
||||
void dgsm_start(void *ctx)
|
||||
{
|
||||
g_hlr->mslookup.client.client = osmo_mslookup_client_new(dgsm_ctx);
|
||||
OSMO_ASSERT(g_hlr->mslookup.client.client);
|
||||
g_hlr->mslookup.allow_startup = true;
|
||||
mslookup_server_mdns_config_apply();
|
||||
dgsm_mdns_client_config_apply();
|
||||
}
|
||||
|
||||
void dgsm_stop()
|
||||
{
|
||||
g_hlr->mslookup.allow_startup = false;
|
||||
mslookup_server_mdns_config_apply();
|
||||
dgsm_mdns_client_config_apply();
|
||||
}
|
||||
|
||||
void dgsm_mdns_client_config_apply(void)
|
||||
{
|
||||
/* Check whether to start/stop/restart mDNS client */
|
||||
const struct osmo_sockaddr_str *current_bind_addr;
|
||||
const char *current_domain_suffix;
|
||||
current_bind_addr = osmo_mslookup_client_method_mdns_get_bind_addr(g_hlr->mslookup.client.mdns.running);
|
||||
current_domain_suffix = osmo_mslookup_client_method_mdns_get_domain_suffix(g_hlr->mslookup.client.mdns.running);
|
||||
|
||||
bool should_run = g_hlr->mslookup.allow_startup
|
||||
&& g_hlr->mslookup.client.enable && g_hlr->mslookup.client.mdns.enable;
|
||||
|
||||
bool should_stop = g_hlr->mslookup.client.mdns.running &&
|
||||
(!should_run
|
||||
|| osmo_sockaddr_str_cmp(&g_hlr->mslookup.client.mdns.query_addr,
|
||||
current_bind_addr)
|
||||
|| strcmp(g_hlr->mslookup.client.mdns.domain_suffix,
|
||||
current_domain_suffix));
|
||||
|
||||
if (should_stop) {
|
||||
osmo_mslookup_client_method_del(g_hlr->mslookup.client.client, g_hlr->mslookup.client.mdns.running);
|
||||
g_hlr->mslookup.client.mdns.running = NULL;
|
||||
LOGP(DDGSM, LOGL_NOTICE, "Stopped mslookup mDNS client\n");
|
||||
}
|
||||
|
||||
if (should_run && !g_hlr->mslookup.client.mdns.running) {
|
||||
g_hlr->mslookup.client.mdns.running =
|
||||
osmo_mslookup_client_add_mdns(g_hlr->mslookup.client.client,
|
||||
g_hlr->mslookup.client.mdns.query_addr.ip,
|
||||
g_hlr->mslookup.client.mdns.query_addr.port,
|
||||
-1,
|
||||
g_hlr->mslookup.client.mdns.domain_suffix);
|
||||
if (!g_hlr->mslookup.client.mdns.running)
|
||||
LOGP(DDGSM, LOGL_ERROR, "Failed to start mslookup mDNS client with target "
|
||||
OSMO_SOCKADDR_STR_FMT "\n",
|
||||
OSMO_SOCKADDR_STR_FMT_ARGS(&g_hlr->mslookup.client.mdns.query_addr));
|
||||
else
|
||||
LOGP(DDGSM, LOGL_NOTICE, "Started mslookup mDNS client, sending mDNS requests to multicast "
|
||||
OSMO_SOCKADDR_STR_FMT "\n",
|
||||
OSMO_SOCKADDR_STR_FMT_ARGS(&g_hlr->mslookup.client.mdns.query_addr));
|
||||
}
|
||||
|
||||
if (g_hlr->mslookup.client.enable && osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.client.gsup_gateway_proxy))
|
||||
LOGP(DDGSM, LOGL_NOTICE,
|
||||
"mslookup client: all GSUP requests for unknown IMSIs will be forwarded to"
|
||||
" gateway-proxy " OSMO_SOCKADDR_STR_FMT "\n",
|
||||
OSMO_SOCKADDR_STR_FMT_ARGS(&g_hlr->mslookup.client.gsup_gateway_proxy));
|
||||
}
|
||||
580
src/dgsm_vty.c
Normal file
580
src/dgsm_vty.c
Normal file
@@ -0,0 +1,580 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <osmocom/vty/vty.h>
|
||||
#include <osmocom/vty/command.h>
|
||||
#include <osmocom/mslookup/mslookup_client_mdns.h>
|
||||
#include <osmocom/mslookup/mdns.h>
|
||||
#include <osmocom/hlr/hlr_vty.h>
|
||||
#include <osmocom/hlr/mslookup_server.h>
|
||||
#include <osmocom/hlr/mslookup_server_mdns.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
|
||||
struct cmd_node mslookup_node = {
|
||||
MSLOOKUP_NODE,
|
||||
"%s(config-mslookup)# ",
|
||||
1,
|
||||
};
|
||||
|
||||
DEFUN(cfg_mslookup,
|
||||
cfg_mslookup_cmd,
|
||||
"mslookup",
|
||||
"Configure Distributed GSM mslookup")
|
||||
{
|
||||
vty->node = MSLOOKUP_NODE;
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
static int mslookup_server_mdns_bind(struct vty *vty, int argc, const char **argv)
|
||||
{
|
||||
const char *ip_str = argc > 0? argv[0] : g_hlr->mslookup.server.mdns.bind_addr.ip;
|
||||
const char *port_str = argc > 1? argv[1] : NULL;
|
||||
uint16_t port_nr = port_str ? atoi(port_str) : g_hlr->mslookup.server.mdns.bind_addr.port;
|
||||
struct osmo_sockaddr_str addr;
|
||||
if (osmo_sockaddr_str_from_str(&addr, ip_str, port_nr)
|
||||
|| !osmo_sockaddr_str_is_nonzero(&addr)) {
|
||||
vty_out(vty, "%% mslookup server: Invalid mDNS bind address: %s %u%s",
|
||||
ip_str, port_nr, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
g_hlr->mslookup.server.mdns.bind_addr = addr;
|
||||
g_hlr->mslookup.server.mdns.enable = true;
|
||||
g_hlr->mslookup.server.enable = true;
|
||||
mslookup_server_mdns_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
static int mslookup_client_mdns_to(struct vty *vty, int argc, const char **argv)
|
||||
{
|
||||
const char *ip_str = argc > 0? argv[0] : g_hlr->mslookup.client.mdns.query_addr.ip;
|
||||
const char *port_str = argc > 1? argv[1] : NULL;
|
||||
uint16_t port_nr = port_str ? atoi(port_str) : g_hlr->mslookup.client.mdns.query_addr.port;
|
||||
struct osmo_sockaddr_str addr;
|
||||
if (osmo_sockaddr_str_from_str(&addr, ip_str, port_nr)
|
||||
|| !osmo_sockaddr_str_is_nonzero(&addr)) {
|
||||
vty_out(vty, "%% mslookup client: Invalid mDNS target address: %s %u%s",
|
||||
ip_str, port_nr, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
g_hlr->mslookup.client.mdns.query_addr = addr;
|
||||
g_hlr->mslookup.client.mdns.enable = true;
|
||||
g_hlr->mslookup.client.enable = true;
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
#define MDNS_STR "Multicast DNS related configuration\n"
|
||||
#define MDNS_IP46_STR "multicast IPv4 address like " OSMO_MSLOOKUP_MDNS_IP4 \
|
||||
" or IPv6 address like " OSMO_MSLOOKUP_MDNS_IP6 "\n"
|
||||
#define MDNS_PORT_STR "mDNS UDP Port number\n"
|
||||
#define MDNS_DOMAIN_SUFFIX_STR "mDNS domain suffix (default: " OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT "). This is appended" \
|
||||
" and stripped from mDNS packets during encoding/decoding, so we don't collide with" \
|
||||
" top-level domains administrated by IANA\n"
|
||||
#define IP46_STR "IPv4 address like 1.2.3.4 or IPv6 address like a:b:c:d::1\n"
|
||||
#define PORT_STR "Service-specific port number\n"
|
||||
|
||||
DEFUN(cfg_mslookup_mdns,
|
||||
cfg_mslookup_mdns_cmd,
|
||||
"mdns bind [IP] [<1-65535>]",
|
||||
MDNS_STR
|
||||
"Convenience shortcut: enable and configure both server and client for mDNS mslookup\n"
|
||||
MDNS_IP46_STR MDNS_PORT_STR)
|
||||
{
|
||||
int rc1 = mslookup_server_mdns_bind(vty, argc, argv);
|
||||
int rc2 = mslookup_client_mdns_to(vty, argc, argv);
|
||||
if (rc1 != CMD_SUCCESS)
|
||||
return rc1;
|
||||
return rc2;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_mdns_domain_suffix,
|
||||
cfg_mslookup_mdns_domain_suffix_cmd,
|
||||
"mdns domain-suffix DOMAIN_SUFFIX",
|
||||
MDNS_STR MDNS_DOMAIN_SUFFIX_STR MDNS_DOMAIN_SUFFIX_STR)
|
||||
{
|
||||
osmo_talloc_replace_string(g_hlr, &g_hlr->mslookup.server.mdns.domain_suffix, argv[0]);
|
||||
osmo_talloc_replace_string(g_hlr, &g_hlr->mslookup.client.mdns.domain_suffix, argv[0]);
|
||||
mslookup_server_mdns_config_apply();
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_no_mdns,
|
||||
cfg_mslookup_no_mdns_cmd,
|
||||
"no mdns bind",
|
||||
NO_STR "Disable both server and client for mDNS mslookup\n")
|
||||
{
|
||||
g_hlr->mslookup.server.mdns.enable = false;
|
||||
g_hlr->mslookup.client.mdns.enable = false;
|
||||
mslookup_server_mdns_config_apply();
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
struct cmd_node mslookup_server_node = {
|
||||
MSLOOKUP_SERVER_NODE,
|
||||
"%s(config-mslookup-server)# ",
|
||||
1,
|
||||
};
|
||||
|
||||
DEFUN(cfg_mslookup_server,
|
||||
cfg_mslookup_server_cmd,
|
||||
"server",
|
||||
"Enable and configure Distributed GSM mslookup server")
|
||||
{
|
||||
vty->node = MSLOOKUP_SERVER_NODE;
|
||||
g_hlr->mslookup.server.enable = true;
|
||||
mslookup_server_mdns_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_no_server,
|
||||
cfg_mslookup_no_server_cmd,
|
||||
"no server",
|
||||
NO_STR "Disable Distributed GSM mslookup server")
|
||||
{
|
||||
g_hlr->mslookup.server.enable = false;
|
||||
mslookup_server_mdns_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_server_mdns_bind,
|
||||
cfg_mslookup_server_mdns_bind_cmd,
|
||||
"mdns bind [IP] [<1-65535>]",
|
||||
MDNS_STR
|
||||
"Configure where the mDNS server listens for mslookup requests\n"
|
||||
MDNS_IP46_STR MDNS_PORT_STR)
|
||||
{
|
||||
return mslookup_server_mdns_bind(vty, argc, argv);
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_server_mdns_domain_suffix,
|
||||
cfg_mslookup_server_mdns_domain_suffix_cmd,
|
||||
"mdns domain-suffix DOMAIN_SUFFIX",
|
||||
MDNS_STR
|
||||
MDNS_DOMAIN_SUFFIX_STR
|
||||
MDNS_DOMAIN_SUFFIX_STR)
|
||||
{
|
||||
osmo_talloc_replace_string(g_hlr, &g_hlr->mslookup.server.mdns.domain_suffix, argv[0]);
|
||||
mslookup_server_mdns_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_server_no_mdns_bind,
|
||||
cfg_mslookup_server_no_mdns_bind_cmd,
|
||||
"no mdns bind",
|
||||
NO_STR "Disable server for mDNS mslookup (do not answer remote requests)\n")
|
||||
{
|
||||
g_hlr->mslookup.server.mdns.enable = false;
|
||||
mslookup_server_mdns_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
struct cmd_node mslookup_server_msc_node = {
|
||||
MSLOOKUP_SERVER_MSC_NODE,
|
||||
"%s(config-mslookup-server-msc)# ",
|
||||
1,
|
||||
};
|
||||
|
||||
DEFUN(cfg_mslookup_server_msc,
|
||||
cfg_mslookup_server_msc_cmd,
|
||||
"msc ipa-name .IPA_NAME",
|
||||
"Configure services for individual local MSCs\n"
|
||||
"Identify locally connected MSC by IPA Unit Name\n"
|
||||
"IPA Unit Name of the local MSC to configure\n")
|
||||
{
|
||||
struct osmo_ipa_name msc_name;
|
||||
struct mslookup_server_msc_cfg *msc;
|
||||
osmo_ipa_name_set_str(&msc_name, argv_concat(argv, argc, 0));
|
||||
|
||||
msc = mslookup_server_msc_get(&msc_name, true);
|
||||
if (!msc) {
|
||||
vty_out(vty, "%% Error creating MSC %s%s", osmo_ipa_name_to_str(&msc_name), VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
vty->node = MSLOOKUP_SERVER_MSC_NODE;
|
||||
vty->index = msc;
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
#define SERVICE_NAME_STR \
|
||||
"mslookup service name, e.g. sip.voice or smpp.sms\n"
|
||||
|
||||
static struct mslookup_server_msc_cfg *msc_from_node(struct vty *vty)
|
||||
{
|
||||
switch (vty->node) {
|
||||
case MSLOOKUP_SERVER_NODE:
|
||||
/* On the mslookup.server node, set services on the wildcard msc, without a particular name. */
|
||||
return mslookup_server_msc_get(&mslookup_server_msc_wildcard, true);
|
||||
case MSLOOKUP_SERVER_MSC_NODE:
|
||||
return vty->index;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_server_msc_service,
|
||||
cfg_mslookup_server_msc_service_cmd,
|
||||
"service NAME at IP <1-65535>",
|
||||
"Configure addresses of local services, as sent in replies to remote mslookup requests.\n"
|
||||
SERVICE_NAME_STR "at\n" IP46_STR PORT_STR)
|
||||
{
|
||||
/* If this command is run on the 'server' node, it produces an empty unit name and serves as wildcard for all
|
||||
* MSCs. If on a 'server' / 'msc' node, set services only for that MSC Unit Name. */
|
||||
struct mslookup_server_msc_cfg *msc = msc_from_node(vty);
|
||||
const char *service = argv[0];
|
||||
const char *ip_str = argv[1];
|
||||
const char *port_str = argv[2];
|
||||
struct osmo_sockaddr_str addr;
|
||||
|
||||
if (!msc) {
|
||||
vty_out(vty, "%% Error: no MSC object on this node%s", VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (osmo_sockaddr_str_from_str(&addr, ip_str, atoi(port_str))
|
||||
|| !osmo_sockaddr_str_is_nonzero(&addr)) {
|
||||
vty_out(vty, "%% mslookup server: Invalid address for service %s: %s %s%s",
|
||||
service, ip_str, port_str, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (mslookup_server_msc_service_set(msc, service, &addr)) {
|
||||
vty_out(vty, "%% mslookup server: Error setting service %s to %s %s%s",
|
||||
service, ip_str, port_str, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
#define NO_SERVICE_AND_NAME_STR NO_STR "Remove one or more service address entries\n" SERVICE_NAME_STR
|
||||
|
||||
DEFUN(cfg_mslookup_server_msc_no_service,
|
||||
cfg_mslookup_server_msc_no_service_cmd,
|
||||
"no service NAME",
|
||||
NO_SERVICE_AND_NAME_STR)
|
||||
{
|
||||
/* If this command is run on the 'server' node, it produces an empty unit name and serves as wildcard for all
|
||||
* MSCs. If on a 'server' / 'msc' node, set services only for that MSC Unit Name. */
|
||||
struct mslookup_server_msc_cfg *msc = msc_from_node(vty);
|
||||
const char *service = argv[0];
|
||||
|
||||
if (!msc) {
|
||||
vty_out(vty, "%% Error: no MSC object on this node%s", VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (mslookup_server_msc_service_del(msc, service, NULL) < 1) {
|
||||
vty_out(vty, "%% mslookup server: cannot remove service '%s'%s",
|
||||
service, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_server_msc_no_service_addr,
|
||||
cfg_mslookup_server_msc_no_service_addr_cmd,
|
||||
"no service NAME at IP <1-65535>",
|
||||
NO_SERVICE_AND_NAME_STR "at\n" IP46_STR PORT_STR)
|
||||
{
|
||||
/* If this command is run on the 'server' node, it produces an empty unit name and serves as wildcard for all
|
||||
* MSCs. If on a 'server' / 'msc' node, set services only for that MSC Unit Name. */
|
||||
struct mslookup_server_msc_cfg *msc = msc_from_node(vty);
|
||||
const char *service = argv[0];
|
||||
const char *ip_str = argv[1];
|
||||
const char *port_str = argv[2];
|
||||
struct osmo_sockaddr_str addr;
|
||||
|
||||
if (!msc) {
|
||||
vty_out(vty, "%% Error: no MSC object on this node%s", VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (osmo_sockaddr_str_from_str(&addr, ip_str, atoi(port_str))
|
||||
|| !osmo_sockaddr_str_is_nonzero(&addr)) {
|
||||
vty_out(vty, "%% mslookup server: Invalid address for 'no service' %s: %s %s%s",
|
||||
service, ip_str, port_str, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (mslookup_server_msc_service_del(msc, service, &addr) < 1) {
|
||||
vty_out(vty, "%% mslookup server: cannot remove service '%s' to %s %s%s",
|
||||
service, ip_str, port_str, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
struct cmd_node mslookup_client_node = {
|
||||
MSLOOKUP_CLIENT_NODE,
|
||||
"%s(config-mslookup-client)# ",
|
||||
1,
|
||||
};
|
||||
|
||||
DEFUN(cfg_mslookup_client,
|
||||
cfg_mslookup_client_cmd,
|
||||
"client",
|
||||
"Enable and configure Distributed GSM mslookup client")
|
||||
{
|
||||
vty->node = MSLOOKUP_CLIENT_NODE;
|
||||
g_hlr->mslookup.client.enable = true;
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_no_client,
|
||||
cfg_mslookup_no_client_cmd,
|
||||
"no client",
|
||||
NO_STR "Disable Distributed GSM mslookup client")
|
||||
{
|
||||
g_hlr->mslookup.client.enable = false;
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_client_timeout,
|
||||
cfg_mslookup_client_timeout_cmd,
|
||||
"timeout <1-100000>",
|
||||
"How long should the mslookup client wait for remote responses before evaluating received results\n"
|
||||
"timeout in milliseconds\n")
|
||||
{
|
||||
uint32_t val = atol(argv[0]);
|
||||
g_hlr->mslookup.client.result_timeout_milliseconds = val;
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
#define EXIT_HINT() \
|
||||
if (vty->type != VTY_FILE) \
|
||||
vty_out(vty, "%% 'exit' this node to apply changes%s", VTY_NEWLINE)
|
||||
|
||||
|
||||
DEFUN(cfg_mslookup_client_mdns_bind,
|
||||
cfg_mslookup_client_mdns_bind_cmd,
|
||||
"mdns bind [IP] [<1-65535>]",
|
||||
MDNS_STR
|
||||
"Enable mDNS client, and configure multicast address to send mDNS mslookup requests to\n"
|
||||
MDNS_IP46_STR MDNS_PORT_STR)
|
||||
{
|
||||
return mslookup_client_mdns_to(vty, argc, argv);
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_client_mdns_domain_suffix,
|
||||
cfg_mslookup_client_mdns_domain_suffix_cmd,
|
||||
"mdns domain-suffix DOMAIN_SUFFIX",
|
||||
MDNS_STR
|
||||
MDNS_DOMAIN_SUFFIX_STR
|
||||
MDNS_DOMAIN_SUFFIX_STR)
|
||||
{
|
||||
osmo_talloc_replace_string(g_hlr, &g_hlr->mslookup.client.mdns.domain_suffix, argv[0]);
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_client_no_mdns_bind,
|
||||
cfg_mslookup_client_no_mdns_bind_cmd,
|
||||
"no mdns bind",
|
||||
NO_STR "Disable mDNS client, do not query remote services by mDNS\n")
|
||||
{
|
||||
g_hlr->mslookup.client.mdns.enable = false;
|
||||
dgsm_mdns_client_config_apply();
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
void config_write_msc_services(struct vty *vty, const char *indent, struct mslookup_server_msc_cfg *msc)
|
||||
{
|
||||
struct mslookup_service_host *e;
|
||||
|
||||
llist_for_each_entry(e, &msc->service_hosts, entry) {
|
||||
if (osmo_sockaddr_str_is_nonzero(&e->host_v4))
|
||||
vty_out(vty, "%sservice %s at %s %u%s", indent, e->service, e->host_v4.ip, e->host_v4.port,
|
||||
VTY_NEWLINE);
|
||||
if (osmo_sockaddr_str_is_nonzero(&e->host_v6))
|
||||
vty_out(vty, "%sservice %s at %s %u%s", indent, e->service, e->host_v6.ip, e->host_v6.port,
|
||||
VTY_NEWLINE);
|
||||
}
|
||||
}
|
||||
|
||||
int config_write_mslookup(struct vty *vty)
|
||||
{
|
||||
if (!g_hlr->mslookup.server.enable
|
||||
&& llist_empty(&g_hlr->mslookup.server.local_site_services)
|
||||
&& !g_hlr->mslookup.client.enable)
|
||||
return CMD_SUCCESS;
|
||||
|
||||
vty_out(vty, "mslookup%s", VTY_NEWLINE);
|
||||
|
||||
if (g_hlr->mslookup.server.enable || !llist_empty(&g_hlr->mslookup.server.local_site_services)) {
|
||||
struct mslookup_server_msc_cfg *msc;
|
||||
|
||||
vty_out(vty, " server%s", VTY_NEWLINE);
|
||||
|
||||
if (g_hlr->mslookup.server.mdns.enable) {
|
||||
vty_out(vty, " mdns bind");
|
||||
if (osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.server.mdns.bind_addr)) {
|
||||
vty_out(vty, " %s %u",
|
||||
g_hlr->mslookup.server.mdns.bind_addr.ip,
|
||||
g_hlr->mslookup.server.mdns.bind_addr.port);
|
||||
}
|
||||
vty_out(vty, "%s", VTY_NEWLINE);
|
||||
}
|
||||
if (strcmp(g_hlr->mslookup.server.mdns.domain_suffix, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT))
|
||||
vty_out(vty, " mdns domain-suffix %s%s",
|
||||
g_hlr->mslookup.server.mdns.domain_suffix,
|
||||
VTY_NEWLINE);
|
||||
|
||||
msc = mslookup_server_msc_get(&mslookup_server_msc_wildcard, false);
|
||||
if (msc)
|
||||
config_write_msc_services(vty, " ", msc);
|
||||
|
||||
llist_for_each_entry(msc, &g_hlr->mslookup.server.local_site_services, entry) {
|
||||
if (!osmo_ipa_name_cmp(&mslookup_server_msc_wildcard, &msc->name))
|
||||
continue;
|
||||
vty_out(vty, " msc %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
|
||||
config_write_msc_services(vty, " ", msc);
|
||||
}
|
||||
|
||||
/* If the server is disabled, still output the above to not lose the service config. */
|
||||
if (!g_hlr->mslookup.server.enable)
|
||||
vty_out(vty, " no server%s", VTY_NEWLINE);
|
||||
}
|
||||
|
||||
if (g_hlr->mslookup.client.enable) {
|
||||
vty_out(vty, " client%s", VTY_NEWLINE);
|
||||
|
||||
if (osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.client.gsup_gateway_proxy))
|
||||
vty_out(vty, " gateway-proxy %s %u%s",
|
||||
g_hlr->mslookup.client.gsup_gateway_proxy.ip,
|
||||
g_hlr->mslookup.client.gsup_gateway_proxy.port,
|
||||
VTY_NEWLINE);
|
||||
|
||||
if (g_hlr->mslookup.client.mdns.enable
|
||||
&& osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.client.mdns.query_addr))
|
||||
vty_out(vty, " mdns bind %s %u%s",
|
||||
g_hlr->mslookup.client.mdns.query_addr.ip,
|
||||
g_hlr->mslookup.client.mdns.query_addr.port,
|
||||
VTY_NEWLINE);
|
||||
if (strcmp(g_hlr->mslookup.client.mdns.domain_suffix, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT))
|
||||
vty_out(vty, " mdns domain-suffix %s%s",
|
||||
g_hlr->mslookup.client.mdns.domain_suffix,
|
||||
VTY_NEWLINE);
|
||||
}
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_client_gateway_proxy,
|
||||
cfg_mslookup_client_gateway_proxy_cmd,
|
||||
"gateway-proxy IP [<1-65535>]",
|
||||
"Configure a fixed IP address to send all GSUP requests for unknown IMSIs to, without invoking a lookup for IMSI\n"
|
||||
"IP address of the remote HLR\n" "GSUP port number (omit for default " OSMO_STRINGIFY_VAL(OSMO_GSUP_PORT) ")\n")
|
||||
{
|
||||
const char *ip_str = argv[0];
|
||||
const char *port_str = argc > 1 ? argv[1] : NULL;
|
||||
struct osmo_sockaddr_str addr;
|
||||
|
||||
if (osmo_sockaddr_str_from_str(&addr, ip_str, port_str ? atoi(port_str) : OSMO_GSUP_PORT)
|
||||
|| !osmo_sockaddr_str_is_nonzero(&addr)) {
|
||||
vty_out(vty, "%% mslookup client: Invalid address for gateway-proxy: %s %s%s",
|
||||
ip_str, port_str ? : "", VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
g_hlr->mslookup.client.gsup_gateway_proxy = addr;
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mslookup_client_no_gateway_proxy,
|
||||
cfg_mslookup_client_no_gateway_proxy_cmd,
|
||||
"no gateway-proxy",
|
||||
NO_STR "Disable gateway proxy for GSUP with unknown IMSIs\n")
|
||||
{
|
||||
g_hlr->mslookup.client.gsup_gateway_proxy = (struct osmo_sockaddr_str){};
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(do_mslookup_show_services,
|
||||
do_mslookup_show_services_cmd,
|
||||
"show mslookup services",
|
||||
SHOW_STR "Distributed GSM / mslookup related information\n"
|
||||
"List configured service addresses as sent to remote mslookup requests\n")
|
||||
{
|
||||
struct mslookup_server_msc_cfg *msc;
|
||||
const struct mslookup_service_host *local_hlr = mslookup_server_get_local_gsup_addr();
|
||||
|
||||
vty_out(vty, "Local GSUP HLR address returned in mslookup responses for local IMSIs:");
|
||||
if (osmo_sockaddr_str_is_nonzero(&local_hlr->host_v4))
|
||||
vty_out(vty, " " OSMO_SOCKADDR_STR_FMT,
|
||||
OSMO_SOCKADDR_STR_FMT_ARGS(&local_hlr->host_v4));
|
||||
if (osmo_sockaddr_str_is_nonzero(&local_hlr->host_v6))
|
||||
vty_out(vty, " " OSMO_SOCKADDR_STR_FMT,
|
||||
OSMO_SOCKADDR_STR_FMT_ARGS(&local_hlr->host_v6));
|
||||
vty_out(vty, "%s", VTY_NEWLINE);
|
||||
|
||||
msc = mslookup_server_msc_get(&mslookup_server_msc_wildcard, false);
|
||||
if (msc)
|
||||
config_write_msc_services(vty, "", msc);
|
||||
|
||||
llist_for_each_entry(msc, &g_hlr->mslookup.server.local_site_services, entry) {
|
||||
if (!osmo_ipa_name_cmp(&mslookup_server_msc_wildcard, &msc->name))
|
||||
continue;
|
||||
vty_out(vty, "msc ipa-name %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
|
||||
config_write_msc_services(vty, " ", msc);
|
||||
}
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
void dgsm_vty_init(void)
|
||||
{
|
||||
install_element(CONFIG_NODE, &cfg_mslookup_cmd);
|
||||
|
||||
install_node(&mslookup_node, config_write_mslookup);
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_mdns_cmd);
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_mdns_domain_suffix_cmd);
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_no_mdns_cmd);
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_server_cmd);
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_no_server_cmd);
|
||||
|
||||
install_node(&mslookup_server_node, NULL);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_mdns_bind_cmd);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_mdns_domain_suffix_cmd);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_no_mdns_bind_cmd);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_service_cmd);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_no_service_cmd);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_no_service_addr_cmd);
|
||||
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_cmd);
|
||||
|
||||
install_node(&mslookup_server_msc_node, NULL);
|
||||
install_element(MSLOOKUP_SERVER_MSC_NODE, &cfg_mslookup_server_msc_service_cmd);
|
||||
install_element(MSLOOKUP_SERVER_MSC_NODE, &cfg_mslookup_server_msc_no_service_cmd);
|
||||
install_element(MSLOOKUP_SERVER_MSC_NODE, &cfg_mslookup_server_msc_no_service_addr_cmd);
|
||||
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_client_cmd);
|
||||
install_element(MSLOOKUP_NODE, &cfg_mslookup_no_client_cmd);
|
||||
install_node(&mslookup_client_node, NULL);
|
||||
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_timeout_cmd);
|
||||
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_mdns_bind_cmd);
|
||||
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_mdns_domain_suffix_cmd);
|
||||
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_no_mdns_bind_cmd);
|
||||
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_gateway_proxy_cmd);
|
||||
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_no_gateway_proxy_cmd);
|
||||
|
||||
install_element_ve(&do_mslookup_show_services_cmd);
|
||||
}
|
||||
@@ -23,17 +23,17 @@
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "gsup_server.h"
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/gsup_router.h>
|
||||
|
||||
struct gsup_route {
|
||||
struct llist_head list;
|
||||
|
||||
uint8_t *addr;
|
||||
struct osmo_gsup_conn *conn;
|
||||
};
|
||||
|
||||
/* find a route for the given address */
|
||||
/*! Find a route for the given address.
|
||||
* \param[in] gs gsup server
|
||||
* \param[in] addr IPA name of the client (SGSN, MSC/VLR). Although this is passed like a blob, together with the
|
||||
* length, it must be nul-terminated! This is for legacy reasons, see the discussion here:
|
||||
* https://gerrit.osmocom.org/#/c/osmo-hlr/+/13048/
|
||||
* \param[in] addrlen length of addr, *including the nul-byte* (strlen(addr) + 1).
|
||||
*/
|
||||
struct osmo_gsup_conn *gsup_route_find(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen)
|
||||
{
|
||||
@@ -47,21 +47,47 @@ struct osmo_gsup_conn *gsup_route_find(struct osmo_gsup_server *gs,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct osmo_gsup_conn *gsup_route_find_by_ipa_name(struct osmo_gsup_server *gs, const struct osmo_ipa_name *ipa_name)
|
||||
{
|
||||
return gsup_route_find(gs, ipa_name->val, ipa_name->len);
|
||||
}
|
||||
|
||||
/*! Find a GSUP connection's route (to read the IPA address from the route).
|
||||
* \param[in] conn GSUP connection
|
||||
* \return GSUP route
|
||||
*/
|
||||
struct gsup_route *gsup_route_find_by_conn(const struct osmo_gsup_conn *conn)
|
||||
{
|
||||
struct gsup_route *gr;
|
||||
|
||||
llist_for_each_entry(gr, &conn->server->routes, list) {
|
||||
if (gr->conn == conn)
|
||||
return gr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* add a new route for the given address to the given conn */
|
||||
int gsup_route_add(struct osmo_gsup_conn *conn, const uint8_t *addr, size_t addrlen)
|
||||
{
|
||||
struct gsup_route *gr;
|
||||
struct osmo_gsup_conn *exists_on_conn;
|
||||
|
||||
/* Check if we already have a route for this address */
|
||||
if (gsup_route_find(conn->server, addr, addrlen))
|
||||
return -EEXIST;
|
||||
exists_on_conn = gsup_route_find(conn->server, addr, addrlen);
|
||||
if (exists_on_conn) {
|
||||
if (exists_on_conn != conn)
|
||||
return -EEXIST;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* allocate new route and populate it */
|
||||
gr = talloc_zero(conn->server, struct gsup_route);
|
||||
if (!gr)
|
||||
return -ENOMEM;
|
||||
|
||||
LOGP(DMAIN, LOGL_INFO, "Adding GSUP route for %s\n", addr);
|
||||
LOGP(DMAIN, LOGL_INFO, "Adding GSUP route for %s via %s:%u\n", addr, conn->conn->addr, conn->conn->port);
|
||||
|
||||
gr->addr = talloc_memdup(gr, addr, addrlen);
|
||||
gr->conn = conn;
|
||||
@@ -70,6 +96,11 @@ int gsup_route_add(struct osmo_gsup_conn *conn, const uint8_t *addr, size_t addr
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gsup_route_add_ipa_name(struct osmo_gsup_conn *conn, const struct osmo_ipa_name *ipa_name)
|
||||
{
|
||||
return gsup_route_add(conn, ipa_name->val, ipa_name->len);
|
||||
}
|
||||
|
||||
/* delete all routes for the given connection */
|
||||
int gsup_route_del_conn(struct osmo_gsup_conn *conn)
|
||||
{
|
||||
@@ -79,7 +110,7 @@ int gsup_route_del_conn(struct osmo_gsup_conn *conn)
|
||||
llist_for_each_entry_safe(gr, gr2, &conn->server->routes, list) {
|
||||
if (gr->conn == conn) {
|
||||
LOGP(DMAIN, LOGL_INFO, "Removing GSUP route for %s (GSUP disconnect)\n",
|
||||
gr->addr);
|
||||
osmo_quote_str_c(OTC_SELECT, (char*)gr->addr, talloc_total_size(gr->addr)));
|
||||
llist_del(&gr->list);
|
||||
talloc_free(gr);
|
||||
num_deleted++;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gsup_server.h"
|
||||
|
||||
struct osmo_gsup_conn *gsup_route_find(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen);
|
||||
|
||||
/* add a new route for the given address to the given conn */
|
||||
int gsup_route_add(struct osmo_gsup_conn *conn, const uint8_t *addr, size_t addrlen);
|
||||
|
||||
/* delete all routes for the given connection */
|
||||
int gsup_route_del_conn(struct osmo_gsup_conn *conn);
|
||||
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg);
|
||||
@@ -21,12 +21,19 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/gsup_router.h>
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
|
||||
/* Send a msgb to a given address using routing */
|
||||
/*! Send a msgb to a given address using routing.
|
||||
* \param[in] gs gsup server
|
||||
* \param[in] addr IPA name of the client (SGSN, MSC/VLR). Although this is passed like a blob, together with the
|
||||
* length, it must be nul-terminated! This is for legacy reasons, see the discussion here:
|
||||
* https://gerrit.osmocom.org/#/c/osmo-hlr/+/13048/
|
||||
* \param[in] addrlen length of addr, *including the nul-byte* (strlen(addr) + 1).
|
||||
* \param[in] msg message buffer
|
||||
*/
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg)
|
||||
@@ -35,7 +42,8 @@ int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
|
||||
conn = gsup_route_find(gs, addr, addrlen);
|
||||
if (!conn) {
|
||||
DEBUGP(DLGSUP, "Cannot find route for addr %s\n", addr);
|
||||
LOGP(DLGSUP, LOGL_ERROR,
|
||||
"Cannot find route for addr %s\n", osmo_quote_str((const char*)addr, addrlen));
|
||||
msgb_free(msg);
|
||||
return -ENODEV;
|
||||
}
|
||||
@@ -43,3 +51,41 @@ int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
return osmo_gsup_conn_send(conn, msg);
|
||||
}
|
||||
|
||||
/*! Send a msgb to a given address using routing.
|
||||
* \param[in] gs gsup server
|
||||
* \param[in] ipa_name IPA unit name of the client (SGSN, MSC/VLR, proxy).
|
||||
* \param[in] msg message buffer
|
||||
*/
|
||||
int osmo_gsup_send_to_ipa_name(struct osmo_gsup_server *gs, const struct osmo_ipa_name *ipa_name, struct msgb *msg)
|
||||
{
|
||||
if (ipa_name->val[ipa_name->len - 1]) {
|
||||
/* Is not nul terminated. But for legacy reasons we (still) require that. */
|
||||
if (ipa_name->len >= sizeof(ipa_name->val)) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "IPA unit name is too long: %s\n",
|
||||
osmo_ipa_name_to_str(ipa_name));
|
||||
return -EINVAL;
|
||||
}
|
||||
struct osmo_ipa_name ipa_name2 = *ipa_name;
|
||||
ipa_name2.val[ipa_name->len] = '\0';
|
||||
ipa_name2.len++;
|
||||
return osmo_gsup_addr_send(gs, ipa_name2.val, ipa_name2.len, msg);
|
||||
}
|
||||
return osmo_gsup_addr_send(gs, ipa_name->val, ipa_name->len, msg);
|
||||
}
|
||||
|
||||
int osmo_gsup_enc_send_to_ipa_name(struct osmo_gsup_server *gs, const struct osmo_ipa_name *ipa_name,
|
||||
const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
struct msgb *msg = osmo_gsup_msgb_alloc("GSUP Tx");
|
||||
int rc;
|
||||
rc = osmo_gsup_encode(msg, gsup);
|
||||
if (rc) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "IMSI-%s: Cannot encode GSUP: %s\n",
|
||||
gsup->imsi, osmo_gsup_message_type_name(gsup->message_type));
|
||||
msgb_free(msg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
LOGP(DLGSUP, LOGL_DEBUG, "IMSI-%s: Tx: %s\n", gsup->imsi, osmo_gsup_message_type_name(gsup->message_type));
|
||||
return osmo_gsup_send_to_ipa_name(gs, ipa_name, msg);
|
||||
}
|
||||
|
||||
@@ -26,9 +26,21 @@
|
||||
#include <osmocom/abis/ipaccess.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
#include <osmocom/gsm/apn.h>
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/gsup_router.h>
|
||||
|
||||
#define LOG_GSUP_CONN(conn, level, fmt, args...) \
|
||||
LOGP(DLGSUP, level, "GSUP peer %s: " fmt, \
|
||||
(conn) ? osmo_ipa_name_to_str(&(conn)->peer_name) : "NULL", ##args)
|
||||
|
||||
struct msgb *osmo_gsup_msgb_alloc(const char *label)
|
||||
{
|
||||
struct msgb *msg = msgb_alloc_headroom(1024+512, 512, label);
|
||||
OSMO_ASSERT(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void osmo_gsup_server_send(struct osmo_gsup_conn *conn,
|
||||
int proto_ext, struct msgb *msg_tx)
|
||||
@@ -50,6 +62,91 @@ int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo_gsup_message *response)
|
||||
{
|
||||
struct osmo_gsup_server *server = req->cb_data;
|
||||
struct osmo_gsup_peer_id *routing;
|
||||
struct osmo_gsup_conn *conn = NULL;
|
||||
struct msgb *msg = osmo_gsup_msgb_alloc("GSUP Tx");
|
||||
int rc;
|
||||
|
||||
if (response->message_type == OSMO_GSUP_MSGT_ROUTING_ERROR
|
||||
&& !osmo_gsup_peer_id_is_empty(&req->via_proxy)) {
|
||||
/* If a routing error occured, we need to route back via the immediate sending peer, not via the
|
||||
* intended final recipient -- because one source of routing errors is a duplicate name for a recipient.
|
||||
* If we resolve to req->source_name, we may send to a completely unrelated recipient. */
|
||||
routing = &req->via_proxy;
|
||||
} else {
|
||||
routing = &req->source_name;
|
||||
}
|
||||
switch (routing->type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
conn = gsup_route_find_by_ipa_name(server, &routing->ipa_name);
|
||||
break;
|
||||
default:
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP peer id kind not supported: %s\n",
|
||||
osmo_gsup_peer_id_type_name(routing->type));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!conn) {
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP client that sent this request not found, cannot respond\n");
|
||||
msgb_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = osmo_gsup_encode(msg, response);
|
||||
if (rc) {
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR, "Unable to encode: {%s}\n",
|
||||
osmo_gsup_message_to_str_c(OTC_SELECT, response));
|
||||
msgb_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = osmo_gsup_conn_send(conn, msg);
|
||||
if (rc)
|
||||
LOG_GSUP_CONN(conn, LOGL_ERROR, "Unable to send: %s\n", osmo_gsup_message_to_str_c(OTC_SELECT, response));
|
||||
}
|
||||
|
||||
struct osmo_gsup_req *osmo_gsup_conn_rx(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
{
|
||||
struct osmo_gsup_req *req;
|
||||
struct osmo_gsup_peer_id gpi = {
|
||||
.type = OSMO_GSUP_PEER_ID_IPA_NAME,
|
||||
.ipa_name = conn->peer_name,
|
||||
};
|
||||
|
||||
req = osmo_gsup_req_new(conn->server, &gpi, msg, gsup_server_send_req_response, conn->server, NULL);
|
||||
if (!req)
|
||||
return NULL;
|
||||
|
||||
if (!osmo_gsup_peer_id_is_empty(&req->via_proxy)) {
|
||||
switch (req->via_proxy.type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
break;
|
||||
default:
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP peer id kind not supported: %s\n",
|
||||
osmo_gsup_peer_id_type_name(req->source_name.type));
|
||||
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The source of the GSUP message is not the immediate GSUP peer, but that peer is our proxy for that
|
||||
* source. Add it to the routes for this conn (so we can route responses back). */
|
||||
if (gsup_route_add_ipa_name(conn, &req->source_name.ipa_name)) {
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR,
|
||||
"GSUP message received from %s via peer %s, but there already exists a"
|
||||
" different route to this source, message is not routable\n",
|
||||
osmo_gsup_peer_id_to_str(&req->source_name),
|
||||
osmo_ipa_name_to_str(&conn->peer_name));
|
||||
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
static int osmo_gsup_conn_oap_handle(struct osmo_gsup_conn *conn,
|
||||
struct msgb *msg_rx)
|
||||
{
|
||||
@@ -195,10 +292,18 @@ static int osmo_gsup_server_ccm_cb(struct ipa_server_conn *conn,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
gsup_route_add(clnt, addr, addr_len);
|
||||
osmo_ipa_name_set(&clnt->peer_name, addr, addr_len);
|
||||
gsup_route_add_ipa_name(clnt, &clnt->peer_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void osmo_gsup_conn_free(struct osmo_gsup_conn *conn)
|
||||
{
|
||||
gsup_route_del_conn(conn);
|
||||
llist_del(&conn->list);
|
||||
talloc_free(conn);
|
||||
}
|
||||
|
||||
static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn)
|
||||
{
|
||||
struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data;
|
||||
@@ -206,10 +311,7 @@ static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn)
|
||||
LOGP(DLGSUP, LOGL_INFO, "Lost GSUP client %s:%d\n",
|
||||
conn->addr, conn->port);
|
||||
|
||||
gsup_route_del_conn(clnt);
|
||||
llist_del(&clnt->list);
|
||||
talloc_free(clnt);
|
||||
|
||||
osmo_gsup_conn_free(clnt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -291,8 +393,7 @@ failed:
|
||||
|
||||
struct osmo_gsup_server *
|
||||
osmo_gsup_server_create(void *ctx, const char *ip_addr, uint16_t tcp_port,
|
||||
osmo_gsup_read_cb_t read_cb,
|
||||
struct llist_head *lu_op_lst, void *priv)
|
||||
osmo_gsup_read_cb_t read_cb, void *priv)
|
||||
{
|
||||
struct osmo_gsup_server *gsups;
|
||||
int rc;
|
||||
@@ -318,8 +419,6 @@ osmo_gsup_server_create(void *ctx, const char *ip_addr, uint16_t tcp_port,
|
||||
if (rc < 0)
|
||||
goto failed;
|
||||
|
||||
gsups->luop = lu_op_lst;
|
||||
|
||||
return gsups;
|
||||
|
||||
failed:
|
||||
@@ -383,8 +482,10 @@ int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup,
|
||||
int len;
|
||||
|
||||
OSMO_ASSERT(gsup);
|
||||
*gsup = (struct osmo_gsup_message){
|
||||
.message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST,
|
||||
};
|
||||
|
||||
gsup->message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST;
|
||||
osmo_strlcpy(gsup->imsi, imsi, sizeof(gsup->imsi));
|
||||
|
||||
if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN)
|
||||
@@ -412,3 +513,39 @@ int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_gsup_peer_id *to_peer,
|
||||
struct osmo_gsup_req *req, struct osmo_gsup_message *modified_gsup)
|
||||
{
|
||||
int rc;
|
||||
/* To forward to a remote entity (HLR, SMSC,...), we need to indicate the original source name in the Source
|
||||
* Name IE to make sure the reply can be routed back. Store the sender in gsup->source_name -- the remote entity
|
||||
* is required to return this as gsup->destination_name so that the reply gets routed to the original sender. */
|
||||
struct osmo_gsup_message forward = *(modified_gsup? : &req->gsup);
|
||||
|
||||
if (req->source_name.type != OSMO_GSUP_PEER_ID_IPA_NAME) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Unsupported GSUP peer id type: %s",
|
||||
osmo_gsup_peer_id_type_name(req->source_name.type));
|
||||
rc = -ENOTSUP;
|
||||
goto routing_error;
|
||||
}
|
||||
forward.source_name = req->source_name.ipa_name.val;
|
||||
forward.source_name_len = req->source_name.ipa_name.len;
|
||||
|
||||
if (to_peer->type != OSMO_GSUP_PEER_ID_IPA_NAME) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Unsupported GSUP peer id type: %s",
|
||||
osmo_gsup_peer_id_type_name(to_peer->type));
|
||||
rc = -ENOTSUP;
|
||||
goto routing_error;
|
||||
}
|
||||
LOG_GSUP_REQ(req, LOGL_INFO, "Forwarding to %s\n", osmo_gsup_peer_id_to_str(to_peer));
|
||||
rc = osmo_gsup_enc_send_to_ipa_name(server, &to_peer->ipa_name, &forward);
|
||||
if (rc)
|
||||
goto routing_error;
|
||||
osmo_gsup_req_free(req);
|
||||
return 0;
|
||||
|
||||
routing_error:
|
||||
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@ AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/incl
|
||||
|
||||
lib_LTLIBRARIES = libosmo-gsup-client.la
|
||||
|
||||
libosmo_gsup_client_la_SOURCES = gsup_client.c
|
||||
libosmo_gsup_client_la_SOURCES = \
|
||||
gsup_peer_id.c \
|
||||
gsup_client.c \
|
||||
gsup_req.c \
|
||||
$(NULL)
|
||||
|
||||
libosmo_gsup_client_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined
|
||||
libosmo_gsup_client_la_LIBADD = $(TALLOC_LIBS) $(LIBOSMOCORE_LIBS) $(LIBOSMOABIS_LIBS)
|
||||
|
||||
@@ -97,6 +97,12 @@ static void connect_timer_cb(void *gsupc_)
|
||||
if (gsupc->is_connected)
|
||||
return;
|
||||
|
||||
if (gsupc->up_down_cb) {
|
||||
/* When the up_down_cb() returns false, the user asks us not to retry connecting. */
|
||||
if (!gsupc->up_down_cb(gsupc, false))
|
||||
return;
|
||||
}
|
||||
|
||||
gsup_client_connect(gsupc);
|
||||
}
|
||||
|
||||
@@ -139,9 +145,18 @@ static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
|
||||
gsup_client_oap_register(gsupc);
|
||||
|
||||
osmo_timer_del(&gsupc->connect_timer);
|
||||
|
||||
if (gsupc->up_down_cb)
|
||||
gsupc->up_down_cb(gsupc, true);
|
||||
} else {
|
||||
osmo_timer_del(&gsupc->ping_timer);
|
||||
|
||||
if (gsupc->up_down_cb) {
|
||||
/* When the up_down_cb() returns false, the user asks us not to retry connecting. */
|
||||
if (!gsupc->up_down_cb(gsupc, false))
|
||||
return;
|
||||
}
|
||||
|
||||
osmo_timer_schedule(&gsupc->connect_timer,
|
||||
OSMO_GSUP_CLIENT_RECONNECT_INTERVAL, 0);
|
||||
}
|
||||
@@ -263,42 +278,40 @@ static void start_test_procedure(struct osmo_gsup_client *gsupc)
|
||||
* Use the provided ipaccess unit as the client-side identifier; ipa_dev should
|
||||
* be allocated in talloc_ctx talloc_ctx as well.
|
||||
* \param[in] talloc_ctx talloc context.
|
||||
* \param[in] ipa_dev IP access unit which contains client identification information; must be allocated
|
||||
* in talloc_ctx as well to ensure it lives throughout the lifetime of the connection.
|
||||
* \param[in] ip_addr GSUP server IP address.
|
||||
* \param[in] tcp_port GSUP server TCP port.
|
||||
* \param[in] read_cb callback for reading from the GSUP connection.
|
||||
* \param[in] oapc_config OPA client configuration.
|
||||
* \returns a GSUP client connection or NULL on failure.
|
||||
* \param[in] config Parameters for setting up the GSUP client.
|
||||
* \return a GSUP client connection, or NULL on failure.
|
||||
*/
|
||||
struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
|
||||
struct ipaccess_unit *ipa_dev,
|
||||
const char *ip_addr,
|
||||
unsigned int tcp_port,
|
||||
osmo_gsup_client_read_cb_t read_cb,
|
||||
struct osmo_oap_client_config *oapc_config)
|
||||
struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx, struct osmo_gsup_client_config *config)
|
||||
{
|
||||
struct osmo_gsup_client *gsupc;
|
||||
int rc;
|
||||
|
||||
OSMO_ASSERT(config->ipa_dev->unit_name);
|
||||
|
||||
gsupc = talloc_zero(talloc_ctx, struct osmo_gsup_client);
|
||||
OSMO_ASSERT(gsupc);
|
||||
gsupc->unit_name = (const char *)ipa_dev->unit_name; /* API backwards compat */
|
||||
gsupc->ipa_dev = ipa_dev;
|
||||
*gsupc = (struct osmo_gsup_client){
|
||||
.unit_name = (const char *)config->ipa_dev->unit_name, /* API backwards compat */
|
||||
.ipa_dev = config->ipa_dev,
|
||||
.read_cb = config->read_cb,
|
||||
.up_down_cb = config->up_down_cb,
|
||||
.data = config->data,
|
||||
};
|
||||
|
||||
/* a NULL oapc_config will mark oap_state disabled. */
|
||||
rc = osmo_oap_client_init(oapc_config, &gsupc->oap_state);
|
||||
rc = osmo_oap_client_init(config->oapc_config, &gsupc->oap_state);
|
||||
if (rc != 0)
|
||||
goto failed;
|
||||
|
||||
gsupc->link = ipa_client_conn_create(gsupc,
|
||||
/* no e1inp */ NULL,
|
||||
0,
|
||||
ip_addr, tcp_port,
|
||||
gsup_client_updown_cb,
|
||||
gsup_client_read_cb,
|
||||
/* default write_cb */ NULL,
|
||||
gsupc);
|
||||
gsupc->link = ipa_client_conn_create2(gsupc,
|
||||
/* no e1inp */ NULL,
|
||||
0,
|
||||
/* no specific local IP:port */ NULL, 0,
|
||||
config->ip_addr, config->tcp_port,
|
||||
gsup_client_updown_cb,
|
||||
gsup_client_read_cb,
|
||||
/* default write_cb */ NULL,
|
||||
gsupc);
|
||||
if (!gsupc->link)
|
||||
goto failed;
|
||||
|
||||
@@ -308,9 +321,6 @@ struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
|
||||
|
||||
if (rc < 0)
|
||||
goto failed;
|
||||
|
||||
gsupc->read_cb = read_cb;
|
||||
|
||||
return gsupc;
|
||||
|
||||
failed:
|
||||
@@ -318,6 +328,26 @@ failed:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Like osmo_gsup_client_create3() but without the up_down_cb and data arguments, and with the oapc_config argument in
|
||||
* a different position.
|
||||
*/
|
||||
struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
|
||||
struct ipaccess_unit *ipa_dev,
|
||||
const char *ip_addr,
|
||||
unsigned int tcp_port,
|
||||
osmo_gsup_client_read_cb_t read_cb,
|
||||
struct osmo_oap_client_config *oapc_config)
|
||||
{
|
||||
struct osmo_gsup_client_config cfg = {
|
||||
.ipa_dev = ipa_dev,
|
||||
.ip_addr = ip_addr,
|
||||
.tcp_port = tcp_port,
|
||||
.oapc_config = oapc_config,
|
||||
.read_cb = read_cb,
|
||||
};
|
||||
return osmo_gsup_client_create3(talloc_ctx, &cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like osmo_gsup_client_create2() except it expects a unit name instead
|
||||
* of a full-blown ipacess_unit as the client-side identifier.
|
||||
@@ -386,7 +416,8 @@ int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
|
||||
rc = osmo_gsup_client_send(gsupc, gsup_msgb);
|
||||
if (rc) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "Couldn't send GSUP message\n");
|
||||
goto error;
|
||||
/* Do not free, osmo_gsup_client_send() already has. */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
187
src/gsupclient/gsup_peer_id.c
Normal file
187
src/gsupclient/gsup_peer_id.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
|
||||
bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name)
|
||||
{
|
||||
return (!ipa_name) || (!ipa_name->len);
|
||||
}
|
||||
|
||||
int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len)
|
||||
{
|
||||
if (!val || !len) {
|
||||
*ipa_name = (struct osmo_ipa_name){};
|
||||
return 0;
|
||||
}
|
||||
if (len > sizeof(ipa_name->val))
|
||||
return -ENOSPC;
|
||||
ipa_name->len = len;
|
||||
memcpy(ipa_name->val, val, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int osmo_ipa_name_set_str_va(struct osmo_ipa_name *ipa_name, const char *str_fmt, va_list ap)
|
||||
{
|
||||
if (!str_fmt)
|
||||
return osmo_ipa_name_set(ipa_name, NULL, 0);
|
||||
vsnprintf((char*)(ipa_name->val), sizeof(ipa_name->val), str_fmt, ap);
|
||||
ipa_name->len = strlen((char*)(ipa_name->val))+1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rc;
|
||||
va_start(ap, str_fmt);
|
||||
rc = osmo_ipa_name_set_str_va(ipa_name, str_fmt, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b)
|
||||
{
|
||||
int cmp;
|
||||
if (a == b)
|
||||
return 0;
|
||||
if (!a)
|
||||
return -1;
|
||||
if (!b)
|
||||
return 1;
|
||||
if (!a->len && !b->len)
|
||||
return 0;
|
||||
if (!a->len && b->len)
|
||||
return -1;
|
||||
if (!b->len && a->len)
|
||||
return 1;
|
||||
|
||||
if (a->len == b->len)
|
||||
return memcmp(a->val, b->val, a->len);
|
||||
else if (a->len < b->len) {
|
||||
cmp = memcmp(a->val, b->val, a->len);
|
||||
if (!cmp)
|
||||
cmp = -1;
|
||||
return cmp;
|
||||
} else {
|
||||
/* a->len > b->len */
|
||||
cmp = memcmp(a->val, b->val, b->len);
|
||||
if (!cmp)
|
||||
cmp = 1;
|
||||
return cmp;
|
||||
}
|
||||
}
|
||||
|
||||
/* Call osmo_ipa_name_to_str_c with OTC_SELECT. */
|
||||
const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name)
|
||||
{
|
||||
return osmo_ipa_name_to_str_c(OTC_SELECT, ipa_name);
|
||||
}
|
||||
|
||||
/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
|
||||
const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_name)
|
||||
{
|
||||
size_t len = ipa_name->len;
|
||||
if (!len)
|
||||
return talloc_strdup(ctx, "");
|
||||
if (ipa_name->val[len-1] == '\0')
|
||||
len--;
|
||||
return osmo_escape_str_c(ctx, (char*)ipa_name->val, len);
|
||||
}
|
||||
|
||||
bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id)
|
||||
{
|
||||
if (!gsup_peer_id)
|
||||
return true;
|
||||
switch (gsup_peer_id->type) {
|
||||
case OSMO_GSUP_PEER_ID_EMPTY:
|
||||
return true;
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
return osmo_ipa_name_is_empty(&gsup_peer_id->ipa_name);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
gsup_peer_id->type = type;
|
||||
switch (type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
return osmo_ipa_name_set(&gsup_peer_id->ipa_name, val, len);
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
|
||||
const char *str_fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rc;
|
||||
|
||||
*gsup_peer_id = (struct osmo_gsup_peer_id){};
|
||||
|
||||
switch (type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
gsup_peer_id->type = OSMO_GSUP_PEER_ID_IPA_NAME;
|
||||
va_start(ap, str_fmt);
|
||||
rc = osmo_ipa_name_set_str_va(&gsup_peer_id->ipa_name, str_fmt, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b)
|
||||
{
|
||||
if (a->type != b->type)
|
||||
return OSMO_CMP(a->type, b->type);
|
||||
switch (a->type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
return osmo_ipa_name_cmp(&a->ipa_name, &b->ipa_name);
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
const struct value_string osmo_gsup_peer_id_type_names[] = {
|
||||
{ OSMO_GSUP_PEER_ID_IPA_NAME, "IPA-name" },
|
||||
{}
|
||||
};
|
||||
|
||||
/* Call osmo_gsup_peer_id_to_str_c with OTC_SELECT */
|
||||
const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gpi)
|
||||
{
|
||||
return osmo_gsup_peer_id_to_str_c(OTC_SELECT, gpi);
|
||||
}
|
||||
|
||||
/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
|
||||
const char *osmo_gsup_peer_id_to_str_c(void *ctx, const struct osmo_gsup_peer_id *gpi)
|
||||
{
|
||||
switch (gpi->type) {
|
||||
case OSMO_GSUP_PEER_ID_IPA_NAME:
|
||||
return osmo_ipa_name_to_str_c(ctx, &gpi->ipa_name);
|
||||
default:
|
||||
return talloc_strdup(ctx, osmo_gsup_peer_id_type_name(gpi->type));
|
||||
}
|
||||
}
|
||||
312
src/gsupclient/gsup_req.c
Normal file
312
src/gsupclient/gsup_req.c
Normal file
@@ -0,0 +1,312 @@
|
||||
/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
|
||||
#include <osmocom/gsupclient/gsup_req.h>
|
||||
|
||||
/*! Create a new osmo_gsup_req record, decode GSUP and add to a provided list of requests.
|
||||
* This function takes ownership of the msgb, which will, on success, be owned by the returned osmo_gsup_req instance
|
||||
* until osmo_gsup_req_free(). If a decoding error occurs, send an error response immediately, and return NULL.
|
||||
*
|
||||
* When this function returns, the original sender is found in req->source_name. If this is not the immediate peer name,
|
||||
* then req->via_proxy is set to the immediate peer, and it is the responsibility of the caller to add req->source_name
|
||||
* to the GSUP routes that are serviced by req->via_proxy (usually not relevant for clients with a single GSUP conn).
|
||||
*
|
||||
* Note: osmo_gsup_req API makes use of OTC_SELECT to allocate volatile buffers for logging. Use of
|
||||
* osmo_select_main_ctx() is mandatory when using osmo_gsup_req.
|
||||
*
|
||||
* \param[in] ctx Talloc context for allocation of the new request.
|
||||
* \param[in] from_peer The IPA unit name of the immediate GSUP peer from which this msgb was received.
|
||||
* \param[in] msg The GSUP message buffer.
|
||||
* \param[in] send_response_cb User specific method to send a GSUP response message, invoked upon
|
||||
* osmo_gsup_req_respond*() functions.
|
||||
* \param[inout] cb_data Context data to be used freely by the caller.
|
||||
* \param[inout] add_to_list List to which to append this request, or NULL for no list.
|
||||
* \return a newly allocated osmo_gsup_req, or NULL on error.
|
||||
*/
|
||||
struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_id *from_peer, struct msgb *msg,
|
||||
osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
|
||||
struct llist_head *add_to_list)
|
||||
{
|
||||
static unsigned int next_req_nr = 1;
|
||||
struct osmo_gsup_req *req;
|
||||
int rc;
|
||||
|
||||
if (!msgb_l2(msg) || !msgb_l2len(msg)) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: missing or empty L2 data\n",
|
||||
osmo_gsup_peer_id_to_str(from_peer));
|
||||
msgb_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
req = talloc_zero(ctx, struct osmo_gsup_req);
|
||||
OSMO_ASSERT(req);
|
||||
/* Note: req->gsup is declared const, so that the incoming message cannot be modified by handlers. */
|
||||
req->nr = next_req_nr++;
|
||||
req->msg = msg;
|
||||
req->send_response_cb = send_response_cb;
|
||||
req->cb_data = cb_data;
|
||||
if (from_peer)
|
||||
req->source_name = *from_peer;
|
||||
rc = osmo_gsup_decode(msgb_l2(req->msg), msgb_l2len(req->msg), (struct osmo_gsup_message*)&req->gsup);
|
||||
if (rc < 0) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: cannot decode (rc=%d)\n", osmo_gsup_peer_id_to_str(from_peer), rc);
|
||||
osmo_gsup_req_free(req);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LOG_GSUP_REQ(req, LOGL_DEBUG, "new request: {%s}\n", osmo_gsup_message_to_str_c(OTC_SELECT, &req->gsup));
|
||||
|
||||
if (req->gsup.source_name_len) {
|
||||
if (osmo_gsup_peer_id_set(&req->source_name, OSMO_GSUP_PEER_ID_IPA_NAME,
|
||||
req->gsup.source_name, req->gsup.source_name_len)) {
|
||||
LOGP(DLGSUP, LOGL_ERROR,
|
||||
"Rx GSUP from %s: failed to decode source_name, message is not routable\n",
|
||||
osmo_gsup_peer_id_to_str(from_peer));
|
||||
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The source of the GSUP message is not the immediate GSUP peer; the peer is our proxy for that source.
|
||||
*/
|
||||
if (osmo_gsup_peer_id_cmp(&req->source_name, from_peer))
|
||||
req->via_proxy = *from_peer;
|
||||
}
|
||||
|
||||
if (!osmo_imsi_str_valid(req->gsup.imsi)) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "invalid IMSI: %s",
|
||||
osmo_quote_str(req->gsup.imsi, -1));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (add_to_list)
|
||||
llist_add_tail(&req->entry, add_to_list);
|
||||
return req;
|
||||
}
|
||||
|
||||
void osmo_gsup_req_free(struct osmo_gsup_req *req)
|
||||
{
|
||||
LOG_GSUP_REQ(req, LOGL_DEBUG, "free\n");
|
||||
if (req->msg)
|
||||
msgb_free(req->msg);
|
||||
if (req->entry.prev)
|
||||
llist_del(&req->entry);
|
||||
talloc_free(req);
|
||||
}
|
||||
|
||||
int _osmo_gsup_req_respond(struct osmo_gsup_req *req, struct osmo_gsup_message *response,
|
||||
bool error, bool final_response, const char *file, int line)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = osmo_gsup_make_response(response, &req->gsup, error, final_response);
|
||||
if (rc) {
|
||||
LOG_GSUP_REQ_SRC(req, LOGL_ERROR, file, line, "Invalid response (rc=%d): {%s}\n",
|
||||
rc, osmo_gsup_message_to_str_c(OTC_SELECT, response));
|
||||
rc = -EINVAL;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
if (!req->send_response_cb) {
|
||||
LOG_GSUP_REQ_SRC(req, LOGL_ERROR, file, line, "No send_response_cb set, cannot send: {%s}\n",
|
||||
osmo_gsup_message_to_str_c(OTC_SELECT, response));
|
||||
rc = -EINVAL;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
LOG_GSUP_REQ_SRC(req, LOGL_DEBUG, file, line, "Tx response: {%s}\n",
|
||||
osmo_gsup_message_to_str_c(OTC_SELECT, response));
|
||||
req->send_response_cb(req, response);
|
||||
|
||||
exit_cleanup:
|
||||
if (final_response)
|
||||
osmo_gsup_req_free(req);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int _osmo_gsup_req_respond_msgt(struct osmo_gsup_req *req, enum osmo_gsup_message_type message_type,
|
||||
bool final_response, const char *file, int line)
|
||||
{
|
||||
struct osmo_gsup_message response = {
|
||||
.message_type = message_type,
|
||||
};
|
||||
return _osmo_gsup_req_respond(req, &response, OSMO_GSUP_IS_MSGT_ERROR(message_type), final_response,
|
||||
file, line);
|
||||
}
|
||||
|
||||
void _osmo_gsup_req_respond_err(struct osmo_gsup_req *req, enum gsm48_gmm_cause cause,
|
||||
const char *file, int line)
|
||||
{
|
||||
struct osmo_gsup_message response = {
|
||||
.cause = cause,
|
||||
};
|
||||
|
||||
/* No need to answer if we couldn't parse an ERROR message type, only REQUESTs need an error reply. */
|
||||
if (!OSMO_GSUP_IS_MSGT_REQUEST(req->gsup.message_type)) {
|
||||
osmo_gsup_req_free(req);
|
||||
return;
|
||||
}
|
||||
|
||||
osmo_gsup_req_respond(req, &response, true, true);
|
||||
}
|
||||
|
||||
/*! This function is implicitly called by the osmo_gsup_req API, if at all possible rather use osmo_gsup_req_respond().
|
||||
* This function is non-static mostly to allow unit testing.
|
||||
*
|
||||
* Set fields, if still unset, that need to be copied from a received message over to its response message, to ensure
|
||||
* the response can be routed back to the requesting peer even via GSUP proxies.
|
||||
*
|
||||
* Note: after calling this function, fields in the reply may reference the same memory as rx and are not deep-copied,
|
||||
* as is the usual way we are handling decoded GSUP messages.
|
||||
*
|
||||
* These fields are set in the reply message, iff they are still unset:
|
||||
* - Set reply->message_type to the rx's matching RESULT code (or ERROR code if error == true).
|
||||
* - IMSI,
|
||||
* - Set reply->destination_name to rx->source_name (for proxy routing),
|
||||
* - sm_rp_mr (for SMS),
|
||||
* - session_id (for SS/USSD),
|
||||
* - if rx->session_state is not NONE, set tx->session_state depending on the final_response argument:
|
||||
* If false, set to OSMO_GSUP_SESSION_STATE_CONTINUE, else OSMO_GSUP_SESSION_STATE_END.
|
||||
*
|
||||
* If values in reply are already set, they will not be overwritten. The return code is an optional way of finding out
|
||||
* whether all values that were already set in 'reply' are indeed matching the 'rx' values that would have been set.
|
||||
*
|
||||
* \param[in] rx Received GSUP message that is being replied to.
|
||||
* \param[inout] reply The message that should be the response to rx, either empty or with some values already set up.
|
||||
* \return 0 if the resulting message is a valid response for rx, nonzero otherwise. A nonzero rc has no effect on the
|
||||
* values set in the reply message: all unset fields are first updated, and then the rc is determined.
|
||||
* The rc is intended to merely warn if the reply message already contained data that is incompatible with rx,
|
||||
* e.g. a mismatching IMSI.
|
||||
*/
|
||||
int osmo_gsup_make_response(struct osmo_gsup_message *reply,
|
||||
const struct osmo_gsup_message *rx, bool error, bool final_response)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (!reply->message_type) {
|
||||
if (error)
|
||||
reply->message_type = OSMO_GSUP_TO_MSGT_ERROR(rx->message_type);
|
||||
else
|
||||
reply->message_type = OSMO_GSUP_TO_MSGT_RESULT(rx->message_type);
|
||||
}
|
||||
|
||||
if (*reply->imsi == '\0')
|
||||
OSMO_STRLCPY_ARRAY(reply->imsi, rx->imsi);
|
||||
|
||||
if (reply->message_class == OSMO_GSUP_MESSAGE_CLASS_UNSET)
|
||||
reply->message_class = rx->message_class;
|
||||
|
||||
if (!reply->destination_name || !reply->destination_name_len) {
|
||||
reply->destination_name = rx->source_name;
|
||||
reply->destination_name_len = rx->source_name_len;
|
||||
}
|
||||
|
||||
/* RP-Message-Reference is mandatory for SM Service */
|
||||
if (!reply->sm_rp_mr)
|
||||
reply->sm_rp_mr = rx->sm_rp_mr;
|
||||
|
||||
/* For SS/USSD, it's important to keep both session state and ID IEs */
|
||||
if (!reply->session_id)
|
||||
reply->session_id = rx->session_id;
|
||||
if (rx->session_state != OSMO_GSUP_SESSION_STATE_NONE
|
||||
&& reply->session_state == OSMO_GSUP_SESSION_STATE_NONE) {
|
||||
if (final_response || rx->session_state == OSMO_GSUP_SESSION_STATE_END)
|
||||
reply->session_state = OSMO_GSUP_SESSION_STATE_END;
|
||||
else
|
||||
reply->session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
|
||||
}
|
||||
|
||||
if (strcmp(reply->imsi, rx->imsi))
|
||||
rc |= 1 << 0;
|
||||
if (reply->message_class != rx->message_class)
|
||||
rc |= 1 << 1;
|
||||
if (rx->sm_rp_mr && (!reply->sm_rp_mr || *rx->sm_rp_mr != *reply->sm_rp_mr))
|
||||
rc |= 1 << 2;
|
||||
if (reply->session_id != rx->session_id)
|
||||
rc |= 1 << 3;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*! Print the most important value of a GSUP message to a string buffer in human readable form.
|
||||
* \param[out] buf The buffer to write to.
|
||||
* \param[out] buflen sizeof(buf).
|
||||
* \param[in] msg GSUP message to print.
|
||||
*/
|
||||
size_t osmo_gsup_message_to_str_buf(char *buf, size_t buflen, const struct osmo_gsup_message *msg)
|
||||
{
|
||||
struct osmo_strbuf sb = { .buf = buf, .len = buflen };
|
||||
if (!msg) {
|
||||
OSMO_STRBUF_PRINTF(sb, "NULL");
|
||||
return sb.chars_needed;
|
||||
}
|
||||
|
||||
if (msg->message_class)
|
||||
OSMO_STRBUF_PRINTF(sb, "%s ", osmo_gsup_message_class_name(msg->message_class));
|
||||
|
||||
OSMO_STRBUF_PRINTF(sb, "%s:", osmo_gsup_message_type_name(msg->message_type));
|
||||
|
||||
OSMO_STRBUF_PRINTF(sb, " imsi=");
|
||||
OSMO_STRBUF_APPEND(sb, osmo_quote_cstr_buf, msg->imsi, strnlen(msg->imsi, sizeof(msg->imsi)));
|
||||
|
||||
if (msg->cause)
|
||||
OSMO_STRBUF_PRINTF(sb, " cause=%s", get_value_string(gsm48_gmm_cause_names, msg->cause));
|
||||
|
||||
switch (msg->cn_domain) {
|
||||
case OSMO_GSUP_CN_DOMAIN_CS:
|
||||
OSMO_STRBUF_PRINTF(sb, " cn_domain=CS");
|
||||
break;
|
||||
case OSMO_GSUP_CN_DOMAIN_PS:
|
||||
OSMO_STRBUF_PRINTF(sb, " cn_domain=PS");
|
||||
break;
|
||||
default:
|
||||
if (msg->cn_domain)
|
||||
OSMO_STRBUF_PRINTF(sb, " cn_domain=?(%d)", msg->cn_domain);
|
||||
break;
|
||||
}
|
||||
|
||||
if (msg->source_name_len) {
|
||||
OSMO_STRBUF_PRINTF(sb, " source_name=");
|
||||
OSMO_STRBUF_APPEND(sb, osmo_quote_cstr_buf, (char*)msg->source_name, msg->source_name_len);
|
||||
}
|
||||
|
||||
if (msg->destination_name_len) {
|
||||
OSMO_STRBUF_PRINTF(sb, " destination_name=");
|
||||
OSMO_STRBUF_APPEND(sb, osmo_quote_cstr_buf, (char*)msg->destination_name, msg->destination_name_len);
|
||||
}
|
||||
|
||||
if (msg->session_id)
|
||||
OSMO_STRBUF_PRINTF(sb, " session_id=%" PRIu32, msg->session_id);
|
||||
if (msg->session_state)
|
||||
OSMO_STRBUF_PRINTF(sb, " session_state=%s", osmo_gsup_session_state_name(msg->session_state));
|
||||
|
||||
if (msg->sm_rp_mr)
|
||||
OSMO_STRBUF_PRINTF(sb, " sm_rp_mr=%" PRIu8, *msg->sm_rp_mr);
|
||||
|
||||
return sb.chars_needed;
|
||||
}
|
||||
|
||||
/*! Same as osmo_gsup_message_to_str_buf() but returns a talloc allocated string. */
|
||||
char *osmo_gsup_message_to_str_c(void *ctx, const struct osmo_gsup_message *msg)
|
||||
{
|
||||
OSMO_NAME_C_IMPL(ctx, 64, "ERROR", osmo_gsup_message_to_str_buf, msg)
|
||||
}
|
||||
649
src/hlr.c
649
src/hlr.c
@@ -23,6 +23,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/stats.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
@@ -32,21 +33,36 @@
|
||||
#include <osmocom/vty/ports.h>
|
||||
#include <osmocom/ctrl/control_vty.h>
|
||||
#include <osmocom/gsm/apn.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
#include <osmocom/gsm/gsm_utils.h>
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
#include <osmocom/mslookup/mslookup_client.h>
|
||||
|
||||
#include "db.h"
|
||||
#include "hlr.h"
|
||||
#include "ctrl.h"
|
||||
#include "logging.h"
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
#include "rand.h"
|
||||
#include "luop.h"
|
||||
#include "hlr_vty.h"
|
||||
#include "hlr_ussd.h"
|
||||
#include <osmocom/gsupclient/gsup_peer_id.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
#include <osmocom/hlr/hlr.h>
|
||||
#include <osmocom/hlr/ctrl.h>
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/gsup_router.h>
|
||||
#include <osmocom/hlr/rand.h>
|
||||
#include <osmocom/hlr/hlr_vty.h>
|
||||
#include <osmocom/hlr/hlr_ussd.h>
|
||||
#include <osmocom/hlr/dgsm.h>
|
||||
#include <osmocom/hlr/proxy.h>
|
||||
#include <osmocom/hlr/lu_fsm.h>
|
||||
#include <osmocom/mslookup/mdns.h>
|
||||
|
||||
struct hlr *g_hlr;
|
||||
static void *hlr_ctx = NULL;
|
||||
static int quit = 0;
|
||||
|
||||
struct osmo_tdef g_hlr_tdefs[] = {
|
||||
/* 4222 is also the OSMO_GSUP_PORT */
|
||||
{ .T = -4222, .default_val = 30, .desc = "GSUP Update Location timeout" },
|
||||
{}
|
||||
};
|
||||
|
||||
/* Trigger 'Insert Subscriber Data' messages to all connected GSUP clients.
|
||||
*
|
||||
* \param[in] subscr A subscriber we have new data to send for.
|
||||
@@ -64,6 +80,8 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
|
||||
return;
|
||||
}
|
||||
|
||||
/* FIXME: send only to current vlr_number and sgsn_number */
|
||||
|
||||
llist_for_each_entry(co, &g_hlr->gs->clients, list) {
|
||||
struct osmo_gsup_message gsup = { };
|
||||
uint8_t msisdn_enc[OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN];
|
||||
@@ -123,7 +141,7 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
|
||||
}
|
||||
|
||||
/* Send ISD to MSC/SGSN */
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ISD UPDATE");
|
||||
msg_out = osmo_gsup_msgb_alloc("GSUP ISD UPDATE");
|
||||
if (msg_out == NULL) {
|
||||
LOGP(DLGSUP, LOGL_ERROR,
|
||||
"IMSI='%s': Cannot notify GSUP client; could not allocate msg buffer "
|
||||
@@ -145,134 +163,183 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
|
||||
}
|
||||
}
|
||||
|
||||
static int generate_new_msisdn(char *msisdn, const char *imsi, unsigned int len)
|
||||
{
|
||||
int i, j, rc;
|
||||
uint8_t rand_buf[GSM23003_MSISDN_MAX_DIGITS];
|
||||
|
||||
OSMO_ASSERT(len <= sizeof(rand_buf));
|
||||
|
||||
/* Generate a random unique MSISDN (with retry) */
|
||||
for (i = 0; i < 10; i++) {
|
||||
/* Get a random number (with retry) */
|
||||
for (j = 0; j < 10; j++) {
|
||||
rc = osmo_get_rand_id(rand_buf, len);
|
||||
if (!rc)
|
||||
break;
|
||||
}
|
||||
if (rc) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "IMSI='%s': Failed to generate new MSISDN, random number generator"
|
||||
" failed (rc=%d)\n", imsi, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Shift 0x00 ... 0xff range to 30 ... 39 (ASCII numbers) */
|
||||
for (j = 0; j < len; j++)
|
||||
msisdn[j] = 48 + (rand_buf[j] % 10);
|
||||
msisdn[j] = '\0';
|
||||
|
||||
/* Ensure there is no subscriber with such MSISDN */
|
||||
if (db_subscr_exists_by_msisdn(g_hlr->dbc, msisdn) == -ENOENT)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Failure */
|
||||
LOGP(DMAIN, LOGL_ERROR, "IMSI='%s': Failed to generate a new MSISDN, consider increasing "
|
||||
"the length for the automatically assigned MSISDNs "
|
||||
"(see 'subscriber-create-on-demand' command)\n", imsi);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int subscr_create_on_demand(const char *imsi)
|
||||
{
|
||||
char msisdn[GSM23003_MSISDN_MAX_DIGITS + 1];
|
||||
int rc;
|
||||
unsigned int rand_msisdn_len = g_hlr->subscr_create_on_demand_rand_msisdn_len;
|
||||
|
||||
if (!g_hlr->subscr_create_on_demand)
|
||||
return -1;
|
||||
if (db_subscr_exists_by_imsi(g_hlr->dbc, imsi) == 0)
|
||||
return -1;
|
||||
if (rand_msisdn_len && generate_new_msisdn(msisdn, imsi, rand_msisdn_len) != 0)
|
||||
return -1;
|
||||
|
||||
LOGP(DMAIN, LOGL_INFO, "IMSI='%s': Creating subscriber on demand\n", imsi);
|
||||
rc = db_subscr_create(g_hlr->dbc, imsi, g_hlr->subscr_create_on_demand_flags);
|
||||
if (rc) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Failed to create subscriber on demand (rc=%d): IMSI='%s'\n", rc, imsi);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!rand_msisdn_len)
|
||||
return 0;
|
||||
|
||||
/* Update MSISDN of the new (just allocated) subscriber */
|
||||
rc = db_subscr_update_msisdn_by_imsi(g_hlr->dbc, imsi, msisdn);
|
||||
if (rc) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "IMSI='%s': Failed to assign MSISDN='%s' (rc=%d)\n", imsi, msisdn, rc);
|
||||
return rc;
|
||||
}
|
||||
LOGP(DMAIN, LOGL_INFO, "IMSI='%s': Successfully assigned MSISDN='%s'\n", imsi, msisdn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Update nam_cs/nam_ps in the db and trigger notifications to GSUP clients.
|
||||
* \param[in,out] hlr Global hlr context.
|
||||
* \param[in] subscr Subscriber from a fresh db_subscr_get_by_*() call.
|
||||
* \param[in] nam_val True to enable CS/PS, false to disable.
|
||||
* \param[in] is_ps True to enable/disable PS, false for CS.
|
||||
* \returns 0 on success, ENOEXEC if there is no need to change, a negative
|
||||
* value on error.
|
||||
*/
|
||||
int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val, bool is_ps)
|
||||
{
|
||||
int rc;
|
||||
bool is_val = is_ps? subscr->nam_ps : subscr->nam_cs;
|
||||
struct osmo_ipa_name vlr_name;
|
||||
struct osmo_gsup_message gsup_del_data = {
|
||||
.message_type = OSMO_GSUP_MSGT_DELETE_DATA_REQUEST,
|
||||
};
|
||||
OSMO_STRLCPY_ARRAY(gsup_del_data.imsi, subscr->imsi);
|
||||
|
||||
if (is_val == nam_val) {
|
||||
LOGP(DAUC, LOGL_DEBUG, "IMSI-%s: Already has the requested value when asked to %s %s\n",
|
||||
subscr->imsi, nam_val ? "enable" : "disable", is_ps ? "PS" : "CS");
|
||||
return ENOEXEC;
|
||||
}
|
||||
|
||||
rc = db_subscr_nam(hlr->dbc, subscr->imsi, nam_val, is_ps);
|
||||
if (rc)
|
||||
return rc > 0? -rc : rc;
|
||||
|
||||
/* If we're disabling, send a notice out to the GSUP client that is
|
||||
* responsible. Otherwise no need. */
|
||||
if (nam_val)
|
||||
return 0;
|
||||
|
||||
if (subscr->vlr_number && osmo_ipa_name_set_str(&vlr_name, subscr->vlr_number))
|
||||
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &vlr_name, &gsup_del_data);
|
||||
if (subscr->sgsn_number && osmo_ipa_name_set_str(&vlr_name, subscr->sgsn_number))
|
||||
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &vlr_name, &gsup_del_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Send Auth Info handling
|
||||
***********************************************************************/
|
||||
|
||||
/* process an incoming SAI request */
|
||||
static int rx_send_auth_info(struct osmo_gsup_conn *conn,
|
||||
const struct osmo_gsup_message *gsup,
|
||||
struct db_context *dbc)
|
||||
static int rx_send_auth_info(struct osmo_gsup_req *req)
|
||||
{
|
||||
struct osmo_gsup_message gsup_out;
|
||||
struct msgb *msg_out;
|
||||
struct osmo_gsup_message gsup_out = {
|
||||
.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT,
|
||||
};
|
||||
bool separation_bit = false;
|
||||
int num_auth_vectors = OSMO_GSUP_MAX_NUM_AUTH_INFO;
|
||||
unsigned int auc_3g_ind;
|
||||
int rc;
|
||||
|
||||
/* initialize return message structure */
|
||||
memset(&gsup_out, 0, sizeof(gsup_out));
|
||||
memcpy(&gsup_out.imsi, &gsup->imsi, sizeof(gsup_out.imsi));
|
||||
subscr_create_on_demand(req->gsup.imsi);
|
||||
|
||||
rc = db_get_auc(dbc, gsup->imsi, conn->auc_3g_ind,
|
||||
if (req->gsup.current_rat_type == OSMO_RAT_EUTRAN_SGS)
|
||||
separation_bit = true;
|
||||
|
||||
if (req->gsup.num_auth_vectors > 0 &&
|
||||
req->gsup.num_auth_vectors <= OSMO_GSUP_MAX_NUM_AUTH_INFO)
|
||||
num_auth_vectors = req->gsup.num_auth_vectors;
|
||||
rc = db_ind(g_hlr->dbc, &req->source_name, &auc_3g_ind);
|
||||
if (rc) {
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR,
|
||||
"Unable to determine 3G auth IND for source %s (rc=%d),"
|
||||
" generating tuples with IND = 0\n",
|
||||
osmo_gsup_peer_id_to_str(&req->source_name), rc);
|
||||
auc_3g_ind = 0;
|
||||
}
|
||||
|
||||
rc = db_get_auc(g_hlr->dbc, req->gsup.imsi, auc_3g_ind,
|
||||
gsup_out.auth_vectors,
|
||||
ARRAY_SIZE(gsup_out.auth_vectors),
|
||||
gsup->rand, gsup->auts);
|
||||
num_auth_vectors,
|
||||
req->gsup.rand, req->gsup.auts, separation_bit);
|
||||
|
||||
if (rc <= 0) {
|
||||
gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR;
|
||||
switch (rc) {
|
||||
case 0:
|
||||
/* 0 means "0 tuples generated", which shouldn't happen.
|
||||
* Treat the same as "no auth data". */
|
||||
case -ENOKEY:
|
||||
LOGP(DAUC, LOGL_NOTICE, "%s: IMSI known, but has no auth data;"
|
||||
" Returning slightly inaccurate cause 'IMSI Unknown' via GSUP\n",
|
||||
gsup->imsi);
|
||||
gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN;
|
||||
break;
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN,
|
||||
"IMSI known, but has no auth data;"
|
||||
" Returning slightly inaccurate cause 'IMSI Unknown' via GSUP");
|
||||
return rc;
|
||||
case -ENOENT:
|
||||
LOGP(DAUC, LOGL_NOTICE, "%s: IMSI not known\n", gsup->imsi);
|
||||
gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN;
|
||||
break;
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN, "IMSI unknown");
|
||||
return rc;
|
||||
default:
|
||||
LOGP(DAUC, LOGL_ERROR, "%s: failure to look up IMSI in db\n", gsup->imsi);
|
||||
gsup_out.cause = GMM_CAUSE_NET_FAIL;
|
||||
break;
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "failure to look up IMSI in db");
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT;
|
||||
gsup_out.num_auth_vectors = rc;
|
||||
}
|
||||
gsup_out.num_auth_vectors = rc;
|
||||
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response");
|
||||
osmo_gsup_encode(msg_out, &gsup_out);
|
||||
return osmo_gsup_conn_send(conn, msg_out);
|
||||
osmo_gsup_req_respond(req, &gsup_out, false, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* LU Operation State / Structure
|
||||
***********************************************************************/
|
||||
|
||||
static LLIST_HEAD(g_lu_ops);
|
||||
|
||||
/*! Receive Cancel Location Result from old VLR/SGSN */
|
||||
void lu_op_rx_cancel_old_ack(struct lu_operation *luop,
|
||||
const struct osmo_gsup_message *gsup)
|
||||
/*! Receive Update Location Request, creates new lu_operation */
|
||||
static int rx_upd_loc_req(struct osmo_gsup_conn *conn, struct osmo_gsup_req *req)
|
||||
{
|
||||
OSMO_ASSERT(luop->state == LU_S_CANCEL_SENT);
|
||||
/* FIXME: Check for spoofing */
|
||||
|
||||
osmo_timer_del(&luop->timer);
|
||||
|
||||
/* FIXME */
|
||||
|
||||
lu_op_tx_insert_subscr_data(luop);
|
||||
}
|
||||
|
||||
/*! Receive Insert Subscriber Data Result from new VLR/SGSN */
|
||||
static void lu_op_rx_insert_subscr_data_ack(struct lu_operation *luop,
|
||||
const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
OSMO_ASSERT(luop->state == LU_S_ISD_SENT);
|
||||
/* FIXME: Check for spoofing */
|
||||
|
||||
osmo_timer_del(&luop->timer);
|
||||
|
||||
/* Subscriber_Present_HLR */
|
||||
/* CS only: Check_SS_required? -> MAP-FW-CHECK_SS_IND.req */
|
||||
|
||||
/* Send final ACK towards inquiring VLR/SGSN */
|
||||
lu_op_tx_ack(luop);
|
||||
}
|
||||
|
||||
/*! Receive GSUP message for given \ref lu_operation */
|
||||
void lu_op_rx_gsup(struct lu_operation *luop,
|
||||
const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
switch (gsup->message_type) {
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_ERROR:
|
||||
/* FIXME */
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_RESULT:
|
||||
lu_op_rx_insert_subscr_data_ack(luop, gsup);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR:
|
||||
/* FIXME */
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT:
|
||||
lu_op_rx_cancel_old_ack(luop, gsup);
|
||||
break;
|
||||
default:
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unhandled GSUP msg_type 0x%02x\n",
|
||||
gsup->message_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*! Receive Update Location Request, creates new \ref lu_operation */
|
||||
static int rx_upd_loc_req(struct osmo_gsup_conn *conn,
|
||||
const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
struct hlr_subscriber *subscr;
|
||||
struct lu_operation *luop = lu_op_alloc_conn(conn);
|
||||
if (!luop) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "LU REQ from conn without addr?\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
subscr = &luop->subscr;
|
||||
|
||||
lu_op_statechg(luop, LU_S_LU_RECEIVED);
|
||||
|
||||
switch (gsup->cn_domain) {
|
||||
switch (req->gsup.cn_domain) {
|
||||
case OSMO_GSUP_CN_DOMAIN_CS:
|
||||
conn->supports_cs = true;
|
||||
break;
|
||||
@@ -283,188 +350,220 @@ static int rx_upd_loc_req(struct osmo_gsup_conn *conn,
|
||||
* a request, the PS Domain is assumed." */
|
||||
case OSMO_GSUP_CN_DOMAIN_PS:
|
||||
conn->supports_ps = true;
|
||||
luop->is_ps = true;
|
||||
break;
|
||||
}
|
||||
llist_add(&luop->list, &g_lu_ops);
|
||||
|
||||
/* Roughly follwing "Process Update_Location_HLR" of TS 09.02 */
|
||||
subscr_create_on_demand(req->gsup.imsi);
|
||||
|
||||
/* check if subscriber is known at all */
|
||||
if (!lu_op_fill_subscr(luop, g_hlr->dbc, gsup->imsi)) {
|
||||
/* Send Error back: Subscriber Unknown in HLR */
|
||||
osmo_strlcpy(luop->subscr.imsi, gsup->imsi, sizeof(luop->subscr.imsi));
|
||||
lu_op_tx_error(luop, GMM_CAUSE_IMSI_UNKNOWN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check if subscriber is generally permitted on CS or PS
|
||||
* service (as requested) */
|
||||
if (!luop->is_ps && !luop->subscr.nam_cs) {
|
||||
lu_op_tx_error(luop, GMM_CAUSE_PLMN_NOTALLOWED);
|
||||
return 0;
|
||||
} else if (luop->is_ps && !luop->subscr.nam_ps) {
|
||||
lu_op_tx_error(luop, GMM_CAUSE_GPRS_NOTALLOWED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO: Set subscriber tracing = deactive in VLR/SGSN */
|
||||
|
||||
#if 0
|
||||
/* Cancel in old VLR/SGSN, if new VLR/SGSN differs from old */
|
||||
if (luop->is_ps == false &&
|
||||
strcmp(subscr->vlr_number, vlr_number)) {
|
||||
lu_op_tx_cancel_old(luop);
|
||||
} else if (luop->is_ps == true &&
|
||||
strcmp(subscr->sgsn_number, sgsn_number)) {
|
||||
lu_op_tx_cancel_old(luop);
|
||||
} else
|
||||
#endif
|
||||
|
||||
/* Store the VLR / SGSN number with the subscriber, so we know where it was last seen. */
|
||||
LOGP(DAUC, LOGL_DEBUG, "IMSI='%s': storing %s = %s\n",
|
||||
subscr->imsi, luop->is_ps ? "SGSN number" : "VLR number",
|
||||
osmo_quote_str((const char*)luop->peer, -1));
|
||||
if (db_subscr_lu(g_hlr->dbc, subscr->id, (const char *)luop->peer, luop->is_ps))
|
||||
LOGP(DAUC, LOGL_ERROR, "IMSI='%s': Cannot update %s in the database\n",
|
||||
subscr->imsi, luop->is_ps ? "SGSN number" : "VLR number");
|
||||
|
||||
{
|
||||
/* TODO: Subscriber allowed to roam in PLMN? */
|
||||
/* TODO: Update RoutingInfo */
|
||||
/* TODO: Reset Flag MS Purged (cs/ps) */
|
||||
/* TODO: Control_Tracing_HLR / Control_Tracing_HLR_with_SGSN */
|
||||
lu_op_tx_insert_subscr_data(luop);
|
||||
}
|
||||
lu_rx_gsup(req);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rx_purge_ms_req(struct osmo_gsup_conn *conn,
|
||||
const struct osmo_gsup_message *gsup)
|
||||
static int rx_purge_ms_req(struct osmo_gsup_req *req)
|
||||
{
|
||||
struct osmo_gsup_message gsup_reply = {0};
|
||||
struct msgb *msg_out;
|
||||
bool is_ps = false;
|
||||
bool is_ps = (req->gsup.cn_domain != OSMO_GSUP_CN_DOMAIN_CS);
|
||||
int rc;
|
||||
|
||||
LOGP(DAUC, LOGL_INFO, "%s: Purge MS (%s)\n", gsup->imsi,
|
||||
is_ps ? "PS" : "CS");
|
||||
|
||||
memcpy(gsup_reply.imsi, gsup->imsi, sizeof(gsup_reply.imsi));
|
||||
|
||||
if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS)
|
||||
is_ps = true;
|
||||
LOG_GSUP_REQ_CAT(req, DAUC, LOGL_INFO, "Purge MS (%s)\n", is_ps ? "PS" : "CS");
|
||||
|
||||
/* FIXME: check if the VLR that sends the purge is the same that
|
||||
* we have on record. Only update if yes */
|
||||
|
||||
/* Perform the actual update of the DB */
|
||||
rc = db_subscr_purge(g_hlr->dbc, gsup->imsi, true, is_ps);
|
||||
rc = db_subscr_purge(g_hlr->dbc, req->gsup.imsi, true, is_ps);
|
||||
|
||||
if (rc == 0)
|
||||
gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT;
|
||||
else if (rc == -ENOENT) {
|
||||
gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR;
|
||||
gsup_reply.cause = GMM_CAUSE_IMSI_UNKNOWN;
|
||||
} else {
|
||||
gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR;
|
||||
gsup_reply.cause = GMM_CAUSE_NET_FAIL;
|
||||
}
|
||||
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response");
|
||||
osmo_gsup_encode(msg_out, &gsup_reply);
|
||||
return osmo_gsup_conn_send(conn, msg_out);
|
||||
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_PURGE_MS_RESULT, true);
|
||||
else if (rc == -ENOENT)
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN, "IMSI unknown");
|
||||
else
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "db error");
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int gsup_send_err_reply(struct osmo_gsup_conn *conn, const char *imsi,
|
||||
enum osmo_gsup_message_type type_in, uint8_t err_cause)
|
||||
static int rx_check_imei_req(struct osmo_gsup_req *req)
|
||||
{
|
||||
int type_err = osmo_gsup_get_err_msg_type(type_in);
|
||||
struct osmo_gsup_message gsup_reply = {0};
|
||||
struct msgb *msg_out;
|
||||
struct osmo_gsup_message gsup_reply;
|
||||
char imei[GSM23003_IMEI_NUM_DIGITS_NO_CHK+1] = {0};
|
||||
const struct osmo_gsup_message *gsup = &req->gsup;
|
||||
int rc;
|
||||
|
||||
if (type_err < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "unable to determine error response for %s\n",
|
||||
osmo_gsup_message_type_name(type_in));
|
||||
return type_err;
|
||||
/* Require IMEI */
|
||||
if (!gsup->imei_enc) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "missing IMEI");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OSMO_STRLCPY_ARRAY(gsup_reply.imsi, imsi);
|
||||
gsup_reply.message_type = type_err;
|
||||
gsup_reply.cause = err_cause;
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ERR response");
|
||||
OSMO_ASSERT(msg_out);
|
||||
osmo_gsup_encode(msg_out, &gsup_reply);
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Tx %s\n", osmo_gsup_message_type_name(type_err));
|
||||
return osmo_gsup_conn_send(conn, msg_out);
|
||||
/* Decode IMEI (fails if IMEI is too long) */
|
||||
rc = gsm48_decode_bcd_number2(imei, sizeof(imei), gsup->imei_enc, gsup->imei_enc_len, 0);
|
||||
if (rc < 0) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO,
|
||||
"failed to decode IMEI %s (rc: %d)",
|
||||
osmo_hexdump_c(OTC_SELECT, gsup->imei_enc, gsup->imei_enc_len),
|
||||
rc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check if IMEI is too short */
|
||||
if (!osmo_imei_str_valid(imei, false)) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO,
|
||||
"invalid IMEI: %s", osmo_quote_str_c(OTC_SELECT, imei, -1));
|
||||
return -1;
|
||||
}
|
||||
|
||||
subscr_create_on_demand(gsup->imsi);
|
||||
|
||||
/* Save in DB if desired */
|
||||
if (g_hlr->store_imei) {
|
||||
LOGP(DAUC, LOGL_DEBUG, "IMSI='%s': storing IMEI = %s\n", gsup->imsi, imei);
|
||||
if (db_subscr_update_imei_by_imsi(g_hlr->dbc, gsup->imsi, imei) < 0) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "Failed to store IMEI in HLR db");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* Check if subscriber exists and print IMEI */
|
||||
LOGP(DMAIN, LOGL_INFO, "IMSI='%s': has IMEI = %s (consider setting 'store-imei')\n", gsup->imsi, imei);
|
||||
struct hlr_subscriber subscr;
|
||||
if (db_subscr_get_by_imsi(g_hlr->dbc, gsup->imsi, &subscr) < 0) {
|
||||
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "IMSI unknown");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Accept all IMEIs */
|
||||
gsup_reply = (struct osmo_gsup_message){
|
||||
.message_type = OSMO_GSUP_MSGT_CHECK_IMEI_RESULT,
|
||||
.imei_result = OSMO_GSUP_IMEI_RESULT_ACK,
|
||||
};
|
||||
return osmo_gsup_req_respond(req, &gsup_reply, false, true);
|
||||
}
|
||||
|
||||
static char namebuf[255];
|
||||
#define LOGP_GSUP_FWD(gsup, level, fmt, args ...) \
|
||||
LOGP(DMAIN, level, "Forward %s (class=%s, IMSI=%s, %s->%s): " fmt, \
|
||||
osmo_gsup_message_type_name((gsup)->message_type), \
|
||||
osmo_gsup_message_class_name((gsup)->message_class), \
|
||||
(gsup)->imsi, \
|
||||
osmo_quote_str((const char *)(gsup)->source_name, (gsup)->source_name_len), \
|
||||
osmo_quote_str_buf2(namebuf, sizeof(namebuf), (const char *)(gsup)->destination_name, (gsup)->destination_name_len), \
|
||||
## args)
|
||||
|
||||
static int read_cb_forward(struct osmo_gsup_req *req)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
const struct osmo_gsup_message *gsup = &req->gsup;
|
||||
struct osmo_gsup_message gsup_err;
|
||||
struct msgb *forward_msg;
|
||||
struct osmo_ipa_name destination_name;
|
||||
|
||||
/* Check for routing IEs */
|
||||
if (!req->gsup.source_name || !req->gsup.source_name_len
|
||||
|| !req->gsup.destination_name || !req->gsup.destination_name_len) {
|
||||
LOGP_GSUP_FWD(&req->gsup, LOGL_ERROR, "missing routing IEs\n");
|
||||
goto routing_error;
|
||||
}
|
||||
|
||||
if (osmo_ipa_name_set(&destination_name, req->gsup.destination_name, req->gsup.destination_name_len)) {
|
||||
LOGP_GSUP_FWD(&req->gsup, LOGL_ERROR, "invalid destination name\n");
|
||||
goto routing_error;
|
||||
}
|
||||
|
||||
LOG_GSUP_REQ(req, LOGL_INFO, "Forwarding to %s\n", osmo_ipa_name_to_str(&destination_name));
|
||||
|
||||
/* Forward message without re-encoding (so we don't remove unknown IEs).
|
||||
* Copy GSUP part to forward, removing incoming IPA header to be able to prepend an outgoing IPA header */
|
||||
forward_msg = osmo_gsup_msgb_alloc("GSUP forward");
|
||||
forward_msg->l2h = msgb_put(forward_msg, msgb_l2len(req->msg));
|
||||
memcpy(forward_msg->l2h, msgb_l2(req->msg), msgb_l2len(req->msg));
|
||||
ret = osmo_gsup_send_to_ipa_name(g_hlr->gs, &destination_name, forward_msg);
|
||||
if (ret) {
|
||||
LOGP_GSUP_FWD(gsup, LOGL_ERROR, "%s (rc=%d)\n",
|
||||
ret == -ENODEV ? "destination not connected" : "unknown error",
|
||||
ret);
|
||||
goto routing_error;
|
||||
}
|
||||
osmo_gsup_req_free(req);
|
||||
return 0;
|
||||
|
||||
routing_error:
|
||||
gsup_err = (struct osmo_gsup_message){
|
||||
.message_type = OSMO_GSUP_MSGT_ROUTING_ERROR,
|
||||
.source_name = gsup->destination_name,
|
||||
.source_name_len = gsup->destination_name_len,
|
||||
};
|
||||
osmo_gsup_req_respond(req, &gsup_err, true, true);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
{
|
||||
static struct osmo_gsup_message gsup;
|
||||
int rc;
|
||||
struct osmo_gsup_req *req = osmo_gsup_conn_rx(conn, msg);
|
||||
if (!req)
|
||||
return -EINVAL;
|
||||
|
||||
rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup);
|
||||
if (rc < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "error in GSUP decode: %d\n", rc);
|
||||
return rc;
|
||||
/* If the GSUP recipient is other than this HLR, forward. */
|
||||
if (req->gsup.destination_name_len) {
|
||||
struct osmo_ipa_name destination_name;
|
||||
struct osmo_ipa_name my_name;
|
||||
osmo_ipa_name_set_str(&my_name, g_hlr->gsup_unit_name.serno);
|
||||
if (!osmo_ipa_name_set(&destination_name, req->gsup.destination_name, req->gsup.destination_name_len)
|
||||
&& osmo_ipa_name_cmp(&destination_name, &my_name)) {
|
||||
return read_cb_forward(req);
|
||||
}
|
||||
}
|
||||
|
||||
/* 3GPP TS 23.003 Section 2.2 clearly states that an IMSI with less than 5
|
||||
* digits is impossible. Even 5 digits is a highly theoretical case */
|
||||
if (strlen(gsup.imsi) < 5)
|
||||
return gsup_send_err_reply(conn, gsup.imsi, gsup.message_type, GMM_CAUSE_INV_MAND_INFO);
|
||||
/* Distributed GSM: check whether to proxy for / lookup a remote HLR.
|
||||
* It would require less database hits to do this only if a local-only operation fails with "unknown IMSI", but
|
||||
* it becomes semantically easier if we do this once-off ahead of time. */
|
||||
if (osmo_mslookup_client_active(g_hlr->mslookup.client.client)
|
||||
|| osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.client.gsup_gateway_proxy)) {
|
||||
if (dgsm_check_forward_gsup_msg(req))
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (gsup.message_type) {
|
||||
/* HLR related messages that are handled at this HLR instance */
|
||||
switch (req->gsup.message_type) {
|
||||
/* requests sent to us */
|
||||
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
|
||||
rx_send_auth_info(conn, &gsup, g_hlr->dbc);
|
||||
rx_send_auth_info(req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
|
||||
rx_upd_loc_req(conn, &gsup);
|
||||
rx_upd_loc_req(conn, req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_PURGE_MS_REQUEST:
|
||||
rx_purge_ms_req(conn, &gsup);
|
||||
rx_purge_ms_req(req);
|
||||
break;
|
||||
/* responses to requests sent by us */
|
||||
case OSMO_GSUP_MSGT_DELETE_DATA_ERROR:
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error while deleting subscriber data "
|
||||
"for IMSI %s\n", gsup.imsi);
|
||||
LOG_GSUP_REQ(req, LOGL_ERROR, "Peer responds with: Error while deleting subscriber data\n");
|
||||
osmo_gsup_req_free(req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_DELETE_DATA_RESULT:
|
||||
LOGP(DMAIN, LOGL_ERROR, "Deleting subscriber data for IMSI %s\n",
|
||||
gsup.imsi);
|
||||
LOG_GSUP_REQ(req, LOGL_DEBUG, "Peer responds with: Subscriber data deleted\n");
|
||||
osmo_gsup_req_free(req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
|
||||
case OSMO_GSUP_MSGT_PROC_SS_RESULT:
|
||||
rx_proc_ss_req(conn, &gsup);
|
||||
rx_proc_ss_req(req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_PROC_SS_ERROR:
|
||||
rx_proc_ss_error(conn, &gsup);
|
||||
rx_proc_ss_error(req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_ERROR:
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_RESULT:
|
||||
case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR:
|
||||
case OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT:
|
||||
{
|
||||
struct lu_operation *luop = lu_op_by_imsi(gsup.imsi,
|
||||
&g_lu_ops);
|
||||
if (!luop) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "GSUP message %s for "
|
||||
"unknown IMSI %s\n",
|
||||
osmo_gsup_message_type_name(gsup.message_type),
|
||||
gsup.imsi);
|
||||
break;
|
||||
}
|
||||
lu_op_rx_gsup(luop, &gsup);
|
||||
}
|
||||
lu_rx_gsup(req);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_CHECK_IMEI_REQUEST:
|
||||
rx_check_imei_req(req);
|
||||
break;
|
||||
default:
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
|
||||
osmo_gsup_message_type_name(gsup.message_type));
|
||||
osmo_gsup_message_type_name(req->gsup.message_type));
|
||||
osmo_gsup_req_free(req);
|
||||
break;
|
||||
}
|
||||
msgb_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -484,6 +583,7 @@ static void print_help()
|
||||
printf(" -T --timestamp Prefix every log line with a timestamp.\n");
|
||||
printf(" -e --log-level number Set a global loglevel.\n");
|
||||
printf(" -U --db-upgrade Allow HLR database schema upgrades.\n");
|
||||
printf(" -C --db-check Quit after opening (and upgrading) the database.\n");
|
||||
printf(" -V --version Print the version of OsmoHLR.\n");
|
||||
}
|
||||
|
||||
@@ -492,9 +592,10 @@ static struct {
|
||||
const char *db_file;
|
||||
bool daemonize;
|
||||
bool db_upgrade;
|
||||
bool db_check;
|
||||
} cmdline_opts = {
|
||||
.config_file = "osmo-hlr.cfg",
|
||||
.db_file = "hlr.db",
|
||||
.db_file = NULL,
|
||||
.daemonize = false,
|
||||
.db_upgrade = false,
|
||||
};
|
||||
@@ -513,6 +614,7 @@ static void handle_options(int argc, char **argv)
|
||||
{"log-level", 1, 0, 'e'},
|
||||
{"timestamp", 0, 0, 'T'},
|
||||
{"db-upgrade", 0, 0, 'U' },
|
||||
{"db-check", 0, 0, 'C' },
|
||||
{"version", 0, 0, 'V' },
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@@ -551,6 +653,9 @@ static void handle_options(int argc, char **argv)
|
||||
case 'U':
|
||||
cmdline_opts.db_upgrade = true;
|
||||
break;
|
||||
case 'C':
|
||||
cmdline_opts.db_check = true;
|
||||
break;
|
||||
case 'V':
|
||||
print_version(1);
|
||||
exit(0);
|
||||
@@ -562,15 +667,19 @@ static void handle_options(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void *hlr_ctx = NULL;
|
||||
if (argc > optind) {
|
||||
fprintf(stderr, "Unsupported positional arguments on command line\n");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
static void signal_hdlr(int signal)
|
||||
{
|
||||
switch (signal) {
|
||||
case SIGTERM:
|
||||
case SIGINT:
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Terminating due to SIGINT\n");
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Terminating due to signal=%d\n", signal);
|
||||
quit++;
|
||||
break;
|
||||
case SIGUSR1:
|
||||
@@ -607,9 +716,12 @@ int main(int argc, char **argv)
|
||||
|
||||
g_hlr = talloc_zero(hlr_ctx, struct hlr);
|
||||
INIT_LLIST_HEAD(&g_hlr->euse_list);
|
||||
INIT_LLIST_HEAD(&g_hlr->iuse_list);
|
||||
INIT_LLIST_HEAD(&g_hlr->ss_sessions);
|
||||
INIT_LLIST_HEAD(&g_hlr->ussd_routes);
|
||||
INIT_LLIST_HEAD(&g_hlr->mslookup.server.local_site_services);
|
||||
g_hlr->db_file_path = talloc_strdup(g_hlr, HLR_DEFAULT_DB_FILE_PATH);
|
||||
g_hlr->mslookup.server.mdns.domain_suffix = talloc_strdup(g_hlr, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT);
|
||||
g_hlr->mslookup.client.mdns.domain_suffix = talloc_strdup(g_hlr, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT);
|
||||
|
||||
/* Init default (call independent) SS session guard timeout value */
|
||||
g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT;
|
||||
@@ -620,10 +732,15 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Set up llists and objects, startup is happening from VTY commands. */
|
||||
dgsm_init(hlr_ctx);
|
||||
|
||||
osmo_stats_init(hlr_ctx);
|
||||
vty_init(&vty_info);
|
||||
ctrl_vty_init(hlr_ctx);
|
||||
handle_options(argc, argv);
|
||||
hlr_vty_init(&hlr_log_info);
|
||||
hlr_vty_init();
|
||||
dgsm_vty_init();
|
||||
|
||||
rc = vty_read_config_file(cmdline_opts.config_file, NULL);
|
||||
if (rc < 0) {
|
||||
@@ -633,12 +750,6 @@ int main(int argc, char **argv)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* start telnet after reading config for vty_get_bind_addr() */
|
||||
rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(),
|
||||
OSMO_VTY_PORT_HLR);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n");
|
||||
|
||||
rc = rand_init();
|
||||
@@ -647,24 +758,48 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true, cmdline_opts.db_upgrade);
|
||||
if (cmdline_opts.db_file)
|
||||
osmo_talloc_replace_string(g_hlr, &g_hlr->db_file_path, cmdline_opts.db_file);
|
||||
|
||||
g_hlr->dbc = db_open(hlr_ctx, g_hlr->db_file_path, true, cmdline_opts.db_upgrade);
|
||||
if (!g_hlr->dbc) {
|
||||
LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
|
||||
LOGP(DMAIN, LOGL_FATAL, "Error opening database %s\n", osmo_quote_str(g_hlr->db_file_path, -1));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (cmdline_opts.db_check) {
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Cmdline option --db-check: Database was opened successfully, quitting.\n");
|
||||
db_close(g_hlr->dbc);
|
||||
log_fini();
|
||||
talloc_free(hlr_ctx);
|
||||
talloc_free(tall_vty_ctx);
|
||||
talloc_disable_null_tracking();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* start telnet after reading config for vty_get_bind_addr() */
|
||||
rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(),
|
||||
OSMO_VTY_PORT_HLR);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
|
||||
g_hlr->gs = osmo_gsup_server_create(hlr_ctx, g_hlr->gsup_bind_addr, OSMO_GSUP_PORT,
|
||||
read_cb, &g_lu_ops, g_hlr);
|
||||
read_cb, g_hlr);
|
||||
if (!g_hlr->gs) {
|
||||
LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n");
|
||||
exit(1);
|
||||
}
|
||||
proxy_init(g_hlr->gs);
|
||||
|
||||
g_hlr->ctrl_bind_addr = ctrl_vty_get_bind_addr();
|
||||
g_hlr->ctrl = hlr_controlif_setup(g_hlr);
|
||||
|
||||
dgsm_start(hlr_ctx);
|
||||
|
||||
osmo_init_ignore_signals();
|
||||
signal(SIGINT, &signal_hdlr);
|
||||
signal(SIGTERM, &signal_hdlr);
|
||||
signal(SIGUSR1, &signal_hdlr);
|
||||
|
||||
if (cmdline_opts.daemonize) {
|
||||
@@ -676,7 +811,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while (!quit)
|
||||
osmo_select_main(0);
|
||||
osmo_select_main_ctx(0);
|
||||
|
||||
dgsm_stop();
|
||||
|
||||
osmo_gsup_server_destroy(g_hlr->gs);
|
||||
db_close(g_hlr->dbc);
|
||||
|
||||
60
src/hlr.h
60
src/hlr.h
@@ -1,60 +0,0 @@
|
||||
/* OsmoHLR generic header */
|
||||
|
||||
/* (C) 2017 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* Author: Max Suraev <msuraev@sysmocom.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
|
||||
struct hlr_euse;
|
||||
|
||||
struct hlr {
|
||||
/* GSUP server pointer */
|
||||
struct osmo_gsup_server *gs;
|
||||
|
||||
/* DB context */
|
||||
struct db_context *dbc;
|
||||
|
||||
/* Control Interface */
|
||||
struct ctrl_handle *ctrl;
|
||||
const char *ctrl_bind_addr;
|
||||
|
||||
/* Local bind addr */
|
||||
char *gsup_bind_addr;
|
||||
|
||||
struct llist_head euse_list;
|
||||
struct hlr_euse *euse_default;
|
||||
struct llist_head iuse_list;
|
||||
|
||||
/* NCSS (call independent) session guard timeout value */
|
||||
int ncss_guard_timeout;
|
||||
|
||||
struct llist_head ussd_routes;
|
||||
|
||||
struct llist_head ss_sessions;
|
||||
};
|
||||
|
||||
extern struct hlr *g_hlr;
|
||||
|
||||
struct hlr_subscriber;
|
||||
|
||||
void osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr);
|
||||
@@ -29,9 +29,9 @@
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/application.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "db.h"
|
||||
#include "rand.h"
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
#include <osmocom/hlr/rand.h>
|
||||
|
||||
struct hlr_db_tool_ctx {
|
||||
/* DB context */
|
||||
@@ -302,7 +302,7 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
|
||||
|
||||
snprintf(imsi_str, sizeof(imsi_str), "%" PRId64, imsi);
|
||||
|
||||
rc = db_subscr_create(dbc, imsi_str);
|
||||
rc = db_subscr_create(dbc, imsi_str, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS);
|
||||
if (rc < 0) {
|
||||
LOGP(DDB, LOGL_ERROR, "OsmoNITB DB import to %s: failed to create IMSI %s: %d: %s\n",
|
||||
dbc->fname,
|
||||
|
||||
257
src/hlr_ussd.c
257
src/hlr_ussd.c
@@ -29,11 +29,12 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "hlr.h"
|
||||
#include "hlr_ussd.h"
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
#include "logging.h"
|
||||
#include <osmocom/hlr/hlr.h>
|
||||
#include <osmocom/hlr/hlr_ussd.h>
|
||||
#include <osmocom/hlr/gsup_server.h>
|
||||
#include <osmocom/hlr/gsup_router.h>
|
||||
#include <osmocom/hlr/logging.h>
|
||||
#include <osmocom/hlr/db.h>
|
||||
|
||||
/***********************************************************************
|
||||
* core data structures expressing config from VTY
|
||||
@@ -149,7 +150,7 @@ struct ss_session {
|
||||
/* link us to hlr->ss_sessions */
|
||||
struct llist_head list;
|
||||
/* imsi of this session */
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+2];
|
||||
char imsi[OSMO_IMSI_BUF_SIZE];
|
||||
/* ID of this session (unique per IMSI) */
|
||||
uint32_t session_id;
|
||||
/* state of the session */
|
||||
@@ -166,9 +167,17 @@ struct ss_session {
|
||||
const struct hlr_iuse *iuse;
|
||||
} u;
|
||||
|
||||
/* subscriber's vlr_number
|
||||
* MO USSD: originating MSC's vlr_number
|
||||
* MT USSD: looked up once per session and cached here */
|
||||
struct osmo_ipa_name vlr_name;
|
||||
|
||||
/* 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 */
|
||||
|
||||
struct osmo_gsup_req *initial_req_from_ms;
|
||||
struct osmo_gsup_req *initial_req_from_euse;
|
||||
};
|
||||
|
||||
struct ss_session *ss_session_find(struct hlr *hlr, const char *imsi, uint32_t session_id)
|
||||
@@ -184,6 +193,10 @@ struct ss_session *ss_session_find(struct hlr *hlr, const char *imsi, uint32_t s
|
||||
void ss_session_free(struct ss_session *ss)
|
||||
{
|
||||
osmo_timer_del(&ss->timeout);
|
||||
if (ss->initial_req_from_ms)
|
||||
osmo_gsup_req_free(ss->initial_req_from_ms);
|
||||
if (ss->initial_req_from_euse)
|
||||
osmo_gsup_req_free(ss->initial_req_from_euse);
|
||||
llist_del(&ss->list);
|
||||
talloc_free(ss);
|
||||
}
|
||||
@@ -222,12 +235,55 @@ struct ss_session *ss_session_alloc(struct hlr *hlr, const char *imsi, uint32_t
|
||||
* 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_to_ms(struct ss_session *ss, struct osmo_gsup_server *gs, struct osmo_gsup_message *gsup)
|
||||
{
|
||||
struct hlr_subscriber subscr = {};
|
||||
struct msgb *msg;
|
||||
int rc;
|
||||
|
||||
if (ss->initial_req_from_ms) {
|
||||
/* Use non-final osmo_gsup_req_respond() to not deallocate the ss->initial_req_from_ms */
|
||||
osmo_gsup_req_respond(ss->initial_req_from_ms, gsup, false, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
msg = osmo_gsup_msgb_alloc("GSUP USSD FW");
|
||||
rc = osmo_gsup_encode(msg, gsup);
|
||||
if (rc) {
|
||||
LOGPSS(ss, LOGL_ERROR, "Failed to encode GSUP message\n");
|
||||
msgb_free(msg);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Use vlr_number as looked up by the caller, or look up now. */
|
||||
if (!ss->vlr_name.len) {
|
||||
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
|
||||
if (rc < 0) {
|
||||
LOGPSS(ss, LOGL_ERROR, "Cannot find subscriber, cannot route GSUP message\n");
|
||||
msgb_free(msg);
|
||||
return -EINVAL;
|
||||
}
|
||||
osmo_ipa_name_set_str(&ss->vlr_name, subscr.vlr_number);
|
||||
}
|
||||
|
||||
/* Check for empty string (all vlr_number strings end in "\0", because otherwise gsup_route_find() fails) */
|
||||
if (ss->vlr_name.len <= 1) {
|
||||
LOGPSS(ss, LOGL_ERROR, "Cannot send GSUP message, no VLR number stored for subscriber\n");
|
||||
msgb_free(msg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
LOGPSS(ss, LOGL_DEBUG, "Tx SS/USSD to VLR %s\n", osmo_ipa_name_to_str(&ss->vlr_name));
|
||||
return osmo_gsup_send_to_ipa_name(gs, &ss->vlr_name, 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)
|
||||
|
||||
{
|
||||
struct osmo_gsup_message resp = {0};
|
||||
struct msgb *resp_msg;
|
||||
int rc;
|
||||
|
||||
resp.message_type = gsup_msg_type;
|
||||
OSMO_STRLCPY_ARRAY(resp.imsi, ss->imsi);
|
||||
@@ -241,13 +297,10 @@ static int ss_tx_to_ms(struct ss_session *ss, enum osmo_gsup_message_type gsup_m
|
||||
resp.ss_info_len = msgb_length(ss_msg);
|
||||
}
|
||||
|
||||
resp_msg = gsm0480_msgb_alloc_name(__func__);
|
||||
OSMO_ASSERT(resp_msg);
|
||||
osmo_gsup_encode(resp_msg, &resp);
|
||||
msgb_free(ss_msg);
|
||||
rc = ss_gsup_send_to_ms(ss, g_hlr->gs, &resp);
|
||||
|
||||
/* 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);
|
||||
msgb_free(ss_msg);
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -262,7 +315,7 @@ static int ss_tx_reject(struct ss_session *ss, int invoke_id, uint8_t problem_ta
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ss_tx_error(struct ss_session *ss, uint8_t invoke_id, uint8_t error_code)
|
||||
static int ss_tx_to_ms_error(struct ss_session *ss, uint8_t invoke_id, uint8_t error_code)
|
||||
{
|
||||
struct msgb *msg = gsm0480_gen_return_error(invoke_id, error_code);
|
||||
LOGPSS(ss, LOGL_NOTICE, "Tx ReturnError(%u, 0x%02x)\n", invoke_id, error_code);
|
||||
@@ -270,7 +323,7 @@ static int ss_tx_error(struct ss_session *ss, uint8_t invoke_id, uint8_t error_c
|
||||
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg);
|
||||
}
|
||||
|
||||
static int ss_tx_ussd_7bit(struct ss_session *ss, bool final, uint8_t invoke_id, const char *text)
|
||||
static int ss_tx_to_ms_ussd_7bit(struct ss_session *ss, bool final, uint8_t invoke_id, const char *text)
|
||||
{
|
||||
struct msgb *msg = gsm0480_gen_ussd_resp_7bit(invoke_id, text);
|
||||
LOGPSS(ss, LOGL_INFO, "Tx USSD '%s'\n", text);
|
||||
@@ -282,9 +335,9 @@ static int ss_tx_ussd_7bit(struct ss_session *ss, bool final, uint8_t invoke_id,
|
||||
* Internal USSD Handlers
|
||||
***********************************************************************/
|
||||
|
||||
#include "db.h"
|
||||
#include <osmocom/hlr/db.h>
|
||||
|
||||
static int handle_ussd_own_msisdn(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
static int handle_ussd_own_msisdn(struct ss_session *ss,
|
||||
const struct osmo_gsup_message *gsup, const struct ss_request *req)
|
||||
{
|
||||
struct hlr_subscriber subscr;
|
||||
@@ -298,25 +351,25 @@ static int handle_ussd_own_msisdn(struct osmo_gsup_conn *conn, struct ss_session
|
||||
snprintf(buf, sizeof(buf), "You have no MSISDN!");
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "Your extension is %s", subscr.msisdn);
|
||||
ss_tx_ussd_7bit(ss, true, req->invoke_id, buf);
|
||||
ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf);
|
||||
break;
|
||||
case -ENOENT:
|
||||
ss_tx_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
|
||||
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
|
||||
break;
|
||||
case -EIO:
|
||||
default:
|
||||
ss_tx_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
|
||||
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_SYSTEM_FAILURE);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_ussd_own_imsi(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
static int handle_ussd_own_imsi(struct ss_session *ss,
|
||||
const struct osmo_gsup_message *gsup, const struct ss_request *req)
|
||||
{
|
||||
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
|
||||
snprintf(buf, sizeof(buf), "Your IMSI is %s", ss->imsi);
|
||||
ss_tx_ussd_7bit(ss, true, req->invoke_id, buf);
|
||||
ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -363,37 +416,28 @@ static bool ss_op_is_ussd(uint8_t opcode)
|
||||
}
|
||||
|
||||
/* is this GSUP connection an EUSE (true) or not (false)? */
|
||||
static bool conn_is_euse(struct osmo_gsup_conn *conn)
|
||||
static bool peer_name_is_euse(const struct osmo_gsup_peer_id *peer_name)
|
||||
{
|
||||
int rc;
|
||||
uint8_t *addr;
|
||||
|
||||
rc = osmo_gsup_conn_ccm_get(conn, &addr, IPAC_IDTAG_SERNR);
|
||||
if (rc <= 5)
|
||||
if (peer_name->type != OSMO_GSUP_PEER_ID_IPA_NAME)
|
||||
return false;
|
||||
if (!strncmp((char *)addr, "EUSE-", 5))
|
||||
return true;
|
||||
else
|
||||
if (peer_name->ipa_name.len <= 5)
|
||||
return false;
|
||||
return strncmp((char *)(peer_name->ipa_name.val), "EUSE-", 5) == 0;
|
||||
}
|
||||
|
||||
static struct hlr_euse *euse_by_conn(struct osmo_gsup_conn *conn)
|
||||
static struct hlr_euse *euse_by_name(const struct osmo_gsup_peer_id *peer_name)
|
||||
{
|
||||
int rc;
|
||||
char *addr;
|
||||
struct hlr *hlr = conn->server->priv;
|
||||
|
||||
rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &addr, IPAC_IDTAG_SERNR);
|
||||
if (rc <= 5)
|
||||
return NULL;
|
||||
if (strncmp(addr, "EUSE-", 5))
|
||||
if (!peer_name_is_euse(peer_name))
|
||||
return NULL;
|
||||
|
||||
return euse_find(hlr, addr+5);
|
||||
/* above peer_name_is_euse() ensures this: */
|
||||
OSMO_ASSERT(peer_name->type == OSMO_GSUP_PEER_ID_IPA_NAME);
|
||||
|
||||
return euse_find(g_hlr, (const char*)(peer_name->ipa_name.val)+5);
|
||||
}
|
||||
|
||||
static int handle_ss(struct ss_session *ss, const struct osmo_gsup_message *gsup,
|
||||
const struct ss_request *req)
|
||||
static int handle_ss(struct ss_session *ss, bool is_euse_originated, const struct osmo_gsup_message *gsup,
|
||||
const struct ss_request *req)
|
||||
{
|
||||
uint8_t comp_type = gsup->ss_info[0];
|
||||
|
||||
@@ -406,17 +450,16 @@ static int handle_ss(struct ss_session *ss, const struct osmo_gsup_message *gsup
|
||||
* we don't handle "structured" SS requests at all.
|
||||
*/
|
||||
LOGPSS(ss, LOGL_NOTICE, "Structured SS requests are not supported, rejecting...\n");
|
||||
ss_tx_error(ss, req->invoke_id, GSM0480_ERR_CODE_FACILITY_NOT_SUPPORTED);
|
||||
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_FACILITY_NOT_SUPPORTED);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/* Handle a USSD GSUP message for a given SS Session received from VLR or EUSE */
|
||||
static int handle_ussd(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
const struct osmo_gsup_message *gsup, const struct ss_request *req)
|
||||
static int handle_ussd(struct ss_session *ss, bool is_euse_originated, const struct osmo_gsup_message *gsup,
|
||||
const struct ss_request *req)
|
||||
{
|
||||
uint8_t comp_type = gsup->ss_info[0];
|
||||
struct msgb *msg_out;
|
||||
bool is_euse_originated = conn_is_euse(conn);
|
||||
|
||||
LOGPSS(ss, LOGL_INFO, "USSD CompType=%s, OpCode=%s '%s'\n",
|
||||
gsm0480_comp_type_name(comp_type), gsm0480_op_code_name(req->opcode),
|
||||
@@ -424,37 +467,35 @@ static int handle_ussd(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
|
||||
if ((ss->is_external && !ss->u.euse) || !ss->u.iuse) {
|
||||
LOGPSS(ss, LOGL_NOTICE, "USSD for unknown code '%s'\n", req->ussd_text);
|
||||
ss_tx_error(ss, req->invoke_id, GSM0480_ERR_CODE_SS_NOT_AVAILABLE);
|
||||
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_SS_NOT_AVAILABLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_euse_originated) {
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP USSD FW");
|
||||
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);
|
||||
/* Need a non-const osmo_gsup_message, because sending might modify some (routing related?) parts. */
|
||||
struct osmo_gsup_message forward = *gsup;
|
||||
ss_gsup_send_to_ms(ss, g_hlr->gs, &forward);
|
||||
} else {
|
||||
/* Received from VLR (MS) */
|
||||
if (ss->is_external) {
|
||||
/* Forward to EUSE */
|
||||
char addr[128];
|
||||
strcpy(addr, "EUSE-");
|
||||
osmo_strlcpy(addr+5, ss->u.euse->name, sizeof(addr)-5);
|
||||
conn = gsup_route_find(conn->server, (uint8_t *)addr, strlen(addr)+1);
|
||||
struct osmo_ipa_name euse_name;
|
||||
struct osmo_gsup_conn *conn;
|
||||
osmo_ipa_name_set_str(&euse_name, "EUSE-%s", ss->u.euse->name);
|
||||
conn = gsup_route_find_by_ipa_name(g_hlr->gs, &euse_name);
|
||||
if (!conn) {
|
||||
LOGPSS(ss, LOGL_ERROR, "Cannot find conn for EUSE %s\n", addr);
|
||||
ss_tx_error(ss, req->invoke_id, GSM0480_ERR_CODE_SYSTEM_FAILURE);
|
||||
LOGPSS(ss, LOGL_ERROR, "Cannot find conn for EUSE %s\n",
|
||||
osmo_ipa_name_to_str(&euse_name));
|
||||
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_SYSTEM_FAILURE);
|
||||
} else {
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP USSD FW");
|
||||
OSMO_ASSERT(msg_out);
|
||||
msg_out = osmo_gsup_msgb_alloc("GSUP USSD FW");
|
||||
osmo_gsup_encode(msg_out, gsup);
|
||||
osmo_gsup_conn_send(conn, msg_out);
|
||||
}
|
||||
} else {
|
||||
/* Handle internally */
|
||||
ss->u.iuse->handle_ussd(conn, ss, gsup, req);
|
||||
ss->u.iuse->handle_ussd(ss, gsup, req);
|
||||
/* Release session immediately */
|
||||
ss_session_free(ss);
|
||||
}
|
||||
@@ -466,24 +507,43 @@ static int handle_ussd(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
|
||||
/* this function is called for any SS_REQ/SS_RESP messages from both the MSC/VLR side as well
|
||||
* as from the EUSE side */
|
||||
int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup)
|
||||
void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
|
||||
{
|
||||
struct hlr *hlr = conn->server->priv;
|
||||
struct hlr *hlr = g_hlr;
|
||||
struct ss_session *ss;
|
||||
struct ss_request req = {0};
|
||||
const struct osmo_gsup_message *gsup = &gsup_req->gsup;
|
||||
/* Remember whether this function should free the incoming gsup_req: if it is placed as ss->initial_req_from_*,
|
||||
* do not free it here. If not, free it here. */
|
||||
struct osmo_gsup_req *free_gsup_req = gsup_req;
|
||||
bool is_euse_originated = peer_name_is_euse(&gsup_req->source_name);
|
||||
|
||||
LOGP(DSS, LOGL_DEBUG, "%s/0x%08x: Process SS (%s)\n", gsup->imsi, gsup->session_id,
|
||||
osmo_gsup_session_state_name(gsup->session_state));
|
||||
|
||||
if (gsup_req->source_name.type != OSMO_GSUP_PEER_ID_IPA_NAME) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Unable to process SS request: Unsupported GSUP peer id type%s\n",
|
||||
gsup->imsi, gsup->session_id,
|
||||
osmo_gsup_peer_id_type_name(gsup_req->source_name.type));
|
||||
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_PROTO_ERR_UNSPEC, "error processing SS request");
|
||||
return;
|
||||
}
|
||||
|
||||
/* decode and find out what kind of SS message it is */
|
||||
if (gsup->ss_info && gsup->ss_info_len) {
|
||||
if (gsm0480_parse_facility_ie(gsup->ss_info, gsup->ss_info_len, &req)) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Unable to parse SS request: %s\n",
|
||||
gsup->imsi, gsup->session_id,
|
||||
osmo_hexdump(gsup->ss_info, gsup->ss_info_len));
|
||||
/* FIXME: Send a Reject component? */
|
||||
goto out_err;
|
||||
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "error parsing SS request");
|
||||
return;
|
||||
}
|
||||
} else if (gsup->session_state != OSMO_GSUP_SESSION_STATE_END) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Missing SS payload for '%s'\n",
|
||||
gsup->imsi, gsup->session_id,
|
||||
osmo_gsup_session_state_name(gsup->session_state));
|
||||
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "missing SS payload");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (gsup->session_state) {
|
||||
@@ -492,18 +552,30 @@ int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *
|
||||
if (ss_session_find(hlr, gsup->imsi, gsup->session_id)) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: BEGIN with non-unique session ID!\n",
|
||||
gsup->imsi, gsup->session_id);
|
||||
goto out_err;
|
||||
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "BEGIN with non-unique session ID");
|
||||
return;
|
||||
}
|
||||
ss = ss_session_alloc(hlr, gsup->imsi, gsup->session_id);
|
||||
if (!ss) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: Unable to allocate SS session\n",
|
||||
gsup->imsi, gsup->session_id);
|
||||
goto out_err;
|
||||
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_NET_FAIL, "Unable to allocate SS session");
|
||||
return;
|
||||
}
|
||||
/* Get IPA name from VLR conn and save as ss->vlr_number */
|
||||
if (!is_euse_originated) {
|
||||
ss->initial_req_from_ms = gsup_req;
|
||||
free_gsup_req = NULL;
|
||||
OSMO_ASSERT(gsup_req->source_name.type == OSMO_GSUP_PEER_ID_IPA_NAME); /* checked above */
|
||||
ss->vlr_name = gsup_req->source_name.ipa_name;
|
||||
} else {
|
||||
ss->initial_req_from_euse = gsup_req;
|
||||
free_gsup_req = NULL;
|
||||
}
|
||||
if (ss_op_is_ussd(req.opcode)) {
|
||||
if (conn_is_euse(conn)) {
|
||||
if (is_euse_originated) {
|
||||
/* EUSE->VLR: MT USSD. EUSE is known ('conn'), VLR is to be resolved */
|
||||
ss->u.euse = euse_by_conn(conn);
|
||||
ss->u.euse = euse_by_name(&gsup_req->source_name);
|
||||
} else {
|
||||
/* VLR->EUSE: MO USSD. VLR is known ('conn'), EUSE is to be resolved */
|
||||
struct hlr_ussd_route *rt;
|
||||
@@ -524,10 +596,10 @@ int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *
|
||||
}
|
||||
}
|
||||
/* dispatch unstructured SS to routing */
|
||||
handle_ussd(conn, ss, gsup, &req);
|
||||
handle_ussd(ss, is_euse_originated, &gsup_req->gsup, &req);
|
||||
} else {
|
||||
/* dispatch non-call SS to internal code */
|
||||
handle_ss(ss, gsup, &req);
|
||||
handle_ss(ss, is_euse_originated, &gsup_req->gsup, &req);
|
||||
}
|
||||
break;
|
||||
case OSMO_GSUP_SESSION_STATE_CONTINUE:
|
||||
@@ -535,7 +607,8 @@ int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *
|
||||
if (!ss) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: CONTINUE for unknown SS session\n",
|
||||
gsup->imsi, gsup->session_id);
|
||||
goto out_err;
|
||||
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "CONTINUE for unknown SS session");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Reschedule self-destruction timer */
|
||||
@@ -544,10 +617,10 @@ int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *
|
||||
|
||||
if (ss_op_is_ussd(req.opcode)) {
|
||||
/* dispatch unstructured SS to routing */
|
||||
handle_ussd(conn, ss, gsup, &req);
|
||||
handle_ussd(ss, is_euse_originated, &gsup_req->gsup, &req);
|
||||
} else {
|
||||
/* dispatch non-call SS to internal code */
|
||||
handle_ss(ss, gsup, &req);
|
||||
handle_ss(ss, is_euse_originated, &gsup_req->gsup, &req);
|
||||
}
|
||||
break;
|
||||
case OSMO_GSUP_SESSION_STATE_END:
|
||||
@@ -555,32 +628,34 @@ int rx_proc_ss_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *
|
||||
if (!ss) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: END for unknown SS session\n",
|
||||
gsup->imsi, gsup->session_id);
|
||||
goto out_err;
|
||||
return;
|
||||
}
|
||||
if (ss_op_is_ussd(req.opcode)) {
|
||||
/* dispatch unstructured SS to routing */
|
||||
handle_ussd(conn, ss, gsup, &req);
|
||||
} else {
|
||||
/* dispatch non-call SS to internal code */
|
||||
handle_ss(ss, gsup, &req);
|
||||
|
||||
/* SS payload is optional for END */
|
||||
if (gsup->ss_info && gsup->ss_info_len) {
|
||||
if (ss_op_is_ussd(req.opcode)) {
|
||||
/* dispatch unstructured SS to routing */
|
||||
handle_ussd(ss, is_euse_originated, &gsup_req->gsup, &req);
|
||||
} else {
|
||||
/* dispatch non-call SS to internal code */
|
||||
handle_ss(ss, is_euse_originated, &gsup_req->gsup, &req);
|
||||
}
|
||||
}
|
||||
|
||||
ss_session_free(ss);
|
||||
break;
|
||||
default:
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: Unknown SS State %d\n", gsup->imsi,
|
||||
gsup->session_id, gsup->session_state);
|
||||
goto out_err;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
return 0;
|
||||
if (free_gsup_req)
|
||||
osmo_gsup_req_free(free_gsup_req);
|
||||
}
|
||||
|
||||
int rx_proc_ss_error(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup)
|
||||
void rx_proc_ss_error(struct osmo_gsup_req *req)
|
||||
{
|
||||
LOGP(DSS, LOGL_NOTICE, "%s/0x%08x: Process SS ERROR (%s)\n", gsup->imsi, gsup->session_id,
|
||||
osmo_gsup_session_state_name(gsup->session_state));
|
||||
return 0;
|
||||
LOGP(DSS, LOGL_NOTICE, "%s/0x%08x: Process SS ERROR (%s)\n", req->gsup.imsi, req->gsup.session_id,
|
||||
osmo_gsup_session_state_name(req->gsup.session_state));
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user