mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr.git
synced 2025-11-02 13:13:29 +00:00
Compare commits
143 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0c6fe5921 | ||
|
|
f58f44543f | ||
|
|
15f624ec53 | ||
|
|
d4e0e4d503 | ||
|
|
2dc7d960a1 | ||
|
|
52c4aa09b2 | ||
|
|
66106c0992 | ||
|
|
783ac81b9c | ||
|
|
df8d454919 | ||
|
|
9ea9bbbc7f | ||
|
|
5c14c9ccca | ||
|
|
705b61bcb7 | ||
|
|
638ba8cc04 | ||
|
|
55f5efa568 | ||
|
|
e6ce52bbde | ||
|
|
d157a56361 | ||
|
|
9c8806acf5 | ||
|
|
4b8be4d12d | ||
|
|
bc9bead62a | ||
|
|
4655e6f1fe | ||
|
|
8f3a7cce80 | ||
|
|
a820ea1f67 | ||
|
|
8aa780bf80 | ||
|
|
f08da2459b | ||
|
|
62ce834fbf | ||
|
|
bf6b4eb0b9 | ||
|
|
79efdf3474 | ||
|
|
b41394a700 | ||
|
|
0c331abdbc | ||
|
|
25e716c849 | ||
|
|
92e49ef363 | ||
|
|
95380ab037 | ||
|
|
849bfd0bef | ||
|
|
7e2d3c7f4c | ||
|
|
8f725ae655 | ||
|
|
1ed4bb4ff1 | ||
|
|
25dd785157 | ||
|
|
4f5f6f83f3 | ||
|
|
e66e525e09 | ||
|
|
4a4bdcdf97 | ||
|
|
cb364bb429 | ||
|
|
d646207553 | ||
|
|
6cee799d5e | ||
|
|
c88bdab96d | ||
|
|
607ce5ca93 | ||
|
|
ccdb970c57 | ||
|
|
a5b36a0904 | ||
|
|
13000d8d14 | ||
|
|
7ebfd065da | ||
|
|
966fcb2ca8 | ||
|
|
6fe1c2220a | ||
|
|
0da9f2f19c | ||
|
|
1eb9869d81 | ||
|
|
3adb33de93 | ||
|
|
791ea72ee4 | ||
|
|
9f7b69a618 | ||
|
|
e6c839ed2d | ||
|
|
b93c44f32e | ||
|
|
a05efe8803 | ||
|
|
764514198b | ||
|
|
5198609a5e | ||
|
|
7c2f430fc5 | ||
|
|
633fddebcd | ||
|
|
7c5e930aa8 | ||
|
|
83df349045 | ||
|
|
05fe0233d2 | ||
|
|
2781bb767e | ||
|
|
f473c7b23c | ||
|
|
dab544e14b | ||
|
|
7d29d59292 | ||
|
|
55d32a1e3c | ||
|
|
95b96d4245 | ||
|
|
9b6bc9e479 | ||
|
|
7f32f5f3e6 | ||
|
|
7266731eca | ||
|
|
97bfb65eeb | ||
|
|
bb77939a86 | ||
|
|
4956ae1f70 | ||
|
|
d5807b8c87 | ||
|
|
21c14fc7f4 | ||
|
|
050eb1d803 | ||
|
|
dc17e05e28 | ||
|
|
953d27ce8f | ||
|
|
ec6915a771 | ||
|
|
9fdb854174 | ||
|
|
4793a7efc3 | ||
|
|
527d934807 | ||
|
|
6b274b95fc | ||
|
|
edca4f88a6 | ||
|
|
b9c1028cb0 | ||
|
|
1442e3a3d3 | ||
|
|
0b8f054b5f | ||
|
|
fa7ee333f7 | ||
|
|
8fbf82b83f | ||
|
|
bd72f1331d | ||
|
|
32acace879 | ||
|
|
b85f60477f | ||
|
|
a1d3b048fb | ||
|
|
f83432c25c | ||
|
|
78f4301025 | ||
|
|
1b8a1dc00a | ||
|
|
9d307ec7ae | ||
|
|
5aeb438194 | ||
|
|
cb360f06c8 | ||
|
|
1cb489231a | ||
|
|
93c5b10310 | ||
|
|
ec9440f1bc | ||
|
|
51530311a8 | ||
|
|
f162252a08 | ||
|
|
8f8401453c | ||
|
|
70e7f21cb1 | ||
|
|
2e78858756 | ||
|
|
3f2a9a2ab1 | ||
|
|
880a34d2ef | ||
|
|
7ee6e554af | ||
|
|
9214c6c7ef | ||
|
|
79fc6984ac | ||
|
|
ba1605afdc | ||
|
|
b6265d1a55 | ||
|
|
6c84da5942 | ||
|
|
84c2f43d00 | ||
|
|
63f68ccc4c | ||
|
|
b5d77012d1 | ||
|
|
fc96f688d4 | ||
|
|
43bd6069e8 | ||
|
|
2dee60ef44 | ||
|
|
ab4d509a83 | ||
|
|
bd1dca0859 | ||
|
|
33eeeef9dc | ||
|
|
33cbde9ced | ||
|
|
671db90ac3 | ||
|
|
d3814b936b | ||
|
|
6f3e8d6297 | ||
|
|
db5dae6c99 | ||
|
|
38f08770a3 | ||
|
|
aee7be901b | ||
|
|
8db490695d | ||
|
|
c82e6ad190 | ||
|
|
0959e8b354 | ||
|
|
4f3841c153 | ||
|
|
bd0d5bf5d8 | ||
|
|
87a04b6b95 | ||
|
|
85e8a64bb4 |
33
.gitignore
vendored
33
.gitignore
vendored
@@ -1,8 +1,11 @@
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.db
|
||||
*.pyc
|
||||
.*.sw?
|
||||
.version
|
||||
.tarball-version
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
@@ -22,10 +25,36 @@ m4
|
||||
missing
|
||||
.deps
|
||||
|
||||
src/osmo-hlr
|
||||
src/db_test
|
||||
*.pc
|
||||
.libs
|
||||
|
||||
src/db_test
|
||||
src/db_bootstrap.h
|
||||
src/osmo-hlr
|
||||
src/osmo-hlr-db-tool
|
||||
src/osmo-euse-demo
|
||||
src/gsupclient/gsup-test-client
|
||||
|
||||
tests/atconfig
|
||||
tests/testsuite
|
||||
tests/testsuite.log
|
||||
|
||||
tests/auc/auc_3g_test
|
||||
tests/auc/auc_ts_55_205_test_sets.c
|
||||
tests/auc/auc_ts_55_205_test_sets
|
||||
tests/auc/auc_test
|
||||
tests/gsup_server/gsup_server_test
|
||||
tests/gsup/gsup_test
|
||||
tests/db/db_test
|
||||
tests/hlr_vty_test.db*
|
||||
|
||||
# manuals
|
||||
doc/manuals/*.html
|
||||
doc/manuals/*.svg
|
||||
doc/manuals/*.pdf
|
||||
doc/manuals/*__*.png
|
||||
doc/manuals/*.check
|
||||
doc/manuals/generated/
|
||||
doc/manuals/osmomsc-usermanual.xml
|
||||
doc/manuals/common
|
||||
doc/manuals/build
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
AUTOMAKE_OPTIONS = foreign dist-bzip2
|
||||
|
||||
SUBDIRS = \
|
||||
doc \
|
||||
src \
|
||||
include \
|
||||
sql \
|
||||
contrib \
|
||||
tests \
|
||||
$(NULL)
|
||||
|
||||
@@ -10,6 +13,12 @@ EXTRA_DIST = \
|
||||
.version \
|
||||
$(NULL)
|
||||
|
||||
AM_DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libosmo-gsup-client.pc
|
||||
|
||||
@RELMAKE@
|
||||
|
||||
BUILT_SOURCES = $(top_srcdir)/.version
|
||||
|
||||
110
configure.ac
110
configure.ac
@@ -34,11 +34,11 @@ PKG_PROG_PKG_CONFIG([0.20])
|
||||
|
||||
PKG_CHECK_MODULES(TALLOC, [talloc >= 2.0.1])
|
||||
|
||||
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.9.5)
|
||||
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 0.9.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.9.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl)
|
||||
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.3.2)
|
||||
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.0.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.0.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.0.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.0.0)
|
||||
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.6.0)
|
||||
|
||||
PKG_CHECK_MODULES(SQLITE3, sqlite3)
|
||||
|
||||
@@ -47,6 +47,36 @@ AC_CONFIG_MACRO_DIR([m4])
|
||||
dnl checks for header files
|
||||
AC_HEADER_STDC
|
||||
|
||||
AC_ARG_ENABLE(sanitize,
|
||||
[AS_HELP_STRING(
|
||||
[--enable-sanitize],
|
||||
[Compile with address sanitizer enabled],
|
||||
)],
|
||||
[sanitize=$enableval], [sanitize="no"])
|
||||
if test x"$sanitize" = x"yes"
|
||||
then
|
||||
CFLAGS="$CFLAGS -fsanitize=address -fsanitize=undefined"
|
||||
CPPFLAGS="$CPPFLAGS -fsanitize=address -fsanitize=undefined"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(werror,
|
||||
[AS_HELP_STRING(
|
||||
[--enable-werror],
|
||||
[Turn all compiler warnings into errors, with exceptions:
|
||||
a) deprecation (allow upstream to mark deprecation without breaking builds);
|
||||
b) "#warning" pragmas (allow to remind ourselves of errors without breaking builds)
|
||||
]
|
||||
)],
|
||||
[werror=$enableval], [werror="no"])
|
||||
if test x"$werror" = x"yes"
|
||||
then
|
||||
WERROR_FLAGS="-Werror"
|
||||
WERROR_FLAGS+=" -Wno-error=deprecated -Wno-error=deprecated-declarations"
|
||||
WERROR_FLAGS+=" -Wno-error=cpp" # "#warning"
|
||||
CFLAGS="$CFLAGS $WERROR_FLAGS"
|
||||
CPPFLAGS="$CPPFLAGS $WERROR_FLAGS"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([external_tests],
|
||||
AC_HELP_STRING([--enable-external-tests],
|
||||
[Include the VTY/CTRL tests in make check [default=no]]),
|
||||
@@ -62,13 +92,83 @@ 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")
|
||||
|
||||
# Generate manuals
|
||||
AC_ARG_ENABLE(manuals,
|
||||
[AS_HELP_STRING(
|
||||
[--enable-manuals],
|
||||
[Generate manual PDFs [default=no]],
|
||||
)],
|
||||
[osmo_ac_build_manuals=$enableval], [osmo_ac_build_manuals="no"])
|
||||
AM_CONDITIONAL([BUILD_MANUALS], [test x"$osmo_ac_build_manuals" = x"yes"])
|
||||
AC_ARG_VAR(OSMO_GSM_MANUALS_DIR, [path to common osmo-gsm-manuals files, overriding pkg-config and "../osmo-gsm-manuals"
|
||||
fallback])
|
||||
if test x"$osmo_ac_build_manuals" = x"yes"
|
||||
then
|
||||
# Find OSMO_GSM_MANUALS_DIR (env, pkg-conf, fallback)
|
||||
if test -n "$OSMO_GSM_MANUALS_DIR"; then
|
||||
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (from env)"
|
||||
else
|
||||
OSMO_GSM_MANUALS_DIR="$($PKG_CONFIG osmo-gsm-manuals --variable=osmogsmmanualsdir 2>/dev/null)"
|
||||
if test -n "$OSMO_GSM_MANUALS_DIR"; then
|
||||
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (from pkg-conf)"
|
||||
else
|
||||
OSMO_GSM_MANUALS_DIR="../osmo-gsm-manuals"
|
||||
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (fallback)"
|
||||
fi
|
||||
fi
|
||||
if ! test -d "$OSMO_GSM_MANUALS_DIR"; then
|
||||
AC_MSG_ERROR("OSMO_GSM_MANUALS_DIR does not exist! Install osmo-gsm-manuals or set OSMO_GSM_MANUALS_DIR.")
|
||||
fi
|
||||
|
||||
# Find and run check-depends
|
||||
CHECK_DEPENDS="$OSMO_GSM_MANUALS_DIR/check-depends.sh"
|
||||
if ! test -x "$CHECK_DEPENDS"; then
|
||||
CHECK_DEPENDS="osmo-gsm-manuals-check-depends"
|
||||
fi
|
||||
if ! $CHECK_DEPENDS; then
|
||||
AC_MSG_ERROR("missing dependencies for --enable-manuals")
|
||||
fi
|
||||
|
||||
# Put in Makefile with absolute path
|
||||
OSMO_GSM_MANUALS_DIR="$(realpath "$OSMO_GSM_MANUALS_DIR")"
|
||||
AC_SUBST([OSMO_GSM_MANUALS_DIR])
|
||||
fi
|
||||
|
||||
# https://www.freedesktop.org/software/systemd/man/daemon.html
|
||||
AC_ARG_WITH([systemdsystemunitdir],
|
||||
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
|
||||
[with_systemdsystemunitdir=auto])
|
||||
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
|
||||
def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
|
||||
|
||||
AS_IF([test "x$def_systemdsystemunitdir" = "x"],
|
||||
[AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
|
||||
[AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
|
||||
with_systemdsystemunitdir=no],
|
||||
[with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
|
||||
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
|
||||
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
|
||||
AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
|
||||
|
||||
AC_MSG_RESULT([CFLAGS="$CFLAGS"])
|
||||
AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"])
|
||||
|
||||
AC_OUTPUT(
|
||||
Makefile
|
||||
doc/Makefile
|
||||
doc/examples/Makefile
|
||||
src/Makefile
|
||||
src/gsupclient/Makefile
|
||||
include/Makefile
|
||||
libosmo-gsup-client.pc
|
||||
sql/Makefile
|
||||
doc/manuals/Makefile
|
||||
contrib/Makefile
|
||||
contrib/systemd/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
|
||||
)
|
||||
|
||||
1
contrib/Makefile.am
Normal file
1
contrib/Makefile.am
Normal file
@@ -0,0 +1 @@
|
||||
SUBDIRS = systemd
|
||||
278
contrib/ipa.py
278
contrib/ipa.py
@@ -1,278 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- mode: python-mode; py-indent-tabs-mode: nil -*-
|
||||
"""
|
||||
/*
|
||||
* Copyright (C) 2016 sysmocom s.f.m.c. GmbH
|
||||
*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
"""
|
||||
|
||||
import struct, random, sys
|
||||
|
||||
class IPA(object):
|
||||
"""
|
||||
Stateless IPA protocol multiplexer: add/remove/parse (extended) header
|
||||
"""
|
||||
version = "0.0.5"
|
||||
TCP_PORT_OML = 3002
|
||||
TCP_PORT_RSL = 3003
|
||||
# OpenBSC extensions: OSMO, MGCP_OLD
|
||||
PROTO = dict(RSL=0x00, CCM=0xFE, SCCP=0xFD, OML=0xFF, OSMO=0xEE, MGCP_OLD=0xFC)
|
||||
# ...OML Router Control, GSUP GPRS extension, Osmocom Authn Protocol
|
||||
EXT = dict(CTRL=0, MGCP=1, LAC=2, SMSC=3, ORC=4, GSUP=5, OAP=6)
|
||||
# OpenBSC extension: SCCP_OLD
|
||||
MSGT = dict(PING=0x00, PONG=0x01, ID_GET=0x04, ID_RESP=0x05, ID_ACK=0x06, SCCP_OLD=0xFF)
|
||||
_IDTAG = dict(SERNR=0, UNITNAME=1, LOCATION=2, TYPE=3, EQUIPVERS=4, SWVERSION=5, IPADDR=6, MACADDR=7, UNIT=8)
|
||||
CTRL_GET = 'GET'
|
||||
CTRL_SET = 'SET'
|
||||
CTRL_REP = 'REPLY'
|
||||
CTRL_ERR = 'ERR'
|
||||
CTRL_TRAP = 'TRAP'
|
||||
|
||||
def _l(self, d, p):
|
||||
"""
|
||||
Reverse dictionary lookup: return key for a given value
|
||||
"""
|
||||
if p is None:
|
||||
return 'UNKNOWN'
|
||||
return list(d.keys())[list(d.values()).index(p)]
|
||||
|
||||
def _tag(self, t, v):
|
||||
"""
|
||||
Create TAG as TLV data
|
||||
"""
|
||||
return struct.pack(">HB", len(v) + 1, t) + v
|
||||
|
||||
def proto(self, p):
|
||||
"""
|
||||
Lookup protocol name
|
||||
"""
|
||||
return self._l(self.PROTO, p)
|
||||
|
||||
def ext(self, p):
|
||||
"""
|
||||
Lookup protocol extension name
|
||||
"""
|
||||
return self._l(self.EXT, p)
|
||||
|
||||
def msgt(self, p):
|
||||
"""
|
||||
Lookup message type name
|
||||
"""
|
||||
return self._l(self.MSGT, p)
|
||||
|
||||
def idtag(self, p):
|
||||
"""
|
||||
Lookup ID tag name
|
||||
"""
|
||||
return self._l(self._IDTAG, p)
|
||||
|
||||
def ext_name(self, proto, exten):
|
||||
"""
|
||||
Return proper extension byte name depending on the protocol used
|
||||
"""
|
||||
if self.PROTO['CCM'] == proto:
|
||||
return self.msgt(exten)
|
||||
if self.PROTO['OSMO'] == proto:
|
||||
return self.ext(exten)
|
||||
return None
|
||||
|
||||
def add_header(self, data, proto, ext=None):
|
||||
"""
|
||||
Add IPA header (with extension if necessary), data must be represented as bytes
|
||||
"""
|
||||
if ext is None:
|
||||
return struct.pack(">HB", len(data) + 1, proto) + data
|
||||
return struct.pack(">HBB", len(data) + 1, proto, ext) + data
|
||||
|
||||
def del_header(self, data):
|
||||
"""
|
||||
Strip IPA protocol header correctly removing extension if present
|
||||
Returns data length, IPA protocol, extension (or None if not defined for a give protocol) and the data without header
|
||||
"""
|
||||
if not len(data):
|
||||
return None, None, None, None
|
||||
(dlen, proto) = struct.unpack('>HB', data[:3])
|
||||
if self.PROTO['OSMO'] == proto or self.PROTO['CCM'] == proto: # there's extension which we have to unpack
|
||||
return struct.unpack('>HBB', data[:4]) + (data[4:], ) # length, protocol, extension, data
|
||||
return dlen, proto, None, data[3:] # length, protocol, _, data
|
||||
|
||||
def split_combined(self, data):
|
||||
"""
|
||||
Split the data which contains multiple concatenated IPA messages into tuple (first, rest) where rest contains remaining messages, first is the single IPA message
|
||||
"""
|
||||
(length, _, _, _) = self.del_header(data)
|
||||
return data[:(length + 3)], data[(length + 3):]
|
||||
|
||||
def tag_serial(self, data):
|
||||
"""
|
||||
Make TAG for serial number
|
||||
"""
|
||||
return self._tag(self._IDTAG['SERNR'], data)
|
||||
|
||||
def tag_name(self, data):
|
||||
"""
|
||||
Make TAG for unit name
|
||||
"""
|
||||
return self._tag(self._IDTAG['UNITNAME'], data)
|
||||
|
||||
def tag_loc(self, data):
|
||||
"""
|
||||
Make TAG for location
|
||||
"""
|
||||
return self._tag(self._IDTAG['LOCATION'], data)
|
||||
|
||||
def tag_type(self, data):
|
||||
"""
|
||||
Make TAG for unit type
|
||||
"""
|
||||
return self._tag(self._IDTAG['TYPE'], data)
|
||||
|
||||
def tag_equip(self, data):
|
||||
"""
|
||||
Make TAG for equipment version
|
||||
"""
|
||||
return self._tag(self._IDTAG['EQUIPVERS'], data)
|
||||
|
||||
def tag_sw(self, data):
|
||||
"""
|
||||
Make TAG for software version
|
||||
"""
|
||||
return self._tag(self._IDTAG['SWVERSION'], data)
|
||||
|
||||
def tag_ip(self, data):
|
||||
"""
|
||||
Make TAG for IP address
|
||||
"""
|
||||
return self._tag(self._IDTAG['IPADDR'], data)
|
||||
|
||||
def tag_mac(self, data):
|
||||
"""
|
||||
Make TAG for MAC address
|
||||
"""
|
||||
return self._tag(self._IDTAG['MACADDR'], data)
|
||||
|
||||
def tag_unit(self, data):
|
||||
"""
|
||||
Make TAG for unit ID
|
||||
"""
|
||||
return self._tag(self._IDTAG['UNIT'], data)
|
||||
|
||||
def identity(self, unit=b'', mac=b'', location=b'', utype=b'', equip=b'', sw=b'', name=b'', serial=b''):
|
||||
"""
|
||||
Make IPA IDENTITY tag list, by default returns empty concatenated bytes of tag list
|
||||
"""
|
||||
return self.tag_unit(unit) + self.tag_mac(mac) + self.tag_loc(location) + self.tag_type(utype) + self.tag_equip(equip) + self.tag_sw(sw) + self.tag_name(name) + self.tag_serial(serial)
|
||||
|
||||
def ping(self):
|
||||
"""
|
||||
Make PING message
|
||||
"""
|
||||
return self.add_header(b'', self.PROTO['CCM'], self.MSGT['PING'])
|
||||
|
||||
def pong(self):
|
||||
"""
|
||||
Make PONG message
|
||||
"""
|
||||
return self.add_header(b'', self.PROTO['CCM'], self.MSGT['PONG'])
|
||||
|
||||
def id_ack(self):
|
||||
"""
|
||||
Make ID_ACK CCM message
|
||||
"""
|
||||
return self.add_header(b'', self.PROTO['CCM'], self.MSGT['ID_ACK'])
|
||||
|
||||
def id_get(self):
|
||||
"""
|
||||
Make ID_GET CCM message
|
||||
"""
|
||||
return self.add_header(self.identity(), self.PROTO['CCM'], self.MSGT['ID_GET'])
|
||||
|
||||
def id_resp(self, data):
|
||||
"""
|
||||
Make ID_RESP CCM message
|
||||
"""
|
||||
return self.add_header(data, self.PROTO['CCM'], self.MSGT['ID_RESP'])
|
||||
|
||||
class Ctrl(IPA):
|
||||
"""
|
||||
Osmocom CTRL protocol implemented on top of IPA multiplexer
|
||||
"""
|
||||
def __init__(self):
|
||||
random.seed()
|
||||
|
||||
def add_header(self, data):
|
||||
"""
|
||||
Add CTRL header
|
||||
"""
|
||||
return super(Ctrl, self).add_header(data.encode('utf-8'), IPA.PROTO['OSMO'], IPA.EXT['CTRL'])
|
||||
|
||||
def rem_header(self, data):
|
||||
"""
|
||||
Remove CTRL header, check for appropriate protocol and extension
|
||||
"""
|
||||
(_, proto, ext, d) = super(Ctrl, self).del_header(data)
|
||||
if self.PROTO['OSMO'] != proto or self.EXT['CTRL'] != ext:
|
||||
return None
|
||||
return d
|
||||
|
||||
def parse(self, data, op=None):
|
||||
"""
|
||||
Parse Ctrl string returning (var, value) pair
|
||||
var could be None in case of ERROR message
|
||||
value could be None in case of GET message
|
||||
"""
|
||||
(s, i, v) = data.split(' ', 2)
|
||||
if s == self.CTRL_ERR:
|
||||
return None, v
|
||||
if s == self.CTRL_GET:
|
||||
return v, None
|
||||
(s, i, var, val) = data.split(' ', 3)
|
||||
if s == self.CTRL_TRAP and i != '0':
|
||||
return None, '%s with non-zero id %s' % (s, i)
|
||||
if op is not None and i != op:
|
||||
if s == self.CTRL_GET + '_' + self.CTRL_REP or s == self.CTRL_SET + '_' + self.CTRL_REP:
|
||||
return None, '%s with unexpected id %s' % (s, i)
|
||||
return var, val
|
||||
|
||||
def trap(self, var, val):
|
||||
"""
|
||||
Make TRAP message with given (vak, val) pair
|
||||
"""
|
||||
return self.add_header("%s 0 %s %s" % (self.CTRL_TRAP, var, val))
|
||||
|
||||
def cmd(self, var, val=None):
|
||||
"""
|
||||
Make SET/GET command message: returns (r, m) tuple where r is random operation id and m is assembled message
|
||||
"""
|
||||
r = random.randint(1, sys.maxsize)
|
||||
if val is not None:
|
||||
return r, self.add_header("%s %s %s %s" % (self.CTRL_SET, r, var, val))
|
||||
return r, self.add_header("%s %s %s" % (self.CTRL_GET, r, var))
|
||||
|
||||
def verify(self, reply, r, var, val=None):
|
||||
"""
|
||||
Verify reply to SET/GET command: returns (b, v) tuple where v is True/False verification result and v is the variable value
|
||||
"""
|
||||
(k, v) = self.parse(reply)
|
||||
if k != var or (val is not None and v != val):
|
||||
return False, v
|
||||
return True, v
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("IPA multiplexer v%s loaded." % IPA.version)
|
||||
@@ -1,5 +1,10 @@
|
||||
#!/bin/sh
|
||||
# jenkins build helper script for osmo-hlr. This is how we build on jenkins.osmocom.org
|
||||
#
|
||||
# environment variables:
|
||||
# * WITH_MANUALS: build manual PDFs if set to "1"
|
||||
# * PUBLISH: upload manuals after building if set to "1" (ignored without WITH_MANUALS = "1")
|
||||
#
|
||||
|
||||
if ! [ -x "$(command -v osmo-build-dep.sh)" ]; then
|
||||
echo "Error: We need to have scripts/osmo-deps.sh from http://git.osmocom.org/osmo-ci/ in PATH !"
|
||||
@@ -22,10 +27,18 @@ verify_value_string_arrays_are_terminated.py $(find . -name "*.[hc]")
|
||||
|
||||
export PKG_CONFIG_PATH="$inst/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||||
export LD_LIBRARY_PATH="$inst/lib"
|
||||
export PATH="$inst/bin:$PATH"
|
||||
|
||||
osmo-build-dep.sh libosmocore "" ac_cv_path_DOXYGEN=false
|
||||
osmo-build-dep.sh libosmo-abis
|
||||
|
||||
# Additional configure options and depends
|
||||
CONFIG=""
|
||||
if [ "$WITH_MANUALS" = "1" ]; then
|
||||
osmo-build-dep.sh osmo-gsm-manuals
|
||||
CONFIG="--enable-manuals"
|
||||
fi
|
||||
|
||||
set +x
|
||||
echo
|
||||
echo
|
||||
@@ -36,11 +49,13 @@ set -x
|
||||
|
||||
cd "$base"
|
||||
autoreconf --install --force
|
||||
./configure --enable-external-tests
|
||||
./configure --enable-sanitize --enable-external-tests --enable-werror $CONFIG
|
||||
$MAKE $PARALLEL_MAKE
|
||||
if [ "x$label" != "xFreeBSD_amd64" ]; then
|
||||
$MAKE check || cat-testlogs.sh
|
||||
$MAKE distcheck || cat-testlogs.sh
|
||||
$MAKE check || cat-testlogs.sh
|
||||
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE distcheck || cat-testlogs.sh
|
||||
|
||||
if [ "$WITH_MANUALS" = "1" ] && [ "$PUBLISH" = "1" ]; then
|
||||
make -C "$base/doc/manuals" publish
|
||||
fi
|
||||
|
||||
osmo-clean-workspace.sh
|
||||
|
||||
6
contrib/systemd/Makefile.am
Normal file
6
contrib/systemd/Makefile.am
Normal file
@@ -0,0 +1,6 @@
|
||||
EXTRA_DIST = osmo-hlr.service
|
||||
|
||||
if HAVE_SYSTEMD
|
||||
systemdsystemunit_DATA = \
|
||||
osmo-hlr.service
|
||||
endif
|
||||
138
debian/changelog
vendored
138
debian/changelog
vendored
@@ -1,3 +1,141 @@
|
||||
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 ]
|
||||
* fix luop crash: use buffer for APN that remains valid
|
||||
* add gsup_test to catch OS#3231
|
||||
* add error handling to osmo_gsup_configure_wildcard_apn()
|
||||
|
||||
-- Pau Espin Pedrol <pespin@sysmocom.de> Fri, 04 May 2018 18:41:35 +0200
|
||||
|
||||
osmo-hlr (0.2.0) unstable; urgency=medium
|
||||
|
||||
[ Neels Hofmeyr ]
|
||||
* vty: skip installing cmds now always installed by default
|
||||
* hlr_db_tool: fix error log strerror invocation
|
||||
* cosmetic: add comment on ignored return value
|
||||
* db-tool: add command 'create'
|
||||
* db-tool: cosmetic: tweak printf output
|
||||
* db-tool: error-exit on too many arguments
|
||||
* add --enable-sanitize config option
|
||||
* db_test: don't verify SQLite issued error messages, they might change
|
||||
* cosmetic: rx_send_auth_info(): decide error cause with switch()
|
||||
* return GMM_CAUSE_IMSI_UNKNOWN if there is no auth data
|
||||
* db_get_auth_data / db_get_auc: clarify return values
|
||||
* osmo-hlr: log details for unknown IMSI / no auth data / db error
|
||||
* db_test: also test db_get_auc() return values
|
||||
* fix test_subscriber_errors.ctrl after libosmocore change
|
||||
* fix debug log: put 'deriving 2G from 3G' in proper place
|
||||
* ctrl test: fix: adjust expectations after stricter ctrl parsing
|
||||
* fix build: db_test: missing LIBOSMOABIS_CFLAGS and _LIBS
|
||||
* configure: add --enable-werror
|
||||
* jenkins.sh: use --enable-werror configure flag, not CFLAGS
|
||||
|
||||
[ Harald Welte ]
|
||||
* hlr.c: Avoid overflow of lu_operation.subscr.imsi
|
||||
* Fix expected test output after new 'logging print file 1' vty command
|
||||
* osmo-hlr: Add talloc context introspection via VTY
|
||||
* vty: Don't print error if removing auth data while none present
|
||||
* Fix responses to PURGE MS
|
||||
|
||||
[ Alexander Couzens ]
|
||||
* debian: include systemd service osmo-hlr.service
|
||||
* doc: install example .cfg files to $(docdir)/examples/
|
||||
* debian: install osmo-hlr.cfg to /etc/osmocom
|
||||
|
||||
[ Max ]
|
||||
* Remove unused check
|
||||
* Remove unused ipa.py
|
||||
* Enable sanitize for CI tests
|
||||
|
||||
[ Pau Espin Pedrol ]
|
||||
* luop.c: Transform FIXME from warning to pragma message
|
||||
* contrib:jenkins.sh: Enable Werror
|
||||
* use osmo_init_logging2
|
||||
* Remove unused src/db_test.c
|
||||
|
||||
[ Alexander Huemer ]
|
||||
* Add missing build products in .gitignore
|
||||
|
||||
[ Stefan Sperling ]
|
||||
* more robust usage of osmo_timer API for osmo-hlr luop timer
|
||||
* notify GSUP clients when HLR subscriber information changes
|
||||
* rewrite subscriber_update_notify() without calls into luop
|
||||
* don't forget to mark luop as a packet switched connection
|
||||
|
||||
-- Pau Espin Pedrol <pespin@sysmocom.de> Thu, 03 May 2018 16:27:13 +0200
|
||||
|
||||
osmo-hlr (0.1.0) unstable; urgency=medium
|
||||
|
||||
[ Neels Hofmeyr ]
|
||||
|
||||
25
debian/control
vendored
25
debian/control
vendored
@@ -32,3 +32,28 @@ Priority: extra
|
||||
Depends: osmo-hlr (= ${binary:Version}), ${misc:Depends}
|
||||
Description: Debug symbols for the osmo-hlr
|
||||
Make debugging possible
|
||||
|
||||
Package: libosmo-gsup-client0
|
||||
Section: libs
|
||||
Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends}
|
||||
Pre-Depends: ${misc:Pre-Depends}
|
||||
Description: Osmocom GSUP (General Subscriber Update Protocol) client library
|
||||
This is a shared library that can be used to implement client programs for
|
||||
the GSUP protocol. The typical GSUP server is OsmoHLR, with OsmoMSC, OsmoSGSN
|
||||
and External USSD Entities (EUSEs) using this library to implement clients.
|
||||
|
||||
Package: libosmo-gsup-client-dev
|
||||
Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends: ${misc:Depends},
|
||||
libosmo-gsup-client0 (= ${binary:Version}),
|
||||
libosmocore-dev
|
||||
Description: Development headers of Osmocom GSUP client library
|
||||
This is a shared library that can be used to implement client programs for
|
||||
the GSUP protocol. The typical GSUP server is OsmoHLR, with OsmoMSC, OsmoSGSN
|
||||
and External USSD Entities (EUSEs) using this library to implement clients.
|
||||
.
|
||||
This package contains the development headers.
|
||||
|
||||
5
debian/libosmo-gsup-client-dev.install
vendored
Normal file
5
debian/libosmo-gsup-client-dev.install
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
usr/include/osmocom/gsupclient
|
||||
usr/lib/*/libosmo-gsup-client*.a
|
||||
usr/lib/*/libosmo-gsup-client*.so
|
||||
usr/lib/*/libosmo-gsup-client*.la
|
||||
usr/lib/*/pkgconfig/libosmo-gsup-client.pc
|
||||
1
debian/libosmo-gsup-client0.install
vendored
Normal file
1
debian/libosmo-gsup-client0.install
vendored
Normal file
@@ -0,0 +1 @@
|
||||
usr/lib/*/libosmo-gsup-client*.so.*
|
||||
7
debian/osmo-hlr.install
vendored
7
debian/osmo-hlr.install
vendored
@@ -1,3 +1,8 @@
|
||||
/etc/osmocom/osmo-hlr.cfg
|
||||
/lib/systemd/system/osmo-hlr.service
|
||||
/usr/bin/osmo-hlr
|
||||
/usr/bin/osmo-hlr-db-tool
|
||||
/usr/share/doc/osmo-hlr/hlr.sql
|
||||
/usr/share/doc/osmo-hlr/sql/hlr.sql
|
||||
/usr/share/doc/osmo-hlr/sql/hlr_data.sql
|
||||
/usr/share/doc/osmo-hlr/examples/osmo-hlr.cfg
|
||||
/var/lib/osmocom
|
||||
|
||||
3
debian/rules
vendored
3
debian/rules
vendored
@@ -15,3 +15,6 @@ override_dh_strip:
|
||||
# Print test results in case of a failure
|
||||
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
|
||||
|
||||
4
doc/Makefile.am
Normal file
4
doc/Makefile.am
Normal file
@@ -0,0 +1,4 @@
|
||||
SUBDIRS = \
|
||||
examples \
|
||||
manuals \
|
||||
$(NULL)
|
||||
27
doc/examples/Makefile.am
Normal file
27
doc/examples/Makefile.am
Normal file
@@ -0,0 +1,27 @@
|
||||
osmoconfdir = $(sysconfdir)/osmocom
|
||||
osmoconf_DATA = osmo-hlr.cfg
|
||||
|
||||
EXTRA_DIST = osmo-hlr.cfg
|
||||
|
||||
CFG_FILES = find $(srcdir) -name '*.cfg*' | sed -e 's,^$(srcdir),,'
|
||||
|
||||
dist-hook:
|
||||
for f in $$($(CFG_FILES)); do \
|
||||
j="$(distdir)/$$f" && \
|
||||
mkdir -p "$$(dirname $$j)" && \
|
||||
$(INSTALL_DATA) $(srcdir)/$$f $$j; \
|
||||
done
|
||||
|
||||
install-data-hook:
|
||||
for f in $$($(CFG_FILES)); do \
|
||||
j="$(DESTDIR)$(docdir)/examples/$$f" && \
|
||||
mkdir -p "$$(dirname $$j)" && \
|
||||
$(INSTALL_DATA) $(srcdir)/$$f $$j; \
|
||||
done
|
||||
|
||||
uninstall-hook:
|
||||
@$(PRE_UNINSTALL)
|
||||
for f in $$($(CFG_FILES)); do \
|
||||
j="$(DESTDIR)$(docdir)/examples/$$f" && \
|
||||
$(RM) $$j; \
|
||||
done
|
||||
@@ -2,13 +2,18 @@
|
||||
! OsmoHLR example configuration
|
||||
!
|
||||
log stderr
|
||||
logging filter all 1
|
||||
logging color 1
|
||||
logging print category 1
|
||||
logging timestamp 1
|
||||
logging print extended-timestamp 1
|
||||
logging level all debug
|
||||
logging level linp error
|
||||
logging filter all 1
|
||||
logging color 1
|
||||
logging print category 1
|
||||
logging print category-hex 0
|
||||
logging print level 1
|
||||
logging print file basename last
|
||||
logging print extended-timestamp 1
|
||||
logging level main notice
|
||||
logging level db notice
|
||||
logging level auc notice
|
||||
logging level ss info
|
||||
logging level linp error
|
||||
!
|
||||
line vty
|
||||
bind 127.0.0.1
|
||||
@@ -17,3 +22,5 @@ ctrl
|
||||
hlr
|
||||
gsup
|
||||
bind ip 127.0.0.1
|
||||
ussd route prefix *#100# internal own-msisdn
|
||||
ussd route prefix *#101# internal own-imsi
|
||||
|
||||
59
doc/manuals/Makefile.am
Normal file
59
doc/manuals/Makefile.am
Normal file
@@ -0,0 +1,59 @@
|
||||
EXTRA_DIST = example_subscriber_add_update_delete.vty \
|
||||
example_subscriber_cs_ps_enabled.ctrl \
|
||||
example_subscriber_info.ctrl \
|
||||
osmohlr-usermanual.adoc \
|
||||
osmohlr-usermanual-docinfo.xml \
|
||||
osmohlr-vty-reference.xml \
|
||||
chapters \
|
||||
vty
|
||||
|
||||
if BUILD_MANUALS
|
||||
ASCIIDOC = osmohlr-usermanual.adoc
|
||||
ASCIIDOC_DEPS = $(srcdir)/chapters/*.adoc $(srcdir)/*.vty $(srcdir)/*.ctrl
|
||||
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
|
||||
|
||||
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.common.inc
|
||||
endif
|
||||
|
||||
TMP_DB = generated/hlr.db
|
||||
|
||||
update-examples: update-examples-ctrl update-examples-vty
|
||||
|
||||
.PHONY: found-update-deps
|
||||
found-update-deps:
|
||||
@if [ ! -f "$(top_srcdir)/sql/hlr.sql" ]; then \
|
||||
echo "You need to define OSMO_HLR_PATH to point at an osmo-hlr.git"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if [ -z "$(shell which osmo-hlr)" ]; then \
|
||||
echo "osmo-hlr needs to be installed / available in the PATH"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if [ -z "$(shell which osmo_verify_transcript_ctrl.py)" ]; then \
|
||||
echo "You need to install git.osmocom.org/python/osmo-python-tests.git"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if [ -z "$(shell which osmo_verify_transcript_vty.py)" ]; then \
|
||||
echo "You need to install git.osmocom.org/python/osmo-python-tests.git"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
update-examples-ctrl: found-update-deps
|
||||
mkdir -p generated
|
||||
rm -f "$(TMP_DB)"
|
||||
sqlite3 "$(TMP_DB)" < "$(top_srcdir)/sql/hlr.sql"
|
||||
sqlite3 "$(TMP_DB)" < "$(top_srcdir)/tests/test_subscriber.sql"
|
||||
osmo_verify_transcript_ctrl.py \
|
||||
-r "osmo-hlr -l $(TMP_DB) -c $(top_srcdir)/doc/examples/osmo-hlr.cfg" \
|
||||
-p 4259 --update *.ctrl
|
||||
|
||||
update-examples-vty: found-update-deps
|
||||
mkdir -p generated
|
||||
rm -f "$(TMP_DB)"
|
||||
sqlite3 "$(TMP_DB)" < "$(top_srcdir)/sql/hlr.sql"
|
||||
osmo_verify_transcript_vty.py \
|
||||
-r "osmo-hlr -l $(TMP_DB) -c $(top_srcdir)/doc/examples/osmo-hlr.cfg" \
|
||||
-p 4258 --update *.vty
|
||||
106
doc/manuals/chapters/control.adoc
Normal file
106
doc/manuals/chapters/control.adoc
Normal file
@@ -0,0 +1,106 @@
|
||||
[[hlr-ctrl]]
|
||||
== Control interface
|
||||
|
||||
The actual protocol is described in <<common-control-if>>, the variables common
|
||||
to all programs using it are described in <<ctrl_common_vars>>. This section
|
||||
describes the CTRL interface variables specific to OsmoHLR.
|
||||
|
||||
All subscriber variables are available by different selectors, which are freely
|
||||
interchangeable:
|
||||
|
||||
.Subscriber selectors available on OsmoHLR's Control interface
|
||||
[options="header",width="100%",cols="35%,65%"]
|
||||
|===
|
||||
|Selector|Comment
|
||||
|subscriber.*by-imsi-*'123456'.*|Subscriber selector by IMSI, replace "123456" with the actual IMSI
|
||||
|subscriber.*by-msisdn-*'123456'.*|Subscriber selector by MSISDN
|
||||
|subscriber.*by-id-*'123456'.*|Subscriber selector by database ID
|
||||
|===
|
||||
|
||||
Each of the above selectors feature all of these control variables:
|
||||
|
||||
.Subscriber variables available on OsmoHLR's Control interface
|
||||
[options="header",width="100%",cols="35%,8%,8%,8%,41%"]
|
||||
|===
|
||||
|Name|Access|Trap|Value|Comment
|
||||
|subscriber.by-\*.*info*|R|No||List (short) subscriber information
|
||||
|subscriber.by-\*.*info-aud*|R|No||List subscriber authentication tokens
|
||||
|subscriber.by-\*.*info-all*|R|No||List both 'info' and 'info-aud' in one
|
||||
|subscriber.by-\*.*cs-enabled*|RW|No|'1' or '0'|Enable/disable circuit-switched access
|
||||
|subscriber.by-\*.*ps-enabled*|RW|No|'1' or '0'|Enable/disable packet-switched access
|
||||
|===
|
||||
|
||||
=== subscriber.by-*.info, info-aud, info-all
|
||||
|
||||
Query the HLR database and return current subscriber record, in multiple lines
|
||||
of the format
|
||||
|
||||
----
|
||||
name<tab>value
|
||||
----
|
||||
|
||||
To keep the reply as short as possible, some values are omitted if they are
|
||||
empty. These are the returned values and their presence
|
||||
modalities; for their meaning, see <<subscriber-params>>:
|
||||
|
||||
.Returned values by OsmoHLR's 'info', 'info-all' and 'info-aud' commands
|
||||
[options="header",width="100%",cols="15%,15%,30%,40%"]
|
||||
|===
|
||||
|Returned by 'info-all' and|Name|Format|Presence
|
||||
|'info'|id|-9223372036854775808 .. 9223372036854775807 (usually not negative)|always
|
||||
|'info'|imsi|6 to 15 decimal digits|always
|
||||
|'info'|msisdn|1 to 15 decimal digits|when non-empty
|
||||
|'info'|nam_cs|'1' if CS is enabled, or '0'|always
|
||||
|'info'|nam_ps|'1' if PS is enabled, or '0'|always
|
||||
|'info'|vlr_number|up to 15 decimal digits|when non-empty
|
||||
|'info'|sgsn_number|up to 15 decimal digits|when non-empty
|
||||
|'info'|sgsn_address||when non-empty
|
||||
|'info'|ms_purged_cs|'1' if CS is purged, or '0'|always
|
||||
|'info'|ms_purged_ps|'1' if PS is purged, or '0'|always
|
||||
|'info'|periodic_lu_timer|0..4294967295|always
|
||||
|'info'|periodic_rau_tau_timer|0..4294967295|always
|
||||
|'info'|lmsi|8 hex digits|always
|
||||
|'info-aud'|aud2g.algo|one of 'comp128v1', 'comp128v2', 'comp128v3' or 'xor'|when valid 2G auth data is set
|
||||
|'info-aud'|aud2g.ki|32 hexadecimal digits|when valid 2G auth data is set
|
||||
|'info-aud'|aud3g.algo|so far always 'milenage'|when valid 3G auth data is set
|
||||
|'info-aud'|aud3g.k|32 hexadecimal digits|when valid 3G auth data is set
|
||||
|'info-aud'|aud3g.op|32 hexadecimal digits|when valid 3G auth data is set, *not* when OPC is set
|
||||
|'info-aud'|aud3g.opc|32 hexadecimal digits|when valid 3G auth data is set, *not* when OP is set
|
||||
|'info-aud'|aud3g.ind_bitlen|0..28|when valid 3G auth data is set
|
||||
|'info-aud'|aud3g.sqn|0 .. 18446744073709551615|when valid 3G auth data is set
|
||||
|===
|
||||
|
||||
This is an example Control Interface transcript that illustrates the various
|
||||
'info' commands:
|
||||
|
||||
----
|
||||
include::../example_subscriber_info.ctrl[]
|
||||
----
|
||||
|
||||
=== subscriber.by-*.ps-enabled, cs-enabled
|
||||
|
||||
Disable or enable packet-/circuit-switched access for the given IMSI;
|
||||
|
||||
* 'ps-enabled' switches access to GPRS or UMTS data services,
|
||||
* 'cs-enabled' switches access to voice services.
|
||||
|
||||
When disabled, the next time this subscriber attempts to do a Location Updating
|
||||
GSUP operation for the given domain (i.e. from the SGSN for 'ps-enabled', from
|
||||
the MSC/VLR for 'cs-enabled'), it will be rejected by OsmoHLR. Currently
|
||||
connected GSUP clients will be notified via GSUP when a subscriber is being
|
||||
disabled, so that the subscriber can be dropped in case it is currently
|
||||
attached.
|
||||
|
||||
The current 'ps-enabled'/'cs-enabled' status can be queried by 'GET' commands,
|
||||
and also by looking at 'nam_ps' and 'nam_cs' in a 'subscriber.by-*.info'
|
||||
response.
|
||||
|
||||
A value of "1" indicates that the given domain is enabled, which is the
|
||||
default; a value of "0" disables access.
|
||||
|
||||
This is an example transcript that illustrates 'ps-enabled' and 'cs-enabled'
|
||||
commands:
|
||||
|
||||
----
|
||||
include::../example_subscriber_cs_ps_enabled.ctrl[]
|
||||
----
|
||||
69
doc/manuals/chapters/overview.adoc
Normal file
69
doc/manuals/chapters/overview.adoc
Normal file
@@ -0,0 +1,69 @@
|
||||
[[overview]]
|
||||
== Overview
|
||||
|
||||
This manual should help you getting started with OsmoHLR. It will cover
|
||||
aspects of configuring and running the OsmoHLR.
|
||||
|
||||
[[intro_overview]]
|
||||
=== About OsmoHLR
|
||||
|
||||
OsmoHLR is Osmocom's minimal implementation of a Home Location Register (HLR)
|
||||
for 2G and 3G GSM and UMTS mobile core networks. Its interfaces are:
|
||||
|
||||
- GSUP, serving towards OsmoMSC and OsmoSGSN;
|
||||
- A local SQLite database;
|
||||
- The Osmocom typical telnet VTY and CTRL interfaces.
|
||||
|
||||
Originally, the OpenBSC project's OsmoNITB all-in-one implementation had an
|
||||
integrated HLR, managing subscribers and SMS in the same local database. Along
|
||||
with the separate OsmoMSC and its new VLR component, OsmoHLR was implemented
|
||||
from scratch to alleviate various shortcomings of the internal HLR:
|
||||
|
||||
- The separate HLR allows using centralized subscriber management for both
|
||||
circuit-switched and packet-switched domains (i.e. one OsmoHLR for both
|
||||
OsmoMSC and OsmoSGSN).
|
||||
|
||||
- VLR and HLR brought full UMTS AKA (Authentication and Key Agreement) support,
|
||||
i.e. Milenage authentication in both the full 3G variant as well as the
|
||||
backwards compatible 2G variant.
|
||||
|
||||
- In contrast to the OsmoNITB, the specific way the new OsmoMSC's VLR accesses
|
||||
OsmoHLR brings fully asynchronous subscriber database access.
|
||||
|
||||
Find the OsmoHLR issue tracker and wiki online at
|
||||
|
||||
- https://osmocom.org/projects/osmo-hlr
|
||||
- https://osmocom.org/projects/osmo-hlr/wiki
|
||||
|
||||
|
||||
[[fig-gsm]]
|
||||
.Typical GSM network architecture used with OsmoHLR
|
||||
[graphviz]
|
||||
----
|
||||
digraph G {
|
||||
rankdir=LR;
|
||||
subgraph cluster_hlr {
|
||||
label = "OsmoHLR";
|
||||
GSUP [label="GSUP server"]
|
||||
DB [label="SQLite DB"]
|
||||
GSUP->DB
|
||||
DB->CTRL [dir="back"]
|
||||
DB->VTY [dir="back"]
|
||||
}
|
||||
|
||||
Admin [label="Admin and\nMaintenance"]
|
||||
SW [label="3rd party software\nintegration"]
|
||||
VTY->Admin [dir="back"]
|
||||
CTRL->SW [dir="back"]
|
||||
|
||||
MSC [label="MSC/VLR"]
|
||||
MSC->GSUP [label="GSUP"]
|
||||
SGSN->GSUP [label="GSUP"]
|
||||
|
||||
BSC->MSC
|
||||
HNBGW->MSC
|
||||
HNBGW->SGSN
|
||||
PCU->SGSN
|
||||
}
|
||||
----
|
||||
|
||||
82
doc/manuals/chapters/running.adoc
Normal file
82
doc/manuals/chapters/running.adoc
Normal file
@@ -0,0 +1,82 @@
|
||||
== Running OsmoHLR
|
||||
|
||||
The OsmoHLR executable (`osmo-hlr`) offers the following command-line
|
||||
arguments:
|
||||
|
||||
=== SYNOPSIS
|
||||
|
||||
*osmo-hlr* [-h] [-c 'CONFIGFILE'] [-l 'DATABASE'] [-d 'DBGMASK'] [-D] [-s] [-T] [-e 'LOGLEVEL'] [-V]
|
||||
|
||||
=== OPTIONS
|
||||
|
||||
// Keep the order the same as in osmo-hlr --help!
|
||||
|
||||
*-h, --help*::
|
||||
Print a short help message about the supported options
|
||||
*-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.
|
||||
*-s, --disable-color*::
|
||||
Disable colors for logging to stderr. This has mostly been
|
||||
deprecated by VTY based logging configuration, see <<logging>>
|
||||
for more information.
|
||||
*-T, --timestamp*::
|
||||
Enable time-stamping of log messages to stderr. This has mostly
|
||||
been deprecated by VTY based logging configuration, see
|
||||
<<logging>> for more information.
|
||||
*-e, --log-level 'LOGLEVEL'*::
|
||||
Set the global log level for logging to stderr. This has mostly
|
||||
been deprecated by VTY based logging configuration, see
|
||||
<<logging>> for more information.
|
||||
*-V, --version*::
|
||||
Print the compile-time version number of the OsmoHLR program
|
||||
|
||||
=== Bootstrap the Database
|
||||
|
||||
If no database exists yet, OsmoHLR will automatically create and bootstrap a
|
||||
database file with empty tables. If no `-l` command-line option is provided,
|
||||
this database file will be created in the current working directory.
|
||||
|
||||
Alternatively, you may use the `osmo-hlr-db-tool`, which is installed along
|
||||
with `osmo-hlr`, to bootstrap an empty database, or to migrate subscriber data
|
||||
from an old 'OsmoNITB' database. See `osmo-hlr-db-tool --help`.
|
||||
|
||||
=== Multiple instances
|
||||
|
||||
Running multiple instances of `osmo-hlr` on the same computer is possible if
|
||||
all interfaces (VTY, CTRL) are separated using the appropriate configuration
|
||||
options. The IP based interfaces are binding to local host by default. In order
|
||||
to separate the processes, the user has to bind those services to specific but
|
||||
different IP addresses and/or ports.
|
||||
|
||||
The VTY and the Control interface can be bound to IP addresses from the loopback
|
||||
address range, for example:
|
||||
|
||||
----
|
||||
line vty
|
||||
bind 127.0.0.2
|
||||
ctrl
|
||||
bind 127.0.0.2
|
||||
----
|
||||
|
||||
The GSUP interface can be bound to a specific IP address by the following
|
||||
configuration options:
|
||||
|
||||
----
|
||||
hlr
|
||||
gsup
|
||||
bind ip 10.23.42.1
|
||||
----
|
||||
|
||||
NOTE: At the time of writing, OsmoHLR lacks a config option to change the GSUP
|
||||
port, which is by default TCP port 4222.
|
||||
69
doc/manuals/chapters/subscribers.adoc
Normal file
69
doc/manuals/chapters/subscribers.adoc
Normal file
@@ -0,0 +1,69 @@
|
||||
== Managing Subscribers
|
||||
|
||||
Subscribers are kept in a local SQLite database file and can be managed via VTY
|
||||
and CTRL interfaces.
|
||||
|
||||
This section provides some examples; also refer to the OsmoHLR VTY reference
|
||||
manual <<vty-ref-osmohlr>> as well as the Control interface described in
|
||||
<<hlr-ctrl>>.
|
||||
|
||||
=== Example: Add/Update/Delete Subscriber via VTY
|
||||
|
||||
The following telnet VTY session adds a subscriber complete with GSM (2G) and
|
||||
UMTS (3G and 2G) authentication tokens, and finally removes the subscriber
|
||||
again; it assumes that osmo-hlr is running and listening for telnet VTY
|
||||
connections on localhost:
|
||||
|
||||
----
|
||||
$ telnet localhost 4258
|
||||
include::../example_subscriber_add_update_delete.vty[]
|
||||
----
|
||||
|
||||
[[subscriber-params]]
|
||||
=== Subscriber Parameters
|
||||
|
||||
The following parameters are managed for each subscriber of the HLR, modelled
|
||||
roughly after 3GPP TS 23.008, version 13.3.0; note that not all of these
|
||||
parameters are necessarily in active use.
|
||||
|
||||
The `aud3g` table also applies to 2G networks: it provides UMTS AKA tokens for
|
||||
Milenage authentication, which is available both on 3G and 2G networks. On 2G,
|
||||
when both MS and network are R99 capable (like OsmoMSC and OsmoSGSN are), the
|
||||
full UMTS AKA with Milenage keys from `aud_3g`, using AUTN and extended RES
|
||||
tokens, is available. With pre-R99 MS or network configurations, the GSM AKA
|
||||
compatible variant of Milenage, still using the Milenage keys from `aud_3g` but
|
||||
transceiving only RAND and SRES, may be applicable. (See 3GPP TS 33.102, chapter
|
||||
6.8.1, Authentication and key agreement of UMTS subscribers.)
|
||||
|
||||
.OsmoHLR's subscriber parameters
|
||||
[options="header",width="100%",cols="20%,20%,60%"]
|
||||
|===
|
||||
|Name|Example|Description
|
||||
|imsi|901700000014701|identity of the SIM/USIM, 3GPP TS 23.008 chapter 2.1.1.1
|
||||
|msisdn|2342123|number to dial to reach this subscriber (multiple MSISDNs can be stored per subscriber), 3GPP TS 23.008 chapter 2.1.2
|
||||
|imeisv|4234234234234275|identity of the mobile device and software version, 3GPP TS 23.008 chapter 2.2.3
|
||||
|aud2g.algo|comp128v3|Authentication algorithm ID for GSM AKA, corresponds to enum osmo_auth_algo
|
||||
|aud2g.ki||Subscriber's secret key (128bit)
|
||||
|aud3g.algo|milenage|Authentication algorithm ID for UMTS AKA (applies to both 3G and 2G networks), corresponds to enum osmo_auth_algo
|
||||
|aud3g.k|(32 hexadecimal digits)|Subscriber's secret key (128bit)
|
||||
|aud3g.op|(32 hexadecimal digits)|Operator's secret key (128bit)
|
||||
|aud3g.opc|(32 hexadecimal digits)|Secret key derived from OP and K (128bit), alternative to using OP which does not disclose OP to subscribers
|
||||
|aud3g.sqn|123|Sequence number of last used key (64bit unsigned)
|
||||
|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
|
||||
|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
|
||||
|gmlc_number||3GPP TS 23.008 chapter 2.4.9.2
|
||||
|smsc_number||3GPP TS 23.008 chapter 2.4.23
|
||||
|periodic_lu_tmr||3GPP TS 23.008 chapter 2.4.24
|
||||
|periodic_rau_tau_tmr||3GPP TS 23.008 chapter 2.13.115
|
||||
|nam_cs|1|Enable/disable voice access (3GPP TS 23.008 chapter 2.1.1.2: network access mode)
|
||||
|nam_ps|0|Enable/disable data access (3GPP TS 23.008 chapter 2.1.1.2: network access mode)
|
||||
|lmsi||3GPP TS 23.008 chapter 2.1.8
|
||||
|ms_purged_cs|0|3GPP TS 23.008 chapter 2.7.5
|
||||
|ms_purged_ps|1|3GPP TS 23.008 chapter 2.7.6
|
||||
|===
|
||||
|
||||
78
doc/manuals/chapters/ussd.adoc
Normal file
78
doc/manuals/chapters/ussd.adoc
Normal file
@@ -0,0 +1,78 @@
|
||||
[[ussd]]
|
||||
== Unstructured Supplementary Services Data (USSD)
|
||||
|
||||
The _Unstructured Supplementary Services Data (USSD)_ is one service within
|
||||
2G/3G networks next to other services such as circuit-switched voice, packet-switched
|
||||
data and SMS (Short Message Service).
|
||||
|
||||
It is on an abstract level quite similar to SMS in that USSD can be used to send
|
||||
textual messages. However, there are the following differences:
|
||||
|
||||
* USSD is between the MS (phone) and an USSD application on the network, while
|
||||
SMS is primarily between two subscribers identified by their MSISDN
|
||||
* USSD is faster, as it doesn't suffer from the complicated three-layer CP/RP/TP
|
||||
protocol stack of SMS with it's acknowledgement of the acknowledged acknowledgement.
|
||||
* USSD is session-oriented, i.e. a dialogue/session between subscriber and application
|
||||
can persist for the transfer of more than one message. The dedicated radio channel
|
||||
on the RAN remains established throughout that dialogue.
|
||||
|
||||
=== USSD in Osmocom
|
||||
|
||||
Until August 2018, OsmoMSC contained some minimalistic internal USSD
|
||||
handling with no
|
||||
ability to attach/extend it with external USSD applications.
|
||||
|
||||
From August 2018 onwards, OsmoMSC doesn't contain any internal USSD
|
||||
handlers/applications anymore. Instead, all USSD is transported to/from
|
||||
OsmoHLR via the GSUP protocol.
|
||||
|
||||
OsmoHLR contains some intenal USSD handlers and can route USSD messages
|
||||
to any number of external USSD entities (EUSEs). The EUSE also use GSUP
|
||||
to communicate USSD from/to OsmoHLR.
|
||||
|
||||
Each EUSE is identified by its name. The name consists of a single-word
|
||||
string preceding a currently fixed ("-00-00-00-00-00-00") suffix.
|
||||
There is no authentication between EUSE and OsmoHLR: Any client program
|
||||
able to connect to the GSUP port of OsmoHLR can register as any EUSE
|
||||
(name).
|
||||
|
||||
NOTE:: We plan to remove the requirement for this suffix as soon as we
|
||||
are done resolving all more important issues.
|
||||
|
||||
=== USSD Configuration
|
||||
|
||||
USSD configuration in OsmoHLR happens within the `hlr` VTY node.
|
||||
|
||||
`euse foobar-00-00-00-00-00-00` defines an EUSE with the given name `foobar`
|
||||
|
||||
`ussd route prefix *123 external foobar-00-00-00-00-00-00` installs a
|
||||
prefix route to the named EUSE. All USSD short codes starting with *123 will be
|
||||
routed to the named EUSE.
|
||||
|
||||
`ussd route prefix *#100# internal own-msisdn` installs a prefix route
|
||||
to the named internal USSD handler. There above command will restore
|
||||
the old behavior, in which *#100# will return a text message containing
|
||||
the subscribers own phone number. There is one other handler called
|
||||
`own-imsi` which will return the IMSI instead of the MSISDN.
|
||||
|
||||
`ussd default-route external foobar-00-00-00-00-00-00` installs a
|
||||
default route to the named EUSE. This means that all USSD codes for
|
||||
which no more specific route exists will be routed to the named EUSE.
|
||||
|
||||
=== Example EUSE program
|
||||
|
||||
We have provided an example EUSE developed in C language using existing
|
||||
Osmocom libraries for GSUP protocol handling and USSD encoding/decoding.
|
||||
It will register as `foobar` EUSE to OsmoHLR on localhost. You can run
|
||||
it on a different machine by specifying e.g. `osmo-euse-demo 1.2.3.4 5678`
|
||||
to make it connect to OsmoHLR on IP address 1.2.3.4 and GSUP/TCP port
|
||||
5678.
|
||||
|
||||
The idea is that you can use this as a template to develop your own USSD
|
||||
applications, or any gateways to other protocols or interfaces.
|
||||
|
||||
You can find it in `osmo-hlr/src/osmo-euse-demo.c` or online by
|
||||
following the link to http://git.osmocom.org/osmo-hlr/tree/src/osmo-euse-demo.c
|
||||
|
||||
This demonstration program will echo back any USSD message sent/routed
|
||||
to it, quoted like _You sent "..."_.
|
||||
34
doc/manuals/example_subscriber_add_update_delete.vty
Normal file
34
doc/manuals/example_subscriber_add_update_delete.vty
Normal file
@@ -0,0 +1,34 @@
|
||||
OsmoHLR> enable
|
||||
OsmoHLR# subscriber imsi 123456789023000 create
|
||||
% Created subscriber 123456789023000
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: none
|
||||
|
||||
OsmoHLR# subscriber imsi 123456789023000 update msisdn 423
|
||||
% Updated subscriber IMSI='123456789023000' to MSISDN='423'
|
||||
|
||||
OsmoHLR# subscriber msisdn 423 update aud3g milenage k deaf0ff1ced0d0dabbedd1ced1cef00d opc cededeffacedacefacedbadfadedbeef
|
||||
OsmoHLR# subscriber msisdn 423 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: 423
|
||||
3G auth: MILENAGE
|
||||
K=deaf0ff1ced0d0dabbedd1ced1cef00d
|
||||
OPC=cededeffacedacefacedbadfadedbeef
|
||||
IND-bitlen=5
|
||||
|
||||
OsmoHLR# subscriber msisdn 423 update aud2g comp128v3 ki beefedcafefaceacedaddeddecadefee
|
||||
OsmoHLR# subscriber msisdn 423 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: 423
|
||||
2G auth: COMP128v3
|
||||
KI=beefedcafefaceacedaddeddecadefee
|
||||
3G auth: MILENAGE
|
||||
K=deaf0ff1ced0d0dabbedd1ced1cef00d
|
||||
OPC=cededeffacedacefacedbadfadedbeef
|
||||
IND-bitlen=5
|
||||
|
||||
OsmoHLR# subscriber imsi 123456789023000 delete
|
||||
% Deleted subscriber for IMSI '123456789023000'
|
||||
71
doc/manuals/example_subscriber_cs_ps_enabled.ctrl
Normal file
71
doc/manuals/example_subscriber_cs_ps_enabled.ctrl
Normal file
@@ -0,0 +1,71 @@
|
||||
GET 1 subscriber.by-msisdn-103.info
|
||||
GET_REPLY 1 subscriber.by-msisdn-103.info
|
||||
id 3
|
||||
imsi 901990000000003
|
||||
msisdn 103
|
||||
nam_cs 1
|
||||
nam_ps 1
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
|
||||
GET 2 subscriber.by-msisdn-103.ps-enabled
|
||||
GET_REPLY 2 subscriber.by-msisdn-103.ps-enabled 1
|
||||
|
||||
SET 3 subscriber.by-msisdn-103.ps-enabled 0
|
||||
SET_REPLY 3 subscriber.by-msisdn-103.ps-enabled OK
|
||||
|
||||
GET 4 subscriber.by-msisdn-103.ps-enabled
|
||||
GET_REPLY 4 subscriber.by-msisdn-103.ps-enabled 0
|
||||
|
||||
GET 5 subscriber.by-msisdn-103.info
|
||||
GET_REPLY 5 subscriber.by-msisdn-103.info
|
||||
id 3
|
||||
imsi 901990000000003
|
||||
msisdn 103
|
||||
nam_cs 1
|
||||
nam_ps 0
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
|
||||
SET 6 subscriber.by-msisdn-103.cs-enabled 0
|
||||
SET_REPLY 6 subscriber.by-msisdn-103.cs-enabled OK
|
||||
|
||||
GET 7 subscriber.by-msisdn-103.cs-enabled
|
||||
GET_REPLY 7 subscriber.by-msisdn-103.cs-enabled 0
|
||||
|
||||
GET 8 subscriber.by-msisdn-103.info
|
||||
GET_REPLY 8 subscriber.by-msisdn-103.info
|
||||
id 3
|
||||
imsi 901990000000003
|
||||
msisdn 103
|
||||
nam_cs 0
|
||||
nam_ps 0
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
|
||||
SET 9 subscriber.by-msisdn-103.cs-enabled 1
|
||||
SET_REPLY 9 subscriber.by-msisdn-103.cs-enabled OK
|
||||
SET 10 subscriber.by-msisdn-103.ps-enabled 1
|
||||
SET_REPLY 10 subscriber.by-msisdn-103.ps-enabled OK
|
||||
|
||||
GET 11 subscriber.by-msisdn-103.info
|
||||
GET_REPLY 11 subscriber.by-msisdn-103.info
|
||||
id 3
|
||||
imsi 901990000000003
|
||||
msisdn 103
|
||||
nam_cs 1
|
||||
nam_ps 1
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
42
doc/manuals/example_subscriber_info.ctrl
Normal file
42
doc/manuals/example_subscriber_info.ctrl
Normal file
@@ -0,0 +1,42 @@
|
||||
GET 1 subscriber.by-imsi-901990000000003.info
|
||||
GET_REPLY 1 subscriber.by-imsi-901990000000003.info
|
||||
id 3
|
||||
imsi 901990000000003
|
||||
msisdn 103
|
||||
nam_cs 1
|
||||
nam_ps 1
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
|
||||
GET 2 subscriber.by-msisdn-103.info-aud
|
||||
GET_REPLY 2 subscriber.by-msisdn-103.info-aud
|
||||
aud2g.algo COMP128v1
|
||||
aud2g.ki 000102030405060708090a0b0c0d0e0f
|
||||
aud3g.algo MILENAGE
|
||||
aud3g.k 000102030405060708090a0b0c0d0e0f
|
||||
aud3g.opc 101112131415161718191a1b1c1d1e1f
|
||||
aud3g.ind_bitlen 5
|
||||
aud3g.sqn 0
|
||||
|
||||
GET 3 subscriber.by-id-3.info-all
|
||||
GET_REPLY 3 subscriber.by-id-3.info-all
|
||||
id 3
|
||||
imsi 901990000000003
|
||||
msisdn 103
|
||||
nam_cs 1
|
||||
nam_ps 1
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
aud2g.algo COMP128v1
|
||||
aud2g.ki 000102030405060708090a0b0c0d0e0f
|
||||
aud3g.algo MILENAGE
|
||||
aud3g.k 000102030405060708090a0b0c0d0e0f
|
||||
aud3g.opc 101112131415161718191a1b1c1d1e1f
|
||||
aud3g.ind_bitlen 5
|
||||
aud3g.sqn 0
|
||||
47
doc/manuals/osmohlr-usermanual-docinfo.xml
Normal file
47
doc/manuals/osmohlr-usermanual-docinfo.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<revhistory>
|
||||
<revision>
|
||||
<revnumber>1</revnumber>
|
||||
<date>September 18th, 2017</date>
|
||||
<authorinitials>NH</authorinitials>
|
||||
<revremark>
|
||||
Initial version; based on OsmoNITB manual version 2.
|
||||
</revremark>
|
||||
</revision>
|
||||
</revhistory>
|
||||
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Neels</firstname>
|
||||
<surname>Hofmeyr</surname>
|
||||
<email>nhofmeyr@sysmocom.de</email>
|
||||
<authorinitials>NH</authorinitials>
|
||||
<affiliation>
|
||||
<shortaffil>sysmocom</shortaffil>
|
||||
<orgname>sysmocom - s.f.m.c. GmbH</orgname>
|
||||
<jobtitle>Senior Developer</jobtitle>
|
||||
</affiliation>
|
||||
</author>
|
||||
</authorgroup>
|
||||
|
||||
<copyright>
|
||||
<year>2017</year>
|
||||
<holder>sysmocom - s.f.m.c. GmbH</holder>
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
<para>
|
||||
Permission is granted to copy, distribute and/or modify this
|
||||
document under the terms of the GNU Free Documentation License,
|
||||
Version 1.3 or any later version published by the Free Software
|
||||
Foundation; with the Invariant Sections being just 'Foreword',
|
||||
'Acknowledgements' and 'Preface', with no Front-Cover Texts,
|
||||
and no Back-Cover Texts. A copy of the license is included in
|
||||
the section entitled "GNU Free Documentation License".
|
||||
</para>
|
||||
<para>
|
||||
The Asciidoc source code of this manual can be found at
|
||||
<ulink url="http://git.osmocom.org/osmo-gsm-manuals/">
|
||||
http://git.osmocom.org/osmo-gsm-manuals/
|
||||
</ulink>
|
||||
</para>
|
||||
</legalnotice>
|
||||
36
doc/manuals/osmohlr-usermanual.adoc
Normal file
36
doc/manuals/osmohlr-usermanual.adoc
Normal file
@@ -0,0 +1,36 @@
|
||||
:gfdl-enabled:
|
||||
:program-name: OsmoHLR
|
||||
|
||||
OsmoHLR User Manual
|
||||
====================
|
||||
Neels Hofmeyr <nhofmeyr@sysmocom.de>
|
||||
|
||||
|
||||
include::./common/chapters/preface.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/overview.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/running.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/subscribers.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/ussd.adoc[]
|
||||
|
||||
include::./common/chapters/vty.adoc[]
|
||||
|
||||
include::./common/chapters/logging.adoc[]
|
||||
|
||||
include::{srcdir}/chapters/control.adoc[]
|
||||
|
||||
include::./common/chapters/control_if.adoc[]
|
||||
|
||||
include::./common/chapters/gsup.adoc[]
|
||||
|
||||
include::./common/chapters/port_numbers.adoc[]
|
||||
|
||||
include::./common/chapters/bibliography.adoc[]
|
||||
|
||||
include::./common/chapters/glossary.adoc[]
|
||||
|
||||
include::./common/chapters/gfdl.adoc[]
|
||||
|
||||
38
doc/manuals/osmohlr-vty-reference.xml
Normal file
38
doc/manuals/osmohlr-vty-reference.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
ex:ts=2:sw=42sts=2:et
|
||||
-*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
-->
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML 5.0//EN"
|
||||
"http://docbook.org/xml/5.0/dtd/docbook.dtd" [
|
||||
<!ENTITY chapter-vty SYSTEM "./common/chapters/vty.xml" >
|
||||
<!ENTITY sections-vty SYSTEM "generated/docbook_vty.xml" >
|
||||
]>
|
||||
|
||||
<book>
|
||||
<info>
|
||||
<revhistory>
|
||||
<revision>
|
||||
<revnumber>v1</revnumber>
|
||||
<date>18th September 2017</date>
|
||||
<authorinitials>nh</authorinitials>
|
||||
<revremark>Initial</revremark>
|
||||
</revision>
|
||||
</revhistory>
|
||||
|
||||
<title>OsmoHLR VTY Reference</title>
|
||||
|
||||
<copyright>
|
||||
<year>2017</year>
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
<para>This work is copyright by <orgname>sysmocom - s.f.m.c. GmbH</orgname>. All rights reserved.
|
||||
</para>
|
||||
</legalnotice>
|
||||
</info>
|
||||
|
||||
<!-- Main chapters-->
|
||||
&chapter-vty;
|
||||
</book>
|
||||
|
||||
2
doc/manuals/vty/hlr_vty_additions.xml
Normal file
2
doc/manuals/vty/hlr_vty_additions.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<vtydoc xmlns='urn:osmocom:xml:libosmocore:vty:doc:1.0'>
|
||||
</vtydoc>
|
||||
1162
doc/manuals/vty/hlr_vty_reference.xml
Normal file
1162
doc/manuals/vty/hlr_vty_reference.xml
Normal file
File diff suppressed because it is too large
Load Diff
2
include/Makefile.am
Normal file
2
include/Makefile.am
Normal file
@@ -0,0 +1,2 @@
|
||||
nobase_include_HEADERS = osmocom/gsupclient/gsup_client.h
|
||||
|
||||
77
include/osmocom/gsupclient/gsup_client.h
Normal file
77
include/osmocom/gsupclient/gsup_client.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* GPRS Subscriber Update Protocol client */
|
||||
|
||||
/* (C) 2014 by Sysmocom s.f.m.c. GmbH
|
||||
* All Rights Reserved
|
||||
*
|
||||
* 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
|
||||
* (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/core/timer.h>
|
||||
#include <osmocom/gsm/oap_client.h>
|
||||
#include <osmocom/gsm/ipa.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
/* a loss of GSUP between MSC and HLR is considered quite serious, let's try to recover as quickly as
|
||||
* possible. Even one new connection attempt per second should be quite acceptable until the link is
|
||||
* re-established */
|
||||
#define OSMO_GSUP_CLIENT_RECONNECT_INTERVAL 1
|
||||
#define OSMO_GSUP_CLIENT_PING_INTERVAL 20
|
||||
|
||||
struct msgb;
|
||||
struct ipa_client_conn;
|
||||
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);
|
||||
|
||||
struct osmo_gsup_client {
|
||||
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
|
||||
|
||||
struct ipa_client_conn *link;
|
||||
osmo_gsup_client_read_cb_t read_cb;
|
||||
void *data;
|
||||
|
||||
struct osmo_oap_client_state oap_state;
|
||||
|
||||
struct osmo_timer_list ping_timer;
|
||||
struct osmo_timer_list connect_timer;
|
||||
int is_connected;
|
||||
int got_ipa_pong;
|
||||
|
||||
struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */
|
||||
};
|
||||
|
||||
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_create(void *talloc_ctx,
|
||||
const char *unit_name,
|
||||
const char *ip_addr,
|
||||
unsigned int tcp_port,
|
||||
osmo_gsup_client_read_cb_t read_cb,
|
||||
struct osmo_oap_client_config *oapc_config);
|
||||
|
||||
void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc);
|
||||
int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
|
||||
int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
|
||||
const struct osmo_gsup_message *gsup_msg);
|
||||
struct msgb *osmo_gsup_client_msgb_alloc(void);
|
||||
|
||||
11
libosmo-gsup-client.pc.in
Normal file
11
libosmo-gsup-client.pc.in
Normal file
@@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: Osmocom GSUP Client Library
|
||||
Description: C Utility Library
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -losmo-gsup-client
|
||||
Cflags: -I${includedir}/
|
||||
|
||||
@@ -3,5 +3,12 @@ EXTRA_DIST = \
|
||||
hlr.sql \
|
||||
$(NULL)
|
||||
|
||||
docsdir = $(datadir)/doc/osmo-hlr
|
||||
docs_DATA = $(srcdir)/hlr.sql
|
||||
sqldir = $(docdir)/sql
|
||||
sql_DATA = $(srcdir)/hlr.sql $(srcdir)/hlr_data.sql
|
||||
|
||||
|
||||
install-data-local:
|
||||
$(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/osmocom
|
||||
|
||||
uninstall-hook:
|
||||
rm -rf $(DESTDIR)$(localstatedir)/lib/osmocom
|
||||
|
||||
22
sql/hlr.sql
22
sql/hlr.sql
@@ -1,4 +1,4 @@
|
||||
CREATE TABLE IF NOT EXISTS subscriber (
|
||||
CREATE TABLE subscriber (
|
||||
-- OsmoHLR's DB scheme is modelled roughly after TS 23.008 version 13.3.0
|
||||
id INTEGER PRIMARY KEY,
|
||||
-- Chapter 2.1.1.1
|
||||
@@ -36,27 +36,31 @@ CREATE TABLE IF NOT EXISTS subscriber (
|
||||
-- Chapter 2.7.5
|
||||
ms_purged_cs BOOLEAN NOT NULL DEFAULT 0,
|
||||
-- Chapter 2.7.6
|
||||
ms_purged_ps BOOLEAN NOT NULL DEFAULT 0
|
||||
ms_purged_ps BOOLEAN NOT NULL DEFAULT 0,
|
||||
|
||||
-- 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
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS subscriber_apn (
|
||||
CREATE TABLE subscriber_apn (
|
||||
subscriber_id INTEGER, -- subscriber.id
|
||||
apn VARCHAR(256) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS subscriber_multi_msisdn (
|
||||
CREATE TABLE subscriber_multi_msisdn (
|
||||
-- Chapter 2.1.3
|
||||
subscriber_id INTEGER, -- subscriber.id
|
||||
msisdn VARCHAR(15) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auc_2g (
|
||||
CREATE TABLE auc_2g (
|
||||
subscriber_id INTEGER PRIMARY KEY, -- subscriber.id
|
||||
algo_id_2g INTEGER NOT NULL, -- enum osmo_auth_algo value
|
||||
ki VARCHAR(32) NOT NULL -- hex string: subscriber's secret key (128bit)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auc_3g (
|
||||
CREATE TABLE auc_3g (
|
||||
subscriber_id INTEGER PRIMARY KEY, -- subscriber.id
|
||||
algo_id_3g INTEGER NOT NULL, -- enum osmo_auth_algo value
|
||||
k VARCHAR(32) NOT NULL, -- hex string: subscriber's secret key (128bit)
|
||||
@@ -66,4 +70,8 @@ CREATE TABLE IF NOT EXISTS auc_3g (
|
||||
ind_bitlen INTEGER NOT NULL DEFAULT 5 -- nr of index bits at lower SQN end
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_subscr_imsi ON subscriber (imsi);
|
||||
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;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
SUBDIRS = gsupclient
|
||||
|
||||
AM_CFLAGS = \
|
||||
-Wall \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
@@ -8,9 +10,12 @@ AM_CFLAGS = \
|
||||
$(SQLITE3_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
populate_hlr_db.pl \
|
||||
db_bootstrap.sed \
|
||||
db_sql2c.sed \
|
||||
$(NULL)
|
||||
|
||||
BUILT_SOURCES = \
|
||||
@@ -30,16 +35,14 @@ noinst_HEADERS = \
|
||||
ctrl.h \
|
||||
hlr_vty.h \
|
||||
hlr_vty_subscr.h \
|
||||
hlr_ussd.h \
|
||||
db_bootstrap.h \
|
||||
$(NULL)
|
||||
|
||||
bin_PROGRAMS = \
|
||||
osmo-hlr \
|
||||
osmo-hlr-db-tool \
|
||||
$(NULL)
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
db_test \
|
||||
osmo-euse-demo \
|
||||
$(NULL)
|
||||
|
||||
osmo_hlr_SOURCES = \
|
||||
@@ -56,6 +59,8 @@ osmo_hlr_SOURCES = \
|
||||
rand_urandom.c \
|
||||
hlr_vty.c \
|
||||
hlr_vty_subscr.c \
|
||||
gsup_send.c \
|
||||
hlr_ussd.c \
|
||||
$(NULL)
|
||||
|
||||
osmo_hlr_LDADD = \
|
||||
@@ -97,13 +102,23 @@ db_test_LDADD = \
|
||||
$(SQLITE3_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
osmo_euse_demo_SOURCES = \
|
||||
osmo-euse-demo.c \
|
||||
$(NULL)
|
||||
|
||||
osmo_euse_demo_LDADD = \
|
||||
$(top_builddir)/src/gsupclient/libosmo-gsup-client.la \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
BOOTSTRAP_SQL = $(top_srcdir)/sql/hlr.sql
|
||||
|
||||
db_bootstrap.h: $(BOOTSTRAP_SQL) $(srcdir)/db_bootstrap.sed
|
||||
echo "/* DO NOT EDIT THIS FILE. It is generated from osmo-hlr.git/sql/hlr.sql */" > "$@"
|
||||
db_bootstrap.h: $(BOOTSTRAP_SQL) $(srcdir)/db_sql2c.sed
|
||||
echo "/* DO NOT EDIT THIS FILE. It is generated from files in osmo-hlr.git/sql/ */" > "$@"
|
||||
echo "#pragma once" >> "$@"
|
||||
echo "static const char *stmt_bootstrap_sql[] = {" >> "$@"
|
||||
cat "$(BOOTSTRAP_SQL)" \
|
||||
| sed -f "$(srcdir)/db_bootstrap.sed" \
|
||||
| sed -f "$(srcdir)/db_sql2c.sed" \
|
||||
>> "$@"
|
||||
echo "};" >> "$@"
|
||||
|
||||
@@ -144,6 +144,7 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
|
||||
|
||||
if (!aud2g) {
|
||||
/* use the 2G tokens from 3G keys */
|
||||
DBGP("vector [%u]: deriving 2G from 3G\n", i);
|
||||
DBGVB(kc);
|
||||
DBGVB(sres);
|
||||
DBGVV("0x%x", auth_types);
|
||||
@@ -151,7 +152,7 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
|
||||
}
|
||||
/* calculate 2G separately */
|
||||
|
||||
DBGP("vector [%u]: deriving 2G from 3G\n", i);
|
||||
DBGP("vector [%u]: calculating 2G separately\n", i);
|
||||
|
||||
rc = osmo_auth_gen_vec(&vtmp, aud2g, rand);
|
||||
if (rc < 0) {
|
||||
|
||||
22
src/ctrl.c
22
src/ctrl.c
@@ -132,7 +132,7 @@ static void print_subscr_info(struct ctrl_cmd *cmd,
|
||||
struct hlr_subscriber *subscr)
|
||||
{
|
||||
ctrl_cmd_reply_printf(cmd,
|
||||
"\nid\t%"PRIu64
|
||||
"\nid\t%" PRIu64
|
||||
FMT_S
|
||||
FMT_S
|
||||
FMT_BOOL
|
||||
@@ -189,7 +189,7 @@ static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_d
|
||||
ctrl_cmd_reply_printf(cmd,
|
||||
"\naud3g.%s\t%s"
|
||||
"\naud3g.ind_bitlen\t%u"
|
||||
"\naud3g.sqn\t%"PRIu64
|
||||
"\naud3g.sqn\t%" PRIu64
|
||||
,
|
||||
aud->u.umts.opc_is_op? "op" : "opc",
|
||||
hexdump_buf(aud->u.umts.opc),
|
||||
@@ -228,11 +228,16 @@ static int get_subscr_info_aud(struct ctrl_cmd *cmd, void *data)
|
||||
|
||||
rc = db_get_auth_data(hlr->dbc, imsi, &aud2g, &aud3g, NULL);
|
||||
|
||||
if (rc == -ENOENT) {
|
||||
switch (rc) {
|
||||
case 0:
|
||||
break;
|
||||
case -ENOENT:
|
||||
case -ENOKEY:
|
||||
/* No auth data found, tell the print*() functions about it. */
|
||||
aud2g.algo = OSMO_AUTH_ALG_NONE;
|
||||
aud3g.algo = OSMO_AUTH_ALG_NONE;
|
||||
} else if (rc) {
|
||||
break;
|
||||
default:
|
||||
cmd->reply = "Error retrieving authentication data.";
|
||||
return CTRL_CMD_ERROR;
|
||||
}
|
||||
@@ -258,11 +263,16 @@ static int get_subscr_info_all(struct ctrl_cmd *cmd, void *data)
|
||||
|
||||
rc = db_get_auth_data(hlr->dbc, subscr.imsi, &aud2g, &aud3g, NULL);
|
||||
|
||||
if (rc == -ENOENT) {
|
||||
switch (rc) {
|
||||
case 0:
|
||||
break;
|
||||
case -ENOENT:
|
||||
case -ENOKEY:
|
||||
/* No auth data found, tell the print*() functions about it. */
|
||||
aud2g.algo = OSMO_AUTH_ALG_NONE;
|
||||
aud3g.algo = OSMO_AUTH_ALG_NONE;
|
||||
} else if (rc) {
|
||||
break;
|
||||
default:
|
||||
cmd->reply = "Error retrieving authentication data.";
|
||||
return CTRL_CMD_ERROR;
|
||||
}
|
||||
|
||||
195
src/db.c
195
src/db.c
@@ -27,6 +27,9 @@
|
||||
#include "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 SEL_COLUMNS \
|
||||
"id," \
|
||||
"imsi," \
|
||||
@@ -40,7 +43,8 @@
|
||||
"nam_ps," \
|
||||
"lmsi," \
|
||||
"ms_purged_cs," \
|
||||
"ms_purged_ps"
|
||||
"ms_purged_ps," \
|
||||
"last_lu_seen"
|
||||
|
||||
static const char *stmt_sql[] = {
|
||||
[DB_STMT_SEL_BY_IMSI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imsi = ?",
|
||||
@@ -62,6 +66,7 @@ static const char *stmt_sql[] = {
|
||||
[DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi) VALUES ($imsi)",
|
||||
[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",
|
||||
[DB_STMT_AUC_2G_INSERT] =
|
||||
"INSERT INTO auc_2g (subscriber_id, algo_id_2g, ki)"
|
||||
" VALUES($subscriber_id, $algo_id_2g, $ki)",
|
||||
@@ -70,6 +75,7 @@ static const char *stmt_sql[] = {
|
||||
"INSERT INTO auc_3g (subscriber_id, algo_id_3g, k, op, opc, ind_bitlen)"
|
||||
" 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",
|
||||
};
|
||||
|
||||
static void sql3_error_log_cb(void *arg, int err_code, const char *msg)
|
||||
@@ -99,6 +105,8 @@ static void sql3_sql_log_cb(void *arg, sqlite3 *s3, const char *stmt, int type)
|
||||
void db_remove_reset(sqlite3_stmt *stmt)
|
||||
{
|
||||
sqlite3_clear_bindings(stmt);
|
||||
/* sqlite3_reset() just repeats an error code already evaluated during sqlite3_step(). */
|
||||
/* coverity[CHECKED_RETURN] */
|
||||
sqlite3_reset(stmt);
|
||||
}
|
||||
|
||||
@@ -171,12 +179,20 @@ bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr)
|
||||
void db_close(struct db_context *dbc)
|
||||
{
|
||||
unsigned int i;
|
||||
int rc;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(dbc->stmt); i++) {
|
||||
/* it is ok to call finalize on NULL */
|
||||
sqlite3_finalize(dbc->stmt[i]);
|
||||
}
|
||||
sqlite3_close(dbc->db);
|
||||
|
||||
/* Ask sqlite3 to close DB */
|
||||
rc = sqlite3_close(dbc->db);
|
||||
if (rc != SQLITE_OK) { /* Make sure it's actually closed! */
|
||||
LOGP(DDB, LOGL_ERROR, "Couldn't close database: (rc=%d) %s\n",
|
||||
rc, sqlite3_errmsg(dbc->db));
|
||||
}
|
||||
|
||||
talloc_free(dbc);
|
||||
}
|
||||
|
||||
@@ -186,35 +202,125 @@ static int db_bootstrap(struct db_context *dbc)
|
||||
for (i = 0; i < ARRAY_SIZE(stmt_bootstrap_sql); i++) {
|
||||
int rc;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
rc = sqlite3_prepare_v2(dbc->db, stmt_bootstrap_sql[i], -1,
|
||||
&stmt, NULL);
|
||||
rc = sqlite3_prepare_v2(dbc->db, stmt_bootstrap_sql[i], -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n",
|
||||
stmt_bootstrap_sql[i]);
|
||||
return -1;
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", stmt_bootstrap_sql[i]);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* execute the statement */
|
||||
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]);
|
||||
return -1;
|
||||
rc, sqlite3_errmsg(dbc->db), stmt_bootstrap_sql[i]);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
struct db_context *db_open(void *ctx, const char *fname)
|
||||
/* https://www.sqlite.org/fileformat2.html#storage_of_the_sql_database_schema */
|
||||
static bool db_table_exists(struct db_context *dbc, const char *table_name)
|
||||
{
|
||||
const char *table_exists_sql = "SELECT name FROM sqlite_master WHERE type='table' AND name=?";
|
||||
sqlite3_stmt *stmt;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_prepare_v2(dbc->db, table_exists_sql, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", table_exists_sql);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!db_bind_text(stmt, NULL, table_name))
|
||||
return false;
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
db_remove_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
return (rc == SQLITE_ROW);
|
||||
}
|
||||
|
||||
/* Indicate whether the database is initialized with tables for schema version 0.
|
||||
* We only check for the 'subscriber' table here because Neels said so. */
|
||||
static bool db_is_bootstrapped_v0(struct db_context *dbc)
|
||||
{
|
||||
if (!db_table_exists(dbc, "subscriber")) {
|
||||
LOGP(DDB, LOGL_DEBUG, "Table 'subscriber' not found in database '%s'\n", dbc->fname);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
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);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version %d\n", 1);
|
||||
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_get_user_version(struct db_context *dbc)
|
||||
{
|
||||
const char *user_version_sql = "PRAGMA user_version";
|
||||
sqlite3_stmt *stmt;
|
||||
int version, rc;
|
||||
|
||||
rc = sqlite3_prepare_v2(dbc->db, user_version_sql, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to prepare SQL statement '%s'\n", user_version_sql);
|
||||
return -1;
|
||||
}
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc == SQLITE_ROW) {
|
||||
version = sqlite3_column_int(stmt, 0);
|
||||
} else {
|
||||
LOGP(DDB, LOGL_ERROR, "SQL statement '%s' failed: %d\n", user_version_sql, rc);
|
||||
version = -1;
|
||||
}
|
||||
|
||||
db_remove_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
return version;
|
||||
}
|
||||
|
||||
struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logging, bool allow_upgrade)
|
||||
{
|
||||
struct db_context *dbc = talloc_zero(ctx, struct db_context);
|
||||
unsigned int i;
|
||||
int rc;
|
||||
bool has_sqlite_config_sqllog = false;
|
||||
int version;
|
||||
|
||||
LOGP(DDB, LOGL_NOTICE, "using database: %s\n", fname);
|
||||
LOGP(DDB, LOGL_INFO, "Compiled against SQLite3 lib version %s\n", SQLITE_VERSION);
|
||||
@@ -231,9 +337,11 @@ struct db_context *db_open(void *ctx, const char *fname)
|
||||
has_sqlite_config_sqllog = true;
|
||||
}
|
||||
|
||||
rc = sqlite3_config(SQLITE_CONFIG_LOG, sql3_error_log_cb, NULL);
|
||||
if (rc != SQLITE_OK)
|
||||
LOGP(DDB, LOGL_NOTICE, "Unable to set SQLite3 error log callback\n");
|
||||
if (enable_sqlite_logging) {
|
||||
rc = sqlite3_config(SQLITE_CONFIG_LOG, sql3_error_log_cb, NULL);
|
||||
if (rc != SQLITE_OK)
|
||||
LOGP(DDB, LOGL_NOTICE, "Unable to set SQLite3 error log callback\n");
|
||||
}
|
||||
|
||||
if (has_sqlite_config_sqllog) {
|
||||
rc = sqlite3_config(SQLITE_CONFIG_SQLLOG, sql3_sql_log_cb, NULL);
|
||||
@@ -261,7 +369,58 @@ struct db_context *db_open(void *ctx, const char *fname)
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to set Write-Ahead Logging: %s\n",
|
||||
err_msg);
|
||||
|
||||
db_bootstrap(dbc);
|
||||
version = db_get_user_version(dbc);
|
||||
if (version < 0) {
|
||||
LOGP(DDB, LOGL_ERROR, "Unable to read user version number from database '%s'\n", dbc->fname);
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
/* An empty database will always report version zero. */
|
||||
if (version == 0 && !db_is_bootstrapped_v0(dbc)) {
|
||||
LOGP(DDB, LOGL_NOTICE, "Missing database tables detected; Bootstrapping database '%s'\n", dbc->fname);
|
||||
rc = db_bootstrap(dbc);
|
||||
if (rc != SQLITE_OK) {
|
||||
LOGP(DDB, LOGL_ERROR, "Failed to bootstrap DB: (rc=%d) %s\n",
|
||||
rc, sqlite3_errmsg(dbc->db));
|
||||
goto out_free;
|
||||
}
|
||||
version = CURRENT_SCHEMA_VERSION;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
LOGP(DDB, LOGL_NOTICE, "Database '%s' has been upgraded to HLR DB schema version %d\n",
|
||||
dbc->fname, version);
|
||||
}
|
||||
|
||||
if (version != CURRENT_SCHEMA_VERSION) {
|
||||
if (version < CURRENT_SCHEMA_VERSION) {
|
||||
LOGP(DDB, LOGL_NOTICE, "HLR DB schema version %d is outdated\n", version);
|
||||
if (!allow_upgrade) {
|
||||
LOGP(DDB, LOGL_ERROR, "Not upgrading HLR database to schema version %d; "
|
||||
"use the --db-upgrade option to allow HLR database upgrades\n",
|
||||
CURRENT_SCHEMA_VERSION);
|
||||
}
|
||||
} else
|
||||
LOGP(DDB, LOGL_ERROR, "HLR DB schema version %d is unknown\n", version);
|
||||
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
/* prepare all SQL statements */
|
||||
for (i = 0; i < ARRAY_SIZE(dbc->stmt); i++) {
|
||||
|
||||
14
src/db.h
14
src/db.h
@@ -20,10 +20,12 @@ enum stmt_idx {
|
||||
DB_STMT_SUBSCR_CREATE,
|
||||
DB_STMT_DEL_BY_ID,
|
||||
DB_STMT_SET_MSISDN_BY_IMSI,
|
||||
DB_STMT_DELETE_MSISDN_BY_IMSI,
|
||||
DB_STMT_AUC_2G_INSERT,
|
||||
DB_STMT_AUC_2G_DELETE,
|
||||
DB_STMT_AUC_3G_INSERT,
|
||||
DB_STMT_AUC_3G_DELETE,
|
||||
DB_STMT_SET_LAST_LU_SEEN,
|
||||
_NUM_DB_STMT
|
||||
};
|
||||
|
||||
@@ -38,7 +40,7 @@ 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);
|
||||
void db_close(struct db_context *dbc);
|
||||
struct db_context *db_open(void *ctx, const char *fname);
|
||||
struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite3_logging, bool allow_upgrades);
|
||||
|
||||
#include <osmocom/crypt/auth.h>
|
||||
|
||||
@@ -69,8 +71,8 @@ struct hlr_subscriber {
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
|
||||
char msisdn[GT_MAX_DIGITS+1];
|
||||
/* imeisv? */
|
||||
char vlr_number[GT_MAX_DIGITS+1];
|
||||
char sgsn_number[GT_MAX_DIGITS+1];
|
||||
char vlr_number[32];
|
||||
char sgsn_number[32];
|
||||
char sgsn_address[GT_MAX_DIGITS+1];
|
||||
/* ggsn number + address */
|
||||
/* gmlc number */
|
||||
@@ -82,8 +84,14 @@ struct hlr_subscriber {
|
||||
uint32_t lmsi;
|
||||
bool ms_purged_cs;
|
||||
bool ms_purged_ps;
|
||||
time_t last_lu_seen;
|
||||
};
|
||||
|
||||
/* A format string for use with strptime(3). This format string is
|
||||
* used to parse the last_lu_seen column stored in the HLR database.
|
||||
* See https://sqlite.org/lang_datefunc.html, function datetime(). */
|
||||
#define DB_LAST_LU_SEEN_FMT "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
/* Like struct osmo_sub_auth_data, but the keys are in hexdump representation.
|
||||
* This is useful because SQLite requires them in hexdump format, and callers
|
||||
* like the VTY and CTRL interface also have them available as hexdump to begin
|
||||
|
||||
17
src/db_auc.c
17
src/db_auc.c
@@ -49,7 +49,7 @@ int db_update_sqn(struct db_context *dbc, int64_t subscr_id, uint64_t new_sqn)
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update SQN for subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update SQN for subscriber ID=%" PRId64
|
||||
": SQL error: (%d) %s\n",
|
||||
subscr_id, rc, sqlite3_errmsg(dbc->db));
|
||||
ret = -EIO;
|
||||
@@ -59,11 +59,11 @@ int db_update_sqn(struct db_context *dbc, int64_t subscr_id, uint64_t new_sqn)
|
||||
/* verify execution result */
|
||||
rc = sqlite3_changes(dbc->db);
|
||||
if (!rc) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update SQN for subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update SQN for subscriber ID=%" PRId64
|
||||
": no auc_3g entry for such subscriber\n", subscr_id);
|
||||
ret = -ENOENT;
|
||||
} else if (rc != 1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Update SQN for subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Update SQN for subscriber ID=%" PRId64
|
||||
": SQL modified %d rows (expected 1)\n", subscr_id, rc);
|
||||
ret = -EIO;
|
||||
}
|
||||
@@ -74,7 +74,9 @@ out:
|
||||
}
|
||||
|
||||
/* obtain the authentication data for a given imsi
|
||||
* returns -1 in case of error, 0 for unknown IMSI, 1 for success */
|
||||
* 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,
|
||||
* -EIO on db failure */
|
||||
int db_get_auth_data(struct db_context *dbc, const char *imsi,
|
||||
struct osmo_sub_auth_data *aud2g,
|
||||
struct osmo_sub_auth_data *aud3g,
|
||||
@@ -163,15 +165,16 @@ int db_get_auth_data(struct db_context *dbc, const char *imsi,
|
||||
LOGAUC(imsi, LOGL_DEBUG, "No 3G Auth Data\n");
|
||||
|
||||
if (aud2g->type == 0 && aud3g->type == 0)
|
||||
ret = -ENOENT;
|
||||
ret = -ENOKEY;
|
||||
|
||||
out:
|
||||
db_remove_reset(stmt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* return -1 in case of error, 0 for unknown imsi, positive for number
|
||||
* of vectors generated */
|
||||
/* return number of vectors generated, negative value on error:
|
||||
* -ENOENT if the IMSI is not known, -ENOKEY if the IMSI is known but has no auth data,
|
||||
* -EIO on db failure */
|
||||
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,
|
||||
|
||||
95
src/db_hlr.c
95
src/db_hlr.c
@@ -17,9 +17,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L /* for strptime(3) */
|
||||
/* These are needed as well due to the above _POSIX_C_SOURCE definition: */
|
||||
#define _DEFAULT_SOURCE /* for struct timezone */
|
||||
#define _XOPEN_SOURCE /* for clockid_t */
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/crypt/auth.h>
|
||||
@@ -92,7 +98,7 @@ int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id)
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DAUC, LOGL_ERROR,
|
||||
"Cannot delete subscriber ID=%"PRId64": SQL error: (%d) %s\n",
|
||||
"Cannot delete subscriber ID=%" PRId64 ": SQL error: (%d) %s\n",
|
||||
subscr_id, rc, sqlite3_errmsg(dbc->db));
|
||||
db_remove_reset(stmt);
|
||||
return -EIO;
|
||||
@@ -101,11 +107,11 @@ int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id)
|
||||
/* verify execution result */
|
||||
rc = sqlite3_changes(dbc->db);
|
||||
if (!rc) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot delete: no such subscriber: ID=%"PRId64"\n",
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot delete: no such subscriber: ID=%" PRId64 "\n",
|
||||
subscr_id);
|
||||
ret = -ENOENT;
|
||||
} else if (rc != 1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Delete subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Delete subscriber ID=%" PRId64
|
||||
": SQL modified %d rows (expected 1)\n", subscr_id, rc);
|
||||
ret = -EIO;
|
||||
}
|
||||
@@ -135,8 +141,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.
|
||||
* \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.
|
||||
*/
|
||||
@@ -146,19 +152,22 @@ int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi,
|
||||
int rc;
|
||||
int ret = 0;
|
||||
|
||||
if (!osmo_msisdn_str_valid(msisdn)) {
|
||||
if (msisdn && !osmo_msisdn_str_valid(msisdn)) {
|
||||
LOGHLR(imsi, LOGL_ERROR,
|
||||
"Cannot update subscriber: invalid MSISDN: '%s'\n",
|
||||
msisdn);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_SET_MSISDN_BY_IMSI];
|
||||
sqlite3_stmt *stmt = dbc->stmt[
|
||||
msisdn ? DB_STMT_SET_MSISDN_BY_IMSI : DB_STMT_DELETE_MSISDN_BY_IMSI];
|
||||
|
||||
if (!db_bind_text(stmt, "$imsi", imsi))
|
||||
return -EIO;
|
||||
if (!db_bind_text(stmt, "$msisdn", msisdn))
|
||||
return -EIO;
|
||||
if (msisdn) {
|
||||
if (!db_bind_text(stmt, "$msisdn", msisdn))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
@@ -312,7 +321,7 @@ int db_subscr_update_aud_by_id(struct db_context *dbc, int64_t subscr_id,
|
||||
* empty, and no entry is not an error then.*/
|
||||
ret = -ENOENT;
|
||||
else if (rc != 1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Delete subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Delete subscriber ID=%" PRId64
|
||||
" from %s: SQL modified %d rows (expected 1)\n",
|
||||
subscr_id, label, rc);
|
||||
ret = -EIO;
|
||||
@@ -383,6 +392,8 @@ static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscri
|
||||
{
|
||||
int rc;
|
||||
int ret = 0;
|
||||
const char *last_lu_seen_str;
|
||||
struct tm tm;
|
||||
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
@@ -415,6 +426,20 @@ static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscri
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
db_remove_reset(stmt);
|
||||
@@ -500,7 +525,7 @@ int db_subscr_get_by_id(struct db_context *dbc, int64_t id,
|
||||
|
||||
rc = db_sel(dbc, stmt, subscr, &err);
|
||||
if (rc)
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot read subscriber from db: ID=%"PRId64": %s\n",
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot read subscriber from db: ID=%" PRId64 ": %s\n",
|
||||
id, err);
|
||||
return rc;
|
||||
}
|
||||
@@ -574,6 +599,7 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
int rc, ret = 0;
|
||||
struct timespec localtime;
|
||||
|
||||
stmt = dbc->stmt[is_ps ? DB_STMT_UPD_SGSN_BY_ID
|
||||
: DB_STMT_UPD_VLR_BY_ID];
|
||||
@@ -587,7 +613,7 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
/* execute the statement */
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Update %s number for subscriber ID=%"PRId64": SQL Error: %s\n",
|
||||
LOGP(DAUC, LOGL_ERROR, "Update %s number for subscriber ID=%" PRId64 ": SQL Error: %s\n",
|
||||
is_ps? "SGSN" : "VLR", subscr_id, sqlite3_errmsg(dbc->db));
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
@@ -596,17 +622,58 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
|
||||
/* verify execution result */
|
||||
rc = sqlite3_changes(dbc->db);
|
||||
if (!rc) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update %s number for subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update %s number for subscriber ID=%" PRId64
|
||||
": no such subscriber\n",
|
||||
is_ps? "SGSN" : "VLR", subscr_id);
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
} else if (rc != 1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Update %s number for subscriber ID=%"PRId64
|
||||
LOGP(DAUC, LOGL_ERROR, "Update %s number for subscriber ID=%" PRId64
|
||||
": SQL modified %d rows (expected 1)\n",
|
||||
is_ps? "SGSN" : "VLR", subscr_id, rc);
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
db_remove_reset(stmt);
|
||||
|
||||
if (osmo_clock_gettime(CLOCK_REALTIME, &localtime) != 0) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot get the current time: (%d) %s\n", errno, strerror(errno));
|
||||
ret = -errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
stmt = dbc->stmt[DB_STMT_SET_LAST_LU_SEEN];
|
||||
|
||||
if (!db_bind_int64(stmt, "$subscriber_id", subscr_id))
|
||||
return -EIO;
|
||||
/* The timestamp will be converted to UTC by SQLite. */
|
||||
if (!db_bind_int64(stmt, "$val", (int64_t)localtime.tv_sec)) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
LOGP(DAUC, LOGL_ERROR,
|
||||
"Cannot update LU timestamp for subscriber ID=%" PRId64 ": SQL error: (%d) %s\n",
|
||||
subscr_id, rc, sqlite3_errmsg(dbc->db));
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* verify execution result */
|
||||
rc = sqlite3_changes(dbc->db);
|
||||
if (!rc) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Cannot update LU timestamp for subscriber ID=%" PRId64
|
||||
": no such subscriber\n", subscr_id);
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
} else if (rc != 1) {
|
||||
LOGP(DAUC, LOGL_ERROR, "Update LU timestamp for subscriber ID=%" PRId64
|
||||
": SQL modified %d rows (expected 1)\n", subscr_id, rc);
|
||||
ret = -EIO;
|
||||
}
|
||||
out:
|
||||
db_remove_reset(stmt);
|
||||
return ret;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Input to this is sql/hlr.sql.
|
||||
# Input to this are sql/*.sql files.
|
||||
#
|
||||
# We want each SQL statement line wrapped in "...\n", and each end (";") to
|
||||
# become a comma:
|
||||
@@ -1,87 +0,0 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/application.h>
|
||||
|
||||
#include "db.h"
|
||||
#include "hlr.h"
|
||||
#include "rand.h"
|
||||
#include "logging.h"
|
||||
|
||||
static struct hlr *g_hlr;
|
||||
|
||||
static int test(const char *imsi, struct db_context *dbc)
|
||||
{
|
||||
struct osmo_auth_vector vec[3];
|
||||
int rc, i;
|
||||
|
||||
/* initialize all vectors with a known token pattern */
|
||||
memset(vec, 0x55, sizeof(vec));
|
||||
for (i = 0; i < ARRAY_SIZE(vec); i++)
|
||||
vec[i].res_len = 0;
|
||||
|
||||
rc = db_get_auc(dbc, imsi, 0, vec, ARRAY_SIZE(vec), NULL, NULL);
|
||||
if (rc <= 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Cannot obtain auth tuples for '%s'\n", imsi);
|
||||
return rc;
|
||||
}
|
||||
LOGP(DMAIN, LOGL_INFO, "Obtained %u tuples for subscriber IMSI %s\n",
|
||||
rc, imsi);
|
||||
|
||||
for (i = 0; i < rc; i++) {
|
||||
struct osmo_auth_vector *v = vec + i;
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Tuple %u, auth_types=0x%x\n", i, v->auth_types);
|
||||
LOGP(DMAIN, LOGL_DEBUG, "RAND=%s\n", osmo_hexdump_nospc(v->rand, sizeof(v->rand)));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "AUTN=%s\n", osmo_hexdump_nospc(v->autn, sizeof(v->autn)));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "CK=%s\n", osmo_hexdump_nospc(v->ck, sizeof(v->ck)));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "IK=%s\n", osmo_hexdump_nospc(v->ik, sizeof(v->ik)));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "RES=%s\n", osmo_hexdump_nospc(v->res, v->res_len));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Kc=%s\n", osmo_hexdump_nospc(v->kc, sizeof(v->kc)));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "SRES=%s\n", osmo_hexdump_nospc(v->sres, sizeof(v->sres)));
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
|
||||
g_hlr = talloc_zero(NULL, struct hlr);
|
||||
|
||||
rc = osmo_init_logging(&hlr_log_info);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error initializing logging\n");
|
||||
exit(1);
|
||||
}
|
||||
LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n");
|
||||
|
||||
rc = rand_init();
|
||||
if (rc < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error initializing random source\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g_hlr->dbc = db_open(NULL, "hlr.db");
|
||||
if (!g_hlr->dbc) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error opening database\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* non-existing subscriber */
|
||||
rc = test("901990123456789", g_hlr->dbc);
|
||||
/* 2G only AUC data (COMP128v1 / MILENAGE) */
|
||||
rc = test("901990000000001", g_hlr->dbc);
|
||||
/* 2G + 3G AUC data (COMP128v1 / MILENAGE) */
|
||||
rc = test("901990000000002", g_hlr->dbc);
|
||||
/* 3G AUC data (MILENAGE) */
|
||||
rc = test("901990000000003", g_hlr->dbc);
|
||||
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Exiting\n");
|
||||
|
||||
db_close(g_hlr->dbc);
|
||||
|
||||
log_fini();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "gsup_server.h"
|
||||
|
||||
struct gsup_route {
|
||||
@@ -60,6 +61,8 @@ int gsup_route_add(struct osmo_gsup_conn *conn, const uint8_t *addr, size_t addr
|
||||
if (!gr)
|
||||
return -ENOMEM;
|
||||
|
||||
LOGP(DMAIN, LOGL_INFO, "Adding GSUP route for %s\n", addr);
|
||||
|
||||
gr->addr = talloc_memdup(gr, addr, addrlen);
|
||||
gr->conn = conn;
|
||||
llist_add_tail(&gr->list, &conn->server->routes);
|
||||
@@ -75,6 +78,8 @@ 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);
|
||||
llist_del(&gr->list);
|
||||
talloc_free(gr);
|
||||
num_deleted++;
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
#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);
|
||||
|
||||
@@ -6,3 +11,7 @@ int gsup_route_add(struct osmo_gsup_conn *conn, const uint8_t *addr, size_t addr
|
||||
|
||||
/* 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);
|
||||
|
||||
45
src/gsup_send.c
Normal file
45
src/gsup_send.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* (C) 2018 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* This is kept separate to be able to override the actual sending functions from unit tests. */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
|
||||
/* Send a msgb to a given address using routing */
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg)
|
||||
{
|
||||
struct osmo_gsup_conn *conn;
|
||||
|
||||
conn = gsup_route_find(gs, addr, addrlen);
|
||||
if (!conn) {
|
||||
DEBUGP(DLGSUP, "Cannot find route for addr %s\n", addr);
|
||||
msgb_free(msg);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return osmo_gsup_conn_send(conn, msg);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/abis/ipa.h>
|
||||
#include <osmocom/abis/ipaccess.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
#include <osmocom/gsm/apn.h>
|
||||
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
@@ -290,7 +292,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)
|
||||
struct llist_head *lu_op_lst, void *priv)
|
||||
{
|
||||
struct osmo_gsup_server *gsups;
|
||||
int rc;
|
||||
@@ -310,6 +312,7 @@ osmo_gsup_server_create(void *ctx, const char *ip_addr, uint16_t tcp_port,
|
||||
goto failed;
|
||||
|
||||
gsups->read_cb = read_cb;
|
||||
gsups->priv = priv;
|
||||
|
||||
rc = ipa_server_link_open(gsups->link);
|
||||
if (rc < 0)
|
||||
@@ -333,3 +336,79 @@ void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups)
|
||||
}
|
||||
talloc_free(gsups);
|
||||
}
|
||||
|
||||
/* Set GSUP message's pdp_infos[0] to a wildcard APN.
|
||||
* Use the provided apn_buf to store the produced APN data. This must remain valid until
|
||||
* osmo_gsup_encode() is done. Return 0 if an entry was added, -ENOMEM if the provided buffer is too
|
||||
* small. */
|
||||
int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup,
|
||||
uint8_t *apn_buf, size_t apn_buf_size)
|
||||
{
|
||||
int l;
|
||||
|
||||
l = osmo_apn_from_str(apn_buf, apn_buf_size, "*");
|
||||
if (l <= 0)
|
||||
return -ENOMEM;
|
||||
|
||||
gsup->pdp_infos[0].apn_enc = apn_buf;
|
||||
gsup->pdp_infos[0].apn_enc_len = l;
|
||||
gsup->pdp_infos[0].have_info = 1;
|
||||
gsup->num_pdp_infos = 1;
|
||||
/* FIXME: use real value: */
|
||||
gsup->pdp_infos[0].context_id = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate a gsup message structure with an Insert Subscriber Data Message.
|
||||
* All required memory buffers for data pointed to by pointers in struct omso_gsup_message
|
||||
* must be allocated by the caller and should have the same lifetime as the gsup parameter.
|
||||
*
|
||||
* \param[out] gsup The gsup message to populate.
|
||||
* \param[in] imsi The subscriber's IMSI.
|
||||
* \param[in] msisdn The subscriber's MSISDN.
|
||||
* \param[out] msisdn_enc A buffer large enough to store the MSISDN in encoded form.
|
||||
* \param[in] msisdn_enc_size Size of the buffer (must be >= OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN).
|
||||
* \param[out] apn_buf A buffer large enough to store an APN (required if cn_domain is OSMO_GSUP_CN_DOMAIN_PS).
|
||||
* \param[in] apn_buf_size Size of APN buffer (must be >= APN_MAXLEN).
|
||||
* \param[in] cn_domain The CN Domain of the subscriber connection.
|
||||
* \returns 0 on success, and negative on error.
|
||||
*/
|
||||
int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, const char *imsi, const char *msisdn,
|
||||
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 len;
|
||||
|
||||
OSMO_ASSERT(gsup);
|
||||
|
||||
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)
|
||||
return -ENOSPC;
|
||||
|
||||
OSMO_ASSERT(msisdn_enc);
|
||||
len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn);
|
||||
if (len < 1) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn);
|
||||
return -ENOSPC;
|
||||
}
|
||||
gsup->msisdn_enc = msisdn_enc;
|
||||
gsup->msisdn_enc_len = len;
|
||||
|
||||
#pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc"
|
||||
|
||||
gsup->cn_domain = cn_domain;
|
||||
if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) {
|
||||
OSMO_ASSERT(apn_buf_size >= APN_MAXLEN);
|
||||
OSMO_ASSERT(apn_buf);
|
||||
/* FIXME: PDP infos - use more fine-grained access control
|
||||
instead of wildcard APN */
|
||||
osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/abis/ipa.h>
|
||||
#include <osmocom/abis/ipaccess.h>
|
||||
#include <osmocom/gsm/gsup.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 */
|
||||
#endif
|
||||
|
||||
struct osmo_gsup_conn;
|
||||
|
||||
@@ -11,6 +16,9 @@ struct osmo_gsup_conn;
|
||||
typedef int (*osmo_gsup_read_cb_t)(struct osmo_gsup_conn *conn, struct msgb *msg);
|
||||
|
||||
struct osmo_gsup_server {
|
||||
/* private data of the application/user */
|
||||
void *priv;
|
||||
|
||||
/* list of osmo_gsup_conn */
|
||||
struct llist_head clients;
|
||||
|
||||
@@ -33,6 +41,10 @@ struct osmo_gsup_conn {
|
||||
struct tlv_parsed ccm;
|
||||
|
||||
unsigned int auc_3g_ind; /*!< IND index used for UMTS AKA SQN */
|
||||
|
||||
/* 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 */
|
||||
};
|
||||
|
||||
|
||||
@@ -44,7 +56,14 @@ 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);
|
||||
struct llist_head *lu_op_lst,
|
||||
void *priv);
|
||||
|
||||
void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups);
|
||||
|
||||
int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup,
|
||||
uint8_t *apn_buf, size_t apn_buf_size);
|
||||
int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, const char *imsi, const char *msisdn,
|
||||
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);
|
||||
|
||||
20
src/gsupclient/Makefile.am
Normal file
20
src/gsupclient/Makefile.am
Normal file
@@ -0,0 +1,20 @@
|
||||
# This is _NOT_ the library release version, it's an API version.
|
||||
# Please read chapter "Library interface versions" of the libtool documentation
|
||||
# before making any modifications: https://www.gnu.org/software/libtool/manual/html_node/Versioning.html
|
||||
LIBVERSION=0:0:0
|
||||
|
||||
AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include \
|
||||
$(TALLOC_CFLAGS) $(LIBOSMOCORE_CFLAGS) $(LIBOSMOABIS_CFLAGS)
|
||||
|
||||
lib_LTLIBRARIES = libosmo-gsup-client.la
|
||||
|
||||
libosmo_gsup_client_la_SOURCES = gsup_client.c
|
||||
|
||||
libosmo_gsup_client_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined
|
||||
libosmo_gsup_client_la_LIBADD = $(TALLOC_LIBS) $(LIBOSMOCORE_LIBS) $(LIBOSMOABIS_LIBS)
|
||||
|
||||
noinst_PROGRAMS = gsup-test-client
|
||||
|
||||
gsup_test_client_SOURCES = gsup_test_client.c
|
||||
gsup_test_client_LDADD = $(TALLOC_LIBS) $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) \
|
||||
libosmo-gsup-client.la
|
||||
402
src/gsupclient/gsup_client.c
Normal file
402
src/gsupclient/gsup_client.c
Normal file
@@ -0,0 +1,402 @@
|
||||
/* Generic Subscriber Update Protocol client */
|
||||
|
||||
/* (C) 2014-2016 by Sysmocom s.f.m.c. GmbH
|
||||
* All Rights Reserved
|
||||
*
|
||||
* Author: Jacob Erlbeck
|
||||
* Author: Neels Hofmeyr
|
||||
*
|
||||
* 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 <osmocom/gsupclient/gsup_client.h>
|
||||
|
||||
#include <osmocom/abis/ipa.h>
|
||||
#include <osmocom/gsm/oap_client.h>
|
||||
#include <osmocom/gsm/protocol/ipaccess.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
static void start_test_procedure(struct osmo_gsup_client *gsupc);
|
||||
|
||||
static void gsup_client_send_ping(struct osmo_gsup_client *gsupc)
|
||||
{
|
||||
struct msgb *msg = osmo_gsup_client_msgb_alloc();
|
||||
|
||||
msg->l2h = msgb_put(msg, 1);
|
||||
msg->l2h[0] = IPAC_MSGT_PING;
|
||||
ipa_msg_push_header(msg, IPAC_PROTO_IPACCESS);
|
||||
ipa_client_conn_send(gsupc->link, msg);
|
||||
}
|
||||
|
||||
static int gsup_client_connect(struct osmo_gsup_client *gsupc)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (gsupc->is_connected)
|
||||
return 0;
|
||||
|
||||
if (osmo_timer_pending(&gsupc->connect_timer)) {
|
||||
LOGP(DLGSUP, LOGL_DEBUG,
|
||||
"GSUP connect: connect timer already running\n");
|
||||
osmo_timer_del(&gsupc->connect_timer);
|
||||
}
|
||||
|
||||
if (osmo_timer_pending(&gsupc->ping_timer)) {
|
||||
LOGP(DLGSUP, LOGL_DEBUG,
|
||||
"GSUP connect: ping timer already running\n");
|
||||
osmo_timer_del(&gsupc->ping_timer);
|
||||
}
|
||||
|
||||
if (ipa_client_conn_clear_queue(gsupc->link) > 0)
|
||||
LOGP(DLGSUP, LOGL_DEBUG, "GSUP connect: discarded stored messages\n");
|
||||
|
||||
rc = ipa_client_conn_open(gsupc->link);
|
||||
|
||||
if (rc >= 0) {
|
||||
LOGP(DLGSUP, LOGL_NOTICE, "GSUP connecting to %s:%d\n",
|
||||
gsupc->link->addr, gsupc->link->port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOGP(DLGSUP, LOGL_ERROR, "GSUP failed to connect to %s:%d: %s\n",
|
||||
gsupc->link->addr, gsupc->link->port, strerror(-rc));
|
||||
|
||||
if (rc == -EBADF || rc == -ENOTSOCK || rc == -EAFNOSUPPORT ||
|
||||
rc == -EINVAL)
|
||||
return rc;
|
||||
|
||||
osmo_timer_schedule(&gsupc->connect_timer,
|
||||
OSMO_GSUP_CLIENT_RECONNECT_INTERVAL, 0);
|
||||
|
||||
LOGP(DLGSUP, LOGL_INFO, "Scheduled timer to retry GSUP connect to %s:%d\n",
|
||||
gsupc->link->addr, gsupc->link->port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void connect_timer_cb(void *gsupc_)
|
||||
{
|
||||
struct osmo_gsup_client *gsupc = gsupc_;
|
||||
|
||||
if (gsupc->is_connected)
|
||||
return;
|
||||
|
||||
gsup_client_connect(gsupc);
|
||||
}
|
||||
|
||||
static void client_send(struct osmo_gsup_client *gsupc, int proto_ext,
|
||||
struct msgb *msg_tx)
|
||||
{
|
||||
ipa_prepend_header_ext(msg_tx, proto_ext);
|
||||
ipa_msg_push_header(msg_tx, IPAC_PROTO_OSMO);
|
||||
ipa_client_conn_send(gsupc->link, msg_tx);
|
||||
/* msg_tx is now queued and will be freed. */
|
||||
}
|
||||
|
||||
static void gsup_client_oap_register(struct osmo_gsup_client *gsupc)
|
||||
{
|
||||
struct msgb *msg_tx;
|
||||
int rc;
|
||||
rc = osmo_oap_client_register(&gsupc->oap_state, &msg_tx);
|
||||
|
||||
if ((rc < 0) || (!msg_tx)) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "GSUP OAP set up, but cannot register.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
client_send(gsupc, IPAC_PROTO_EXT_OAP, msg_tx);
|
||||
}
|
||||
|
||||
static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
|
||||
{
|
||||
struct osmo_gsup_client *gsupc = link->data;
|
||||
|
||||
LOGP(DLGSUP, LOGL_INFO, "GSUP link to %s:%d %s\n",
|
||||
link->addr, link->port, up ? "UP" : "DOWN");
|
||||
|
||||
gsupc->is_connected = up;
|
||||
|
||||
if (up) {
|
||||
start_test_procedure(gsupc);
|
||||
|
||||
if (gsupc->oap_state.state == OSMO_OAP_INITIALIZED)
|
||||
gsup_client_oap_register(gsupc);
|
||||
|
||||
osmo_timer_del(&gsupc->connect_timer);
|
||||
} else {
|
||||
osmo_timer_del(&gsupc->ping_timer);
|
||||
|
||||
osmo_timer_schedule(&gsupc->connect_timer,
|
||||
OSMO_GSUP_CLIENT_RECONNECT_INTERVAL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int gsup_client_oap_handle(struct osmo_gsup_client *gsupc, struct msgb *msg_rx)
|
||||
{
|
||||
int rc;
|
||||
struct msgb *msg_tx;
|
||||
|
||||
/* If the oap_state is disabled, this will reject the messages. */
|
||||
rc = osmo_oap_client_handle(&gsupc->oap_state, msg_rx, &msg_tx);
|
||||
msgb_free(msg_rx);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
if (msg_tx)
|
||||
client_send(gsupc, IPAC_PROTO_EXT_OAP, msg_tx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gsup_client_read_cb(struct ipa_client_conn *link, struct msgb *msg)
|
||||
{
|
||||
struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
|
||||
struct ipaccess_head_ext *he = (struct ipaccess_head_ext *) msgb_l2(msg);
|
||||
struct osmo_gsup_client *gsupc = (struct osmo_gsup_client *)link->data;
|
||||
int rc;
|
||||
|
||||
OSMO_ASSERT(gsupc->unit_name);
|
||||
|
||||
msg->l2h = &hh->data[0];
|
||||
|
||||
rc = ipaccess_bts_handle_ccm(link, gsupc->ipa_dev, msg);
|
||||
|
||||
if (rc < 0) {
|
||||
LOGP(DLGSUP, LOGL_NOTICE,
|
||||
"GSUP received an invalid IPA/CCM message from %s:%d\n",
|
||||
link->addr, link->port);
|
||||
/* Link has been closed */
|
||||
gsupc->is_connected = 0;
|
||||
msgb_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc == 1) {
|
||||
uint8_t msg_type = *(msg->l2h);
|
||||
/* CCM message */
|
||||
if (msg_type == IPAC_MSGT_PONG) {
|
||||
LOGP(DLGSUP, LOGL_DEBUG, "GSUP receiving PONG\n");
|
||||
gsupc->got_ipa_pong = 1;
|
||||
}
|
||||
|
||||
msgb_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (hh->proto != IPAC_PROTO_OSMO)
|
||||
goto invalid;
|
||||
|
||||
if (!he || msgb_l2len(msg) < sizeof(*he))
|
||||
goto invalid;
|
||||
|
||||
msg->l2h = &he->data[0];
|
||||
|
||||
if (he->proto == IPAC_PROTO_EXT_GSUP) {
|
||||
OSMO_ASSERT(gsupc->read_cb != NULL);
|
||||
gsupc->read_cb(gsupc, msg);
|
||||
/* expecting read_cb() to free msg */
|
||||
} else if (he->proto == IPAC_PROTO_EXT_OAP) {
|
||||
return gsup_client_oap_handle(gsupc, msg);
|
||||
/* gsup_client_oap_handle frees msg */
|
||||
} else
|
||||
goto invalid;
|
||||
|
||||
return 0;
|
||||
|
||||
invalid:
|
||||
LOGP(DLGSUP, LOGL_NOTICE,
|
||||
"GSUP received an invalid IPA message from %s:%d, size = %d\n",
|
||||
link->addr, link->port, msgb_length(msg));
|
||||
|
||||
msgb_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void ping_timer_cb(void *gsupc_)
|
||||
{
|
||||
struct osmo_gsup_client *gsupc = gsupc_;
|
||||
|
||||
LOGP(DLGSUP, LOGL_INFO, "GSUP ping callback (%s, %s PONG)\n",
|
||||
gsupc->is_connected ? "connected" : "not connected",
|
||||
gsupc->got_ipa_pong ? "got" : "didn't get");
|
||||
|
||||
if (gsupc->got_ipa_pong) {
|
||||
start_test_procedure(gsupc);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGP(DLGSUP, LOGL_NOTICE, "GSUP ping timed out, reconnecting\n");
|
||||
ipa_client_conn_close(gsupc->link);
|
||||
gsupc->is_connected = 0;
|
||||
|
||||
gsup_client_connect(gsupc);
|
||||
}
|
||||
|
||||
static void start_test_procedure(struct osmo_gsup_client *gsupc)
|
||||
{
|
||||
osmo_timer_setup(&gsupc->ping_timer, ping_timer_cb, gsupc);
|
||||
|
||||
gsupc->got_ipa_pong = 0;
|
||||
osmo_timer_schedule(&gsupc->ping_timer, OSMO_GSUP_CLIENT_PING_INTERVAL, 0);
|
||||
LOGP(DLGSUP, LOGL_DEBUG, "GSUP sending PING\n");
|
||||
gsup_client_send_ping(gsupc);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Create a gsup client connecting to the specified IP address and TCP port.
|
||||
* 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.
|
||||
*/
|
||||
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 *gsupc;
|
||||
int rc;
|
||||
|
||||
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;
|
||||
|
||||
/* a NULL oapc_config will mark oap_state disabled. */
|
||||
rc = osmo_oap_client_init(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);
|
||||
if (!gsupc->link)
|
||||
goto failed;
|
||||
|
||||
osmo_timer_setup(&gsupc->connect_timer, connect_timer_cb, gsupc);
|
||||
|
||||
rc = gsup_client_connect(gsupc);
|
||||
|
||||
if (rc < 0)
|
||||
goto failed;
|
||||
|
||||
gsupc->read_cb = read_cb;
|
||||
|
||||
return gsupc;
|
||||
|
||||
failed:
|
||||
osmo_gsup_client_destroy(gsupc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like osmo_gsup_client_create2() except it expects a unit name instead
|
||||
* of a full-blown ipacess_unit as the client-side identifier.
|
||||
*/
|
||||
struct osmo_gsup_client *osmo_gsup_client_create(void *talloc_ctx,
|
||||
const char *unit_name,
|
||||
const char *ip_addr,
|
||||
unsigned int tcp_port,
|
||||
osmo_gsup_client_read_cb_t read_cb,
|
||||
struct osmo_oap_client_config *oapc_config)
|
||||
{
|
||||
struct ipaccess_unit *ipa_dev = talloc_zero(talloc_ctx, struct ipaccess_unit);
|
||||
ipa_dev->unit_name = talloc_strdup(ipa_dev, unit_name);
|
||||
return osmo_gsup_client_create2(talloc_ctx, ipa_dev, ip_addr, tcp_port, read_cb, oapc_config);
|
||||
}
|
||||
|
||||
void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc)
|
||||
{
|
||||
osmo_timer_del(&gsupc->connect_timer);
|
||||
osmo_timer_del(&gsupc->ping_timer);
|
||||
|
||||
if (gsupc->link) {
|
||||
ipa_client_conn_close(gsupc->link);
|
||||
ipa_client_conn_destroy(gsupc->link);
|
||||
gsupc->link = NULL;
|
||||
}
|
||||
talloc_free(gsupc);
|
||||
}
|
||||
|
||||
int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg)
|
||||
{
|
||||
if (!gsupc || !gsupc->is_connected) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "GSUP not connected, unable to send %s\n", msgb_hexdump(msg));
|
||||
msgb_free(msg);
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
client_send(gsupc, IPAC_PROTO_EXT_GSUP, msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Encode and send a GSUP message.
|
||||
* \param[in] gsupc GSUP client.
|
||||
* \param[in] gsup_msg GSUP message to be sent.
|
||||
* \returns 0 in case of success, negative on error.
|
||||
*/
|
||||
int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
|
||||
const struct osmo_gsup_message *gsup_msg)
|
||||
{
|
||||
struct msgb *gsup_msgb;
|
||||
int rc;
|
||||
|
||||
gsup_msgb = osmo_gsup_client_msgb_alloc();
|
||||
if (!gsup_msgb) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "Couldn't allocate GSUP message\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = osmo_gsup_encode(gsup_msgb, gsup_msg);
|
||||
if (rc) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "Couldn't encode GSUP message\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
rc = osmo_gsup_client_send(gsupc, gsup_msgb);
|
||||
if (rc) {
|
||||
LOGP(DLGSUP, LOGL_ERROR, "Couldn't send GSUP message\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
talloc_free(gsup_msgb);
|
||||
return rc;
|
||||
}
|
||||
|
||||
struct msgb *osmo_gsup_client_msgb_alloc(void)
|
||||
{
|
||||
return msgb_alloc_headroom(4000, 64, __func__);
|
||||
}
|
||||
321
src/gsupclient/gsup_test_client.c
Normal file
321
src/gsupclient/gsup_test_client.c
Normal file
@@ -0,0 +1,321 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
#include <osmocom/gsupclient/gsup_client.h>
|
||||
|
||||
static struct osmo_gsup_client *g_gc;
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* IMSI Operation
|
||||
***********************************************************************/
|
||||
static LLIST_HEAD(g_imsi_ops);
|
||||
|
||||
struct imsi_op_stats {
|
||||
uint32_t num_alloc;
|
||||
uint32_t num_released;
|
||||
uint32_t num_rx_success;
|
||||
uint32_t num_rx_error;
|
||||
uint32_t num_timeout;
|
||||
};
|
||||
|
||||
enum imsi_op_type {
|
||||
IMSI_OP_SAI,
|
||||
IMSI_OP_LU,
|
||||
IMSI_OP_ISD,
|
||||
_NUM_IMSI_OP
|
||||
};
|
||||
|
||||
static const struct value_string imsi_op_names[] = {
|
||||
{ IMSI_OP_SAI, "SAI" },
|
||||
{ IMSI_OP_LU, "LU" },
|
||||
{ IMSI_OP_ISD, "ISD" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static struct imsi_op_stats imsi_op_stats[_NUM_IMSI_OP];
|
||||
|
||||
struct imsi_op {
|
||||
struct llist_head list;
|
||||
char imsi[17];
|
||||
enum imsi_op_type type;
|
||||
struct osmo_timer_list timer;
|
||||
};
|
||||
|
||||
static struct imsi_op *imsi_op_find(const char *imsi,
|
||||
enum imsi_op_type type)
|
||||
{
|
||||
struct imsi_op *io;
|
||||
|
||||
llist_for_each_entry(io, &g_imsi_ops, list) {
|
||||
if (!strcmp(io->imsi, imsi) && io->type == type)
|
||||
return io;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void imsi_op_timer_cb(void *data);
|
||||
|
||||
static struct imsi_op *imsi_op_alloc(void *ctx, const char *imsi,
|
||||
enum imsi_op_type type)
|
||||
{
|
||||
struct imsi_op *io;
|
||||
|
||||
if (imsi_op_find(imsi, type))
|
||||
return NULL;
|
||||
|
||||
io = talloc_zero(ctx, struct imsi_op);
|
||||
OSMO_STRLCPY_ARRAY(io->imsi, imsi);
|
||||
io->type = type;
|
||||
osmo_timer_setup(&io->timer, imsi_op_timer_cb, io);
|
||||
llist_add(&io->list, &g_imsi_ops);
|
||||
imsi_op_stats[type].num_alloc++;
|
||||
|
||||
return io;
|
||||
}
|
||||
|
||||
static void imsi_op_release(struct imsi_op *io)
|
||||
{
|
||||
osmo_timer_del(&io->timer);
|
||||
llist_del(&io->list);
|
||||
imsi_op_stats[io->type].num_released++;
|
||||
talloc_free(io);
|
||||
}
|
||||
|
||||
static void imsi_op_timer_cb(void *data)
|
||||
{
|
||||
struct imsi_op *io = data;
|
||||
printf("%s: Timer expiration\n", io->imsi);
|
||||
imsi_op_stats[io->type].num_timeout++;
|
||||
imsi_op_release(io);
|
||||
}
|
||||
|
||||
/* allocate + generate + send Send-Auth-Info */
|
||||
static int req_auth_info(const char *imsi)
|
||||
{
|
||||
struct imsi_op *io = imsi_op_alloc(g_gc, imsi, IMSI_OP_SAI);
|
||||
struct osmo_gsup_message gsup = {0};
|
||||
struct msgb *msg = msgb_alloc_headroom(1200, 200, __func__);
|
||||
int rc;
|
||||
|
||||
OSMO_STRLCPY_ARRAY(gsup.imsi, io->imsi);
|
||||
gsup.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST;
|
||||
|
||||
rc = osmo_gsup_encode(msg, &gsup);
|
||||
if (rc < 0) {
|
||||
printf("%s: encoding failure (%s)\n", imsi, strerror(-rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
return osmo_gsup_client_send(g_gc, msg);
|
||||
}
|
||||
|
||||
/* allocate + generate + send Send-Auth-Info */
|
||||
static int req_loc_upd(const char *imsi)
|
||||
{
|
||||
struct imsi_op *io = imsi_op_alloc(g_gc, imsi, IMSI_OP_LU);
|
||||
struct osmo_gsup_message gsup = {0};
|
||||
struct msgb *msg = msgb_alloc_headroom(1200, 200, __func__);
|
||||
int rc;
|
||||
|
||||
OSMO_STRLCPY_ARRAY(gsup.imsi, io->imsi);
|
||||
gsup.message_type = OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST;
|
||||
|
||||
rc = osmo_gsup_encode(msg, &gsup);
|
||||
if (rc < 0) {
|
||||
printf("%s: encoding failure (%s)\n", imsi, strerror(-rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
return osmo_gsup_client_send(g_gc, msg);
|
||||
}
|
||||
|
||||
static int resp_isd(struct imsi_op *io)
|
||||
{
|
||||
struct osmo_gsup_message gsup = {0};
|
||||
struct msgb *msg = msgb_alloc_headroom(1200, 200, __func__);
|
||||
int rc;
|
||||
|
||||
OSMO_STRLCPY_ARRAY(gsup.imsi, io->imsi);
|
||||
gsup.message_type = OSMO_GSUP_MSGT_INSERT_DATA_RESULT;
|
||||
|
||||
rc = osmo_gsup_encode(msg, &gsup);
|
||||
if (rc < 0) {
|
||||
printf("%s: encoding failure (%s)\n", io->imsi, strerror(-rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
imsi_op_release(io);
|
||||
|
||||
return osmo_gsup_client_send(g_gc, msg);
|
||||
}
|
||||
|
||||
/* receive an incoming GSUP message */
|
||||
static void imsi_op_rx_gsup(struct imsi_op *io, const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
int is_error = 0, rc;
|
||||
|
||||
if (OSMO_GSUP_IS_MSGT_ERROR(gsup->message_type)) {
|
||||
imsi_op_stats[io->type].num_rx_error++;
|
||||
is_error = 1;
|
||||
} else
|
||||
imsi_op_stats[io->type].num_rx_success++;
|
||||
|
||||
switch (io->type) {
|
||||
case IMSI_OP_SAI:
|
||||
printf("%s; SAI Response%s\n", io->imsi, is_error ? ": ERROR" : "");
|
||||
/* now that we have auth tuples, request LU */
|
||||
rc = req_loc_upd(io->imsi);
|
||||
if (rc < 0)
|
||||
printf("Failed to request Location Update for %s\n", io->imsi);
|
||||
imsi_op_release(io);
|
||||
break;
|
||||
case IMSI_OP_LU:
|
||||
printf("%s; LU Response%s\n", io->imsi, is_error ? ": ERROR" : "");
|
||||
imsi_op_release(io);
|
||||
break;
|
||||
case IMSI_OP_ISD:
|
||||
printf("%s; ISD Request%s\n", io->imsi, is_error ? ": ERROR" : "");
|
||||
rc = resp_isd(io);
|
||||
if (rc < 0)
|
||||
printf("Failed to insert subscriber data for %s\n", io->imsi);
|
||||
break;
|
||||
default:
|
||||
printf("%s: Unknown\n", io->imsi);
|
||||
imsi_op_release(io);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int op_type_by_gsup_msgt(enum osmo_gsup_message_type msg_type)
|
||||
{
|
||||
switch (msg_type) {
|
||||
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT:
|
||||
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR:
|
||||
return IMSI_OP_SAI;
|
||||
case OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT:
|
||||
case OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR:
|
||||
return IMSI_OP_LU;
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_REQUEST:
|
||||
return IMSI_OP_ISD;
|
||||
default:
|
||||
printf("Unknown GSUP msg_type %u\n", msg_type);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg)
|
||||
{
|
||||
struct osmo_gsup_message gsup_msg = {0};
|
||||
struct imsi_op *io = NULL;
|
||||
int rc;
|
||||
|
||||
DEBUGP(DLGSUP, "Rx GSUP %s\n", msgb_hexdump(msg));
|
||||
|
||||
rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup_msg);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
if (!gsup_msg.imsi[0])
|
||||
return -1;
|
||||
|
||||
rc = op_type_by_gsup_msgt(gsup_msg.message_type);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
switch (rc) {
|
||||
case IMSI_OP_SAI:
|
||||
case IMSI_OP_LU:
|
||||
io = imsi_op_find(gsup_msg.imsi, rc);
|
||||
break;
|
||||
case IMSI_OP_ISD:
|
||||
/* ISD is an inbound transaction */
|
||||
io = imsi_op_alloc(g_gc, gsup_msg.imsi, IMSI_OP_ISD);
|
||||
break;
|
||||
}
|
||||
if (!io)
|
||||
return -1;
|
||||
|
||||
imsi_op_rx_gsup(io, &gsup_msg);
|
||||
msgb_free(msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_report(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(imsi_op_stats); i++) {
|
||||
struct imsi_op_stats *st = &imsi_op_stats[i];
|
||||
const char *name = get_value_string(imsi_op_names, i);
|
||||
printf("%s: %u alloc, %u released, %u success, %u error , %u tout\n",
|
||||
name, st->num_alloc, st->num_released, st->num_rx_success,
|
||||
st->num_rx_error, st->num_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
static void sig_cb(int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
print_report();
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* default categories */
|
||||
static struct log_info_cat default_categories[] = {
|
||||
};
|
||||
|
||||
static const struct log_info gsup_test_client_log_info = {
|
||||
.cat = default_categories,
|
||||
.num_cat = ARRAY_SIZE(default_categories),
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned long long i;
|
||||
char *server_host = "127.0.0.1";
|
||||
uint16_t server_port = OSMO_GSUP_PORT;
|
||||
void *ctx = talloc_named_const(NULL, 0, "gsup_test_client");
|
||||
|
||||
osmo_init_logging2(ctx, &gsup_test_client_log_info);
|
||||
|
||||
g_gc = osmo_gsup_client_create(ctx, "GSUPTEST", server_host, server_port,
|
||||
gsupc_read_cb, NULL);
|
||||
|
||||
|
||||
signal(SIGINT, sig_cb);
|
||||
|
||||
for (i = 0; i < 10000; i++) {
|
||||
unsigned long long imsi = 901790000000000 + i;
|
||||
char imsi_buf[17] = { 0 };
|
||||
int rc;
|
||||
|
||||
snprintf(imsi_buf, sizeof(imsi_buf), "%015llu", imsi);
|
||||
rc = req_auth_info(imsi_buf);
|
||||
if (rc < 0)
|
||||
printf("Failed to request Auth Info for %s\n", imsi_buf);
|
||||
|
||||
osmo_select_main(0);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
osmo_select_main(0);
|
||||
}
|
||||
|
||||
print_report();
|
||||
exit(0);
|
||||
}
|
||||
304
src/hlr.c
304
src/hlr.c
@@ -26,13 +26,13 @@
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsm/apn.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
#include <osmocom/vty/vty.h>
|
||||
#include <osmocom/vty/command.h>
|
||||
#include <osmocom/vty/telnet_interface.h>
|
||||
#include <osmocom/vty/ports.h>
|
||||
#include <osmocom/ctrl/control_vty.h>
|
||||
#include <osmocom/gsm/apn.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
|
||||
#include "db.h"
|
||||
#include "hlr.h"
|
||||
@@ -43,8 +43,108 @@
|
||||
#include "rand.h"
|
||||
#include "luop.h"
|
||||
#include "hlr_vty.h"
|
||||
#include "hlr_ussd.h"
|
||||
|
||||
static struct hlr *g_hlr;
|
||||
struct hlr *g_hlr;
|
||||
static int quit = 0;
|
||||
|
||||
/* Trigger 'Insert Subscriber Data' messages to all connected GSUP clients.
|
||||
*
|
||||
* \param[in] subscr A subscriber we have new data to send for.
|
||||
*/
|
||||
void
|
||||
osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
|
||||
{
|
||||
struct osmo_gsup_conn *co;
|
||||
|
||||
if (g_hlr->gs == NULL) {
|
||||
LOGP(DLGSUP, LOGL_DEBUG,
|
||||
"IMSI %s: NOT Notifying peers of subscriber data change,"
|
||||
" there is no GSUP server\n",
|
||||
subscr->imsi);
|
||||
return;
|
||||
}
|
||||
|
||||
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];
|
||||
uint8_t apn[APN_MAXLEN];
|
||||
struct msgb *msg_out;
|
||||
uint8_t *peer;
|
||||
int peer_len;
|
||||
size_t peer_strlen;
|
||||
const char *peer_compare;
|
||||
enum osmo_gsup_cn_domain cn_domain;
|
||||
|
||||
if (co->supports_ps) {
|
||||
cn_domain = OSMO_GSUP_CN_DOMAIN_PS;
|
||||
peer_compare = subscr->sgsn_number;
|
||||
} else if (co->supports_cs) {
|
||||
cn_domain = OSMO_GSUP_CN_DOMAIN_CS;
|
||||
peer_compare = subscr->vlr_number;
|
||||
} else {
|
||||
/* We have not yet received a location update from this GSUP client.*/
|
||||
continue;
|
||||
}
|
||||
|
||||
peer_len = osmo_gsup_conn_ccm_get(co, &peer, IPAC_IDTAG_SERNR);
|
||||
if (peer_len < 0) {
|
||||
LOGP(DLGSUP, LOGL_ERROR,
|
||||
"IMSI='%s': cannot get peer name for connection %s:%u\n", subscr->imsi,
|
||||
co && co->conn && co->conn->server? co->conn->server->addr : "unset",
|
||||
co && co->conn && co->conn->server? co->conn->server->port : 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
peer_strlen = strnlen((const char*)peer, peer_len);
|
||||
if (strlen(peer_compare) != peer_strlen || strncmp(peer_compare, (const char *)peer, peer_len)) {
|
||||
/* Mismatch. The subscriber is not subscribed with this GSUP client. */
|
||||
/* I hope peer is always nul terminated... */
|
||||
if (peer_strlen < peer_len)
|
||||
LOGP(DLGSUP, LOGL_DEBUG,
|
||||
"IMSI %s: subscriber change: skipping %s peer %s\n",
|
||||
subscr->imsi, cn_domain == OSMO_GSUP_CN_DOMAIN_PS ? "PS" : "CS",
|
||||
osmo_quote_str((char*)peer, -1));
|
||||
continue;
|
||||
}
|
||||
|
||||
LOGP(DLGSUP, LOGL_DEBUG,
|
||||
"IMSI %s: subscriber change: notifying %s peer %s\n",
|
||||
subscr->imsi, cn_domain == OSMO_GSUP_CN_DOMAIN_PS ? "PS" : "CS",
|
||||
osmo_quote_str(peer_compare, -1));
|
||||
|
||||
if (osmo_gsup_create_insert_subscriber_data_msg(&gsup, subscr->imsi, subscr->msisdn, msisdn_enc,
|
||||
sizeof(msisdn_enc), apn, sizeof(apn), cn_domain) != 0) {
|
||||
LOGP(DLGSUP, LOGL_ERROR,
|
||||
"IMSI='%s': Cannot notify GSUP client; could not create gsup message "
|
||||
"for %s:%u\n", subscr->imsi,
|
||||
co && co->conn && co->conn->server? co->conn->server->addr : "unset",
|
||||
co && co->conn && co->conn->server? co->conn->server->port : 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Send ISD to MSC/SGSN */
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ISD UPDATE");
|
||||
if (msg_out == NULL) {
|
||||
LOGP(DLGSUP, LOGL_ERROR,
|
||||
"IMSI='%s': Cannot notify GSUP client; could not allocate msg buffer "
|
||||
"for %s:%u\n", subscr->imsi,
|
||||
co && co->conn && co->conn->server? co->conn->server->addr : "unset",
|
||||
co && co->conn && co->conn->server? co->conn->server->port : 0);
|
||||
continue;
|
||||
}
|
||||
osmo_gsup_encode(msg_out, &gsup);
|
||||
|
||||
if (osmo_gsup_addr_send(g_hlr->gs, peer, peer_len, msg_out) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR,
|
||||
"IMSI='%s': Cannot notify GSUP client; send operation failed "
|
||||
"for %s:%u\n", subscr->imsi,
|
||||
co && co->conn && co->conn->server? co->conn->server->addr : "unset",
|
||||
co && co->conn && co->conn->server? co->conn->server->port : 0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Send Auth Info handling
|
||||
@@ -67,12 +167,27 @@ static int rx_send_auth_info(struct osmo_gsup_conn *conn,
|
||||
gsup_out.auth_vectors,
|
||||
ARRAY_SIZE(gsup_out.auth_vectors),
|
||||
gsup->rand, gsup->auts);
|
||||
if (rc < 0) {
|
||||
if (rc <= 0) {
|
||||
gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR;
|
||||
gsup_out.cause = GMM_CAUSE_NET_FAIL;
|
||||
} else if (rc == 0) {
|
||||
gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR;
|
||||
gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN;
|
||||
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;
|
||||
case -ENOENT:
|
||||
LOGP(DAUC, LOGL_NOTICE, "%s: IMSI not known\n", gsup->imsi);
|
||||
gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN;
|
||||
break;
|
||||
default:
|
||||
LOGP(DAUC, LOGL_ERROR, "%s: failure to look up IMSI in db\n", gsup->imsi);
|
||||
gsup_out.cause = GMM_CAUSE_NET_FAIL;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT;
|
||||
gsup_out.num_auth_vectors = rc;
|
||||
@@ -147,16 +262,31 @@ void lu_op_rx_gsup(struct lu_operation *luop,
|
||||
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);
|
||||
|
||||
if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS)
|
||||
switch (gsup->cn_domain) {
|
||||
case OSMO_GSUP_CN_DOMAIN_CS:
|
||||
conn->supports_cs = true;
|
||||
break;
|
||||
default:
|
||||
/* The client didn't send a CN_DOMAIN IE; assume packet-switched in
|
||||
* accordance with the GSUP spec in osmo-hlr's user manual (section
|
||||
* 11.6.15 "CN Domain" says "if no CN Domain IE is present within
|
||||
* 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 */
|
||||
@@ -164,7 +294,7 @@ static int rx_upd_loc_req(struct osmo_gsup_conn *conn,
|
||||
/* 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 */
|
||||
strcpy(luop->subscr.imsi, gsup->imsi);
|
||||
osmo_strlcpy(luop->subscr.imsi, gsup->imsi, sizeof(luop->subscr.imsi));
|
||||
lu_op_tx_error(luop, GMM_CAUSE_IMSI_UNKNOWN);
|
||||
return 0;
|
||||
}
|
||||
@@ -191,13 +321,21 @@ static int rx_upd_loc_req(struct osmo_gsup_conn *conn,
|
||||
lu_op_tx_cancel_old(luop);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -223,9 +361,9 @@ static int rx_purge_ms_req(struct osmo_gsup_conn *conn,
|
||||
/* Perform the actual update of the DB */
|
||||
rc = db_subscr_purge(g_hlr->dbc, gsup->imsi, true, is_ps);
|
||||
|
||||
if (rc == 1)
|
||||
if (rc == 0)
|
||||
gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT;
|
||||
else if (rc == 0) {
|
||||
else if (rc == -ENOENT) {
|
||||
gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR;
|
||||
gsup_reply.cause = GMM_CAUSE_IMSI_UNKNOWN;
|
||||
} else {
|
||||
@@ -238,6 +376,61 @@ static int rx_purge_ms_req(struct osmo_gsup_conn *conn,
|
||||
return osmo_gsup_conn_send(conn, msg_out);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int type_err = osmo_gsup_get_err_msg_type(type_in);
|
||||
struct osmo_gsup_message gsup_reply = {0};
|
||||
struct msgb *msg_out;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static int rx_check_imei_req(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
struct osmo_gsup_message gsup_reply = {0};
|
||||
struct msgb *msg_out;
|
||||
char imei[GSM23003_IMEI_NUM_DIGITS+1] = {0};
|
||||
|
||||
/* Encoded IMEI length check */
|
||||
if (!gsup->imei_enc || gsup->imei_enc_len < 1 || gsup->imei_enc[0] >= sizeof(imei)) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "%s: wrong encoded IMEI length\n", gsup->imsi);
|
||||
gsup_send_err_reply(conn, gsup->imsi, gsup->message_type, GMM_CAUSE_INV_MAND_INFO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Decode IMEI */
|
||||
if (gsm48_decode_bcd_number(imei, sizeof(imei), gsup->imei_enc, 0) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "%s: failed to decode IMEI\n", gsup->imsi);
|
||||
gsup_send_err_reply(conn, gsup->imsi, gsup->message_type, GMM_CAUSE_INV_MAND_INFO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Only print the IMEI for now, it's planned to store it here (OS#2541) */
|
||||
LOGP(DMAIN, LOGL_INFO, "%s: has IMEI: %s\n", gsup->imsi, imei);
|
||||
|
||||
/* Accept all IMEIs */
|
||||
gsup_reply.imei_result = OSMO_GSUP_IMEI_RESULT_ACK;
|
||||
gsup_reply.message_type = OSMO_GSUP_MSGT_CHECK_IMEI_RESULT;
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP Check_IMEI response");
|
||||
memcpy(gsup_reply.imsi, gsup->imsi, sizeof(gsup_reply.imsi));
|
||||
osmo_gsup_encode(msg_out, &gsup_reply);
|
||||
return osmo_gsup_conn_send(conn, msg_out);
|
||||
}
|
||||
|
||||
static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
{
|
||||
static struct osmo_gsup_message gsup;
|
||||
@@ -249,6 +442,11 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
switch (gsup.message_type) {
|
||||
/* requests sent to us */
|
||||
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
|
||||
@@ -269,6 +467,13 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
LOGP(DMAIN, LOGL_ERROR, "Deleting subscriber data for IMSI %s\n",
|
||||
gsup.imsi);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
|
||||
case OSMO_GSUP_MSGT_PROC_SS_RESULT:
|
||||
rx_proc_ss_req(conn, &gsup);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_PROC_SS_ERROR:
|
||||
rx_proc_ss_error(conn, &gsup);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_ERROR:
|
||||
case OSMO_GSUP_MSGT_INSERT_DATA_RESULT:
|
||||
case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR:
|
||||
@@ -286,6 +491,9 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
|
||||
lu_op_rx_gsup(luop, &gsup);
|
||||
}
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_CHECK_IMEI_REQUEST:
|
||||
rx_check_imei_req(conn, &gsup);
|
||||
break;
|
||||
default:
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
|
||||
osmo_gsup_message_type_name(gsup.message_type));
|
||||
@@ -310,6 +518,7 @@ static void print_help()
|
||||
printf(" -s --disable-color Do not print ANSI colors in the log\n");
|
||||
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(" -V --version Print the version of OsmoHLR.\n");
|
||||
}
|
||||
|
||||
@@ -317,10 +526,12 @@ static struct {
|
||||
const char *config_file;
|
||||
const char *db_file;
|
||||
bool daemonize;
|
||||
bool db_upgrade;
|
||||
} cmdline_opts = {
|
||||
.config_file = "osmo-hlr.cfg",
|
||||
.db_file = "hlr.db",
|
||||
.daemonize = false,
|
||||
.db_upgrade = false,
|
||||
};
|
||||
|
||||
static void handle_options(int argc, char **argv)
|
||||
@@ -336,11 +547,12 @@ static void handle_options(int argc, char **argv)
|
||||
{"disable-color", 0, 0, 's'},
|
||||
{"log-level", 1, 0, 'e'},
|
||||
{"timestamp", 0, 0, 'T'},
|
||||
{"db-upgrade", 0, 0, 'U' },
|
||||
{"version", 0, 0, 'V' },
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "hc:l:d:Dse:TV",
|
||||
c = getopt_long(argc, argv, "hc:l:d:Dse:TUV",
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
@@ -371,6 +583,9 @@ static void handle_options(int argc, char **argv)
|
||||
case 'T':
|
||||
log_set_print_timestamp(osmo_stderr_target, 1);
|
||||
break;
|
||||
case 'U':
|
||||
cmdline_opts.db_upgrade = true;
|
||||
break;
|
||||
case 'V':
|
||||
print_version(1);
|
||||
exit(0);
|
||||
@@ -391,11 +606,7 @@ static void signal_hdlr(int signal)
|
||||
switch (signal) {
|
||||
case SIGINT:
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Terminating due to SIGINT\n");
|
||||
osmo_gsup_server_destroy(g_hlr->gs);
|
||||
db_close(g_hlr->dbc);
|
||||
log_fini();
|
||||
talloc_report_full(hlr_ctx, stderr);
|
||||
exit(0);
|
||||
quit++;
|
||||
break;
|
||||
case SIGUSR1:
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Talloc Report due to SIGUSR1\n");
|
||||
@@ -422,12 +633,23 @@ int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Track the use of talloc NULL memory contexts */
|
||||
talloc_enable_null_tracking();
|
||||
|
||||
hlr_ctx = talloc_named_const(NULL, 1, "OsmoHLR");
|
||||
msgb_talloc_ctx_init(hlr_ctx, 0);
|
||||
vty_info.tall_ctx = hlr_ctx;
|
||||
|
||||
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);
|
||||
|
||||
rc = osmo_init_logging(&hlr_log_info);
|
||||
/* Init default (call independent) SS session guard timeout value */
|
||||
g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT;
|
||||
|
||||
rc = osmo_init_logging2(hlr_ctx, &hlr_log_info);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error initializing logging\n");
|
||||
exit(1);
|
||||
@@ -436,7 +658,7 @@ int main(int argc, char **argv)
|
||||
vty_init(&vty_info);
|
||||
ctrl_vty_init(hlr_ctx);
|
||||
handle_options(argc, argv);
|
||||
hlr_vty_init(g_hlr, &hlr_log_info);
|
||||
hlr_vty_init(&hlr_log_info);
|
||||
|
||||
rc = vty_read_config_file(cmdline_opts.config_file, NULL);
|
||||
if (rc < 0) {
|
||||
@@ -460,14 +682,14 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file);
|
||||
g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true, cmdline_opts.db_upgrade);
|
||||
if (!g_hlr->dbc) {
|
||||
LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g_hlr->gs = osmo_gsup_server_create(hlr_ctx, g_hlr->gsup_bind_addr, OSMO_GSUP_PORT,
|
||||
read_cb, &g_lu_ops);
|
||||
read_cb, &g_lu_ops, g_hlr);
|
||||
if (!g_hlr->gs) {
|
||||
LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n");
|
||||
exit(1);
|
||||
@@ -488,13 +710,29 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
while (!quit)
|
||||
osmo_select_main(0);
|
||||
}
|
||||
|
||||
osmo_gsup_server_destroy(g_hlr->gs);
|
||||
db_close(g_hlr->dbc);
|
||||
|
||||
log_fini();
|
||||
|
||||
exit(0);
|
||||
/**
|
||||
* Report the heap state of root context, then free,
|
||||
* so both ASAN and Valgrind are happy...
|
||||
*/
|
||||
talloc_report_full(hlr_ctx, stderr);
|
||||
talloc_free(hlr_ctx);
|
||||
|
||||
/* FIXME: VTY code still uses NULL-context */
|
||||
talloc_free(tall_vty_ctx);
|
||||
|
||||
/**
|
||||
* Report the heap state of NULL context, then free,
|
||||
* so both ASAN and Valgrind are happy...
|
||||
*/
|
||||
talloc_report_full(NULL, stderr);
|
||||
talloc_disable_null_tracking();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
20
src/hlr.h
20
src/hlr.h
@@ -23,6 +23,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
|
||||
struct hlr_euse;
|
||||
|
||||
struct hlr {
|
||||
/* GSUP server pointer */
|
||||
@@ -37,4 +40,21 @@ struct hlr {
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -44,15 +44,16 @@ static struct {
|
||||
const char *db_file;
|
||||
bool bootstrap;
|
||||
const char *import_nitb_db;
|
||||
bool db_upgrade;
|
||||
} cmdline_opts = {
|
||||
.db_file = "hlr.db",
|
||||
.db_upgrade = false,
|
||||
};
|
||||
|
||||
static void print_help()
|
||||
{
|
||||
printf("\n");
|
||||
printf("Usage: osmo-hlr-db-tool [-l <hlr.db>] import-nitb-db <nitb.db>]\n");
|
||||
printf("Call without arguments to create a new empty ./hlr.db.\n");
|
||||
printf("Usage: osmo-hlr-db-tool [-l <hlr.db>] [create|import-nitb-db <nitb.db>]\n");
|
||||
printf(" -l --database db-name The OsmoHLR database to use, default '%s'.\n",
|
||||
cmdline_opts.db_file);
|
||||
printf(" -h --help This text.\n");
|
||||
@@ -60,9 +61,15 @@ static void print_help()
|
||||
printf(" -s --disable-color Do not print ANSI colors in the log\n");
|
||||
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(" -V --version Print the version of OsmoHLR-db-tool.\n");
|
||||
printf("\n");
|
||||
printf(" import-nitb-db db Add OsmoNITB db's subscribers to OsmoHLR db.\n");
|
||||
printf("Commands:\n");
|
||||
printf("\n");
|
||||
printf(" create Create an empty OsmoHLR database.\n");
|
||||
printf(" (All commands imply this if none exists yet.)\n");
|
||||
printf("\n");
|
||||
printf(" import-nitb-db <nitb.db> Add OsmoNITB db's subscribers to OsmoHLR db.\n");
|
||||
printf(" Be aware that the import is lossy, only the\n");
|
||||
printf(" IMSI, MSISDN, nam_cs/ps and 2G auth data are set.\n");
|
||||
}
|
||||
@@ -92,11 +99,12 @@ static void handle_options(int argc, char **argv)
|
||||
{"disable-color", 0, 0, 's'},
|
||||
{"timestamp", 0, 0, 'T'},
|
||||
{"log-level", 1, 0, 'e'},
|
||||
{"db-upgrade", 0, 0, 'U' },
|
||||
{"version", 0, 0, 'V' },
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "hl:d:sTe:V",
|
||||
c = getopt_long(argc, argv, "hl:d:sTe:UV",
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
@@ -120,6 +128,9 @@ static void handle_options(int argc, char **argv)
|
||||
case 'e':
|
||||
log_set_log_level(osmo_stderr_target, atoi(optarg));
|
||||
break;
|
||||
case 'U':
|
||||
cmdline_opts.db_upgrade = true;
|
||||
break;
|
||||
case 'V':
|
||||
print_version(1);
|
||||
exit(EXIT_SUCCESS);
|
||||
@@ -139,9 +150,11 @@ static void handle_options(int argc, char **argv)
|
||||
}
|
||||
|
||||
cmd = argv[optind++];
|
||||
printf("command '%s', %d extra arguments\n", cmd, argc - optind);
|
||||
|
||||
if (!strcmp(cmd, "import-nitb-db")) {
|
||||
if (!strcmp(cmd, "create")) {
|
||||
/* Nothing to do, just run the main program to open the database without running any
|
||||
* action, which will bootstrap all tables. */
|
||||
} else if (!strcmp(cmd, "import-nitb-db")) {
|
||||
if (argc - optind < 1) {
|
||||
fprintf(stderr, "You must specify an input db file\n");
|
||||
print_help();
|
||||
@@ -153,6 +166,12 @@ static void handle_options(int argc, char **argv)
|
||||
print_help();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (argc - optind > 0) {
|
||||
fprintf(stderr, "Too many arguments: '%s'\n", argv[optind]);
|
||||
print_help();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
static void signal_hdlr(int signal)
|
||||
@@ -281,15 +300,15 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
|
||||
|
||||
imsi = sqlite3_column_int64(stmt, 0);
|
||||
|
||||
snprintf(imsi_str, sizeof(imsi_str), "%"PRId64, imsi);
|
||||
snprintf(imsi_str, sizeof(imsi_str), "%" PRId64, imsi);
|
||||
|
||||
rc = db_subscr_create(dbc, imsi_str);
|
||||
if (rc) {
|
||||
if (rc < 0) {
|
||||
LOGP(DDB, LOGL_ERROR, "OsmoNITB DB import to %s: failed to create IMSI %s: %d: %s\n",
|
||||
dbc->fname,
|
||||
imsi_str,
|
||||
rc,
|
||||
strerror(rc));
|
||||
strerror(-rc));
|
||||
/* on error, still attempt to continue */
|
||||
}
|
||||
|
||||
@@ -303,13 +322,13 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
|
||||
|
||||
/* find the just created id */
|
||||
rc = db_subscr_get_by_imsi(dbc, imsi_str, &subscr);
|
||||
if (rc) {
|
||||
if (rc < 0) {
|
||||
LOGP(DDB, LOGL_ERROR, "OsmoNITB DB import to %s: created IMSI %s,"
|
||||
" but failed to get new subscriber id: %d: %s\n",
|
||||
dbc->fname,
|
||||
imsi_str,
|
||||
rc,
|
||||
strerror(rc));
|
||||
strerror(-rc));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -374,7 +393,7 @@ int main(int argc, char **argv)
|
||||
OSMO_ASSERT(g_hlr_db_tool_ctx);
|
||||
talloc_set_name_const(g_hlr_db_tool_ctx, "OsmoHLR-db-tool");
|
||||
|
||||
rc = osmo_init_logging(&hlr_log_info);
|
||||
rc = osmo_init_logging2(g_hlr_db_tool_ctx, &hlr_log_info);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error initializing logging\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -387,7 +406,8 @@ int main(int argc, char **argv)
|
||||
goto too_many_actions;
|
||||
main_action = import_nitb_db;
|
||||
}
|
||||
/* Future: add more main_actions, besides --import-nitb-db, here. */
|
||||
/* Future: add more main_actions, besides import-nitb-db, here.
|
||||
* For command 'create', no action is required. */
|
||||
|
||||
/* Just in case any db actions need randomness */
|
||||
rc = rand_init();
|
||||
@@ -396,7 +416,7 @@ int main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
g_hlr_db_tool_ctx->dbc = db_open(g_hlr_db_tool_ctx, cmdline_opts.db_file);
|
||||
g_hlr_db_tool_ctx->dbc = db_open(g_hlr_db_tool_ctx, cmdline_opts.db_file, true, cmdline_opts.db_upgrade);
|
||||
if (!g_hlr_db_tool_ctx->dbc) {
|
||||
LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
586
src/hlr_ussd.c
Normal file
586
src/hlr_ussd.c
Normal file
@@ -0,0 +1,586 @@
|
||||
/* OsmoHLR SS/USSD implementation */
|
||||
|
||||
/* (C) 2018 Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* 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/core/talloc.h>
|
||||
#include <osmocom/core/timer.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsm/gsm0480.h>
|
||||
#include <osmocom/gsm/protocol/gsm_04_80.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "hlr.h"
|
||||
#include "hlr_ussd.h"
|
||||
#include "gsup_server.h"
|
||||
#include "gsup_router.h"
|
||||
#include "logging.h"
|
||||
|
||||
/***********************************************************************
|
||||
* core data structures expressing config from VTY
|
||||
***********************************************************************/
|
||||
|
||||
struct hlr_euse *euse_find(struct hlr *hlr, const char *name)
|
||||
{
|
||||
struct hlr_euse *euse;
|
||||
|
||||
llist_for_each_entry(euse, &hlr->euse_list, list) {
|
||||
if (!strcmp(euse->name, name))
|
||||
return euse;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct hlr_euse *euse_alloc(struct hlr *hlr, const char *name)
|
||||
{
|
||||
struct hlr_euse *euse = euse_find(hlr, name);
|
||||
if (euse)
|
||||
return NULL;
|
||||
|
||||
euse = talloc_zero(hlr, struct hlr_euse);
|
||||
euse->name = talloc_strdup(euse, name);
|
||||
euse->hlr = hlr;
|
||||
llist_add_tail(&euse->list, &hlr->euse_list);
|
||||
|
||||
return euse;
|
||||
}
|
||||
|
||||
void euse_del(struct hlr_euse *euse)
|
||||
{
|
||||
llist_del(&euse->list);
|
||||
talloc_free(euse);
|
||||
}
|
||||
|
||||
|
||||
struct hlr_ussd_route *ussd_route_find_prefix(struct hlr *hlr, const char *prefix)
|
||||
{
|
||||
struct hlr_ussd_route *rt;
|
||||
|
||||
llist_for_each_entry(rt, &hlr->ussd_routes, list) {
|
||||
if (!strcmp(rt->prefix, prefix))
|
||||
return rt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct hlr_ussd_route *ussd_route_prefix_alloc_int(struct hlr *hlr, const char *prefix,
|
||||
const struct hlr_iuse *iuse)
|
||||
{
|
||||
struct hlr_ussd_route *rt;
|
||||
|
||||
if (ussd_route_find_prefix(hlr, prefix))
|
||||
return NULL;
|
||||
|
||||
rt = talloc_zero(hlr, struct hlr_ussd_route);
|
||||
rt->prefix = talloc_strdup(rt, prefix);
|
||||
rt->u.iuse = iuse;
|
||||
llist_add_tail(&rt->list, &hlr->ussd_routes);
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
struct hlr_ussd_route *ussd_route_prefix_alloc_ext(struct hlr *hlr, const char *prefix,
|
||||
struct hlr_euse *euse)
|
||||
{
|
||||
struct hlr_ussd_route *rt;
|
||||
|
||||
if (ussd_route_find_prefix(hlr, prefix))
|
||||
return NULL;
|
||||
|
||||
rt = talloc_zero(hlr, struct hlr_ussd_route);
|
||||
rt->prefix = talloc_strdup(rt, prefix);
|
||||
rt->is_external = true;
|
||||
rt->u.euse = euse;
|
||||
llist_add_tail(&rt->list, &hlr->ussd_routes);
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
void ussd_route_del(struct hlr_ussd_route *rt)
|
||||
{
|
||||
llist_del(&rt->list);
|
||||
talloc_free(rt);
|
||||
}
|
||||
|
||||
static struct hlr_ussd_route *ussd_route_lookup_7bit(struct hlr *hlr, const char *ussd_code)
|
||||
{
|
||||
struct hlr_ussd_route *rt;
|
||||
llist_for_each_entry(rt, &hlr->ussd_routes, list) {
|
||||
if (!strncmp(ussd_code, rt->prefix, strlen(rt->prefix))) {
|
||||
LOGP(DSS, LOGL_DEBUG, "Found %s '%s' (prefix '%s') for USSD "
|
||||
"Code '%s'\n", rt->is_external ? "EUSE" : "IUSE",
|
||||
rt->is_external ? rt->u.euse->name : rt->u.iuse->name,
|
||||
rt->prefix, ussd_code);
|
||||
return rt;
|
||||
}
|
||||
}
|
||||
|
||||
LOGP(DSS, LOGL_DEBUG, "Could not find Route for USSD Code '%s'\n", ussd_code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* handling functions for individual GSUP messages
|
||||
***********************************************************************/
|
||||
|
||||
#define LOGPSS(ss, lvl, fmt, args...) \
|
||||
LOGP(DSS, lvl, "%s/0x%08x: " fmt, (ss)->imsi, (ss)->session_id, ## args)
|
||||
|
||||
struct ss_session {
|
||||
/* link us to hlr->ss_sessions */
|
||||
struct llist_head list;
|
||||
/* imsi of this session */
|
||||
char imsi[GSM23003_IMSI_MAX_DIGITS+2];
|
||||
/* ID of this session (unique per IMSI) */
|
||||
uint32_t session_id;
|
||||
/* state of the session */
|
||||
enum osmo_gsup_session_state state;
|
||||
/* time-out when we will delete the session */
|
||||
struct osmo_timer_list timeout;
|
||||
|
||||
/* is this USSD for an external handler (EUSE): true */
|
||||
bool is_external;
|
||||
union {
|
||||
/* external USSD Entity responsible for this session */
|
||||
struct hlr_euse *euse;
|
||||
/* internal USSD Entity responsible for this session */
|
||||
const struct hlr_iuse *iuse;
|
||||
} u;
|
||||
|
||||
/* 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 ss_session *ss_session_find(struct hlr *hlr, const char *imsi, uint32_t session_id)
|
||||
{
|
||||
struct ss_session *ss;
|
||||
llist_for_each_entry(ss, &hlr->ss_sessions, list) {
|
||||
if (!strcmp(ss->imsi, imsi) && ss->session_id == session_id)
|
||||
return ss;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ss_session_free(struct ss_session *ss)
|
||||
{
|
||||
osmo_timer_del(&ss->timeout);
|
||||
llist_del(&ss->list);
|
||||
talloc_free(ss);
|
||||
}
|
||||
|
||||
static void ss_session_timeout(void *data)
|
||||
{
|
||||
struct ss_session *ss = data;
|
||||
|
||||
LOGPSS(ss, LOGL_NOTICE, "SS Session Timeout, destroying\n");
|
||||
/* FIXME: should we send a ReturnError component to the MS? */
|
||||
ss_session_free(ss);
|
||||
}
|
||||
|
||||
struct ss_session *ss_session_alloc(struct hlr *hlr, const char *imsi, uint32_t session_id)
|
||||
{
|
||||
struct ss_session *ss;
|
||||
|
||||
OSMO_ASSERT(!ss_session_find(hlr, imsi, session_id));
|
||||
|
||||
ss = talloc_zero(hlr, struct ss_session);
|
||||
OSMO_ASSERT(ss);
|
||||
|
||||
OSMO_STRLCPY_ARRAY(ss->imsi, imsi);
|
||||
ss->session_id = session_id;
|
||||
|
||||
/* Schedule self-destruction timer */
|
||||
osmo_timer_setup(&ss->timeout, ss_session_timeout, ss);
|
||||
if (g_hlr->ncss_guard_timeout > 0)
|
||||
osmo_timer_schedule(&ss->timeout, g_hlr->ncss_guard_timeout, 0);
|
||||
|
||||
llist_add_tail(&ss->list, &hlr->ss_sessions);
|
||||
return ss;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* handling functions for encoding SS messages + wrapping them in GSUP
|
||||
***********************************************************************/
|
||||
|
||||
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;
|
||||
|
||||
resp.message_type = gsup_msg_type;
|
||||
OSMO_STRLCPY_ARRAY(resp.imsi, ss->imsi);
|
||||
if (final)
|
||||
resp.session_state = OSMO_GSUP_SESSION_STATE_END;
|
||||
else
|
||||
resp.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
|
||||
resp.session_id = ss->session_id;
|
||||
if (ss_msg) {
|
||||
resp.ss_info = msgb_data(ss_msg);
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int ss_tx_reject(struct ss_session *ss, int invoke_id, uint8_t problem_tag,
|
||||
uint8_t problem_code)
|
||||
{
|
||||
struct msgb *msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code);
|
||||
LOGPSS(ss, LOGL_NOTICE, "Tx Reject(%u, 0x%02x, 0x%02x)\n", invoke_id,
|
||||
problem_tag, problem_code);
|
||||
OSMO_ASSERT(msg);
|
||||
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ss_tx_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);
|
||||
OSMO_ASSERT(msg);
|
||||
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)
|
||||
{
|
||||
struct msgb *msg = gsm0480_gen_ussd_resp_7bit(invoke_id, text);
|
||||
LOGPSS(ss, LOGL_INFO, "Tx USSD '%s'\n", text);
|
||||
OSMO_ASSERT(msg);
|
||||
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, final, msg);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Internal USSD Handlers
|
||||
***********************************************************************/
|
||||
|
||||
#include "db.h"
|
||||
|
||||
static int handle_ussd_own_msisdn(struct osmo_gsup_conn *conn, struct ss_session *ss,
|
||||
const struct osmo_gsup_message *gsup, const struct ss_request *req)
|
||||
{
|
||||
struct hlr_subscriber subscr;
|
||||
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
|
||||
int rc;
|
||||
|
||||
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
|
||||
switch (rc) {
|
||||
case 0:
|
||||
if (strlen(subscr.msisdn) == 0)
|
||||
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);
|
||||
break;
|
||||
case -ENOENT:
|
||||
ss_tx_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
|
||||
break;
|
||||
case -EIO:
|
||||
default:
|
||||
ss_tx_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_ussd_own_imsi(struct osmo_gsup_conn *conn, 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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const struct hlr_iuse hlr_iuses[] = {
|
||||
{
|
||||
.name = "own-msisdn",
|
||||
.handle_ussd = handle_ussd_own_msisdn,
|
||||
},
|
||||
{
|
||||
.name = "own-imsi",
|
||||
.handle_ussd = handle_ussd_own_imsi,
|
||||
},
|
||||
};
|
||||
|
||||
const struct hlr_iuse *iuse_find(const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hlr_iuses); i++) {
|
||||
const struct hlr_iuse *iuse = &hlr_iuses[i];
|
||||
if (!strcmp(name, iuse->name))
|
||||
return iuse;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* handling functions for individual GSUP messages
|
||||
***********************************************************************/
|
||||
|
||||
static bool ss_op_is_ussd(uint8_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case GSM0480_OP_CODE_PROCESS_USS_DATA:
|
||||
case GSM0480_OP_CODE_PROCESS_USS_REQ:
|
||||
case GSM0480_OP_CODE_USS_REQUEST:
|
||||
case GSM0480_OP_CODE_USS_NOTIFY:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* is this GSUP connection an EUSE (true) or not (false)? */
|
||||
static bool conn_is_euse(struct osmo_gsup_conn *conn)
|
||||
{
|
||||
int rc;
|
||||
uint8_t *addr;
|
||||
|
||||
rc = osmo_gsup_conn_ccm_get(conn, &addr, IPAC_IDTAG_SERNR);
|
||||
if (rc <= 5)
|
||||
return false;
|
||||
if (!strncmp((char *)addr, "EUSE-", 5))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct hlr_euse *euse_by_conn(struct osmo_gsup_conn *conn)
|
||||
{
|
||||
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))
|
||||
return NULL;
|
||||
|
||||
return euse_find(hlr, addr+5);
|
||||
}
|
||||
|
||||
static int handle_ss(struct ss_session *ss, const struct osmo_gsup_message *gsup,
|
||||
const struct ss_request *req)
|
||||
{
|
||||
uint8_t comp_type = gsup->ss_info[0];
|
||||
|
||||
LOGPSS(ss, LOGL_INFO, "SS CompType=%s, OpCode=%s\n",
|
||||
gsm0480_comp_type_name(comp_type), gsm0480_op_code_name(req->opcode));
|
||||
|
||||
/**
|
||||
* FIXME: As we don't store any SS related information
|
||||
* (e.g. call forwarding preferences) in the database,
|
||||
* 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);
|
||||
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)
|
||||
{
|
||||
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),
|
||||
req->ussd_text);
|
||||
|
||||
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);
|
||||
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);
|
||||
} 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);
|
||||
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);
|
||||
} else {
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP USSD FW");
|
||||
OSMO_ASSERT(msg_out);
|
||||
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);
|
||||
/* Release session immediately */
|
||||
ss_session_free(ss);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
struct hlr *hlr = conn->server->priv;
|
||||
struct ss_session *ss;
|
||||
struct ss_request req = {0};
|
||||
|
||||
LOGP(DSS, LOGL_DEBUG, "%s/0x%08x: Process SS (%s)\n", gsup->imsi, gsup->session_id,
|
||||
osmo_gsup_session_state_name(gsup->session_state));
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
switch (gsup->session_state) {
|
||||
case OSMO_GSUP_SESSION_STATE_BEGIN:
|
||||
/* Check for overlapping Session ID usage */
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (ss_op_is_ussd(req.opcode)) {
|
||||
if (conn_is_euse(conn)) {
|
||||
/* EUSE->VLR: MT USSD. EUSE is known ('conn'), VLR is to be resolved */
|
||||
ss->u.euse = euse_by_conn(conn);
|
||||
} else {
|
||||
/* VLR->EUSE: MO USSD. VLR is known ('conn'), EUSE is to be resolved */
|
||||
struct hlr_ussd_route *rt;
|
||||
rt = ussd_route_lookup_7bit(hlr, (const char *) req.ussd_text);
|
||||
if (rt) {
|
||||
if (rt->is_external) {
|
||||
ss->is_external = true;
|
||||
ss->u.euse = rt->u.euse;
|
||||
} else if (rt) {
|
||||
ss->is_external = false;
|
||||
ss->u.iuse = rt->u.iuse;
|
||||
}
|
||||
} else {
|
||||
if (hlr->euse_default) {
|
||||
ss->is_external = true;
|
||||
ss->u.euse = hlr->euse_default;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* dispatch unstructured SS to routing */
|
||||
handle_ussd(conn, ss, gsup, &req);
|
||||
} else {
|
||||
/* dispatch non-call SS to internal code */
|
||||
handle_ss(ss, gsup, &req);
|
||||
}
|
||||
break;
|
||||
case OSMO_GSUP_SESSION_STATE_CONTINUE:
|
||||
ss = ss_session_find(hlr, gsup->imsi, gsup->session_id);
|
||||
if (!ss) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: CONTINUE for unknown SS session\n",
|
||||
gsup->imsi, gsup->session_id);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* Reschedule self-destruction timer */
|
||||
if (g_hlr->ncss_guard_timeout > 0)
|
||||
osmo_timer_schedule(&ss->timeout, g_hlr->ncss_guard_timeout, 0);
|
||||
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case OSMO_GSUP_SESSION_STATE_END:
|
||||
ss = ss_session_find(hlr, gsup->imsi, gsup->session_id);
|
||||
if (!ss) {
|
||||
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: END for unknown SS session\n",
|
||||
gsup->imsi, gsup->session_id);
|
||||
goto out_err;
|
||||
}
|
||||
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_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;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rx_proc_ss_error(struct osmo_gsup_conn *conn, const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
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;
|
||||
}
|
||||
61
src/hlr_ussd.h
Normal file
61
src/hlr_ussd.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
#include "gsup_server.h"
|
||||
|
||||
#define NCSS_GUARD_TIMEOUT_DEFAULT 30
|
||||
|
||||
struct hlr_ussd_route {
|
||||
/* g_hlr.routes */
|
||||
struct llist_head list;
|
||||
const char *prefix;
|
||||
bool is_external;
|
||||
union {
|
||||
struct hlr_euse *euse;
|
||||
const struct hlr_iuse *iuse;
|
||||
} u;
|
||||
};
|
||||
|
||||
struct hlr_euse {
|
||||
/* list in the per-hlr list of EUSEs */
|
||||
struct llist_head list;
|
||||
struct hlr *hlr;
|
||||
/* name (must match the IPA ID tag) */
|
||||
const char *name;
|
||||
/* human-readable description */
|
||||
const char *description;
|
||||
|
||||
/* GSUP connection to the EUSE, if any */
|
||||
struct osmo_gsup_conn *conn;
|
||||
};
|
||||
|
||||
struct hlr_euse *euse_find(struct hlr *hlr, const char *name);
|
||||
struct hlr_euse *euse_alloc(struct hlr *hlr, const char *name);
|
||||
void euse_del(struct hlr_euse *euse);
|
||||
|
||||
const struct hlr_iuse *iuse_find(const char *name);
|
||||
|
||||
struct hlr_ussd_route *ussd_route_find_prefix(struct hlr *hlr, const char *prefix);
|
||||
struct hlr_ussd_route *ussd_route_prefix_alloc_int(struct hlr *hlr, const char *prefix,
|
||||
const struct hlr_iuse *iuse);
|
||||
struct hlr_ussd_route *ussd_route_prefix_alloc_ext(struct hlr *hlr, const char *prefix,
|
||||
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);
|
||||
|
||||
struct ss_session;
|
||||
struct ss_request;
|
||||
|
||||
/* Internal USSD Handler */
|
||||
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);
|
||||
};
|
||||
250
src/hlr_vty.c
250
src/hlr_vty.c
@@ -1,9 +1,14 @@
|
||||
/* OsmoHLR VTY implementation */
|
||||
|
||||
/* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
||||
* Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
|
||||
* (C) 2018 Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
|
||||
* (C) 2018 Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* 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
|
||||
@@ -24,11 +29,14 @@
|
||||
#include <osmocom/vty/vty.h>
|
||||
#include <osmocom/vty/command.h>
|
||||
#include <osmocom/vty/logging.h>
|
||||
#include <osmocom/vty/misc.h>
|
||||
#include <osmocom/abis/ipa.h>
|
||||
|
||||
#include "hlr.h"
|
||||
#include "hlr_vty.h"
|
||||
#include "hlr_vty_subscr.h"
|
||||
|
||||
static struct hlr *g_hlr = NULL;
|
||||
#include "hlr_ussd.h"
|
||||
#include "gsup_server.h"
|
||||
|
||||
struct cmd_node hlr_node = {
|
||||
HLR_NODE,
|
||||
@@ -74,6 +82,33 @@ static int config_write_hlr_gsup(struct vty *vty)
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
|
||||
{
|
||||
const struct ipa_server_conn *isc = conn->conn;
|
||||
char *name;
|
||||
int rc;
|
||||
|
||||
rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
|
||||
OSMO_ASSERT(rc);
|
||||
|
||||
vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
|
||||
name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
|
||||
VTY_NEWLINE);
|
||||
}
|
||||
|
||||
DEFUN(show_gsup_conn, show_gsup_conn_cmd,
|
||||
"show gsup-connections",
|
||||
SHOW_STR "GSUP Connections from VLRs, SGSNs, EUSEs\n")
|
||||
{
|
||||
struct osmo_gsup_server *gs = g_hlr->gs;
|
||||
struct osmo_gsup_conn *conn;
|
||||
|
||||
llist_for_each_entry(conn, &gs->clients, list)
|
||||
show_one_conn(vty, conn);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_hlr_gsup_bind_ip,
|
||||
cfg_hlr_gsup_bind_ip_cmd,
|
||||
"bind ip A.B.C.D",
|
||||
@@ -88,12 +123,200 @@ DEFUN(cfg_hlr_gsup_bind_ip,
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* USSD Entity
|
||||
***********************************************************************/
|
||||
|
||||
#include "hlr_ussd.h"
|
||||
|
||||
#define USSD_STR "USSD Configuration\n"
|
||||
#define UROUTE_STR "Routing Configuration\n"
|
||||
#define PREFIX_STR "Prefix-Matching Route\n" "USSD Prefix\n"
|
||||
|
||||
#define INT_CHOICE "(own-msisdn|own-imsi)"
|
||||
#define INT_STR "Internal USSD Handler\n" \
|
||||
"Respond with subscribers' own MSISDN\n" \
|
||||
"Respond with subscribers' own IMSI\n"
|
||||
|
||||
#define EXT_STR "External USSD Handler\n" \
|
||||
"Name of External USSD Handler (IPA CCM ID)\n"
|
||||
|
||||
DEFUN(cfg_ussd_route_pfx_int, cfg_ussd_route_pfx_int_cmd,
|
||||
"ussd route prefix PREFIX internal " INT_CHOICE,
|
||||
USSD_STR UROUTE_STR PREFIX_STR INT_STR)
|
||||
{
|
||||
const struct hlr_iuse *iuse = iuse_find(argv[1]);
|
||||
struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
|
||||
if (rt) {
|
||||
vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
ussd_route_prefix_alloc_int(g_hlr, argv[0], iuse);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_ussd_route_pfx_ext, cfg_ussd_route_pfx_ext_cmd,
|
||||
"ussd route prefix PREFIX external EUSE",
|
||||
USSD_STR UROUTE_STR PREFIX_STR EXT_STR)
|
||||
{
|
||||
struct hlr_euse *euse = euse_find(g_hlr, argv[1]);
|
||||
struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
|
||||
if (rt) {
|
||||
vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
if (!euse) {
|
||||
vty_out(vty, "%% Cannot find euse '%s'%s", argv[1], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
ussd_route_prefix_alloc_ext(g_hlr, argv[0], euse);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_ussd_no_route_pfx, cfg_ussd_no_route_pfx_cmd,
|
||||
"no ussd route prefix PREFIX",
|
||||
NO_STR USSD_STR UROUTE_STR PREFIX_STR)
|
||||
{
|
||||
struct hlr_ussd_route *rt = ussd_route_find_prefix(g_hlr, argv[0]);
|
||||
if (!rt) {
|
||||
vty_out(vty, "%% Cannot find route for prefix %s%s", argv[0], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
ussd_route_del(rt);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_ussd_defaultroute, cfg_ussd_defaultroute_cmd,
|
||||
"ussd default-route external EUSE",
|
||||
USSD_STR "Configure default-route for all USSD to unknown destinations\n"
|
||||
EXT_STR)
|
||||
{
|
||||
struct hlr_euse *euse;
|
||||
|
||||
euse = euse_find(g_hlr, argv[0]);
|
||||
if (!euse) {
|
||||
vty_out(vty, "%% Cannot find EUSE %s%s", argv[0], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (g_hlr->euse_default != euse) {
|
||||
vty_out(vty, "Switching default route from %s to %s%s",
|
||||
g_hlr->euse_default ? g_hlr->euse_default->name : "<none>",
|
||||
euse->name, VTY_NEWLINE);
|
||||
g_hlr->euse_default = euse;
|
||||
}
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_ussd_no_defaultroute, cfg_ussd_no_defaultroute_cmd,
|
||||
"no ussd default-route",
|
||||
NO_STR USSD_STR "Remove the default-route for all USSD to unknown destinations\n")
|
||||
{
|
||||
g_hlr->euse_default = NULL;
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
struct cmd_node euse_node = {
|
||||
EUSE_NODE,
|
||||
"%s(config-hlr-euse)# ",
|
||||
1,
|
||||
};
|
||||
|
||||
DEFUN(cfg_euse, cfg_euse_cmd,
|
||||
"euse NAME",
|
||||
"Configure a particular External USSD Entity\n"
|
||||
"Alphanumeric name of the External USSD Entity\n")
|
||||
{
|
||||
struct hlr_euse *euse;
|
||||
const char *id = argv[0];
|
||||
|
||||
euse = euse_find(g_hlr, id);
|
||||
if (!euse) {
|
||||
euse = euse_alloc(g_hlr, id);
|
||||
if (!euse)
|
||||
return CMD_WARNING;
|
||||
}
|
||||
vty->index = euse;
|
||||
vty->index_sub = &euse->description;
|
||||
vty->node = EUSE_NODE;
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_no_euse, cfg_no_euse_cmd,
|
||||
"no euse NAME",
|
||||
NO_STR "Remove a particular External USSD Entity\n"
|
||||
"Alphanumeric name of the External USSD Entity\n")
|
||||
{
|
||||
struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
|
||||
if (!euse) {
|
||||
vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
if (g_hlr->euse_default == euse) {
|
||||
vty_out(vty, "%% Cannot remove EUSE %s, it is the default route%s", argv[0], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
euse_del(euse);
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
static void dump_one_euse(struct vty *vty, struct hlr_euse *euse)
|
||||
{
|
||||
vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE);
|
||||
}
|
||||
|
||||
static int config_write_euse(struct vty *vty)
|
||||
{
|
||||
struct hlr_euse *euse;
|
||||
struct hlr_ussd_route *rt;
|
||||
|
||||
llist_for_each_entry(euse, &g_hlr->euse_list, list)
|
||||
dump_one_euse(vty, euse);
|
||||
|
||||
llist_for_each_entry(rt, &g_hlr->ussd_routes, list) {
|
||||
vty_out(vty, " ussd route prefix %s %s %s%s", rt->prefix,
|
||||
rt->is_external ? "external" : "internal",
|
||||
rt->is_external ? rt->u.euse->name : rt->u.iuse->name,
|
||||
VTY_NEWLINE);
|
||||
}
|
||||
|
||||
if (g_hlr->euse_default)
|
||||
vty_out(vty, " ussd default-route external %s%s", g_hlr->euse_default->name, VTY_NEWLINE);
|
||||
|
||||
if (g_hlr->ncss_guard_timeout != NCSS_GUARD_TIMEOUT_DEFAULT)
|
||||
vty_out(vty, " ncss-guard-timeout %i%s",
|
||||
g_hlr->ncss_guard_timeout, VTY_NEWLINE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFUN(cfg_ncss_guard_timeout, cfg_ncss_guard_timeout_cmd,
|
||||
"ncss-guard-timeout <0-255>",
|
||||
"Set guard timer for NCSS (call independent SS) session activity\n"
|
||||
"Guard timer value (sec.), or 0 to disable")
|
||||
{
|
||||
g_hlr->ncss_guard_timeout = atoi(argv[0]);
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Common Code
|
||||
***********************************************************************/
|
||||
|
||||
int hlr_vty_go_parent(struct vty *vty)
|
||||
{
|
||||
switch (vty->node) {
|
||||
case GSUP_NODE:
|
||||
case EUSE_NODE:
|
||||
vty->node = HLR_NODE;
|
||||
vty->index = NULL;
|
||||
vty->index_sub = NULL;
|
||||
break;
|
||||
default:
|
||||
case HLR_NODE:
|
||||
@@ -121,21 +344,30 @@ int hlr_vty_is_config_node(struct vty *vty, int node)
|
||||
}
|
||||
}
|
||||
|
||||
void hlr_vty_init(struct hlr *hlr, const struct log_info *cat)
|
||||
void hlr_vty_init(const struct log_info *cat)
|
||||
{
|
||||
g_hlr = hlr;
|
||||
|
||||
logging_vty_add_cmds(cat);
|
||||
osmo_talloc_vty_add_cmds();
|
||||
|
||||
install_element_ve(&show_gsup_conn_cmd);
|
||||
|
||||
install_element(CONFIG_NODE, &cfg_hlr_cmd);
|
||||
install_node(&hlr_node, config_write_hlr);
|
||||
install_default(HLR_NODE);
|
||||
|
||||
install_element(HLR_NODE, &cfg_gsup_cmd);
|
||||
install_node(&gsup_node, config_write_hlr_gsup);
|
||||
install_default(GSUP_NODE);
|
||||
|
||||
install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
|
||||
|
||||
hlr_vty_subscriber_init(hlr);
|
||||
install_element(HLR_NODE, &cfg_euse_cmd);
|
||||
install_element(HLR_NODE, &cfg_no_euse_cmd);
|
||||
install_node(&euse_node, config_write_euse);
|
||||
install_element(HLR_NODE, &cfg_ussd_route_pfx_int_cmd);
|
||||
install_element(HLR_NODE, &cfg_ussd_route_pfx_ext_cmd);
|
||||
install_element(HLR_NODE, &cfg_ussd_no_route_pfx_cmd);
|
||||
install_element(HLR_NODE, &cfg_ussd_defaultroute_cmd);
|
||||
install_element(HLR_NODE, &cfg_ussd_no_defaultroute_cmd);
|
||||
install_element(HLR_NODE, &cfg_ncss_guard_timeout_cmd);
|
||||
|
||||
hlr_vty_subscriber_init();
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@
|
||||
enum hlr_vty_node {
|
||||
HLR_NODE = _LAST_OSMOVTY_NODE + 1,
|
||||
GSUP_NODE,
|
||||
EUSE_NODE,
|
||||
};
|
||||
|
||||
int hlr_vty_is_config_node(struct vty *vty, int node);
|
||||
int hlr_vty_go_parent(struct vty *vty);
|
||||
void hlr_vty_init(struct hlr *hlr, const struct log_info *cat);
|
||||
void hlr_vty_init(const struct log_info *cat);
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
#include <osmocom/vty/vty.h>
|
||||
@@ -33,13 +35,24 @@ struct vty;
|
||||
|
||||
#define hexdump_buf(buf) osmo_hexdump_nospc((void*)buf, sizeof(buf))
|
||||
|
||||
static struct hlr *g_hlr = NULL;
|
||||
static char *
|
||||
get_datestr(const time_t *t, char *datebuf)
|
||||
{
|
||||
char *p, *s = ctime_r(t, datebuf);
|
||||
|
||||
/* Strip trailing newline. */
|
||||
p = strchr(s, '\n');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
|
||||
{
|
||||
int rc;
|
||||
struct osmo_sub_auth_data aud2g;
|
||||
struct osmo_sub_auth_data aud3g;
|
||||
char datebuf[26]; /* for ctime_r(3) */
|
||||
|
||||
vty_out(vty, " ID: %"PRIu64"%s", subscr->id, VTY_NEWLINE);
|
||||
|
||||
@@ -65,6 +78,8 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
|
||||
vty_out(vty, " PS disabled%s", VTY_NEWLINE);
|
||||
if (subscr->ms_purged_ps)
|
||||
vty_out(vty, " PS purged%s", VTY_NEWLINE);
|
||||
if (subscr->last_lu_seen)
|
||||
vty_out(vty, " last LU seen: %s UTC%s", get_datestr(&subscr->last_lu_seen, datebuf), VTY_NEWLINE);
|
||||
|
||||
if (!*subscr->imsi)
|
||||
return;
|
||||
@@ -72,14 +87,17 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
|
||||
OSMO_ASSERT(g_hlr);
|
||||
rc = db_get_auth_data(g_hlr->dbc, subscr->imsi, &aud2g, &aud3g, NULL);
|
||||
|
||||
if (rc) {
|
||||
if (rc == -ENOENT) {
|
||||
aud2g.algo = OSMO_AUTH_ALG_NONE;
|
||||
aud3g.algo = OSMO_AUTH_ALG_NONE;
|
||||
} else {
|
||||
vty_out(vty, "%% Error retrieving data from database (%d)%s", rc, VTY_NEWLINE);
|
||||
return;
|
||||
}
|
||||
switch (rc) {
|
||||
case 0:
|
||||
break;
|
||||
case -ENOENT:
|
||||
case -ENOKEY:
|
||||
aud2g.algo = OSMO_AUTH_ALG_NONE;
|
||||
aud3g.algo = OSMO_AUTH_ALG_NONE;
|
||||
break;
|
||||
default:
|
||||
vty_out(vty, "%% Error retrieving data from database (%d)%s", rc, VTY_NEWLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (aud2g.type != OSMO_AUTH_TYPE_NONE && aud2g.type != OSMO_AUTH_TYPE_GSM) {
|
||||
@@ -129,18 +147,19 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id,
|
||||
#define SUBSCR_CMD "subscriber "
|
||||
#define SUBSCR_CMD_HELP "Subscriber management commands\n"
|
||||
|
||||
#define SUBSCR_ID "(imsi|msisdn|id) IDENT "
|
||||
#define SUBSCR_ID "(imsi|msisdn|id) IDENT"
|
||||
#define SUBSCR_ID_HELP \
|
||||
"Identify subscriber by IMSI\n" \
|
||||
"Identify subscriber by MSISDN (phone number)\n" \
|
||||
"Identify subscriber by database ID\n" \
|
||||
"IMSI/MSISDN/ID of the subscriber\n"
|
||||
|
||||
#define SUBSCR SUBSCR_CMD SUBSCR_ID
|
||||
#define SUBSCR SUBSCR_CMD SUBSCR_ID " "
|
||||
#define SUBSCR_HELP SUBSCR_CMD_HELP SUBSCR_ID_HELP
|
||||
|
||||
#define SUBSCR_UPDATE SUBSCR "update "
|
||||
#define SUBSCR_UPDATE_HELP SUBSCR_HELP "Set or update subscriber data\n"
|
||||
#define SUBSCR_MSISDN_HELP "Set MSISDN (phone number) of the subscriber\n"
|
||||
|
||||
DEFUN(subscriber_show,
|
||||
subscriber_show_cmd,
|
||||
@@ -158,12 +177,17 @@ DEFUN(subscriber_show,
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
ALIAS(subscriber_show, show_subscriber_cmd,
|
||||
"show " SUBSCR_CMD SUBSCR_ID,
|
||||
SHOW_STR SUBSCR_CMD_HELP SUBSCR_ID_HELP);
|
||||
|
||||
DEFUN(subscriber_create,
|
||||
subscriber_create_cmd,
|
||||
SUBSCR_CMD "imsi IDENT create",
|
||||
SUBSCR_CMD_HELP
|
||||
"Create subscriber by IMSI\n"
|
||||
"IMSI/MSISDN/ID of the subscriber\n")
|
||||
"Identify subscriber by IMSI\n"
|
||||
"IMSI/MSISDN/ID of the subscriber\n"
|
||||
"Create subscriber by IMSI\n")
|
||||
{
|
||||
int rc;
|
||||
struct hlr_subscriber subscr;
|
||||
@@ -222,9 +246,9 @@ DEFUN(subscriber_delete,
|
||||
|
||||
DEFUN(subscriber_msisdn,
|
||||
subscriber_msisdn_cmd,
|
||||
SUBSCR_UPDATE "msisdn MSISDN",
|
||||
SUBSCR_UPDATE_HELP
|
||||
"Set MSISDN (phone number) of the subscriber\n"
|
||||
SUBSCR_UPDATE "msisdn (none|MSISDN)",
|
||||
SUBSCR_UPDATE_HELP SUBSCR_MSISDN_HELP
|
||||
"Remove MSISDN (phone number)\n"
|
||||
"New MSISDN (phone number)\n")
|
||||
{
|
||||
struct hlr_subscriber subscr;
|
||||
@@ -232,15 +256,19 @@ DEFUN(subscriber_msisdn,
|
||||
const char *id = argv[1];
|
||||
const char *msisdn = argv[2];
|
||||
|
||||
if (strlen(msisdn) > sizeof(subscr.msisdn) - 1) {
|
||||
vty_out(vty, "%% MSISDN is too long, max. %zu characters are allowed%s",
|
||||
sizeof(subscr.msisdn)-1, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
if (strcmp(msisdn, "none") == 0)
|
||||
msisdn = NULL;
|
||||
else {
|
||||
if (strlen(msisdn) > sizeof(subscr.msisdn) - 1) {
|
||||
vty_out(vty, "%% MSISDN is too long, max. %zu characters are allowed%s",
|
||||
sizeof(subscr.msisdn)-1, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (!osmo_msisdn_str_valid(msisdn)) {
|
||||
vty_out(vty, "%% MSISDN invalid: '%s'%s", msisdn, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
if (!osmo_msisdn_str_valid(msisdn)) {
|
||||
vty_out(vty, "%% MSISDN invalid: '%s'%s", msisdn, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
if (get_subscr_by_argv(vty, id_type, id, &subscr))
|
||||
@@ -252,8 +280,19 @@ DEFUN(subscriber_msisdn,
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
vty_out(vty, "%% Updated subscriber IMSI='%s' to MSISDN='%s'%s",
|
||||
subscr.imsi, msisdn, VTY_NEWLINE);
|
||||
if (msisdn) {
|
||||
vty_out(vty, "%% Updated subscriber IMSI='%s' to MSISDN='%s'%s",
|
||||
subscr.imsi, msisdn, VTY_NEWLINE);
|
||||
|
||||
if (db_subscr_get_by_msisdn(g_hlr->dbc, msisdn, &subscr) == 0)
|
||||
osmo_hlr_subscriber_update_notify(&subscr);
|
||||
} else {
|
||||
vty_out(vty, "%% Updated subscriber IMSI='%s': removed MSISDN%s",
|
||||
subscr.imsi, VTY_NEWLINE);
|
||||
|
||||
osmo_hlr_subscriber_update_notify(&subscr);
|
||||
}
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -331,7 +370,7 @@ DEFUN(subscriber_no_aud2g,
|
||||
|
||||
rc = db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud);
|
||||
|
||||
if (rc) {
|
||||
if (rc && rc != -ENOENT) {
|
||||
vty_out(vty, "%% Error: cannot disable 2G auth data for IMSI='%s'%s",
|
||||
subscr.imsi, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
@@ -402,7 +441,7 @@ DEFUN(subscriber_no_aud3g,
|
||||
|
||||
rc = db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud);
|
||||
|
||||
if (rc) {
|
||||
if (rc && rc != -ENOENT) {
|
||||
vty_out(vty, "%% Error: cannot disable 3G auth data for IMSI='%s'%s",
|
||||
subscr.imsi, VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
@@ -469,11 +508,10 @@ DEFUN(subscriber_aud3g,
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
void hlr_vty_subscriber_init(struct hlr *hlr)
|
||||
void hlr_vty_subscriber_init(void)
|
||||
{
|
||||
g_hlr = hlr;
|
||||
|
||||
install_element_ve(&subscriber_show_cmd);
|
||||
install_element_ve(&show_subscriber_cmd);
|
||||
install_element(ENABLE_NODE, &subscriber_create_cmd);
|
||||
install_element(ENABLE_NODE, &subscriber_delete_cmd);
|
||||
install_element(ENABLE_NODE, &subscriber_msisdn_cmd);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void hlr_vty_subscriber_init(struct hlr *hlr);
|
||||
void hlr_vty_subscriber_init(void);
|
||||
|
||||
@@ -19,6 +19,13 @@ const struct log_info_cat hlr_log_info_cat[] = {
|
||||
.color = "\033[1;33m",
|
||||
.enabled = 1, .loglevel = LOGL_NOTICE,
|
||||
},
|
||||
[DSS] = {
|
||||
.name = "DSS",
|
||||
.description = "Supplementary Services",
|
||||
.color = "\033[1;34m",
|
||||
.enabled = 1, .loglevel = LOGL_NOTICE,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
const struct log_info hlr_log_info = {
|
||||
|
||||
@@ -7,6 +7,7 @@ enum {
|
||||
DDB,
|
||||
DGSUP,
|
||||
DAUC,
|
||||
DSS,
|
||||
};
|
||||
|
||||
extern const struct log_info hlr_log_info;
|
||||
|
||||
67
src/luop.c
67
src/luop.c
@@ -25,7 +25,6 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsm/apn.h>
|
||||
|
||||
@@ -52,6 +51,7 @@ static void _luop_tx_gsup(struct lu_operation *luop,
|
||||
struct msgb *msg_out;
|
||||
|
||||
msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP LUOP");
|
||||
OSMO_ASSERT(msg_out);
|
||||
osmo_gsup_encode(msg_out, gsup);
|
||||
|
||||
osmo_gsup_addr_send(luop->gsup_server, luop->peer,
|
||||
@@ -108,8 +108,7 @@ struct lu_operation *lu_op_alloc(struct osmo_gsup_server *srv)
|
||||
luop = talloc_zero(srv, struct lu_operation);
|
||||
OSMO_ASSERT(luop);
|
||||
luop->gsup_server = srv;
|
||||
luop->timer.cb = lu_op_timer_cb;
|
||||
luop->timer.data = luop;
|
||||
osmo_timer_setup(&luop->timer, lu_op_timer_cb, luop);
|
||||
|
||||
return luop;
|
||||
}
|
||||
@@ -119,6 +118,10 @@ void lu_op_free(struct lu_operation *luop)
|
||||
/* Only attempt to remove when it was ever added to a list. */
|
||||
if (luop->list.next)
|
||||
llist_del(&luop->list);
|
||||
|
||||
/* Delete timer just in case it is still pending. */
|
||||
osmo_timer_del(&luop->timer);
|
||||
|
||||
talloc_free(luop);
|
||||
}
|
||||
|
||||
@@ -162,23 +165,6 @@ void lu_op_statechg(struct lu_operation *luop, enum lu_state new_state)
|
||||
luop->state = new_state;
|
||||
}
|
||||
|
||||
/* Send a msgb to a given address using routing */
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg)
|
||||
{
|
||||
struct osmo_gsup_conn *conn;
|
||||
|
||||
conn = gsup_route_find(gs, addr, addrlen);
|
||||
if (!conn) {
|
||||
DEBUGP(DMAIN, "Cannot find route for addr %s\n", addr);
|
||||
msgb_free(msg);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return osmo_gsup_conn_send(conn, msg);
|
||||
}
|
||||
|
||||
/*! Transmit UPD_LOC_ERROR and destroy lu_operation */
|
||||
void lu_op_tx_error(struct lu_operation *luop, enum gsm48_gmm_cause cause)
|
||||
{
|
||||
@@ -229,44 +215,27 @@ void lu_op_tx_cancel_old(struct lu_operation *luop)
|
||||
/*! Transmit Insert Subscriber Data to new VLR/SGSN */
|
||||
void lu_op_tx_insert_subscr_data(struct lu_operation *luop)
|
||||
{
|
||||
struct osmo_gsup_message gsup;
|
||||
struct hlr_subscriber *subscr = &luop->subscr;
|
||||
struct osmo_gsup_message gsup = { };
|
||||
uint8_t msisdn_enc[OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN];
|
||||
uint8_t apn[APN_MAXLEN];
|
||||
uint8_t msisdn_enc[43]; /* TODO use constant; TS 24.008 10.5.4.7 */
|
||||
int l;
|
||||
enum osmo_gsup_cn_domain cn_domain;
|
||||
|
||||
OSMO_ASSERT(luop->state == LU_S_LU_RECEIVED ||
|
||||
luop->state == LU_S_CANCEL_ACK_RECEIVED);
|
||||
|
||||
fill_gsup_msg(&gsup, luop, OSMO_GSUP_MSGT_INSERT_DATA_REQUEST);
|
||||
if (luop->is_ps)
|
||||
cn_domain = OSMO_GSUP_CN_DOMAIN_PS;
|
||||
else
|
||||
cn_domain = OSMO_GSUP_CN_DOMAIN_CS;
|
||||
|
||||
l = gsm48_encode_bcd_number(msisdn_enc, sizeof(msisdn_enc), 0,
|
||||
luop->subscr.msisdn);
|
||||
if (l < 1) {
|
||||
if (osmo_gsup_create_insert_subscriber_data_msg(&gsup, subscr->imsi, subscr->msisdn, msisdn_enc,
|
||||
sizeof(msisdn_enc), apn, sizeof(apn), cn_domain) != 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR,
|
||||
"%s: Error: cannot encode MSISDN '%s'\n",
|
||||
luop->subscr.imsi, luop->subscr.msisdn);
|
||||
lu_op_tx_error(luop, GMM_CAUSE_PROTO_ERR_UNSPEC);
|
||||
"IMSI='%s': Cannot notify GSUP client; could not create gsup message "
|
||||
"for %s\n", subscr->imsi, luop->peer);
|
||||
return;
|
||||
}
|
||||
gsup.msisdn_enc = msisdn_enc;
|
||||
gsup.msisdn_enc_len = l;
|
||||
|
||||
/* FIXME: deal with encoding the following data */
|
||||
gsup.hlr_enc;
|
||||
|
||||
if (luop->is_ps) {
|
||||
/* FIXME: PDP infos - use more fine-grained access control
|
||||
instead of wildcard APN */
|
||||
l = osmo_apn_from_str(apn, sizeof(apn), "*");
|
||||
if (l > 0) {
|
||||
gsup.pdp_infos[0].apn_enc = apn;
|
||||
gsup.pdp_infos[0].apn_enc_len = l;
|
||||
gsup.pdp_infos[0].have_info = 1;
|
||||
gsup.num_pdp_infos = 1;
|
||||
/* FIXME: use real value: */
|
||||
gsup.pdp_infos[0].context_id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send ISD to new VLR/SGSN */
|
||||
_luop_tx_gsup(luop, &gsup);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
#include "db.h"
|
||||
#include "gsup_server.h"
|
||||
|
||||
#define CANCEL_TIMEOUT_SECS 30
|
||||
#define ISD_TIMEOUT_SECS 30
|
||||
@@ -62,9 +63,6 @@ struct lu_operation {
|
||||
uint8_t *peer;
|
||||
};
|
||||
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg);
|
||||
|
||||
struct lu_operation *lu_op_alloc(struct osmo_gsup_server *srv);
|
||||
struct lu_operation *lu_op_alloc_conn(struct osmo_gsup_conn *conn);
|
||||
|
||||
239
src/osmo-euse-demo.c
Normal file
239
src/osmo-euse-demo.c
Normal file
@@ -0,0 +1,239 @@
|
||||
/* osmo-demo-euse: An External USSD Entity (EUSE) for demo purpose */
|
||||
|
||||
/* (C) 2018 by Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program illustrates how to implement an external USSD application using
|
||||
* the existing osmocom libraries, particularly libosmocore, libosmogsm and libosmo-gsup-client.
|
||||
*
|
||||
* It will receive any MS-originated USSD message that is routed to it via the HLR, and
|
||||
* simply respond it quoted in the following string: 'You sent "foobar"' (assuming the original
|
||||
* message was 'foobar').
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
#include <osmocom/gsm/gsm0480.h>
|
||||
#include <osmocom/gsm/protocol/gsm_04_80.h>
|
||||
|
||||
#include <osmocom/gsupclient/gsup_client.h>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
static struct osmo_gsup_client *g_gc;
|
||||
|
||||
/*! send a SS/USSD response to a given imsi/session.
|
||||
* \param[in] gsupc GSUP client connection through which to send
|
||||
* \param[in] imsi IMSI of the subscriber
|
||||
* \param[in] session_id Unique identifier of SS session for which this response is
|
||||
* \param[in] gsup_msg_type GSUP message type (OSMO_GSUP_MSGT_PROC_SS_{REQUEST,RESULT,ERROR})
|
||||
* \param[in] final Is this the final result (true=END) or an intermediate result (false=CONTINUE)
|
||||
* \param[in] msg Optional binary/BER encoded SS date (for FACILITY IE). Can be NULL. Freed in
|
||||
* this function call.
|
||||
*/
|
||||
static int euse_tx_ss(struct osmo_gsup_client *gsupc, const char *imsi, uint32_t session_id,
|
||||
enum osmo_gsup_message_type gsup_msg_type, bool final, struct msgb *ss_msg)
|
||||
{
|
||||
struct osmo_gsup_message resp = {0};
|
||||
struct msgb *resp_msg;
|
||||
|
||||
switch (gsup_msg_type) {
|
||||
case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
|
||||
case OSMO_GSUP_MSGT_PROC_SS_RESULT:
|
||||
case OSMO_GSUP_MSGT_PROC_SS_ERROR:
|
||||
break;
|
||||
default:
|
||||
msgb_free(ss_msg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
resp.message_type = gsup_msg_type;
|
||||
OSMO_STRLCPY_ARRAY(resp.imsi, imsi);
|
||||
if (final)
|
||||
resp.session_state = OSMO_GSUP_SESSION_STATE_END;
|
||||
else
|
||||
resp.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
|
||||
resp.session_id = session_id;
|
||||
if (ss_msg) {
|
||||
resp.ss_info = msgb_data(ss_msg);
|
||||
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);
|
||||
return osmo_gsup_client_send(gsupc, resp_msg);
|
||||
}
|
||||
|
||||
/*! send a SS/USSD reject to a given IMSI/session.
|
||||
* \param[in] gsupc GSUP client connection through which to send
|
||||
* \param[in] imsi IMSI of the subscriber
|
||||
* \param[in] session_id Unique identifier of SS session for which this response is
|
||||
* \param[in] invoke_id InvokeID of the request
|
||||
* \param[in] problem_tag Problem code tag (table 3.13)
|
||||
* \param[in] problem_code Problem code (table 3.14-3.17)
|
||||
*/
|
||||
static int euse_tx_ussd_reject(struct osmo_gsup_client *gsupc, const char *imsi, uint32_t session_id,
|
||||
int invoke_id, uint8_t problem_tag, uint8_t problem_code)
|
||||
{
|
||||
struct msgb *msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code);
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Tx %s/0x%08x: Reject(%d, 0x%02x, 0x%02x)\n", imsi, session_id,
|
||||
invoke_id, problem_tag, problem_code);
|
||||
OSMO_ASSERT(msg);
|
||||
return euse_tx_ss(gsupc, imsi, session_id, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg);
|
||||
}
|
||||
|
||||
/*! send a SS/USSD response in 7-bit GSM default alphabet o a given imsi/session.
|
||||
* \param[in] gsupc GSUP client connection through which to send
|
||||
* \param[in] imsi IMSI of the subscriber
|
||||
* \param[in] session_id Unique identifier of SS session for which this response is
|
||||
* \param[in] final Is this the final result (true=END) or an intermediate result
|
||||
* (false=CONTINUE)
|
||||
* \param[in] invoke_id InvokeID of the request
|
||||
*/
|
||||
static int euse_tx_ussd_resp_7bit(struct osmo_gsup_client *gsupc, const char *imsi, uint32_t session_id,
|
||||
bool final, uint8_t invoke_id, const char *text)
|
||||
{
|
||||
struct msgb *ss_msg;
|
||||
|
||||
/* encode response; remove L3 header */
|
||||
ss_msg = gsm0480_gen_ussd_resp_7bit(invoke_id, text);
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Tx %s/0x%08x: USSD Result(%d, %s, '%s')\n", imsi, session_id,
|
||||
invoke_id, final ? "END" : "CONTINUE", text);
|
||||
OSMO_ASSERT(ss_msg);
|
||||
return euse_tx_ss(gsupc, imsi, session_id, OSMO_GSUP_MSGT_PROC_SS_RESULT, final, ss_msg);
|
||||
}
|
||||
|
||||
static int euse_rx_proc_ss_req(struct osmo_gsup_client *gsupc, const struct osmo_gsup_message *gsup)
|
||||
{
|
||||
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
|
||||
struct ss_request req = {0};
|
||||
|
||||
if (gsup->ss_info && gsup->ss_info_len) {
|
||||
if (gsm0480_parse_facility_ie(gsup->ss_info, gsup->ss_info_len, &req)) {
|
||||
return euse_tx_ussd_reject(gsupc, gsup->imsi, gsup->session_id, -1,
|
||||
GSM_0480_PROBLEM_CODE_TAG_GENERAL,
|
||||
GSM_0480_GEN_PROB_CODE_BAD_STRUCTURE);
|
||||
}
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_INFO, "Rx %s/0x%08x: USSD SessionState=%s, OpCode=%s, '%s'\n", gsup->imsi,
|
||||
gsup->session_id, osmo_gsup_session_state_name(gsup->session_state),
|
||||
gsm0480_op_code_name(req.opcode), req.ussd_text);
|
||||
|
||||
/* we only handle single-request-response USSD in this demo */
|
||||
if (gsup->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) {
|
||||
return euse_tx_ussd_reject(gsupc, gsup->imsi, gsup->session_id, req.invoke_id,
|
||||
GSM_0480_PROBLEM_CODE_TAG_GENERAL,
|
||||
GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "You sent \"%s\"", req.ussd_text);
|
||||
return euse_tx_ussd_resp_7bit(gsupc, gsup->imsi, gsup->session_id, true, req.invoke_id, buf);
|
||||
}
|
||||
|
||||
static int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg)
|
||||
{
|
||||
struct osmo_gsup_message gsup_msg = {0};
|
||||
int rc;
|
||||
|
||||
rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup_msg);
|
||||
if (rc < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error decoding GSUP: %s\n", msgb_hexdump(msg));
|
||||
return rc;
|
||||
}
|
||||
DEBUGP(DMAIN, "Rx GSUP %s: %s\n", osmo_gsup_message_type_name(gsup_msg.message_type),
|
||||
msgb_hexdump(msg));
|
||||
|
||||
switch (gsup_msg.message_type) {
|
||||
case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
|
||||
case OSMO_GSUP_MSGT_PROC_SS_RESULT:
|
||||
euse_rx_proc_ss_req(gsupc, &gsup_msg);
|
||||
break;
|
||||
case OSMO_GSUP_MSGT_PROC_SS_ERROR:
|
||||
break;
|
||||
default:
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
|
||||
osmo_gsup_message_type_name(gsup_msg.message_type));
|
||||
break;
|
||||
}
|
||||
|
||||
msgb_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct log_info_cat default_categories[] = {
|
||||
[DMAIN] = {
|
||||
.name = "DMAIN",
|
||||
.description = "Main Program",
|
||||
.enabled = 1, .loglevel = LOGL_DEBUG,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct log_info gsup_log_info = {
|
||||
.cat = default_categories,
|
||||
.num_cat = ARRAY_SIZE(default_categories),
|
||||
};
|
||||
|
||||
static void print_usage(void)
|
||||
{
|
||||
printf("Usage: osmo-euse-demo [hlr-ip [hlr-gsup-port]]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *server_host = "127.0.0.1";
|
||||
uint16_t server_port = OSMO_GSUP_PORT;
|
||||
void *ctx = talloc_named_const(NULL, 0, "demo-euse");
|
||||
|
||||
osmo_init_logging2(ctx, &gsup_log_info);
|
||||
|
||||
printf("argc=%d\n", argc);
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
|
||||
print_usage();
|
||||
exit(0);
|
||||
} else
|
||||
server_host = argv[1];
|
||||
}
|
||||
if (argc > 2)
|
||||
server_port = atoi(argv[2]);
|
||||
|
||||
g_gc = osmo_gsup_client_create(ctx, "EUSE-foobar", server_host, server_port, gsupc_read_cb, NULL);
|
||||
|
||||
while (1) {
|
||||
osmo_select_main(0);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ SUBDIRS = \
|
||||
auc \
|
||||
gsup_server \
|
||||
db \
|
||||
gsup \
|
||||
$(NULL)
|
||||
|
||||
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
|
||||
@@ -43,6 +44,10 @@ python-tests:
|
||||
# don't run vty and ctrl tests concurrently so that the ports don't conflict
|
||||
$(MAKE) vty-test
|
||||
$(MAKE) ctrl-test
|
||||
else
|
||||
python-tests:
|
||||
echo "Not running python-based external tests (determined at configure-time)"
|
||||
endif
|
||||
|
||||
VTY_TEST_DB = hlr_vty_test.db
|
||||
|
||||
@@ -56,6 +61,7 @@ vty-test:
|
||||
-r "$(top_builddir)/src/osmo-hlr -c $(top_srcdir)/doc/examples/osmo-hlr.cfg -l $(VTY_TEST_DB)" \
|
||||
$(U) $(srcdir)/*.vty
|
||||
-rm -f $(VTY_TEST_DB)
|
||||
-rm $(VTY_TEST_DB)-*
|
||||
|
||||
CTRL_TEST_DB = hlr_ctrl_test.db
|
||||
|
||||
@@ -71,11 +77,7 @@ ctrl-test:
|
||||
-r "$(top_builddir)/src/osmo-hlr -c $(top_srcdir)/doc/examples/osmo-hlr.cfg -l $(CTRL_TEST_DB)" \
|
||||
$(U) $(srcdir)/*.ctrl
|
||||
-rm -f $(CTRL_TEST_DB)
|
||||
|
||||
else
|
||||
python-tests:
|
||||
echo "Not running python-based tests (determined at configure-time)"
|
||||
endif
|
||||
-rm $(CTRL_TEST_DB)-*
|
||||
|
||||
check-local: atconfig $(TESTSUITE)
|
||||
$(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
|
||||
|
||||
@@ -610,7 +610,9 @@ int main(int argc, char **argv)
|
||||
|
||||
handle_options(argc, argv);
|
||||
|
||||
osmo_init_logging(&hlr_log_info);
|
||||
void *tall_ctx = talloc_named_const(NULL, 1, "auc_test");
|
||||
|
||||
osmo_init_logging2(tall_ctx, &hlr_log_info);
|
||||
log_set_print_filename(osmo_stderr_target, cmdline_opts.verbose);
|
||||
log_set_print_timestamp(osmo_stderr_target, 0);
|
||||
log_set_use_color(osmo_stderr_target, 0);
|
||||
|
||||
@@ -35,7 +35,7 @@ DAUC vector [0]: ck = f64735036e5871319c679f4742a75ea1
|
||||
DAUC vector [0]: ik = 27497388b6cb044648f396aa155b95ef
|
||||
DAUC vector [0]: res = e229c19e791f2e410000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: calculating 2G separately
|
||||
DAUC vector [0]: kc = 241a5b16aeb8e400
|
||||
DAUC vector [0]: sres = 429d5b27
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -55,7 +55,7 @@ DAUC vector [0]: ck = f64735036e5871319c679f4742a75ea1
|
||||
DAUC vector [0]: ik = 27497388b6cb044648f396aa155b95ef
|
||||
DAUC vector [0]: res = e229c19e791f2e410000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: calculating 2G separately
|
||||
DAUC vector [0]: kc = 241a5b16aeb8e400
|
||||
DAUC vector [0]: sres = 429d5b27
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -78,6 +78,7 @@ DAUC vector [0]: ck = f64735036e5871319c679f4742a75ea1
|
||||
DAUC vector [0]: ik = 27497388b6cb044648f396aa155b95ef
|
||||
DAUC vector [0]: res = e229c19e791f2e410000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 059a4f668f6fbe39
|
||||
DAUC vector [0]: sres = 9b36efdf
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -96,6 +97,7 @@ DAUC vector [0]: ck = f64735036e5871319c679f4742a75ea1
|
||||
DAUC vector [0]: ik = 27497388b6cb044648f396aa155b95ef
|
||||
DAUC vector [0]: res = e229c19e791f2e410000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 059a4f668f6fbe39
|
||||
DAUC vector [0]: sres = 9b36efdf
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -117,6 +119,7 @@ DAUC vector [0]: ck = e9922bd036718ed9e40bd1d02c3b81a5
|
||||
DAUC vector [0]: ik = f19c20ca863137f8892326d959ec5e01
|
||||
DAUC vector [0]: res = 9af5a557902d2db80000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 7526fc13c5976685
|
||||
DAUC vector [0]: sres = 0ad888ef
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -137,6 +140,7 @@ DAUC vector [0]: ck = e9922bd036718ed9e40bd1d02c3b81a5
|
||||
DAUC vector [0]: ik = f19c20ca863137f8892326d959ec5e01
|
||||
DAUC vector [0]: res = 9af5a557902d2db80000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 7526fc13c5976685
|
||||
DAUC vector [0]: sres = 0ad888ef
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -147,6 +151,7 @@ DAUC vector [1]: ck = 3686f05df057d1899c66ae4eb18cf941
|
||||
DAUC vector [1]: ik = 79f21ed53bcb47787de57d136ff803a5
|
||||
DAUC vector [1]: res = 43023475cb29292c0000000000000000
|
||||
DAUC vector [1]: res_len = 8
|
||||
DAUC vector [1]: deriving 2G from 3G
|
||||
DAUC vector [1]: kc = aef73dd515e86c15
|
||||
DAUC vector [1]: sres = 882b1d59
|
||||
DAUC vector [1]: auth_types = 0x3
|
||||
@@ -157,6 +162,7 @@ DAUC vector [2]: ck = d86c3191a36fc0602e48202ef2080964
|
||||
DAUC vector [2]: ik = 648dab72016181406243420649e63dc9
|
||||
DAUC vector [2]: res = 010cab11cc63a6e40000000000000000
|
||||
DAUC vector [2]: res_len = 8
|
||||
DAUC vector [2]: deriving 2G from 3G
|
||||
DAUC vector [2]: kc = f0eaf8cb19e0758d
|
||||
DAUC vector [2]: sres = cd6f0df5
|
||||
DAUC vector [2]: auth_types = 0x3
|
||||
@@ -179,6 +185,7 @@ DAUC vector [0]: ck = e9922bd036718ed9e40bd1d02c3b81a5
|
||||
DAUC vector [0]: ik = f19c20ca863137f8892326d959ec5e01
|
||||
DAUC vector [0]: res = 9af5a557902d2db80000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 7526fc13c5976685
|
||||
DAUC vector [0]: sres = 0ad888ef
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -189,6 +196,7 @@ DAUC vector [1]: ck = 3686f05df057d1899c66ae4eb18cf941
|
||||
DAUC vector [1]: ik = 79f21ed53bcb47787de57d136ff803a5
|
||||
DAUC vector [1]: res = 43023475cb29292c0000000000000000
|
||||
DAUC vector [1]: res_len = 8
|
||||
DAUC vector [1]: deriving 2G from 3G
|
||||
DAUC vector [1]: kc = aef73dd515e86c15
|
||||
DAUC vector [1]: sres = 882b1d59
|
||||
DAUC vector [1]: auth_types = 0x3
|
||||
@@ -199,6 +207,7 @@ DAUC vector [2]: ck = d86c3191a36fc0602e48202ef2080964
|
||||
DAUC vector [2]: ik = 648dab72016181406243420649e63dc9
|
||||
DAUC vector [2]: res = 010cab11cc63a6e40000000000000000
|
||||
DAUC vector [2]: res_len = 8
|
||||
DAUC vector [2]: deriving 2G from 3G
|
||||
DAUC vector [2]: kc = f0eaf8cb19e0758d
|
||||
DAUC vector [2]: sres = cd6f0df5
|
||||
DAUC vector [2]: auth_types = 0x3
|
||||
|
||||
@@ -12,6 +12,7 @@ DAUC vector [0]: ck = b40ba9a3c58b2a05bbf0d987b21bf8cb
|
||||
DAUC vector [0]: ik = f769bcd751044604127672711c6d3441
|
||||
DAUC vector [0]: res = a54211d5e3ba50bf0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = eae4be823af9a08b
|
||||
DAUC vector [0]: sres = 46f8416a
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -34,6 +35,7 @@ DAUC vector [0]: ck = 5dbdbb2954e8f3cde665b046179a5098
|
||||
DAUC vector [0]: ik = 59a92d3b476a0443487055cf88b2307b
|
||||
DAUC vector [0]: res = 8011c48c0c214ed20000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = aa01739b8caa976d
|
||||
DAUC vector [0]: sres = 8c308a5e
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -56,6 +58,7 @@ DAUC vector [0]: ck = e203edb3971574f5a94b0d61b816345d
|
||||
DAUC vector [0]: ik = 0c4524adeac041c4dd830d20854fc46b
|
||||
DAUC vector [0]: res = f365cd683cd92e960000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 9a8ec95f408cc507
|
||||
DAUC vector [0]: sres = cfbce3fe
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -78,6 +81,7 @@ DAUC vector [0]: ck = 7657766b373d1c2138f307e3de9242f9
|
||||
DAUC vector [0]: ik = 1c42e960d89b8fa99f2744e0708ccb53
|
||||
DAUC vector [0]: res = 5860fc1bce351e7e0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = cdc1dc0841b81a22
|
||||
DAUC vector [0]: sres = 9655e265
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -100,6 +104,7 @@ DAUC vector [0]: ck = 3f8c7587fe8e4b233af676aede30ba3b
|
||||
DAUC vector [0]: ik = a7466cc1e6b2a1337d49d3b66e95d7b4
|
||||
DAUC vector [0]: res = 16c8233f05a0ac280000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = df75bc5ea899879f
|
||||
DAUC vector [0]: sres = 13688f17
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -122,6 +127,7 @@ DAUC vector [0]: ck = 4cd0846020f8fa0731dd47cbdc6be411
|
||||
DAUC vector [0]: ik = 88ab80a415f15c73711254a1d388f696
|
||||
DAUC vector [0]: res = 8c25a16cd918a1df0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 84b417ae3aeab4f3
|
||||
DAUC vector [0]: sres = 553d00b3
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -144,6 +150,7 @@ DAUC vector [0]: ck = 10f05bab75a99a5fbb98a9c287679c3b
|
||||
DAUC vector [0]: ik = f9ec0865eb32f22369cade40c59c3a44
|
||||
DAUC vector [0]: res = a63241e1ffc3e5ab0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 3b4e244cdc60ce03
|
||||
DAUC vector [0]: sres = 59f1a44a
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -166,6 +173,7 @@ DAUC vector [0]: ck = 71236b7129f9b22ab77ea7a54c96da22
|
||||
DAUC vector [0]: ik = 90527ebaa5588968db41727325a04d9e
|
||||
DAUC vector [0]: res = 4a90b2171ac83a760000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 8d4ec01de597acfe
|
||||
DAUC vector [0]: sres = 50588861
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -188,6 +196,7 @@ DAUC vector [0]: ck = 08cef6d004ec61471a3c3cda048137fa
|
||||
DAUC vector [0]: ik = ed0318ca5deb9206272f6e8fa64ba411
|
||||
DAUC vector [0]: res = 4bc2212d8624910a0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = d8debc4ffbcd60aa
|
||||
DAUC vector [0]: sres = cde6b027
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -210,6 +219,7 @@ DAUC vector [0]: ck = 69b1cae7c7429d975e245cacb05a517c
|
||||
DAUC vector [0]: ik = 74f24e8c26df58e1b38d7dcd4f1b7fbd
|
||||
DAUC vector [0]: res = 6fc30fee6d1235230000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = f0eaa50a1edcebb7
|
||||
DAUC vector [0]: sres = 02d13acd
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -232,6 +242,7 @@ DAUC vector [0]: ck = 908c43f0569cb8f74bc971e706c36c5f
|
||||
DAUC vector [0]: ik = c251df0d888dd9329bcf46655b226e40
|
||||
DAUC vector [0]: res = aefa357beac2a87a0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 82dbab7f83f063da
|
||||
DAUC vector [0]: sres = 44389d01
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -254,6 +265,7 @@ DAUC vector [0]: ck = 44c0f23c5493cfd241e48f197e1d1012
|
||||
DAUC vector [0]: ik = 0c9fb81613884c2535dd0eabf3b440d8
|
||||
DAUC vector [0]: res = 98dbbd099b3b408d0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 3c66cb98cab2d33d
|
||||
DAUC vector [0]: sres = 03e0fd84
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -276,6 +288,7 @@ DAUC vector [0]: ck = 5af86b80edb70df5292cc1121cbad50c
|
||||
DAUC vector [0]: ik = 7f4d6ae7440e18789a8b75ad3f42f03a
|
||||
DAUC vector [0]: res = af4a411e1139f2c20000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 9612b5d88a4130bb
|
||||
DAUC vector [0]: sres = be73b3dc
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -298,6 +311,7 @@ DAUC vector [0]: ck = 3f8c3f3ccf7625bf77fc94bcfd22fd26
|
||||
DAUC vector [0]: ik = abcbae8fd46115e9961a55d0da5f2078
|
||||
DAUC vector [0]: res = 7bffa5c2f41fbc050000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 75a150df3c6aed08
|
||||
DAUC vector [0]: sres = 8fe019c7
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -320,6 +334,7 @@ DAUC vector [0]: ck = d42b2d615e49a03ac275a5aef97af892
|
||||
DAUC vector [0]: ik = 0b3f8d024fe6bfafaa982b8f82e319c2
|
||||
DAUC vector [0]: res = 7e3f44c7591f6f450000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = b7f92e426a36fec5
|
||||
DAUC vector [0]: sres = 27202b82
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -342,6 +357,7 @@ DAUC vector [0]: ck = 6edaf99e5bd9f85d5f36d91c1272fb4b
|
||||
DAUC vector [0]: ik = d61c853c280dd9c46f297baec386de17
|
||||
DAUC vector [0]: res = 70f6bdb9ad21525f0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 88d9de10a22004c5
|
||||
DAUC vector [0]: sres = ddd7efe6
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -364,6 +380,7 @@ DAUC vector [0]: ck = 66195dbed0313274c5ca7766615fa25e
|
||||
DAUC vector [0]: ik = 66bec707eb2afc476d7408a8f2927b36
|
||||
DAUC vector [0]: res = 479dd25c20792d630000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = a819e577a8d6175b
|
||||
DAUC vector [0]: sres = 67e4ff3f
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -386,6 +403,7 @@ DAUC vector [0]: ck = 5349fbe098649f948f5d2e973a81c00f
|
||||
DAUC vector [0]: ik = 9744871ad32bf9bbd1dd5ce54e3e2e5a
|
||||
DAUC vector [0]: res = 28d7b0f2a2ec3de50000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = 9a8d0e883ff0887a
|
||||
DAUC vector [0]: sres = 8a3b8d17
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
@@ -408,6 +426,7 @@ DAUC vector [0]: ck = b5f2da03883b69f96bf52e029ed9ac45
|
||||
DAUC vector [0]: ik = b4721368bc16ea67875c5598688bb0ef
|
||||
DAUC vector [0]: res = a95100e2760952cd0000000000000000
|
||||
DAUC vector [0]: res_len = 8
|
||||
DAUC vector [0]: deriving 2G from 3G
|
||||
DAUC vector [0]: kc = ed29b2f1c27f9f34
|
||||
DAUC vector [0]: sres = df58522f
|
||||
DAUC vector [0]: auth_types = 0x3
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
|
||||
#include <osmocom/crypt/auth.h>
|
||||
|
||||
@@ -102,7 +103,9 @@ FUNCTIONS
|
||||
int main()
|
||||
{
|
||||
printf("3GPP TS 55.205 Test Sets\n");
|
||||
osmo_init_logging(&hlr_log_info);
|
||||
void *tall_ctx = talloc_named_const(NULL, 1, "test");
|
||||
msgb_talloc_ctx_init(tall_ctx, 0);
|
||||
osmo_init_logging2(tall_ctx, &hlr_log_info);
|
||||
log_set_print_filename(osmo_stderr_target, 0);
|
||||
log_set_print_timestamp(osmo_stderr_target, 0);
|
||||
log_set_use_color(osmo_stderr_target, 0);
|
||||
|
||||
@@ -6,6 +6,7 @@ AM_CFLAGS = \
|
||||
-ggdb3 \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(LIBOSMOABIS_CFLAGS) \
|
||||
$(SQLITE3_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
@@ -27,6 +28,7 @@ db_test_LDADD = \
|
||||
$(top_srcdir)/src/logging.c \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(LIBOSMOABIS_LIBS) \
|
||||
$(SQLITE3_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -100,6 +100,22 @@ static void _fill_invalid(void *dest, size_t size)
|
||||
fprintf(stderr, "\n"); \
|
||||
} while (0)
|
||||
|
||||
#define N_VECTORS 3
|
||||
|
||||
#define ASSERT_DB_GET_AUC(imsi, expect_rc) \
|
||||
do { \
|
||||
struct osmo_auth_vector vec[N_VECTORS]; \
|
||||
ASSERT_RC(db_get_auc(dbc, imsi, 3, vec, N_VECTORS, NULL, NULL), expect_rc); \
|
||||
} while (0)
|
||||
|
||||
/* Not linking the real auc_compute_vectors(), just returning num_vec.
|
||||
* This gets called by db_get_auc(), but we're only interested in its rc. */
|
||||
int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
|
||||
struct osmo_sub_auth_data *aud2g,
|
||||
struct osmo_sub_auth_data *aud3g,
|
||||
const uint8_t *rand_auts, const uint8_t *auts)
|
||||
{ return num_vec; }
|
||||
|
||||
static struct db_context *dbc = NULL;
|
||||
static void *ctx = NULL;
|
||||
static struct hlr_subscriber g_subscr;
|
||||
@@ -457,6 +473,7 @@ static void test_subscr_aud()
|
||||
|
||||
comment("Get auth data for non-existent subscriber");
|
||||
ASSERT_SEL_AUD(unknown_imsi, -ENOENT, 0);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOENT);
|
||||
|
||||
comment("Create subscriber");
|
||||
|
||||
@@ -464,7 +481,8 @@ static void test_subscr_aud()
|
||||
ASSERT_SEL(imsi, imsi0, 0);
|
||||
|
||||
id = g_subscr.id;
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOKEY);
|
||||
|
||||
|
||||
comment("Set auth data, 2G only");
|
||||
@@ -473,6 +491,7 @@ static void test_subscr_aud()
|
||||
mk_aud_2g(OSMO_AUTH_ALG_COMP128v1, "0123456789abcdef0123456789abcdef")),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, 0, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, N_VECTORS);
|
||||
|
||||
/* same again */
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
@@ -500,7 +519,8 @@ static void test_subscr_aud()
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
mk_aud_2g(OSMO_AUTH_ALG_NONE, NULL)),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOKEY);
|
||||
|
||||
/* Removing nothing results in -ENOENT */
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
@@ -515,7 +535,8 @@ static void test_subscr_aud()
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
mk_aud_2g(OSMO_AUTH_ALG_NONE, "f000000000000f00000000000f000000")),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOKEY);
|
||||
|
||||
|
||||
comment("Set auth data, 3G only");
|
||||
@@ -526,6 +547,7 @@ static void test_subscr_aud()
|
||||
"C01ffedC1cadaeAc1d1f1edAcac1aB0a", 5)),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, 0, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, N_VECTORS);
|
||||
|
||||
/* same again */
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
@@ -562,7 +584,8 @@ static void test_subscr_aud()
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
mk_aud_3g(OSMO_AUTH_ALG_NONE, NULL, false, NULL, 0)),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOKEY);
|
||||
|
||||
/* Removing nothing results in -ENOENT */
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
@@ -575,13 +598,15 @@ static void test_subscr_aud()
|
||||
"BeefedCafeFaceAcedAddedDecadeFee", 5)),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, 0, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, N_VECTORS);
|
||||
|
||||
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
|
||||
mk_aud_3g(OSMO_AUTH_ALG_NONE,
|
||||
"asdfasdfasd", false,
|
||||
"asdfasdfasdf", 99999)),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOKEY);
|
||||
|
||||
|
||||
comment("Set auth data, 2G and 3G");
|
||||
@@ -595,6 +620,7 @@ static void test_subscr_aud()
|
||||
"DeafBeddedBabeAcceededFadedDecaf", 5)),
|
||||
0);
|
||||
ASSERT_SEL_AUD(imsi0, 0, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, N_VECTORS);
|
||||
|
||||
|
||||
comment("Set invalid auth data");
|
||||
@@ -669,10 +695,12 @@ static void test_subscr_aud()
|
||||
/* For this test to work, we want to get the same subscriber ID back,
|
||||
* and make sure there are no auth data leftovers for this ID. */
|
||||
OSMO_ASSERT(id == g_subscr.id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOKEY);
|
||||
|
||||
ASSERT_RC(db_subscr_delete_by_id(dbc, id), 0);
|
||||
ASSERT_SEL(imsi, imsi0, -ENOENT);
|
||||
ASSERT_DB_GET_AUC(imsi0, -ENOENT);
|
||||
|
||||
comment_end();
|
||||
}
|
||||
@@ -697,15 +725,15 @@ static void test_subscr_sqn()
|
||||
ASSERT_SEL(imsi, imsi0, 0);
|
||||
|
||||
id = g_subscr.id;
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
|
||||
comment("Set SQN, but no 3G auth data present");
|
||||
|
||||
ASSERT_RC(db_update_sqn(dbc, id, 123), -ENOENT);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
|
||||
ASSERT_RC(db_update_sqn(dbc, id, 543), -ENOENT);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOENT, id);
|
||||
ASSERT_SEL_AUD(imsi0, -ENOKEY, id);
|
||||
|
||||
comment("Set auth 3G data");
|
||||
|
||||
@@ -811,7 +839,7 @@ int main(int argc, char **argv)
|
||||
|
||||
handle_options(argc, argv);
|
||||
|
||||
osmo_init_logging(&hlr_log_info);
|
||||
osmo_init_logging2(ctx, &hlr_log_info);
|
||||
log_set_print_filename(osmo_stderr_target, cmdline_opts.verbose);
|
||||
log_set_print_timestamp(osmo_stderr_target, 0);
|
||||
log_set_use_color(osmo_stderr_target, 0);
|
||||
@@ -820,7 +848,9 @@ int main(int argc, char **argv)
|
||||
|
||||
/* omit the SQLite version and compilation flags from test output */
|
||||
log_set_log_level(osmo_stderr_target, LOGL_ERROR);
|
||||
dbc = db_open(ctx, "db_test.db");
|
||||
/* Disable SQLite logging so that we're not vulnerable on SQLite error messages changing across
|
||||
* library versions. */
|
||||
dbc = db_open(ctx, "db_test.db", false, false);
|
||||
log_set_log_level(osmo_stderr_target, 0);
|
||||
OSMO_ASSERT(dbc);
|
||||
|
||||
@@ -833,11 +863,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* stubs */
|
||||
int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
|
||||
struct osmo_sub_auth_data *aud2g,
|
||||
struct osmo_sub_auth_data *aud3g,
|
||||
const uint8_t *rand_auts, const uint8_t *auts)
|
||||
{ OSMO_ASSERT(false); return -1; }
|
||||
void *lu_op_alloc_conn(void *conn)
|
||||
{ OSMO_ASSERT(false); return NULL; }
|
||||
void lu_op_tx_del_subscr_data(void *luop)
|
||||
|
||||
@@ -28,7 +28,6 @@ struct hlr_subscriber {
|
||||
}
|
||||
|
||||
db_subscr_create(dbc, imsi0) --> -EIO
|
||||
DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
|
||||
DAUC IMSI='123456789000000': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
|
||||
|
||||
db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
|
||||
@@ -38,11 +37,9 @@ struct hlr_subscriber {
|
||||
}
|
||||
|
||||
db_subscr_create(dbc, imsi1) --> -EIO
|
||||
DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
|
||||
DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
|
||||
|
||||
db_subscr_create(dbc, imsi1) --> -EIO
|
||||
DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
|
||||
DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
|
||||
|
||||
db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
|
||||
@@ -52,11 +49,9 @@ struct hlr_subscriber {
|
||||
}
|
||||
|
||||
db_subscr_create(dbc, imsi2) --> -EIO
|
||||
DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
|
||||
DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
|
||||
|
||||
db_subscr_create(dbc, imsi2) --> -EIO
|
||||
DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
|
||||
DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
|
||||
|
||||
db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0
|
||||
@@ -720,6 +715,9 @@ db_get_auth_data(dbc, unknown_imsi, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
DAUC IMSI='999999999': No such subscriber
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -2
|
||||
DAUC IMSI='123456789000000': No such subscriber
|
||||
|
||||
|
||||
--- Create subscriber
|
||||
|
||||
@@ -731,11 +729,15 @@ struct hlr_subscriber {
|
||||
.imsi = '123456789000000',
|
||||
}
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
--- Set auth data, 2G only
|
||||
|
||||
@@ -751,6 +753,11 @@ DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
}
|
||||
3G: none
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> 3
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
DAUC IMSI='123456789000000': Calling to generate 3 vectors
|
||||
DAUC IMSI='123456789000000': Generated 3 vectors
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_COMP128v1, "0123456789abcdef0123456789abcdef")) --> 0
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
|
||||
@@ -804,11 +811,15 @@ DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_NONE, NULL)) --> 0
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_NONE, NULL)) --> -ENOENT
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR, "CededEffacedAceFacedBadFadedBeef")) --> 0
|
||||
@@ -825,11 +836,15 @@ DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_NONE, "f000000000000f00000000000f000000")) --> 0
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
--- Set auth data, 3G only
|
||||
|
||||
@@ -849,6 +864,12 @@ DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
.u.umts.ind_bitlen = 5,
|
||||
}
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> 3
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': Calling to generate 3 vectors
|
||||
DAUC IMSI='123456789000000': Generated 3 vectors
|
||||
DAUC IMSI='123456789000000': Updating SQN=0 in DB
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_3g(OSMO_AUTH_ALG_MILENAGE, "BeefedCafeFaceAcedAddedDecadeFee", true, "C01ffedC1cadaeAc1d1f1edAcac1aB0a", 5)) --> 0
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
|
||||
@@ -917,11 +938,15 @@ DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_3g(OSMO_AUTH_ALG_NONE, NULL, false, NULL, 0)) --> 0
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_3g(OSMO_AUTH_ALG_NONE, NULL, false, NULL, 0)) --> -ENOENT
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_3g(OSMO_AUTH_ALG_MILENAGE, "CededEffacedAceFacedBadFadedBeef", false, "BeefedCafeFaceAcedAddedDecadeFee", 5)) --> 0
|
||||
@@ -940,13 +965,23 @@ DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
.u.umts.ind_bitlen = 5,
|
||||
}
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> 3
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': Calling to generate 3 vectors
|
||||
DAUC IMSI='123456789000000': Generated 3 vectors
|
||||
DAUC IMSI='123456789000000': Updating SQN=0 in DB
|
||||
|
||||
db_subscr_update_aud_by_id(dbc, id, mk_aud_3g(OSMO_AUTH_ALG_NONE, "asdfasdfasd", false, "asdfasdfasdf", 99999)) --> 0
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
--- Set auth data, 2G and 3G
|
||||
|
||||
@@ -971,6 +1006,11 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
|
||||
.u.umts.ind_bitlen = 5,
|
||||
}
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> 3
|
||||
DAUC IMSI='123456789000000': Calling to generate 3 vectors
|
||||
DAUC IMSI='123456789000000': Generated 3 vectors
|
||||
DAUC IMSI='123456789000000': Updating SQN=0 in DB
|
||||
|
||||
|
||||
--- Set invalid auth data
|
||||
|
||||
@@ -1179,16 +1219,23 @@ struct hlr_subscriber {
|
||||
.imsi = '123456789000000',
|
||||
}
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
db_subscr_delete_by_id(dbc, id) --> 0
|
||||
|
||||
db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> -ENOENT
|
||||
DAUC Cannot read subscriber from db: IMSI='123456789000000': No such subscriber
|
||||
|
||||
db_get_auc(dbc, imsi0, 3, vec, N_VECTORS, NULL, NULL) --> -2
|
||||
DAUC IMSI='123456789000000': No such subscriber
|
||||
|
||||
===== test_subscr_aud: SUCCESS
|
||||
|
||||
|
||||
@@ -1219,7 +1266,7 @@ struct hlr_subscriber {
|
||||
.imsi = '123456789000000',
|
||||
}
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
@@ -1230,7 +1277,7 @@ DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
db_update_sqn(dbc, id, 123) --> -ENOENT
|
||||
DAUC Cannot update SQN for subscriber ID=1: no auc_3g entry for such subscriber
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
@@ -1238,7 +1285,7 @@ DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
db_update_sqn(dbc, id, 543) --> -ENOENT
|
||||
DAUC Cannot update SQN for subscriber ID=1: no auc_3g entry for such subscriber
|
||||
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -2
|
||||
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -126
|
||||
DAUC IMSI='123456789000000': No 2G Auth Data
|
||||
DAUC IMSI='123456789000000': No 3G Auth Data
|
||||
|
||||
|
||||
41
tests/gsup/Makefile.am
Normal file
41
tests/gsup/Makefile.am
Normal file
@@ -0,0 +1,41 @@
|
||||
AM_CPPFLAGS = \
|
||||
$(all_includes) \
|
||||
-I$(top_srcdir)/src \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
-Wall \
|
||||
-ggdb3 \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(LIBOSMOABIS_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
AM_LDFLAGS = \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
gsup_test.ok \
|
||||
gsup_test.err \
|
||||
$(NULL)
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
gsup_test \
|
||||
$(NULL)
|
||||
|
||||
gsup_test_SOURCES = \
|
||||
gsup_test.c \
|
||||
$(NULL)
|
||||
|
||||
gsup_test_LDADD = \
|
||||
$(top_srcdir)/src/luop.c \
|
||||
$(top_srcdir)/src/gsup_server.c \
|
||||
$(top_srcdir)/src/gsup_router.c \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(LIBOSMOABIS_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
.PHONY: update_exp
|
||||
update_exp:
|
||||
$(builddir)/gsup_test >"$(srcdir)/gsup_test.ok" 2>"$(srcdir)/gsup_test.err"
|
||||
91
tests/gsup/gsup_test.c
Normal file
91
tests/gsup/gsup_test.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/* (C) 2018 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 <string.h>
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/gsm/gsup.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "luop.h"
|
||||
|
||||
struct osmo_gsup_server;
|
||||
|
||||
/* override osmo_gsup_addr_send() to not actually send anything. */
|
||||
int osmo_gsup_addr_send(struct osmo_gsup_server *gs,
|
||||
const uint8_t *addr, size_t addrlen,
|
||||
struct msgb *msg)
|
||||
{
|
||||
LOGP(DMAIN, LOGL_DEBUG, "%s\n", msgb_hexdump(msg));
|
||||
msgb_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
|
||||
struct hlr_subscriber *subscr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Verify that the internally allocated msgb is large enough */
|
||||
void test_gsup_tx_insert_subscr_data()
|
||||
{
|
||||
struct lu_operation luop = {
|
||||
.state = LU_S_LU_RECEIVED,
|
||||
.subscr = {
|
||||
.imsi = "123456789012345",
|
||||
.msisdn = "987654321098765",
|
||||
.nam_cs = true,
|
||||
.nam_ps = true,
|
||||
},
|
||||
.is_ps = true,
|
||||
};
|
||||
|
||||
lu_op_tx_insert_subscr_data(&luop);
|
||||
}
|
||||
|
||||
const struct log_info_cat default_categories[] = {
|
||||
[DMAIN] = {
|
||||
.name = "DMAIN",
|
||||
.description = "Main Program",
|
||||
.enabled = 1, .loglevel = LOGL_DEBUG,
|
||||
},
|
||||
};
|
||||
|
||||
static struct log_info info = {
|
||||
.cat = default_categories,
|
||||
.num_cat = ARRAY_SIZE(default_categories),
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *ctx = talloc_named_const(NULL, 0, "gsup_test");
|
||||
osmo_init_logging2(ctx, &info);
|
||||
log_set_print_filename(osmo_stderr_target, 0);
|
||||
log_set_print_timestamp(osmo_stderr_target, 0);
|
||||
log_set_use_color(osmo_stderr_target, 0);
|
||||
log_set_print_category(osmo_stderr_target, 1);
|
||||
|
||||
test_gsup_tx_insert_subscr_data();
|
||||
|
||||
printf("Done.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
2
tests/gsup/gsup_test.err
Normal file
2
tests/gsup/gsup_test.err
Normal file
@@ -0,0 +1,2 @@
|
||||
DMAIN 10 01 08 21 43 65 87 09 21 43 f5 08 09 08 89 67 45 23 01 89 67 f5 05 07 10 01 01 12 02 01 2a 28 01 01
|
||||
DMAIN LU OP state change: LU RECEIVED -> ISD SENT
|
||||
1
tests/gsup/gsup_test.ok
Normal file
1
tests/gsup/gsup_test.ok
Normal file
@@ -0,0 +1 @@
|
||||
Done.
|
||||
@@ -13,7 +13,12 @@ OsmoHLR> list
|
||||
...
|
||||
show logging vty
|
||||
show alarms
|
||||
show talloc-context (application|all) (full|brief|DEPTH)
|
||||
show talloc-context (application|all) (full|brief|DEPTH) tree ADDRESS
|
||||
show talloc-context (application|all) (full|brief|DEPTH) filter REGEXP
|
||||
show gsup-connections
|
||||
subscriber (imsi|msisdn|id) IDENT show
|
||||
show subscriber (imsi|msisdn|id) IDENT
|
||||
|
||||
OsmoHLR> enable
|
||||
OsmoHLR# list
|
||||
@@ -66,6 +71,14 @@ OsmoHLR(config-hlr)# list
|
||||
exit
|
||||
end
|
||||
gsup
|
||||
euse NAME
|
||||
no euse NAME
|
||||
ussd route prefix PREFIX internal (own-msisdn|own-imsi)
|
||||
ussd route prefix PREFIX external EUSE
|
||||
no ussd route prefix PREFIX
|
||||
ussd default-route external EUSE
|
||||
no ussd default-route
|
||||
ncss-guard-timeout <0-255>
|
||||
|
||||
OsmoHLR(config-hlr)# gsup
|
||||
OsmoHLR(config-hlr-gsup)# list
|
||||
@@ -96,22 +109,15 @@ Current configuration:
|
||||
!
|
||||
!
|
||||
log stderr
|
||||
logging filter all 1
|
||||
logging color 1
|
||||
logging print category 1
|
||||
logging print extended-timestamp 1
|
||||
logging level all debug
|
||||
logging level main notice
|
||||
logging level db notice
|
||||
logging level auc notice
|
||||
...
|
||||
!
|
||||
line vty
|
||||
no login
|
||||
!
|
||||
ctrl
|
||||
bind 127.0.0.1
|
||||
logging level main notice
|
||||
logging level db notice
|
||||
logging level auc notice
|
||||
logging level ss info
|
||||
...
|
||||
hlr
|
||||
gsup
|
||||
bind ip 127.0.0.1
|
||||
ussd route prefix *#100# internal own-msisdn
|
||||
ussd route prefix *#101# internal own-imsi
|
||||
end
|
||||
|
||||
@@ -3,9 +3,10 @@ OsmoHLR> enable
|
||||
OsmoHLR# list
|
||||
...
|
||||
subscriber (imsi|msisdn|id) IDENT show
|
||||
show subscriber (imsi|msisdn|id) IDENT
|
||||
subscriber imsi IDENT create
|
||||
subscriber (imsi|msisdn|id) IDENT delete
|
||||
subscriber (imsi|msisdn|id) IDENT update msisdn MSISDN
|
||||
subscriber (imsi|msisdn|id) IDENT update msisdn (none|MSISDN)
|
||||
subscriber (imsi|msisdn|id) IDENT update aud2g none
|
||||
subscriber (imsi|msisdn|id) IDENT update aud2g (comp128v1|comp128v2|comp128v3|xor) ki KI
|
||||
subscriber (imsi|msisdn|id) IDENT update aud3g none
|
||||
@@ -33,6 +34,13 @@ OsmoHLR# subscriber id 1 show
|
||||
OsmoHLR# subscriber msisdn 12345 show
|
||||
% No subscriber for msisdn = '12345'
|
||||
|
||||
OsmoHLR# show subscriber imsi 123456789023000
|
||||
% No subscriber for imsi = '123456789023000'
|
||||
OsmoHLR# show subscriber id 1
|
||||
% No subscriber for id = '1'
|
||||
OsmoHLR# show subscriber msisdn 12345
|
||||
% No subscriber for msisdn = '12345'
|
||||
|
||||
OsmoHLR# subscriber imsi 1234567890230001 create
|
||||
% Not a valid IMSI: 1234567890230001
|
||||
OsmoHLR# subscriber imsi 12345678902300x create
|
||||
@@ -78,6 +86,21 @@ OsmoHLR# subscriber msisdn 12345 update msisdn 423
|
||||
OsmoHLR# subscriber msisdn 12345 show
|
||||
% No subscriber for msisdn = '12345'
|
||||
|
||||
OsmoHLR# subscriber msisdn 423 update msisdn none
|
||||
% Updated subscriber IMSI='123456789023000': removed MSISDN
|
||||
OsmoHLR# subscriber msisdn 423 show
|
||||
% No subscriber for msisdn = '423'
|
||||
OsmoHLR# subscriber imsi 123456789023000 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: none
|
||||
OsmoHLR# subscriber imsi 123456789023000 update msisdn 423
|
||||
% Updated subscriber IMSI='123456789023000' to MSISDN='423'
|
||||
OsmoHLR# subscriber msisdn 423 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
MSISDN: 423
|
||||
|
||||
OsmoHLR# subscriber imsi 123456789023000 show
|
||||
ID: 1
|
||||
IMSI: 123456789023000
|
||||
@@ -96,6 +119,10 @@ OsmoHLR# subscriber imsi 123456789023000 update ?
|
||||
aud2g Set 2G authentication data
|
||||
aud3g Set UMTS authentication data (3G, and 2G with UMTS AKA)
|
||||
|
||||
OsmoHLR# subscriber imsi 123456789023000 update msisdn ?
|
||||
none Remove MSISDN (phone number)
|
||||
MSISDN New MSISDN (phone number)
|
||||
|
||||
OsmoHLR# subscriber imsi 123456789023000 update aud2g ?
|
||||
none Delete 2G authentication data
|
||||
comp128v1 Use COMP128v1 algorithm
|
||||
|
||||
@@ -62,26 +62,26 @@ GET 28 subscriber.by-id--9223372036854775809.info
|
||||
ERROR 28 Invalid value part of 'by-xxx-value' selector.
|
||||
|
||||
GET 29 subscriber.by-id-1+1.info
|
||||
ERROR 29 Invalid value part of 'by-xxx-value' selector.
|
||||
ERROR 29 GET variable contains invalid characters
|
||||
GET 30 subscriber.by-id--.info
|
||||
ERROR 30 Invalid value part of 'by-xxx-value' selector.
|
||||
GET 31 subscriber.by-id-+1.info
|
||||
ERROR 31 Invalid value part of 'by-xxx-value' selector.
|
||||
ERROR 31 GET variable contains invalid characters
|
||||
GET 32 subscriber.by-id-+-1.info
|
||||
ERROR 32 Invalid value part of 'by-xxx-value' selector.
|
||||
ERROR 32 GET variable contains invalid characters
|
||||
GET 33 subscriber.by-id--+1.info
|
||||
ERROR 33 Invalid value part of 'by-xxx-value' selector.
|
||||
ERROR 33 GET variable contains invalid characters
|
||||
GET 34 subscriber.by-id-++1.info
|
||||
ERROR 34 Invalid value part of 'by-xxx-value' selector.
|
||||
ERROR 34 GET variable contains invalid characters
|
||||
GET 35 subscriber.by-id---1.info
|
||||
ERROR 35 Invalid value part of 'by-xxx-value' selector.
|
||||
|
||||
GET 36 subscriber.by-id- 1.info
|
||||
ERROR 36 Command not present.
|
||||
ERROR 36 GET with trailing characters
|
||||
GET 37 subscriber.by-id-+ 1.info
|
||||
ERROR 37 Command not present.
|
||||
ERROR 37 GET variable contains invalid characters
|
||||
GET 38 subscriber.by-id-- 1.info
|
||||
ERROR 38 Command not present.
|
||||
ERROR 38 GET with trailing characters
|
||||
|
||||
|
||||
SET 39 subscriber.by-imsi-901990000000001.info foo
|
||||
@@ -97,9 +97,9 @@ SET 43 subscriber.by-imsi-901990000000001.cs-enabled nonsense
|
||||
ERROR 43 Value failed verification.
|
||||
|
||||
SET 44 subscriber.by-imsi-901990000000001.ps-enabled
|
||||
ERROR err Command parser error.
|
||||
ERROR 44 SET incomplete
|
||||
SET 45 subscriber.by-imsi-901990000000001.cs-enabled
|
||||
ERROR err Command parser error.
|
||||
ERROR 45 SET incomplete
|
||||
|
||||
GET 46 subscriber.by-imsi-1234567890123456.ps-enabled
|
||||
ERROR 46 Invalid value part of 'by-xxx-value' selector.
|
||||
|
||||
@@ -15,6 +15,13 @@ cat $abs_srcdir/auc/auc_ts_55_205_test_sets.err > experr
|
||||
AT_CHECK([$abs_top_builddir/tests/auc/auc_ts_55_205_test_sets], [], [expout], [experr])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([gsup])
|
||||
AT_KEYWORDS([gsup])
|
||||
cat $abs_srcdir/gsup/gsup_test.ok > expout
|
||||
cat $abs_srcdir/gsup/gsup_test.err > experr
|
||||
AT_CHECK([$abs_top_builddir/tests/gsup/gsup_test], [], [expout], [experr])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([gsup_server])
|
||||
AT_KEYWORDS([gsup_server])
|
||||
cat $abs_srcdir/gsup_server/gsup_server_test.ok > expout
|
||||
|
||||
Reference in New Issue
Block a user