Compare commits

..

141 Commits

Author SHA1 Message Date
Oliver Smith
bb7d5b2a61 Bump version: 1.9.0.2-1a71e → 1.9.1
Change-Id: Ib8bdcee7a6fa4ae9821d9748a8a7ea4aecbea62e
2025-04-02 15:12:36 +02:00
Oliver Smith
1a71e73fdc db: flush after changing schema version
Flush the cache after changing the version, to make the scenario less
likely that after an unclean shutdown the DB gets restored with the
right table layout but wrong version.

When that happens, osmo-hlr tries to upgrade the database layout again
and fails with errors like "duplicate column name".

Related: SYS#7394
Change-Id: I5943a1cb3447c038c6e7972f68f9656b73a9248b
2025-03-17 14:43:12 +01:00
Pau Espin Pedrol
bb8591dfab Drop use of deprecated vty is_config_node() cb
This callback was drepecated and is not ever called since
libosmocore.git 70ce871532ab21955e0955d7e230eae65438f047 (release 1.3.0).

See also libosmocore.git d31de237582f6fe3315d61bb9a488d4cda92654e.

Change-Id: I0a77ff4c0a880230116a361651c78c77328db989
2025-03-04 18:21:43 +01:00
Oliver Smith
521fe02d41 Bump version: 1.8.0.15-74e4-dirty → 1.9.0
Change-Id: I1acb428ed42dd2217a734bedd286bbc60d0cc526
2025-02-12 12:17:53 +01:00
Pau Espin Pedrol
74e413c014 jenkins.sh: Use --disable-doxygen configure param
Change-Id: If5213e1080e22ad1fe87c61582a9cc4c2c164174
2024-12-10 22:32:01 +00:00
Pau Espin Pedrol
b08796d279 Drop unneeded use of abis/ipa.h header
Direct include of abis/ipa.h is not needed there, remove it to ease
later deprecation of such header.

Change-Id: I72d0787d4f5641a6a2fbe51427ac490120cbc616
2024-12-10 14:45:45 +01:00
Pau Espin Pedrol
35d4c5b376 gsup_client: Avoid double memset 0
Memory is already zeroed during talloc_zero, no need to reset it to
zero.

Change-Id: I66515fc893ffc64a36abedc01a75b57aed7e932d
2024-12-04 14:39:29 +01:00
Pau Espin Pedrol
558160be4b gsup_client: Add new APIs to avoid users accessing struct fields
This is a first step towards changing gsup_client implementation to use
an osmo_stream_cli instead of libosmo-abis' ipa_client_conn.
The libosmo-abis' ipa_client_conn will eventually be deprecated together
with all IPA related code in libosmo-abis.

In order to be able to make the implementation change, we first need to
make sure no users are using the struct fields of gsup_client (this
patch); 2nd step will be making the struct private by moving it to a
private header; 3rd step will be changing the implementation to use
osmo_stream.

Related: OS#5896
Change-Id: I401af83232022f1c141eef1f428cbe206a8aaaa2
2024-12-04 14:32:19 +01:00
Pau Espin Pedrol
e9dc7eaeda Drop use of libosmo-abis osmocom/abis/ipaccess.h
That header is only really used to provide an old hack for
ipaccess-proxy tool in openbsc.h/osmo-bsc.h, and will be deprecated
soon.

Take the chance to organize a bit better the includes based on dependency
chain.

Change-Id: I393cd23a09af6d1eefa68dc955415f4fe334d71b
2024-11-29 18:52:06 +01:00
Pau Espin Pedrol
19929d873b jenkins.sh: libosmo-netif no longer depends on libosmo-abis
Change-Id: I98b233e2ebb209803be5b6523bb1154ca694041c
Depends: libosmo-abis.git Change-Id I079dc3999de508301dd37ed03e399356a58d3cab
Depends: libosmo-netif.git Change-Id I13d6e88158f6d9ce017986283183ee9c2cc68cae
2024-11-21 14:49:03 +01:00
Mychaela N. Falconia
ada985a0ea change default no-proxy reject cause to net-fail
If LU has to be rejected because DGSM mechanism cannot reach the
needed HLR, then returning reject cause #17 (Network Failure)
is the most accurate and truthful description of what is actually
happening.

Reject cause #2 (IMSI unknown in HLR) is unlikely to be a good
choice: in areas where regular commercial cell services are present
alongside with experimental/adventurous Osmocom-based GSM networks,
this reject cause is acutely dangerous as described in the previous
commit, and even in areas where no regular commercial cell services
are present (the presumed intended use case for DGSM), the behavior
of commanding LU-failing phones "please don't ever again try to
connect to ANY network until the user power-cycles you" is unlikely
to be correct/desirable.  If that behavior _is_ desired, it should
be configured explicitly, not by default.

Change-Id: I557ae1d3291066a87228b5db4f2e207ea721329c
2024-11-21 03:33:38 +00:00
Mychaela N. Falconia
6b5616fd36 change default reject cause to plmn-not-allowed
Unless the Osmocom-based network operator has very carefully
considered what they are doing, returning MM/GMM reject cause #2
(IMSI unknown in HLR) to LU requests from bystander phones is a
very bad idea.  Here is what typically happens when someone sets
up an Osmocom-based GSM network for development, testing or
research, without roaming interconnection with any commercial
operators:

* Even when the private network operates its BTS at very low power
  levels, bystander phones in close proximity (e.g., in directly
  adjacent neighbor apartments or office suites) will receive a much
  stronger signal from the private/test network BTS than from any
  commercial operator, i.e., the private/test network will be
  the strongest signal.

* Many phones will attempt to "jump ship" to this strongest signal
  even if it broadcasts a completely unknown PLMN ID that is not in
  the preferred operator list, and even when they were previously
  not roaming at all, registered to their most preferred home operator
  with perfectly good reception quality.

* If these wayward phones receive reject cause #2 in response to their
  LU attempt, the spec effectively requires them to go into a "black
  hole" where they no longer attempt to register to any operator,
  including their own legitimate one.

Returning reject cause #11 instead (PLMN not allowed) solves this
problem: wayward phones that erroneously attempted to register to the
private/test network go back to their own legitimate commercial
operator, and everyone is happy.

This bug should be considered critical: when the reject cause is set
to #2 by default, any private Osmocom-based network, no matter how
low-power, will effectively cause service disruption to all nearby
commercially-served phones even when there is no clash in terms of
used radio frequencies.

Change-Id: Icff1d19670c398b119ec68b1d5f0fad87b605702
2024-11-21 03:33:38 +00:00
Mychaela N. Falconia
96dab5f886 vty: always emit reject-cause lines in saved config
When reject-cause (not-found|no-proxy) setting was added, it was
implemented such that the new setting is not written into saved
config files if it equals the default of 'imsi-unknown'.  Change
this behavior to always write out the current setting for each of
not-found and no-proxy, whether or not they match compiled-in
defaults.

Change-Id: I18708fc1c08a85e98582c97ec59dd3822a0767fb
2024-11-21 03:33:38 +00:00
Pau Espin Pedrol
db2f1f65da gsup: Replace deprecated ipa_msg_push_header()
Use the libosmocore API, which does the same except setting the l2h
pointer, which we don't really need here.

Change-Id: I7a4d05a0b09032d8133d8775fb4707a4da8f0cf3
2024-11-19 14:47:44 +01:00
Alexander Couzens
0451b13e0d debian/copyright: add gsup_client under GPLv2+
Change-Id: Idddcd6356af76987bf57ecd21096299cb2ba896f
2024-10-13 23:43:57 +02:00
Alexander Couzens
26c82ba2be gsupclient: add missing SPDX line
SPDX is a spec to describe the license of a file
in a machine readable format.

Change-Id: Iaded691cc0eb2f5dd85efd1915ddef1a747fe518
2024-10-13 23:39:26 +02:00
Alexander Couzens
e1aed27178 gsupclient: Introduce gsup_client_mux
GSUP supports different message classes (e.g. SMS, USSD, Subscriber management),
within a daemon, the messages are usually handled in different parts of it.
The gsup client mux allow to place callbacks for the different message class.

This code original comes from the osmo-msc code and is here
re-licensed under the GPLv2.

Change-Id: I916c1bb6cfc48f92fc5db2b5c914eb1b4e25fa7f
2024-10-13 23:31:45 +02:00
Vadim Yanitskiy
7c06eea5b2 subscriber-create-on-demand: add mode for MSISDN=IMSI
In may be desirable for some users to assign deterministic MSISDNs
when subscriber-create-on-demand is enabled.  This can be achieved
by assigning MSISDN=IMSI.  This commit adds a new mode for that.

Change-Id: I3470492f5e46de7246d9a74e80c37f80f455d851
2024-08-22 02:32:07 +07:00
Vadim Yanitskiy
d4693f652a subscriber-create-on-demand: rework configuration
This commit prepares for adding a new subscriber-create-on-demand
mode (MSISDN=IMSI), which is implemented in a follow-up patch.

* add an enumerated type for subscriber-create-on-demand mode;
* store the related parameters in an anonymous structure.

Change-Id: Ib553172655f83dad1ac0e0254615c8c207d79ca9
2024-08-07 16:20:14 +07:00
Oliver Smith
c819234a42 Bump version: 1.7.0.17-bae13 → 1.8.0
Change-Id: I3b05d5ac5417f5c995e7057474adba72326ebf11
2024-07-24 16:22:50 +02:00
Oliver Smith
bae137d9eb mslookup: don't ignore return value of write()
Fix GCC 13.2.0 refuses to build this with -Werror:

src/mslookup/osmo-mslookup-client.c: In function 'socket_client_respond_result':
src/osmo-hlr/src/mslookup/osmo-mslookup-client.c:432:9: error: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Werror=unused-result]
  432 |         write(c->ofd.fd, response, strlen(response));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/mslookup/osmo-mslookup-client.c: In function 'socket_accept':
src/osmo-hlr/src/mslookup/osmo-mslookup-client.c:530:17: error: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Werror=unused-result]
  530 |                 write(c->ofd.fd, CSV_HEADERS, strlen(CSV_HEADERS));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I4b2e5cabe5306a999197f7c98362d872a3739078
2024-07-03 10:45:25 +02:00
Vadim Yanitskiy
413f5e3670 README.md: cosmetic: fix a typo
Change-Id: Idd4270a74c2a9921943606c1157343f4756b1643
2024-06-05 18:34:07 +07:00
Oliver Smith
6b771e34bd debian/postinst: add checks, be verbose
Do not attempt to change permissions/ownership if the package gets
upgraded from a version higher than the next release.

Do not fail if the user deleted the config file.

Be verbose when changing permissions.

Related: OS#4107
Change-Id: I1bcbe414fd18101e4d875a16539deab7baf9cb5f
2024-05-15 11:47:40 +00:00
Oliver Smith
a005ad6495 contrib: remove rpm spec file
Related: https://osmocom.org/news/255
Related: OS#6446
Change-Id: Idd67d52ca736c4e145387ea8d4030f9cf4b9596d
2024-05-08 14:40:58 +02:00
Oliver Smith
e391c4c58d .deb/.rpm: various fixes related to non-root
* Explicitly chown /var/lib/osmocom to osmocom:osmocom, instead of
  relying on systemd to do it when the service starts up. This does not
  work with the systemd versions in debian 10 and almalinux 8.
* deb: Use "useradd" instead of the interactive "adduser" perl script
  from Debian. This makes it consistent with how we do it in rpm, and
  avoids the dependency on "adduser".
* deb: Remove support for the "dpkg-statoverride --list" logic. This
  seems to be a rather obscure feature to override permissions for
  certain files or directories. Let's rather remove this complexity to
  make the postinst script more maintainable and more similar to the
  rpm spec file. If users need this, they can achieve something similar
  by using their own Osmocom config file in a different path with
  different permissions.
* deb: Consistently use tabs throughout postinst, instead of mixing
  tabs and spaces.

Related: OS#4107
Change-Id: Ib20406dd253f5e8720552e92e9002e45591218fa
2024-04-26 15:07:32 +02:00
Max
a26abc6aa8 .deb/.rpm: add osmocom user during package install
Created osmocom user & group during package installation.
Fix the configuration dir/files permission to match.

Related: OS#4107
Tweaked-By: Oliver Smith <osmith@sysmocom.de>
Change-Id: I625c993ab03dfe32976c651acca9c35c33a768e7
2024-04-24 11:52:09 +02:00
Harald Welte
da4fc0eab9 README.md: Add Forum and Issue Tracker sections
Change-Id: Ic88d30fc8952762565af6115c8bb7d67fa7d7866
2024-03-23 17:28:12 +01:00
Harald Welte
507315eed8 README.md: Improve mark-down formatting
Change-Id: Ib608ec568572af672934d1e2960e1dabc3a2a45c
2024-03-23 17:26:19 +01:00
Harald Welte
72f92e28c9 Add funding link to github mirror
see https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository

Change-Id: I935ec923362fd8d3f03a8db8e93e033f86f0a5ac
2024-03-23 17:22:45 +01:00
Vadim Yanitskiy
ac1365fddf build: include {README.md,git-version-gen} into the release tarball
Change-Id: I072b5899ac77326f619d351f17aa78490946f452
2024-01-26 23:33:48 +07:00
Mychaela N. Falconia
be8bcd30eb ctrl: add subscriber.by-*.imsi GET-able variable
There may be a need in various OsmoCNI-attached entities (for example,
external SMSC implementations) to perform a mapping from known MSISDN
to unknown IMSI, querying OsmoHLR subscriber db for it.  Querying for
subscriber.by-msisdn-*.imsi will be much more efficient (and easier on
client-side implementors) than querying for subscriber.by-msisdn-*.info
and fishing the IMSI out of the long multiline response, discarding all
other irrelevant info.

Related: OS#6312
Change-Id: Icea1a74d0c664047f46758ab4ad75508782f3d12
2023-12-17 21:47:21 +00:00
Andreas Eversberg
947e137918 Use uniform log format for default config files
Related: OS#6272
Change-Id: I4319b688286845d2ffbd944e51e9cc2e5159563c
2023-12-01 12:41:19 +01:00
Mychaela N. Falconia
e513c43857 SMS over GSUP: handle READY-FOR-SM.req from MSCs
When an MS indicates that it is ready to receive MT SMS, the MSC will
send us a READY-FOR-SM.req message.  Handle it by sending copies of
the same message to all connected SMSCs and returning OK result
to the MS that indicates its ready status.

Related: OS#6135
Change-Id: I731545a3a0d0804289e24a7769e13bfd3f645132
2023-09-21 02:06:58 +00:00
Mychaela N. Falconia
f6a303c669 SMS over GSUP: implement forwarding of MT SMS
When an SMSC tries to deliver an SM to a subscriber, it will send us
an MT-forwardSM.req GSUP message.  We look up the subscriber by IMSI
and see if they are attached to a VLR.  If the subscriber is attached,
we forward the message to the MSC/VLR, otherwise return an error
to the SMSC.

Related: OS#6135
Change-Id: Ib3551bf7839690606c677461758c5cfef5f0aa7b
2023-09-21 02:06:49 +00:00
Mychaela N. Falconia
786ec5b91c SMS over GSUP: implement forwarding of MO SMS
MO-forwardSM.req messages are now forwarded to a connected SMSC
based on the SMSC address (SM-RP-DA) in the MO SM and the vty-defined
mapping from SMSC numeric addresses to IPA names.

Related: OS#6135
Depends: Iea5c29909c5be80f81dbbc2873656ff5cf590a5d (libosmocore)
Change-Id: Iaad4531922c41583d261c79f42561a1bdbe03521
2023-09-21 02:05:15 +00:00
Mychaela N. Falconia
ff7c7ea085 SMS over GSUP: implement vty config of SMSC routing
At the user-visible level (advanced settings menus on phones,
GSM 07.05 AT commands, SIM programming) each SMSC is identified
by a numeric address that looks like a phone number, originally
meant to be a Global Title.  OsmoMSC passes these SMSC addresses
through as-is to MO-forwardSM.req GSUP message - however, SMSCs
that connect to OsmoHLR via GSUP identify themselves by their
IPA names instead.  Hence we need a mapping mechanism in OsmoHLR
config.

To accommodate different styles of network design ranging from
strict recreation of classic GSM architecture to guest roaming
arrangements, a two-level configuration is implemented, modeled
after EUSE/USSD configuration: first one defines which SMSCs exist
as entities, identified only by their IPA names, and then one
defines which numeric SMSC address (in SM-RP-DA) should go to which
configured SMSC, with the additional possibility of a default route.

Related: OS#6135
Change-Id: I1624dcd9d22b4efca965ccdd1c74f0063a94a33c
2023-09-21 01:56:21 +00:00
Vadim Yanitskiy
fa6af8872f hlr_vty.c: drop redundant include of hlr_ussd.h
Change-Id: Ia873c3ea7fb76cb83628811f159e9d5f2de8dcbd
2023-09-17 02:04:05 +00:00
Pau Espin Pedrol
d052f076e3 Bump version: 1.6.0.20-37f0-dirty → 1.7.0
Change-Id: I3f169ff8f9b10a4d4b5c50286951d326fa713245
2023-09-12 14:41:34 +02:00
Alexander Couzens
37f0b3a8f3 Add support for multiple APN profiles for subscriber data
Previously the HLR sent in the Insert Subscriber Data call only the
wildcard APN as a single entry.
This violates the spec because the first entry (with the lowest context_id) is
always the default APN, but it is forbidden to have a wildcard APN as default apn.

Introduce a default template/profile which can contain multiple APNs.
This profile is always sent out to the SGSN/MME as part of Insert-Subscriber-Data.
In the future a subscriber might have a profile template name written into the
database which will resolve to a "pdp-profile premium" in the configuration.

To be backward compatible, if the pdp-profile default section is missing,
the HLR will send out only a wildcard APN.

Config example:

hlr
 ps
  pdp-profile default
   profile 1
    apn internet
   profile 2
    apn *

Changes to the apn list will be only handed out to subscribers
when the subscriber do a location update.

Related: SYS#6391
Change-Id: I540132ee5dcfd09f4816e02e702927e1074ca50f
2023-09-12 09:48:02 +00:00
Harald Welte
7a763aa012 Add VTY support for TUAK algorithm
Change-Id: If2611658f7cb990b484d7429ab2f944f56fd2eb6
Depends: libosmocore.git Ib905b8d8bdf248e8299bf50666ee1bca8298433d
2023-08-29 13:42:41 +00:00
Harald Welte
626f5eb740 db: extend database schema to support 256bit K and/or OP[c] values
Other UMTS AKA algorithms than MILENAGE (notably TUAK) support K sizes
of up to 256bit, or mandate a OP/OPc size of 256 bit.

Let's extend our database schema to accommodate such larger sizes.

Change-Id: Ibbde68484c904507a15c35cbfdf88cd47d0c7039
2023-08-29 13:42:41 +00:00
Vadim Yanitskiy
5800f3add5 USSD: fix handling of ussd-DataCodingScheme != 0x0f
The usual Data Coding Scheme value in the mobile-originated USSD
request (processUnstructuredSS-Request) is 0x0f, which means:

  0000 .... = Coding Group: Coding Group 0 (Language using the GSM 7 bit default alphabet)
  .... 1111 = Language: unspecified

However some modems are known to use a different default value, if
not specified explicitly (AT+CUSD has optional DCS parameter):

  0000 .... = Coding Group: Coding Group 0 (Language using the GSM 7 bit default alphabet)
  .... 0000 = Language: German (0)

In function rx_proc_ss_req(), we should not be using req.ussd_text,
because this field has been deprecated and may contain unexpected
data.  For example, in the abovementioned case it would contain the
7 bit encoded ussd-String 'aa510c061b01'O and osmo-hlr would indeed
fail to find a matching route for a non-ASCII string.

Instead of relaying on gsm0480_parse_facility_ie(), let's check the
Data Coding Scheme value and decode the request string ourselves.
Expect the Coding Group 0, but be more tolerant to the indicated
language: print a warning and treat it as '1111'B (unspecified).

Change-Id: Ib7bac660b1a7942adcfbe7b14f162c95061a25db
Related: OS#6075
2023-07-21 12:49:20 +00:00
Vadim Yanitskiy
f8b73f0682 gsup_server: fix msgb memleak in osmo_gsup_server_read_cb()
I noticed that inability to send IPA PONG in response to IPA PING
from osmo-{msc,sgsn} results in an "IPA Multiplex" chunk being leaked.

No matter what's returned from ipa_server_conn_ccm(), we need to free
the msgb containing the incoming IPA message.

Change-Id: I5c5acbffc2913f78db4894ae3633b5eca9c2e8d6
2023-07-05 01:10:43 +07:00
Vadim Yanitskiy
f4223f5b53 ussd: fix GSUP memleaks in rx_proc_ss_{req,error}()
Also take a chance to use a more suitable error cause value.

Change-Id: I22ba5ad470989b7e8ba8fe2be170eac4adcb48c5
2023-07-05 00:24:19 +07:00
Vadim Yanitskiy
1c23f304d1 lu_fsm: fix memleak in lu_fsm_wait_insert_data_result()
Currently osmo-hlr leaks memory (msgb holding 1203 bytes of data and
a struct osmo_gsup_req) on receipt of OSMO_GSUP_MSGT_INSERT_DATA_ERROR.

Change-Id: I4c70a06169158c869360707a7a62436dbf13b9b3
2023-07-05 00:15:17 +07:00
Harald Welte
f4159bd54c src/db.c: Switch from "const char *statements" to "const char * const"
This is primarily to make the linter happy, which spews "static const
char * array should probably be static const char * const" errors in
gerrit when adding similar new code to this existing file.  So let's
first convert the old code and then add new code that makes the linter
happy.  I guess it does have a point, as both the individual string
pointers as well as the array of the pointers are constant.

Change-Id: I39e9fb6bd8052f4878cfc95061775bf940631ae5
2023-06-14 14:53:07 +02:00
Harald Welte
a854b48762 Port to new libosmogsm 'struct osmo_sub_auth_data2'
libosmogsm has recently introdcued a 'struct osmo_sub_auth_data2' as
successor to 'struct osmo_sub_auth_data', together with updated
osmo_auth_gen_vec2/osmo_auth_gen_vec_auts2 API.

The rationale of this new API is to enable
* support for AKA algorithms which use K and/or OP[c] values of 256bit
  (instead of the classic 128bit)
* support for RES length sizes of 4 and 16 bytes (instead of the classic
  8 bytes)

This commit just jumps over to the new API without adding any related
functionality to osmo-hlr.  The latter is left for subsequent commits.

Change-Id: I3207c7bfb73e9ff5471e5c26b66639549e4d48a2
Depends: libosmocore.git Ie775fedba4a3fa12314c0f7c8a369662ef6a40df
2023-06-14 14:53:04 +02:00
Harald Welte
91150802f8 cosmetic: gen_ts_55_205_test_sets/main_template tabs istead of spaces
Let's consistently use our normal tab indent style

Change-Id: I4172b59131ac4166174c1860fcb07b7bee3df728
2023-06-03 19:32:44 +02:00
Harald Welte
8f3fa656e7 cosmetic: gen_ts_55_205_test_sets/func_template.c: Use tab-indent
This templates is used for generating C code, so it should use our
normal tab-based code indenting.

Change-Id: I0be7eb2d7b551d7eaaee15994ef37262694819f6
2023-06-03 19:29:46 +02:00
Harald Welte
829713a69d Introduce support for XOR-2G algorithm
So far we supported a "xor" algorithm in osmo-hlr, without specifying
whether it's the XOR-3G or the (different) XOR-2G algorithm.

Furthermore, it was buggy in the sense that it permitted the XOR[-3G]
for 2G authentication data in the database.

This patch
* renames existing "xor" to "xor-3g"
* disallows "xor-3g" usage with 2G authentication data
* introduces support for XOR-2G as "xor-2g" in the VTY

Change-Id: I039a1f84fda54a908a82fe621e7fd078cb85e4c6
Depends: libosmocore.git I0ee0565382c1e4515d44ff9b1752685c0a66ae39
2023-05-30 21:43:14 +02:00
Oliver Smith
5edf387353 systemd: depend on networking-online.target
Related: SYS#6400
Change-Id: I29e547242b2ed1cfc4750c7d7e5f8636c2e8f3dc
2023-05-26 14:10:45 +02:00
Alexander Couzens
2989873a68 hlr: use talloc for memory allocation in osmo_gsup_create_insert_subscriber_data_msg
Don't use static buffers for APN and MSISDN.
When encoding multiple APNs the static buffer might be too small.
In prepration to support multiple APNs in subscriber data

Change-Id: I00b5c2dfadcf6e0740e93b4c3292d2654d22e80c
2023-05-10 07:58:57 +00:00
Oliver Smith
390f6fcf13 debian: set compat level to 10
Related: OS#5958
Change-Id: I5d26ab03aacf3b8ef8c1c4c669c12090fd0b7899
2023-04-25 16:48:22 +02:00
Vadim Yanitskiy
d10c2ef366 tests/*/Makefile.am: move -I to AM_CPPFLAGS
Change-Id: I654053e11b0cc824c198f68e4ff0a0fcb295efb0
2023-03-14 20:11:45 +00:00
Vadim Yanitskiy
974aed9c04 tests/auc/Makefile.am: put object files to LDADD
Change-Id: Iaefcfe7a8904841a29094fe40eb5850912544b4c
2023-03-14 20:11:45 +00:00
Pau Espin Pedrol
cf535dbcbd mslookup: Call osmo_fd_unregister() before closing and changing bfd->fd
Change-Id: I26bba0dd092ad5fd6b4959b173fae93b542a93f1
2023-03-14 11:42:24 +01:00
Oliver Smith
a55e63b087 tests/db/db_test.err: adjust to XOR-3G rename
Adjust the test to the related libosmocore change.

Related: libosmocore I446e54d0ddf4a18c46ee022b1249af73552e3ce1
Change-Id: I68878d24340659f888e5e348b937161cffbd54e2
2023-02-22 16:58:57 +01:00
Oliver Smith
62e5c1b2c7 Run struct_endianness.py
Ensure there is no diff to prepare to run this in CI.

Related: OS#5884
Change-Id: I4294a18871214b70cef267fcaaaaada42cb61bf9
2023-02-20 10:48:57 +01:00
Pau Espin Pedrol
ed939154f8 Bump version: 1.5.0.19-268a-dirty → 1.6.0
Change-Id: Ide480a902bbfadefa396f3a0cb925f5dceab4f9c
2023-02-07 16:49:15 +01:00
Alexander Couzens
268a33e58b Add vty reject-cause to set the reject cause
Allow to set the LU reject cause independently for both of the
following cases; either when an IMSI is unknown to the HLR or
when the mslookup client does not a receive a timely response
to a GSUP request for the remote home HLR.

Original patchset modified by <keith@rhizomatica.org>

Change-Id: Icea39020c23fbbea9e92847df76af8986fdbf48a
2023-01-20 14:03:01 +00:00
Neels Hofmeyr
8804a2335a fix memleak of proxy_subscr_listentry
Patch-by: whytek
Related: OS#5854
Change-Id: Ic1ec4911fa5ae91cc75aa865c8201edd83af41ed
2023-01-15 22:45:31 +01:00
Keith
c27bc90ae6 Vty: Fixup config shown/written from vty
This commit fixes the following errors:
Missing timeout param for mslookup.
Fails to start reading a written config if an msc node
is configured in the mslookup server.
Places the individual msc node services in the
top-level wildcard node due to incorrect indentation.

* Add missing timeout param.
* Add missing "ipa-name" part to mslookup-server-msc section.
* Add one extra space indentation for msc services.

This commit also adds a DEFINE for the default timeout value.

Change-Id: Ibb60e74a0803f05f37ac13ca529d77b4cb736025
2022-12-27 17:03:08 +00:00
Oliver Smith
f80ab768d0 osmo_mdns_rfc_record/question_encode: remove ctx
Remove the ctx argument to both functions, as it's not used anymore.

Related: OS#5821
Change-Id: I5e3dd18bf08f7aa42f49c262e13250778ea0c6a2
2022-12-23 13:51:28 +01:00
Oliver Smith
5decd49713 mslookup: use apn functions from libosmocore
Use the apn functions from libosmocore to encode and decode qnames to
avoid code duplication and to avoid unnecessary dynamic allocation.

The unit tests for encoding and decoding rfc_question / rfc_record are
still passing and have the same output.

Fixes: OS#5821
Change-Id: I09d3c617fd6eb4075084ee106d3f3c5803861d2f
2022-12-23 13:51:22 +01:00
Oliver Smith
c5f034b13d osmo_mdns_rfc_record_decode: proper free on err
Free the whole talloc tree of ret if we can't allocate memory for
ret->rdata.

Related: OS#5821
Change-Id: Iefc89e3c75a4bf4ffee3871c7b551a2a608f7d5f
2022-12-23 13:38:19 +01:00
Oliver Smith
01155eaee6 osmo_mdns_rfc_record_decode: check ret of talloc
Related: OS#5821
Change-Id: Icd0f54a8eb80ca50976f248e017f6e5c727385f3
2022-12-23 13:38:15 +01:00
arehbein
e4143234c8 osmo-hlr: Transition to use of 'telnet_init_default'
Related: OS#5809
Change-Id: I5cee719a9c4437712915f0f9760d606f6ec2dd43
2022-12-23 11:13:19 +00:00
Max
6263cf350a ctrl: take both address and port from vty config
Change-Id: Iecae15333a4e77b38d9bce8c8e591af3d5fcf347
2022-12-17 20:59:00 +03:00
Harald Welte
63eefabdde Add -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition
... if --enable-werror is used

Change-Id: Id465254bf12eb84acb116c86711a5b52b4d3ad35
2022-11-03 12:56:24 +01:00
Harald Welte
7a4765325d Support building with -Werror=strict-prototypes / -Werror=old-style-definition
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that
uses constructs of earlier C standards, which were abandoned in C99.

See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for
some related discussion.

Change-Id: I861be39275b40c522c02f553074c5a4489e87127
2022-11-03 12:56:24 +01:00
Max
53f6067e97 hlr_vty.c: fix typo
Change-Id: If79ebd9a8998e64be55e52af43e426f37e3972af
2022-09-24 01:55:46 +00:00
Max
8023d246f2 Debian: install osmo-hlr-dgsm.cfg as example config
Related: OS#4107
Change-Id: Ia64f14ada006acb31c5f725dfa0d52f482d3e8b4
2022-09-18 20:19:42 +07:00
Max
00aea9e0d9 systemd: enable basic hardening
This ensures that systemd will not allow us to modify
/home, /root and /run/user which we shouldn't be doing anyway.
See https://www.freedesktop.org/software/systemd/man/systemd.exec.html
for details.

It should also should silence corresponding lintian warning.

Related: OS#4107
Change-Id: Ida5f13bdb9e5bd956c440a381d94eecc18f0b2ef
2022-09-18 19:23:52 +07:00
Max
023c6524a2 Debian: reformat package description
Shorten the lines of package description to comply with
Debian Policy Manual section 3.4.1

Related: OS#4107
Change-Id: Id6bbfc0b013f0e8da80af76206d3ac7fd6b6b0d4
2022-09-18 19:23:52 +07:00
Max
1d02b51a68 Debian: bump copyright year to match current
Related: OS#4107
Change-Id: I581e62b5410a9dddc6b5fd974081d633cc20416d
2022-09-18 19:23:23 +07:00
Max
78a9f92fda Ignore .deb build byproducts
Change-Id: Id36f55cd55be25f764c2b9515eff84d106bab1dc
2022-09-09 22:08:35 +07:00
Max
ad8866e86e Set working directory in systemd service file
By default systemd will execute service with root directory (or home directory for user instance) which might result in
attempts to create files in unexpected place. Let's set it to 'osmocom' subdir of state directory (/var/lib for system
instance) instead.

Related: OS#4821
Change-Id: I40b5d50470cb55ca94af5e17f21658181a02d4c2
2022-08-29 19:45:03 +07:00
Vadim Yanitskiy
6156950634 db_auc: hexparse_stmt(): check value returned by osmo_hexparse()
Change-Id: I78bb3aff9dd57a38278bb34113ea764e0a54c439
Fixes: CID#272997
2022-06-29 11:30:12 +00:00
Pau Espin Pedrol
65f51535d0 Bump version: 1.4.0.16-3863-dirty → 1.5.0
Change-Id: I016ddf4fd955c3b518e620a35f9a817f489e81c4
2022-06-28 18:38:31 +02:00
Pau Espin Pedrol
386381662c doc: Document new subscriber CTRL commands
Related: SYS#5993
Change-Id: I3e38d067bbc2ebb7f788dc56a5d56e1e4cafdc9c
2022-06-21 10:35:40 +02:00
Pau Espin Pedrol
777860ddb5 ctrl: Introduce CTRL command subscriber.by-*.aud3g <algo[,KI,(op|opc),OP_C[,ind_bitlen]]>
This command provides getter and setter to set and retrieve the
authentication data for 3g subscribers.

Change-Id: Ibe7aeec3cabab0406eb7a84ecd24e529ef1696c2
Related: SYS#5993
2022-06-21 10:35:40 +02:00
Pau Espin Pedrol
1d0a030aa4 ctrl: Introduce CTRL command subscriber.by-*.aud2g <algo[,ki]>
This command provides getter and setter to set and retrieve the
authentication data for 2g subscribers.

Change-Id: Ibebac232fa173bce8a075cacf477214d5bdb590f
Related: SYS#5993
2022-06-21 10:35:18 +02:00
Pau Espin Pedrol
3ca9a1fd4f ctrl: Introduce cmd SET subscriber.delete <imsi>
On success SET_REPLY contains the ID of the deleted subscriber.

Related: SYS#5993
Change-Id: I24c6149d7c223a12549d712a7929666220c0210f
2022-06-20 18:05:36 +02:00
Pau Espin Pedrol
b74769f1b4 cosmetic: hlr_vty_subscr.c: Fix trailing whitespace
Change-Id: Id751d227a52f39e3a8874d8b78c633b8d3eb9e74
2022-06-20 18:05:36 +02:00
Pau Espin Pedrol
140dffd8f7 ctrl: Introduce CTRL command subscriber.by-*.msisdn
This command provides getter and setter to set and retrieve the MSISDN
of a subscriber.

Related: SYS#5993
Change-Id: I5f2e807859f7e28e0984c8dc37edc69319fd8e10
2022-06-20 13:37:59 +02:00
Pau Espin Pedrol
d63ec88dba ctrl: Introduce cmd SET subscriber.create <imsi>
Create a new subscriber from CTRL, similar to VTY command
"imsi IDENT create".

On success SET_REPLY contains the ID of the newly created subscriber.

Related: SYS#5993
Change-Id: Id1b760cd07712245a0eeabaac7891bce93c1fe8e
2022-06-20 13:37:53 +02:00
Harald Welte
e427bb299f update git URLs (git -> https; gitea)
Change-Id: Iaab27a8e258a29a0bb51ee8d9f5faeb2c025f139
2022-06-18 12:08:31 +02:00
Pau Espin Pedrol
d456fced21 Fix db_subscr_create() not returning -EEXIST expected by VTY subscriber create cmd
As a result, the -EEXIST code path printing a specific error for
inserting already existing subscribers was not being triggered.

Change-Id: Id24dc6e0ff5115c8c9025404dd7296250d2b03ee
2022-06-17 19:09:39 +02:00
Pau Espin Pedrol
c772e525ef tests/ctrl: Move ERROR test scenario to proper file
Change-Id: I26ba561c22c40877d99f2aed27be2df9faaa4bec
2022-06-17 17:07:56 +02:00
Pau Espin Pedrol
83a41471da tests: Allow specyfing specific ctrl test to run
Similar to what's already available for vty tests.

Change-Id: I3b01edfb22197f4d46bd24e15bdcd37ea0382e4a
2022-06-17 17:03:25 +02:00
Pau Espin Pedrol
b4f25a0d1a ctrl: Mark function as static
Also move it more towards the end, where it is more expected as usually
done in ctrl/vty code.

Change-Id: Ieb956fb855752cfbe83d11aa0326685229a115e3
2022-06-17 15:56:27 +02:00
Vadim Yanitskiy
b246580900 tests: use 'check_PROGRAMS' instead of 'noinst_PROGRAMS'
When using 'check_PROGRAMS', autoconf/automake generates smarter
Makefiles, so that the test programs are not being compiled during
the normal 'make all', but only during 'make check'.

Change-Id: I70cf75b3cb6ae59c92248cc529546750fb0da07b
2022-04-14 02:22:14 +03:00
Vadim Yanitskiy
0c13953ed0 debian: add new 'osmo-mslookup-utils' package
Change-Id: I9dbe00187678a5032fb4ae32b496892fdc86ddb7
Related: OS#4706
2022-02-08 13:51:31 +06:00
Vadim Yanitskiy
77a1bf66e6 fixup: debian: remove unneeded dependency libdbd-sqlite3
Change-Id: I3ece7c32151f6f334d0595fdbf9099c930b22bb9
Fixes: I5bfe9c71740c1ced5bad0a41dfca568b9e00070c
2022-02-05 22:52:22 +06:00
Oliver Smith
37a5b70195 treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I4b20c685b6370bf5dc472a42664e2665eb0d8f8c
2021-12-14 12:15:54 +01:00
Pau Espin Pedrol
4d7cbfcc9a Bump version: 1.3.0.7-bfee → 1.4.0
Change-Id: I39bbc42009bf6291884f652618bfdf94b329a295
2021-11-16 14:56:41 +01:00
Oliver Smith
bfeea69cab debian/control: remove dh-systemd build-depend
Related: OS#5223
Change-Id: Ieb8669a9a43ea1acc6b2d8d2e363f2466c51697a
2021-09-01 16:07:06 +02:00
Neels Hofmeyr
3f9d1977df db v6: determine 3G AUC IND from VLR name
Each VLR requesting auth tuples should use a distinct IND pool for 3G
auth.  So far we tied the IND to the GSUP peer connection; MSC and SGSN
were always distinct GSUP peers, they ended up using distinct INDs.

However, we have implemented a GSUP proxy, so that, in a distributed
setup, a remotely roaming subscriber has only one direct GSUP peer
proxying for both remote MSC and SGSN. That means as soon as a
subscriber roams to a different site, we would use the GSUP proxy name
to determine the IND instead of the separate MSC and SGSN. The site's
MSC and SGSN appear as the same client, get the same IND bucket, waste
SQNs rapidly and cause auth tuple generation load.

So instead of using the local client as IND, persistently keep a list of
VLR names and assign a different IND to each. Use the
gsup_req->source_name as indicator, which reflects the actual remote
VLR's name (remote MSC or SGSN).

Persist the site <-> IND assignments in the database.

Add an IND test to db_test.c

There was an earlier patch version that separated the IND pools by
cn_domain, but it turned out to add complex semantics, while only
solving one aspect of the "adjacent VLR" problem. We need a solution not
only for CS vs PS, but also for 2,3G vs 4G, and for sites that are
physically adjacent to each other. This patch version does not offer any
automatic solution for that -- as soon as more than 2^IND_bitlen
(usually 32) VLRs show up, it is the responsibility of the admin to
ensure the 'ind' table in the hlr.db does not have unfortunate IND
assignments. So far no VTY commands exist for that, they may be added in
the future.

Related: OS#4319
Change-Id: I6f0a6bbef3a27507605c3b4a0e1a89bdfd468374
2021-07-19 09:01:06 +00:00
Pau Espin Pedrol
608e2e483f db: Avoid use uninitialized rc if running 0 statements
Caught by new gcc 11.1.0:
/git/osmo-hlr/src/db.c:257:16: error: ‘rc’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  257 |         return rc;
      |                ^~

Change-Id: I45e1fede234cd4446a7061fb908bf344eee72f5a
2021-07-15 13:33:16 +02:00
Oliver Smith
60673e7f77 Add post-upgrade script for automatic db upgrade
Closes: OS#5138
Change-Id: I34e943e5020285f63a2162010eb42675af1520bf
2021-06-01 09:29:00 +02:00
Keith
ca8e6efca6 vty: enable show subscribers filtered by IMEI
In 89fda3024a I added a
vty command to show a summary of filtered subscribers by imsi
or msisdn. In practice there is a also need to be able to
filter on IMEI.

The idea here is not to replace every operation that could be
done directly on the sql database in the vty, but this one
is useful.

Change-Id: Ic4a11d3ebcf8909c68e9f4617e94dc822491e008
2021-05-13 18:00:43 +00:00
Harald Welte
ed2e36316b add README.md file as customary for cgit, github, gitlab, etc.
Change-Id: Ide03584aae21d5972e96e7862feb86e1265c29b3
2021-03-21 22:46:07 +01:00
Keith
649c335602 Correct configuration written from vty
osmo-hlr would not read back written configuration due to
bad indentation in the mslookup->server->service section.

Also ipa-name was missing.

Change-Id: Ied4b9504f06a51c3895054a8b9d07a67eda3aeeb
2021-02-26 01:21:41 +01:00
Pau Espin Pedrol
6240465503 Bump version: 1.2.0.78-8c90-dirty → 1.3.0
Change-Id: Iffdee17c1f70f472fb9cfe722b77967c2634ea37
2021-02-23 18:13:54 +01:00
Harald Welte
8c9087dd16 manuals: generate vty reference xml at build time
Move 'doc' subdir further down to "make sure" the osmo-hlr binary is built
before the docs

Remove hlr_vty_reference from the source tree.

In manuals//Makefile.am use the new BUILT_REFERENCE_XML feature recently added
to osmo-gsm-manuals, and add a build target to generate the XML using the new
osmo-hlr --vty-ref-xml cmdline switch.

Change-Id: I02c9862ced48ce4271b328a0963d5f09086b295c
Depends: I613d692328050a036d05b49a436ab495fc2087ba
Related: OS#5041
2021-02-23 16:48:36 +00:00
Harald Welte
2bd1a45553 main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
Change-Id: I939f75d6c03145dbe185d849b95b2dd99782f35c
Depends: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
Related: OS#5041
2021-02-23 16:48:36 +00:00
Pau Espin Pedrol
d6993ea4b5 tests: Replace deprecated API log_set_print_filename
log_set_print_category_hex(0) is added in some places since the old API
used to set that internally to keep backward compatiblity.

Change-Id: I3cf46b7c24452254319d5c3eacceff418211bcf7
2021-02-19 13:31:13 +01:00
Pau Espin Pedrol
f551ccf9fb .gitignore: Ignore new autofoo tmp files
Change-Id: I155e9fd644263a8b47301f6b0986b9beb5a45d0f
2021-02-04 12:46:34 +01:00
Keith
b5a5676cff Fix Coverity Warnings
Explicitly check filter_type is not NULL even though the current code
never passed a NULL filter_type unless filter was also NULL.

Remove unreachable code.

Change-Id: Ib2bd9b2d6e9e559e61a895a25235669dae05fdf6
Related: coverity CID#216865
Related: coverity CID#216867
2021-01-30 07:35:26 +01:00
Keith
89fda3024a Add vty command to show summary of all or filtered subscribers
Adds the following commands:

show subscribers all - Display summary of all entries in HLR
show subscribers (imsi|msisdn|cs|ps) ... As above but filter on search field/string
show subscribers last seen - Display only subscribers with data in
Last LU update field, and sorts by Last LU.

Change-Id: I7f0573381a6d0d13841ac6d42d50f0e8389decf4
2021-01-29 21:26:08 +00:00
Oliver Smith
dd746949d0 configure.ac: set -std=gnu11
Change-Id: I5ea5365338248e29591a40ec1e19db95f8ae6877
2021-01-28 09:28:12 +00:00
Keith
cc90bfd0f4 Correct vty inline help for show subscriber
Change-Id: I035435859b60ce6d54da307c0d6397d4bd515439
2021-01-19 07:18:50 +00:00
Oliver Smith
f4d64cb98b contrib/jenkins: don't build osmo-gsm-manuals
Related: OS#4912
Change-Id: I22246f3ff105183a7a7a0279fd6c5cde9cd19952
2021-01-13 13:15:54 +01:00
Harald Welte
bd94b41fa8 auc_test.c: Add some comments on what the test cases actually do
Change-Id: Id2b9cf12823e05aeadc6f15df396f8a46ae1639d
2021-01-04 14:03:25 +01:00
Harald Welte
6e237d3a90 support the XOR algorithm for UMTS AKA
Test USIMs as specified by 3GPP use the XOR algorithm not only for 2G
but also for 3G.  libosmocore includes the XOR-3G support since v1.3.0,
but osmo-hlr somehow never made use of it.

Change-Id: I3a452af9c18cd90d00ab4766d6bd1679456bc1a2
Closes: OS#4924
2020-12-28 22:40:09 +01:00
Vadim Yanitskiy
dac855e5c8 USSD: add special 'idle' handler to IUSE for testing
Change-Id: I0d566a60e95ce2da951f22ad47c6155c5b6a338c
2020-11-17 18:50:27 +07:00
Vadim Yanitskiy
6a6c7f87ca USSD: fix handle_ussd(): do not free() unconditionally
An internal handler may want to continue session, e.g. to request
more information from the MS.  Let's make the handlers responsible
for session state management, and check that state before calling
ss_session_free(), so a session can remain alive.

Before this patch ss->state was not set/used at all...

Change-Id: I49262e7fe26f29dedbf126087cfb8f3bb3c548dc
2020-11-17 18:47:58 +07:00
Vadim Yanitskiy
6cfef3ac26 doc/manuals: re-organize description of internal USSD handlers
Change-Id: Ieddde02f3f41e0eb05b7223026da4252c17c3712
2020-11-17 18:47:58 +07:00
Vadim Yanitskiy
66f0b5fbea doc/manuals: fix s/There/The/ in 'USSD Configuration'
Change-Id: Idbff93b6be5f546f18642ee330746e8734378b39
2020-11-17 18:47:58 +07:00
Vadim Yanitskiy
c47d5c0d77 cosmetic: fix spelling in logging message: existAnt -> existEnt
Change-Id: Id803d0c71f3762b8353289853918ea78859780b4
2020-10-29 18:05:22 +07:00
Harald Welte
dfbc2cbbc2 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: I24a9a81382ea723ad20b8caa61fb5c2abcdd86d0
2020-10-18 22:39:01 +02:00
Pau Espin Pedrol
89649ea997 contrib/jenkins: Enable parallel make in make distcheck
Change-Id: I1973e7a2a3be07b2db1db1cf5f05fd29101ee06a
Related: OS#4421
2020-10-12 19:29:36 +02:00
Pau Espin Pedrol
23ac586522 Set TCP NODELAY sockopt to GSUP cli and srv connections
GSUP is message based on top of IPA, and hence TCP. We don't want to
have Nagle algorithm enabled, since we are interested in having messages
sent as quickly as possible and there's no need for lower layers to wait
for more data (because we send all the message data at once).

Related: OS#4499
Change-Id: I4653b95ef0d4e1184f81f28408e9eb5d665206ec
2020-10-12 16:39:58 +02:00
Keith
de50b20116 osmo-hlr-db-tool: Make import from osmo-nitb less "lossy"
Include the IMEI and the last seen time in an import from
an osmo-nitb database.

Change-Id: Ic47e549be3551ae43ab6a84228d47ae03e9652a6
2020-09-23 19:41:27 +02:00
Pau Espin Pedrol
ed18fa908c Support setting rt-prio and cpu-affinity mask through VTY
Change-Id: I33101aae3e2851febc335f6fbf96228eab7cf6df
Depends: libosmocore.git Change-Id If76a4bd2cc7b3c7adf5d84790a944d78be70e10a
Depends: osmo-gsm-masnuals.git Change-Id Icd75769ef630c3fa985fc5e2154d5521689cdd3c
Related: SYS#4986
2020-08-18 13:25:34 +02:00
Pau Espin Pedrol
f464fff173 doc: Update VTY reference xml file
Change-Id: Ifdefba331ae2542b1cdc5860d0f9e53ef9f703c4
2020-08-18 12:50:21 +02:00
Pau Espin Pedrol
e893eeb1b3 configure.ac: Fix trailing whitespace
Change-Id: If0569167922695bb88c8f168f89fa300dd181c72
2020-08-18 12:49:05 +02:00
Vadim Yanitskiy
b77d568196 debian/control: change maintainer to the Osmocom team / mailing list
Change-Id: I6b38640b57480c6950be491eeb3c5167be1c6aab
2020-08-13 16:09:02 +07:00
Neels Hofmeyr
80cb6c93b9 manual: describe subscriber import by SQL
It seems a bad idea to cement the internal SQL structure in the user manual,
but since we currently lack a safe and portable import mechanism (like CSV
import in osmo-hlr-db-tool), this is currently valuable info to users.

Change-Id: I3246e6d5364215a71c33b5aca876deab7b6cfd70
2020-06-29 17:12:06 +02:00
Neels Hofmeyr
565cf83a42 osmo-mslookup-client: fix segfault for respond_error() caller
respond_error() passes r == 0. On error, consider it the last response for that
request.

Change-Id: I1acb0b8aa00c098d1f1f1cc17035daa38ce29fd3
2020-06-03 18:38:56 +02:00
Vadim Yanitskiy
fa20702e67 gsup_server: fix typo: s/omso_gsup_message/osmo_gsup_message/
Change-Id: I77eac6df9836f2361d87df7ba5ab6fc14ba06b1d
2020-05-31 18:52:38 +00:00
Oliver Smith
949a53cdf0 Makefile.am: EXTRA_DIST: debian, contrib/*.spec.in
Change-Id: I401a4849ae186bddd667446ff7247976090e1db7
2020-05-22 13:40:09 +02:00
Oliver Smith
102e362943 contrib: integrate RPM spec
Remove OpenSUSE bug report link, set version to @VERSION@, make it build
with CentOS 8 etc.

Related: OS#4550
Change-Id: I38f80d0f867a2bbaa09b5a42cad5028f23a8effa
2020-05-19 17:08:28 +02:00
Oliver Smith
2f7fb2e36b contrib: import RPM spec
Copy the RPM spec file from:
https://build.opensuse.org/project/show/home:mnhauke:osmocom:nightly

Related: OS#4550
Change-Id: Icb6f4335d5157f058b39701e9fcb332264911ba3
2020-05-19 17:08:28 +02:00
Philipp Maier
377fe5a645 doc: do not use loglevel info for log category ss
The log category ss uses info as loglevel vor ss, this is to verbose,
lets use notice instead.

Change-Id: I192a5f07cb7f45adb6f3af1c511b706738bdadf4
2020-05-12 13:34:13 +02:00
Neels Hofmeyr
c7ea21357a esme_dgsm.py: add --always-fail option for debugging SMPP
Change-Id: Ibacf2676cae40712c89b57ced34085311d9a416d
2020-05-09 21:07:53 +00:00
Neels Hofmeyr
9b8e7b4e39 hlr_subscr_nam(): fix condition to fix nam=false notifications
Firstly, vlr_number[] is an array and we need to check the first char for nul
instead of the pointer.

Also, osmo_ipa_name_set_str() returns zero on success, so the condition is
reversed.

hlr_subscr_nam() was rewritten in I3a8dff3d4a1cbe10d6ab08257a0138d6b2a082d9
ad868e29ba and this likely fixes a bug introduced
there.

Related: coverity CID#210169
Change-Id: I3a0e9ed4b865c88aa4a6341a3bf1a96c10d20ed9
2020-05-04 19:24:26 +02:00
Neels Hofmeyr
010ceb8206 osmo_mslookup_server_mdns_rx(): handle read() rc == 0
Coverity says "tainted buffer", I hope it means the case of read() returning
zero.

Related: coverity CID#210170
Change-Id: Ia2d57cb8bbacc6f54dc410047da69a983aedd24d
2020-05-04 19:15:29 +02:00
Neels Hofmeyr
1bd3ec49b1 gsup_server.c: properly handle negative rc from osmo_gsup_conn_ccm_get()
Related: coverity CID#210171
Change-Id: I5b56fe33cbc75679a3fffc034a53f06cd0e4043b
2020-05-04 17:53:52 +02:00
Neels Hofmeyr
dfe6f41c81 osmo_gsup_req_new(): require from_peer != NULL
In practice, from_peer is always non-NULL, yet some conditions checked against
NULL, looking like a possible NULL deref. Require non-NULL.

Related: coverity CID#210172
Change-Id: I3cb73ec0d31f84d4b613ecb026169c944d240e4c
2020-05-04 17:37:15 +02:00
Neels Hofmeyr
3e79a38440 make osmo_cni_peer_id_cmp() NULL safe
Related: coverity CID#210172
Change-Id: I400b23ac3f0eb68d5e4c757ea02d130fbe12f80b
2020-05-04 17:33:36 +02:00
107 changed files with 4218 additions and 2658 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
open_collective: osmocom

19
.gitignore vendored
View File

@@ -26,6 +26,7 @@ m4
*.m4
missing
.deps
*~
*.pc
.libs
@@ -67,3 +68,21 @@ doc/manuals/generated/
doc/manuals/osmomsc-usermanual.xml
doc/manuals/common
doc/manuals/build
contrib/osmo-hlr.spec
/debian/.debhelper/
/debian/libosmo-gsup-client-dev/
/debian/files
/debian/autoreconf.after
/debian/autoreconf.before
/debian/libosmo-gsup-client0/
/debian/libosmo-mslookup0/
/debian/osmo-hlr-dbg/
/debian/tmp/
/doc/manuals/vty/hlr_vty_reference.xml
/debian/libosmo-mslookup-dev/
/debian/osmo-hlr-doc/
/debian/osmo-hlr/
/debian/osmo-mslookup-utils/
/debian/*.log
/debian/*.substvars

View File

@@ -1,9 +1,9 @@
AUTOMAKE_OPTIONS = foreign dist-bzip2
SUBDIRS = \
doc \
src \
include \
doc \
sql \
contrib \
tests \
@@ -11,6 +11,9 @@ SUBDIRS = \
EXTRA_DIST = \
.version \
README.md \
debian \
git-version-gen \
$(NULL)
AM_DISTCHECK_CONFIGURE_FLAGS = \

80
README.md Normal file
View File

@@ -0,0 +1,80 @@
osmo-hlr - Osmocom HLR Implementation
=====================================
This repository contains a C-language implementation of a GSM *Home
Location Register (HLR)*. It is part of the
[Osmocom](https://osmocom.org/) Open Source Mobile Communications
project.
Warning: While the HLR logical functionality is implemented, OsmoHLR
does not use the ETSI/3GPP TCAP/MAP protocol stack. Instead, a much
simpler custom protocol (GSUP) is used. This means, OsmoHLR is of
no use outside the context of an Osmocom core network. You can use
it with [OsmoMSC](https://osmocom.org/projects/osmomsc/wiki),
[OsmoSGSN](https://osmocom.org/projects/osmosgsn/wiki) etc. -
but not directly with third party components.
Homepage
--------
The official homepage of the project is <https://osmocom.org/projects/osmo-hlr/wiki>.
GIT Repository
--------------
You can clone from the official osmo-hlr.git repository using
git clone https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr
There is a web interface at <https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr>
Documentation
-------------
User Manuals and VTY reference manuals are [optionally] built in PDF form
as part of the build process.
Pre-rendered PDF versions of the current `master` can be found at
* [User Manual](https://ftp.osmocom.org/docs/latest/osmohlr-usermanual.pdf)
* [VTY Reference Manual for osmo-hlr](https://ftp.osmocom.org/docs/latest/osmohlr-vty-reference.pdf)
Forum
-----
We welcome any osmo-hlr related discussions in the
[Cellular Network Infrastructure -> 2G/3G Core Network](https://discourse.osmocom.org/c/cni/2g-3g-cn)
section of the osmocom discourse (web based Forum).
Mailing List
------------
Discussions related to osmo-hlr are happening on the
openbsc@lists.osmocom.org mailing list, please see
https://lists.osmocom.org/mailman/listinfo/openbsc for subscription
options and the list archive.
Please observe the [Osmocom Mailing List
Rules](https://osmocom.org/projects/cellular-infrastructure/wiki/Mailing_List_Rules)
when posting.
Issue Tracker
-------------
We use the [issue tracker of the osmo-hlr project on osmocom.org](https://osmocom.org/projects/osmo-hlr/issues) for
tracking the state of bug reports and feature requests. Feel free to submit any issues you may find, or help
us out by resolving existing issues.
Contributing
------------
Our coding standards are described at
<https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards>
We use a Gerrit based patch submission/review process for managing
contributions. Please see
<https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit> for
more details
The current patch queue for osmo-hlr can be seen at
<https://gerrit.osmocom.org/#/q/project:osmo-hlr+status:open>

9
TODO-RELEASE Normal file
View File

@@ -0,0 +1,9 @@
# When cleaning up this file: bump API version in corresponding Makefile.am and rename corresponding debian/lib*.install
# according to https://osmocom.org/projects/cellular-infrastructure/wiki/Make_a_new_release
# In short: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
# LIBVERSION=c:r:a
# If the library source code has changed at all since the last update, then increment revision: c:r + 1:a.
# If any interfaces have been added, removed, or changed since the last update: c + 1:0:a.
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line

View File

@@ -12,6 +12,8 @@ AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip 1.9])
AC_CONFIG_TESTDIR(tests)
CFLAGS="$CFLAGS -std=gnu11"
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -25,7 +27,7 @@ AC_PROG_MKDIR_P
AC_PROG_CC
AC_PROG_INSTALL
dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang
dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang
AS_CASE(["$LD"],[*clang*],
[AS_CASE(["${host_os}"],
[*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])])
@@ -39,11 +41,11 @@ PKG_PROG_PKG_CONFIG([0.20])
PKG_CHECK_MODULES(TALLOC, [talloc >= 2.0.1])
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.3.0)
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.3.0)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.3.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.3.0)
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.6.0)
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.11.0)
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.11.0)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.11.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.11.0)
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 2.0.0)
PKG_CHECK_MODULES(SQLITE3, sqlite3)
@@ -91,6 +93,7 @@ AC_ARG_ENABLE(werror,
if test x"$werror" = x"yes"
then
WERROR_FLAGS="-Werror"
WERROR_FLAGS+=" -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition"
WERROR_FLAGS+=" -Wno-error=deprecated -Wno-error=deprecated-declarations"
WERROR_FLAGS+=" -Wno-error=cpp" # "#warning"
CFLAGS="$CFLAGS $WERROR_FLAGS"
@@ -105,7 +108,7 @@ if test "x$enable_ext_tests" = "xyes" ; then
AM_PATH_PYTHON
AC_CHECK_PROG(OSMOTESTEXT_CHECK,osmotestvty.py,yes)
if test "x$OSMOTESTEXT_CHECK" != "xyes" ; then
AC_MSG_ERROR([Please install git://osmocom.org/python/osmo-python-tests to run the VTY/CTRL tests.])
AC_MSG_ERROR([Please install https://gitea.osmocom.org/cellular-infrastructure/osmo-python-tests to run the VTY/CTRL tests.])
fi
fi
AC_MSG_CHECKING([whether to enable VTY/CTRL tests])
@@ -203,7 +206,6 @@ AC_OUTPUT(
tests/Makefile
tests/auc/Makefile
tests/auc/gen_ts_55_205_test_sets/Makefile
tests/gsup_server/Makefile
tests/gsup/Makefile
tests/db/Makefile
tests/db_upgrade/Makefile

View File

@@ -2,3 +2,13 @@ SUBDIRS = \
systemd \
dgsm \
$(NULL)
EXTRA_DIST = osmo-hlr-post-upgrade.sh
install-data-hook:
install -Dm755 $(srcdir)/osmo-hlr-post-upgrade.sh \
-t $(DESTDIR)$(datadir)/osmocom/
uninstall-hook:
@$(PRE_UNINSTALL)
$(RM) $(DESTDIR)$(datadir)/osmocom/osmo-hlr-post-upgrade.sh

View File

@@ -100,6 +100,9 @@ def rx_deliver_sm(pdu):
time.sleep(args.sleep)
logging.info("Sleep done")
if args.always_fail is not None:
return args.always_fail
result = query_mslookup("smpp.sms", msisdn)
if 'v4' not in result or not result['v4']:
logging.info('No IPv4 result from mslookup! This example only'
@@ -147,12 +150,35 @@ def main():
parser.add_argument('--sleep', default=0, type=float,
help='sleep time in seconds before forwarding an SMS,'
' to test multithreading (default: 0)')
parser.add_argument('--always-fail', default=None, metavar='SMPP_ESME_ERRCODE',
help='test delivery failure: always return an error code on Deliver-SM,'
' pass an smpplib error code name like RDELIVERYFAILURE (see smpplib/consts.py),'
' or an SMPP error code in hex digits')
args = parser.parse_args()
logging.basicConfig(level=logging.INFO, format='[%(asctime)s]'
' (%(threadName)s) %(message)s', datefmt="%H:%M:%S")
if args.always_fail:
resolved = None
name = 'SMPP_ESME_' + args.always_fail
if hasattr(smpplib.consts, name):
resolved = getattr(smpplib.consts, name)
if resolved is None:
try:
resolved = int(args.always_fail, 16)
except ValueError:
resolved = None
if resolved is None:
print('Invalid argument for --always-fail: %r' % args.always_fail)
exit(1)
args.always_fail = resolved
logging.info('--always-fail: returning error code %s to all Deliver-SM' % hex(args.always_fail))
smpp_bind()
if __name__ == "__main__":
main()
# vim: expandtab tabstop=4 shiftwidth=4

View File

@@ -29,13 +29,13 @@ 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 libosmocore "" --disable-doxygen
osmo-build-dep.sh libosmo-netif "" --disable-doxygen
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
@@ -57,11 +57,11 @@ autoreconf --install --force
$CONFIG
$MAKE $PARALLEL_MAKE
$MAKE check || cat-testlogs.sh
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE distcheck || cat-testlogs.sh
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE $PARALLEL_MAKE distcheck || cat-testlogs.sh
if [ "$WITH_MANUALS" = "1" ] && [ "$PUBLISH" = "1" ]; then
make -C "$base/doc/manuals" publish
fi
$MAKE maintainer-clean
$MAKE $PARALLEL_MAKE maintainer-clean
osmo-clean-workspace.sh

View File

@@ -0,0 +1,95 @@
#!/bin/sh -e
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright 2021 sysmocom s.f.m.c GmbH <info@sysmocom.de>
#
# Packagers are supposed to call this script in post-upgrade, so it can safely
# upgrade the database scheme if required.
DB="/var/lib/osmocom/hlr.db"
IS_ACTIVE=0
msg() {
echo "osmo-hlr-post-upgrade: $@"
}
err() {
msg "ERROR: $@"
}
open_db() {
# Attempt to open the database with osmo-hlr-db-tool, it will fail if
# upgrading the schema is required
osmo-hlr-db-tool -s -l "$DB" create
}
check_upgrade_required() {
if ! [ -e "$DB" ]; then
msg "nothing to do (no existing database)"
exit 0
fi
if open_db 2>/dev/null; then
msg "nothing to do (database version is up to date)"
exit 0
fi
msg "database upgrade is required"
}
stop_service() {
if systemctl is-active -q osmo-hlr; then
IS_ACTIVE=1
msg "stopping osmo-hlr service"
systemctl stop osmo-hlr
# Verify that it stopped
for i in $(seq 1 100); do
if ! systemctl is-active -q osmo-hlr; then
return
fi
sleep 0.1
done
err "failed to stop osmo-hlr service"
exit 1
else
msg "osmo-hlr service is not running"
fi
}
create_backup() {
backup="$DB.$(date +%Y%m%d%H%M%S).bak"
msg "creating backup: $backup"
if [ -e "$backup" ]; then
err "backup already exists: $backup"
exit 1
fi
cp "$DB" "$backup"
}
upgrade() {
msg "performing database upgrade"
osmo-hlr-db-tool -s -U -l "$DB" create
if ! open_db 2>/dev/null; then
err "failed to open the database after upgrade"
err "osmo-hlr-db-tool output:"
open_db
# exit because of "set -e"
fi
msg "database upgrade successful"
}
start_service() {
if [ "$IS_ACTIVE" = "1" ]; then
msg "starting osmo-hlr service"
systemctl start osmo-hlr
fi
}
check_upgrade_required
stop_service
create_backup
upgrade
start_service

View File

@@ -1,12 +1,19 @@
[Unit]
Description=Osmocom Home Location Register (OsmoHLR)
Documentation=https://osmocom.org/projects/osmo-hlr/wiki/OsmoHLR
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
Restart=always
StateDirectory=osmocom
WorkingDirectory=%S/osmocom
User=osmocom
Group=osmocom
ExecStart=/usr/bin/osmo-hlr -c /etc/osmocom/osmo-hlr.cfg -l /var/lib/osmocom/hlr.db
RestartSec=2
ProtectHome=true
[Install]
WantedBy=multi-user.target

292
debian/changelog vendored
View File

@@ -1,8 +1,294 @@
osmo-hlr (1.2.0-fw.1) unstable; urgency=medium
osmo-hlr (1.9.1) unstable; urgency=medium
* relocated to master:a450a8595
[ Pau Espin Pedrol ]
* Drop use of deprecated vty is_config_node() cb
-- Kirill Zakharenko <kirill.zakharenko@fairwaves.co> Fri, 1 May 2020 18:23:29 +0300
[ Oliver Smith ]
* db: flush after changing schema version
-- Oliver Smith <osmith@sysmocom.de> Wed, 02 Apr 2025 15:12:35 +0200
osmo-hlr (1.9.0) unstable; urgency=medium
[ Vadim Yanitskiy ]
* subscriber-create-on-demand: rework configuration
* subscriber-create-on-demand: add mode for MSISDN=IMSI
[ Alexander Couzens ]
* gsupclient: Introduce gsup_client_mux
* gsupclient: add missing SPDX line
* debian/copyright: add gsup_client under GPLv2+
[ Pau Espin Pedrol ]
* gsup: Replace deprecated ipa_msg_push_header()
* jenkins.sh: libosmo-netif no longer depends on libosmo-abis
* Drop use of libosmo-abis osmocom/abis/ipaccess.h
* gsup_client: Add new APIs to avoid users accessing struct fields
* gsup_client: Avoid double memset 0
* Drop unneeded use of abis/ipa.h header
* jenkins.sh: Use --disable-doxygen configure param
[ Mychaela N. Falconia ]
* vty: always emit reject-cause lines in saved config
* change default reject cause to plmn-not-allowed
* change default no-proxy reject cause to net-fail
-- Oliver Smith <osmith@sysmocom.de> Wed, 12 Feb 2025 12:17:52 +0100
osmo-hlr (1.8.0) unstable; urgency=medium
[ Vadim Yanitskiy ]
* hlr_vty.c: drop redundant include of hlr_ussd.h
* build: include {README.md,git-version-gen} into the release tarball
* README.md: cosmetic: fix a typo
[ Mychaela N. Falconia ]
* SMS over GSUP: implement vty config of SMSC routing
* SMS over GSUP: implement forwarding of MO SMS
* SMS over GSUP: implement forwarding of MT SMS
* SMS over GSUP: handle READY-FOR-SM.req from MSCs
* ctrl: add subscriber.by-*.imsi GET-able variable
[ Andreas Eversberg ]
* Use uniform log format for default config files
[ Harald Welte ]
* Add funding link to github mirror
* README.md: Improve mark-down formatting
* README.md: Add Forum and Issue Tracker sections
[ Max ]
* .deb/.rpm: add osmocom user during package install
[ Oliver Smith ]
* .deb/.rpm: various fixes related to non-root
* contrib: remove rpm spec file
* debian/postinst: add checks, be verbose
* mslookup: don't ignore return value of write()
-- Oliver Smith <osmith@sysmocom.de> Wed, 24 Jul 2024 15:29:12 +0200
osmo-hlr (1.7.0) unstable; urgency=medium
[ Oliver Smith ]
* Run struct_endianness.py
* tests/db/db_test.err: adjust to XOR-3G rename
* debian: set compat level to 10
* systemd: depend on networking-online.target
[ Pau Espin Pedrol ]
* mslookup: Call osmo_fd_unregister() before closing and changing bfd->fd
[ Vadim Yanitskiy ]
* tests/auc/Makefile.am: put object files to LDADD
* tests/*/Makefile.am: move -I to AM_CPPFLAGS
* lu_fsm: fix memleak in lu_fsm_wait_insert_data_result()
* ussd: fix GSUP memleaks in rx_proc_ss_{req,error}()
* gsup_server: fix msgb memleak in osmo_gsup_server_read_cb()
* USSD: fix handling of ussd-DataCodingScheme != 0x0f
[ Alexander Couzens ]
* hlr: use talloc for memory allocation in osmo_gsup_create_insert_subscriber_data_msg
* Add support for multiple APN profiles for subscriber data
[ Harald Welte ]
* Introduce support for XOR-2G algorithm
* cosmetic: gen_ts_55_205_test_sets/func_template.c: Use tab-indent
* cosmetic: gen_ts_55_205_test_sets/main_template tabs istead of spaces
* Port to new libosmogsm 'struct osmo_sub_auth_data2'
* src/db.c: Switch from "const char *statements" to "const char * const"
* db: extend database schema to support 256bit K and/or OP[c] values
* Add VTY support for TUAK algorithm
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 12 Sep 2023 14:41:33 +0200
osmo-hlr (1.6.0) unstable; urgency=medium
[ Vadim Yanitskiy ]
* db_auc: hexparse_stmt(): check value returned by osmo_hexparse()
[ Max ]
* Set working directory in systemd service file
* Ignore .deb build byproducts
* Debian: bump copyright year to match current
* Debian: reformat package description
* systemd: enable basic hardening
* Debian: install osmo-hlr-dgsm.cfg as example config
* hlr_vty.c: fix typo
* ctrl: take both address and port from vty config
[ Harald Welte ]
* Support building with -Werror=strict-prototypes / -Werror=old-style-definition
* Add -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition
[ arehbein ]
* osmo-hlr: Transition to use of 'telnet_init_default'
[ Oliver Smith ]
* osmo_mdns_rfc_record_decode: check ret of talloc
* osmo_mdns_rfc_record_decode: proper free on err
* mslookup: use apn functions from libosmocore
* osmo_mdns_rfc_record/question_encode: remove ctx
[ Keith ]
* Vty: Fixup config shown/written from vty
[ Neels Hofmeyr ]
* fix memleak of proxy_subscr_listentry
[ Alexander Couzens ]
* Add vty `reject-cause` to set the reject cause
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 07 Feb 2023 16:49:14 +0100
osmo-hlr (1.5.0) unstable; urgency=medium
[ Oliver Smith ]
* treewide: remove FSF address
[ Vadim Yanitskiy ]
* fixup: debian: remove unneeded dependency libdbd-sqlite3
* debian: add new 'osmo-mslookup-utils' package
* tests: use 'check_PROGRAMS' instead of 'noinst_PROGRAMS'
[ Pau Espin Pedrol ]
* ctrl: Mark function as static
* tests: Allow specyfing specific ctrl test to run
* tests/ctrl: Move ERROR test scenario to proper file
* Fix db_subscr_create() not returning -EEXIST expected by VTY subscriber create cmd
* ctrl: Introduce cmd SET subscriber.create <imsi>
* ctrl: Introduce CTRL command subscriber.by-*.msisdn
* cosmetic: hlr_vty_subscr.c: Fix trailing whitespace
* ctrl: Introduce cmd SET subscriber.delete <imsi>
* ctrl: Introduce CTRL command subscriber.by-*.aud2g <algo[,ki]>
* ctrl: Introduce CTRL command subscriber.by-*.aud3g <algo[,KI,(op|opc),OP_C[,ind_bitlen]]>
* doc: Document new subscriber CTRL commands
[ Harald Welte ]
* update git URLs (git -> https; gitea)
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 28 Jun 2022 18:38:31 +0200
osmo-hlr (1.4.0) unstable; urgency=medium
[ Keith ]
* Correct configuration written from vty
* vty: enable show subscribers filtered by IMEI
[ Harald Welte ]
* add README.md file as customary for cgit, github, gitlab, etc.
[ Oliver Smith ]
* Add post-upgrade script for automatic db upgrade
* debian/control: remove dh-systemd build-depend
[ Pau Espin Pedrol ]
* db: Avoid use uninitialized rc if running 0 statements
[ Neels Hofmeyr ]
* db v6: determine 3G AUC IND from VLR name
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 16 Nov 2021 14:56:41 +0100
osmo-hlr (1.3.0) unstable; urgency=medium
[ Alexander Couzens ]
* hlr: respect the num_auth_vectors requested
* hlr: remove unused internal USSD list
[ Oliver Smith ]
* add libosmo-mslookup abstract client
* add mDNS lookup method to libosmo-mslookup
* Makefile.am: fix pkgconfig_DATA
* add mDNS lookup method to libosmo-mslookup (#2)
* contrib/dgsm/ add example esme and dialplan
* mslookup_client.c: fix dereferencing null pointer
* mdns_msg.c: always call va_end
* mslookup_client_mdns.c: fix dereferencing null
* osmo-mslookup-client.c: fix dereferencing null
* osmo-mslookup-client: fix dereferencing null
* mdns_sock.c: fix resource leak of sock
* mdns_rfc.c: fix possible access of uninit. mem
* mslookup_client_mdns_test: disable by default
* mslookup_client_mdns_test: no automatic skip
* Cosmetic: mention OS#4491 in location cancel code
* hlr_vty_subscr: prettier output for last LU seen
* contrib: import RPM spec
* contrib: integrate RPM spec
* Makefile.am: EXTRA_DIST: debian, contrib/*.spec.in
* contrib/jenkins: don't build osmo-gsm-manuals
* configure.ac: set -std=gnu11
[ Neels Hofmeyr ]
* add osmo-mslookup-client program
* add osmo-mslookup-client program (#2)
* fix missing braces in LOGP_GSUP_FWD
* gsup_client.c: fix deprecation for client create func
* 1/2: refactor: add and use lu_fsm, osmo_gsup_req, osmo_ipa_name
* 2/2: wrap ipa_name in osmo_cni_peer_id with type enum and union
* gsup client: add up_down_cb(), add osmo_gsup_client_create3()
* db v5: prep for D-GSM: add vlr_via_proxy and sgsn_via_proxy
* enlarge the GSUP message headroom
* test_nodes.vty: remove cruft
* D-GSM 1/n: add mslookup server in osmo-hlr
* D-GSM 2/n: implement mDNS method of mslookup server
* D-GSM 3/n: implement roaming by mslookup in osmo-hlr
* gsup_server: send routing error back to the correct peer
* adoc: add D-GSM chapter to osmohlr-usermanual
* drop error log for when a subscriber does not exist
* vty: show subscriber: change format of 'last LU seen'
* vty: show subscriber: show lu d,h,m,s ago, not just seconds
* auc3g: officially wrap IND around IND_bitlen space
* make osmo_cni_peer_id_cmp() NULL safe
* osmo_gsup_req_new(): require from_peer != NULL
* gsup_server.c: properly handle negative rc from osmo_gsup_conn_ccm_get()
* osmo_mslookup_server_mdns_rx(): handle read() rc == 0
* hlr_subscr_nam(): fix condition to fix nam=false notifications
* esme_dgsm.py: add --always-fail option for debugging SMPP
* osmo-mslookup-client: fix segfault for respond_error() caller
* manual: describe subscriber import by SQL
[ Harald Welte ]
* Revert "add osmo-mslookup-client program"
* Revert "add mDNS lookup method to libosmo-mslookup"
* Use OSMO_FD_* instead of deprecated BSC_FD_*
* support the XOR algorithm for UMTS AKA
* auc_test.c: Add some comments on what the test cases actually do
* main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
* manuals: generate vty reference xml at build time
[ Vadim Yanitskiy ]
* db: fix possible SQLite3 allocated memory leak in db_open()
* gsup_server: fix typo: s/omso_gsup_message/osmo_gsup_message/
* debian/control: change maintainer to the Osmocom team / mailing list
* cosmetic: fix spelling in logging message: existAnt -> existEnt
* doc/manuals: fix s/There/The/ in 'USSD Configuration'
* doc/manuals: re-organize description of internal USSD handlers
* USSD: fix handle_ussd(): do not free() unconditionally
* USSD: add special 'idle' handler to IUSE for testing
[ Eric ]
* configure.ac: fix libtool issue with clang and sanitizer
[ Philipp Maier ]
* doc: do not use loglevel info for log category ss
[ Pau Espin Pedrol ]
* configure.ac: Fix trailing whitespace
* doc: Update VTY reference xml file
* Support setting rt-prio and cpu-affinity mask through VTY
* Set TCP NODELAY sockopt to GSUP cli and srv connections
* contrib/jenkins: Enable parallel make in make distcheck
* .gitignore: Ignore new autofoo tmp files
* tests: Replace deprecated API log_set_print_filename
[ Keith ]
* osmo-hlr-db-tool: Make import from osmo-nitb less "lossy"
* Correct vty inline help for show subscriber
* Add vty command to show summary of all or filtered subscribers
* Fix Coverity Warnings
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 23 Feb 2021 18:13:53 +0100
osmo-hlr (1.2.0) unstable; urgency=medium

2
debian/compat vendored
View File

@@ -1 +1 @@
9
10

38
debian/control vendored
View File

@@ -1,30 +1,30 @@
Source: osmo-hlr
Section: net
Priority: optional
Maintainer: Max Suraev <msuraev@sysmocom.de>
Build-Depends: debhelper (>= 9),
Maintainer: Osmocom team <openbsc@lists.osmocom.org>
Build-Depends: debhelper (>= 10),
pkg-config,
dh-autoreconf,
dh-systemd (>= 1.5),
autotools-dev,
python3-minimal,
libosmocore-dev,
libosmo-abis-dev,
libosmo-netif-dev,
libosmocore-dev (>= 1.11.0),
libosmo-abis-dev (>= 2.0.0),
libosmo-netif-dev (>= 1.6.0),
libsqlite3-dev,
sqlite3,
osmo-gsm-manuals-dev
osmo-gsm-manuals-dev (>= 1.6.0)
Standards-Version: 3.9.6
Vcs-Browser: http://cgit.osmocom.org/osmo-hlr
Vcs-Git: git://git.osmocom.org/osmo-hlr
Vcs-Browser: https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr
Vcs-Git: https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr
Homepage: https://projects.osmocom.org/projects/osmo-hlr
Package: osmo-hlr
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libdbd-sqlite3
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Osmocom Home Location Register
OsmoHLR is a Osmocom implementation of HLR (Home Location Registrar) which works over GSUP
protocol. The subscribers are store in sqlite DB. It supports both 2G and 3G authentication.
OsmoHLR is a Osmocom implementation of HLR (Home Location Registrar) which
works over GSUP protocol. The subscribers are store in sqlite DB.
It supports both 2G and 3G authentication.
Package: osmo-hlr-dbg
Architecture: any
@@ -59,7 +59,7 @@ Description: Development headers of Osmocom GSUP client library
.
This package contains the development headers.
Package: libosmo-mslookup0
Package: libosmo-mslookup1
Section: libs
Architecture: any
Multi-Arch: same
@@ -73,7 +73,7 @@ Package: libosmo-mslookup-dev
Architecture: any
Multi-Arch: same
Depends: ${misc:Depends},
libosmo-mslookup0 (= ${binary:Version}),
libosmo-mslookup1 (= ${binary:Version}),
libosmocore-dev
Pre-Depends: ${misc:Pre-Depends}
Description: Development headers of Osmocom MS lookup library
@@ -81,6 +81,16 @@ Description: Development headers of Osmocom MS lookup library
.
This package contains the development headers.
Package: osmo-mslookup-utils
Architecture: any
Section: utils
Depends: ${shlibs:Depends},
libosmo-mslookup1 (= ${binary:Version}),
${misc:Depends}
Multi-Arch: same
Description: Utilities for Osmocom MS lookup
This package contains a simple MS lookup client utility.
Package: osmo-hlr-doc
Architecture: all
Section: doc

20
debian/copyright vendored
View File

@@ -3,9 +3,13 @@ Upstream-Name: OsmoHLR
Source: http://cgit.osmocom.org/osmo-hlr/
Files: *
Copyright: 2016-2017 Sysmocom s. f. m. c. GmbH <info@sysmocom.de>
Copyright: 2016-2022 Sysmocom s. f. m. c. GmbH <info@sysmocom.de>
License: AGPL-3+
Files: src/gsupclient/*
Copyright: 2014-2016,2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
License: GPL-2+
License: AGPL-3+
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
@@ -19,3 +23,17 @@ License: AGPL-3+
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/>.
License: GPL-2+
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/>.

View File

@@ -5,4 +5,5 @@
/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
/usr/share/doc/osmo-hlr/examples/osmo-hlr-dgsm.cfg
/usr/share/osmocom/osmo-hlr-post-upgrade.sh

1
debian/osmo-mslookup-utils.install vendored Normal file
View File

@@ -0,0 +1 @@
usr/bin/osmo-mslookup-client

43
debian/postinst vendored Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/sh -e
# Debian's postinst script is called on both installation and upgrade. Call the
# post-upgrade script in both cases, it won't do anything if there is nothing
# to do.
/usr/share/osmocom/osmo-hlr-post-upgrade.sh
case "$1" in
configure)
# Create the osmocom group and user (if it doesn't exist yet)
if ! getent group osmocom >/dev/null; then
groupadd --system osmocom
fi
if ! getent passwd osmocom >/dev/null; then
useradd \
--system \
--gid osmocom \
--home-dir /var/lib/osmocom \
--shell /sbin/nologin \
--comment "Open Source Mobile Communications" \
osmocom
fi
# Fix permissions of previous (root-owned) install (OS#4107)
if dpkg --compare-versions "$2" le "1.8.0"; then
if [ -e /etc/osmocom/osmo-hlr.cfg ]; then
chown -v osmocom:osmocom /etc/osmocom/osmo-hlr.cfg
chmod -v 0660 /etc/osmocom/osmo-hlr.cfg
fi
if [ -d /etc/osmocom ]; then
chown -v root:osmocom /etc/osmocom
chmod -v 2775 /etc/osmocom
fi
mkdir -p /var/lib/osmocom
chown -R -v osmocom:osmocom /var/lib/osmocom
fi
;;
esac
# dh_installdeb(1) will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#

View File

@@ -1,4 +1,12 @@
# OsmoHLR example configuration for Distributed GSM (mslookup)
log stderr
logging color 1
logging print category-hex 0
logging print category 1
logging timestamp 0
logging print file basename last
logging print level 1
hlr
gsup
# For D-GSM roaming, osmo-hlr's GSUP must listen on a public IP:

View File

@@ -4,15 +4,15 @@
log stderr
logging filter all 1
logging color 1
logging print category 1
logging print category-hex 0
logging print level 1
logging print category 1
logging timestamp 0
logging print file basename last
logging print extended-timestamp 1
logging print level 1
logging level main notice
logging level db notice
logging level auc notice
logging level ss info
logging level ss notice
logging level linp error
!
line vty
@@ -24,3 +24,9 @@ hlr
bind ip 127.0.0.1
ussd route prefix *#100# internal own-msisdn
ussd route prefix *#101# internal own-imsi
ps
pdp-profiles default
profile 1
apn internet
profile 2
apn *

View File

@@ -1,6 +1,10 @@
EXTRA_DIST = example_subscriber_add_update_delete.vty \
EXTRA_DIST = \
example_subscriber_add_update_delete.vty \
example_subscriber_aud2g.ctrl \
example_subscriber_aud3g.ctrl \
example_subscriber_cs_ps_enabled.ctrl \
example_subscriber_info.ctrl \
example_subscriber_msisdn.ctrl \
osmohlr-usermanual.adoc \
osmohlr-usermanual-docinfo.xml \
osmohlr-vty-reference.xml \
@@ -14,6 +18,12 @@ if BUILD_MANUALS
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.asciidoc.inc
VTY_REFERENCE = osmohlr-vty-reference.xml
BUILT_REFERENCE_XML = $(builddir)/vty/hlr_vty_reference.xml
$(builddir)/vty/hlr_vty_reference.xml: $(top_builddir)/src/osmo-hlr
mkdir -p $(builddir)/vty
$(top_builddir)/src/osmo-hlr --vty-ref-xml > $@
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.vty-reference.inc
OSMO_REPOSITORY = osmo-hlr

View File

@@ -5,6 +5,16 @@ 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.
Subscribers can be created and deleted using the following SET commands:
.Subscriber management commands available on OsmoHLR's Control interface
[options="header",width="100%",cols="35%,65%"]
|===
|Command|Comment
|subscriber.create '123456'|Create a new subscriber with IMSI "123456" to the database. Returns database ID of the subscriber being created.
|subscriber.delete '123456'|Delete subscriber with IMSI "123456" from database. Returns database ID of the subscriber being deleted.
|===
All subscriber variables are available by different selectors, which are freely
interchangeable:
@@ -28,6 +38,9 @@ Each of the above selectors feature all of these control variables:
|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-\*.*msisdn*|RW|No|valid MSISDN string|Get/Set assigned MSISDN
|subscriber.by-\*.*aud2g*|RW|No|'algo[,KI]'|Get/Set 2g Authentication Data
|subscriber.by-\*.*aud2g*|RW|No|'algo[,KI,("op"|"opc"),OP_C[,ind_bitlen]]'|Get/Set 3g Authentication Data
|===
=== subscriber.by-*.info, info-aud, info-all
@@ -104,3 +117,63 @@ commands:
----
include::../example_subscriber_cs_ps_enabled.ctrl[]
----
=== subscriber.by-*.msisdn
Get or set the MSISDN currently assigned to a subscriber.
This is an example transcript that illustrates use of this command:
----
include::../example_subscriber_msisdn.ctrl[]
----
=== subscriber.by-*.aud2g
Get or set the 2G Authentication data of a subscriber.
The information is stored/retrieved as a comma separated list of fields:
----
algo[,KI]
----
Where::
* *KI* is the KI as a hexadecimal string.
* *algo* is one of the following algorithms: _none, xor, comp128v1, comp128v2,
comp128v3_.
All values are case insensitive.
This is an example transcript that illustrates use of this command:
----
include::../example_subscriber_aud2g.ctrl[]
----
=== subscriber.by-*.aud3g
Get or set the 3G Authentication data of a subscriber.
The information is stored/retrieved as a comma separated list of fields:
----
algo[,KI,("op"|"opc"),OP_C[,ind_bitlen]]
----
Where:
* *KI* is the KI as a hexadecimal string.
* *algo* is one of the following algorithms: _none, xor, milenage_.
* "op" or "opc" indicates whether next field is an OP or OPC value.
* *OP_C* contains an OP or OPC values as hexadecimal string, based on what the
previous field specifies.
* *ind_bitlen* is set to 5 by default if not provided.
All values are case insensitive.
This is an example transcript that illustrates use of this command:
----
include::../example_subscriber_aud3g.ctrl[]
----

View File

@@ -54,7 +54,7 @@ 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`.
from an old 'OsmoNITB' database. See <<db_import_nitb>>.
=== Multiple instances

View File

@@ -127,3 +127,83 @@ OsmoHLR# subscriber imei 35761300444848 show
----
<1> Randomly generated 5 digit MSISDN
<2> Disabled CS and PS NAM prevent the subscriber from accessing the network
=== Import Subscriber Data
==== Scripted Import
WARNING: It is not generally a good idea to depend on the HLR database's internal table structure, but in the lack of an
automated import procedure, this example is provided as an ad-hoc method to aid automated subscriber import. This is not
guaranteed to remain valid.
NOTE: We may add CSV and other import methods to the `osmo-hlr-db-tool`, but so far that is not implemented. Contact the
community if you are interested in such a feature being implemented.
NOTE: `sqlite3` is available from your distribution packages or `sqlite.org`.
Currently, probably the easiest way to automatically import subscribers to OsmoHLR is to write out a text file with SQL
commands per subscriber, and feed that to `sqlite3`, as described below.
A difficulty is to always choose subscriber IDs that are not yet in use. For an initial import, the subscriber ID may be
incremented per subscriber record. If adding more subscribers to an existing database, it is necessary to choose
subscriber IDs that are not yet in use. Get the highest ID in use with:
----
sqlite3 hlr.db 'select max(id) from subscriber'
----
A full SQL example of adding a single subscriber with id 23, IMSI 001010123456789, MSISDN 1234, Ki for COMP128v1, and K
and OPC for Milenage:
----
INSERT subscriber (id, imsi, msisdn) VALUES (23, '001010123456789', '1234');
INSERT INTO auc_2g (subscriber_id, algo_id_2g, ki)
VALUES(23, 1, '0123456789abcdef0123456789abcdef');
INSERT INTO auc_3g (subscriber_id, algo_id_3g, k, op, opc)
VALUES(23, 5, '0123456789abcdef0123456789abcdef',NULL,'0123456789abcdef0123456789abcdef');
----
Table entries to `auc_2g` and/or `auc_3g` may be omitted if no such key material is required.
UMTS Milenage auth (on both 2G and 3G RAN) is configured by the `auc_3g` table. `algo_id_3g` must currently always be 5
(MILENAGE).
The algorithm IDs for `algo_id_2g` and `algo_id_3g` are:
.Algorithm IDs in OsmoHLR's database
[options="header",width="50%",cols="40%,60%"]
|===
|`algo_id_2g` / `algo_id_3g` | Authentication Algorithm
| 1 | COMP128v1
| 2 | COMP128v2
| 3 | COMP128v3
| 4 | XOR
| 5 | MILENAGE
|===
Create an empty HLR database with
----
osmo-hlr-db-tool -l hlr.db create
----
Repeat above SQL commands per subscriber, incrementing the subscriber ID for each block, then feed the SQL commands for
the subscribers to be imported to the `sqlite3` command line tool:
----
sqlite3 hlr.db < subscribers.sql
----
[[db_import_nitb]]
==== Import OsmoNITB database
To upgrade from old OsmoNITB to OsmoHLR, use `osmo-hlr-db-tool`:
----
osmo-hlr-db-tool -l hlr.db import-nitb-db nitb.db
----
Be aware that the import is lossy, only the IMSI, MSISDN, nam_cs/ps and 2G auth data are set.

View File

@@ -50,15 +50,29 @@ 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
to the named internal USSD handler. The 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.
the subscribers own phone number. More information on internal USSD
handlers can be found in <<iuse_handlers>>.
`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.
[[iuse_handlers]]
=== Built-in USSD handlers
OsmoHLR has an Internal USSD Entity (IUSE) that allows to handle some
USSD requests internally. It features a set of simple handlers, which
can be assigned to one or more USSD request prefixes:
* `own-msisdn` returns subscriber's MSISDN (if assigned);
* `own-imsi` returns subscriber's IMSI;
* `test-idle` keeps the session idle until the MS terminates it, or
the guard timer expires (may be useful for testing).
Additional handlers can be added on request.
=== Example EUSE program
We have provided an example EUSE developed in C language using existing

View File

@@ -0,0 +1,14 @@
GET 1 subscriber.by-imsi-901991234567891.aud2g
GET_REPLY 1 subscriber.by-imsi-901991234567891.aud2g none
SET 2 subscriber.by-imsi-901991234567891.aud2g xor,c01ffedc1cadaeac1d1f1edacac1ab0a
SET_REPLY 2 subscriber.by-imsi-901991234567891.aud2g OK
GET 3 subscriber.by-imsi-901991234567891.aud2g
GET_REPLY 3 subscriber.by-imsi-901991234567891.aud2g XOR,c01ffedc1cadaeac1d1f1edacac1ab0a
SET 4 subscriber.by-imsi-901991234567891.aud2g none
SET_REPLY 4 subscriber.by-imsi-901991234567891.aud2g OK
GET 5 subscriber.by-imsi-901991234567891.aud2g
GET_REPLY 5 subscriber.by-imsi-901991234567891.aud2g none

View File

@@ -0,0 +1,20 @@
GET 117 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 117 subscriber.by-imsi-901991234567891.aud3g none
SET 118 subscriber.by-imsi-901991234567891.aud3g milenage,c01ffedc1cadaeac1d1f1edacac1ab0a,OP,FB2A3D1B360F599ABAB99DB8669F8308
SET_REPLY 118 subscriber.by-imsi-901991234567891.aud3g OK
GET 119 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 119 subscriber.by-imsi-901991234567891.aud3g MILENAGE,c01ffedc1cadaeac1d1f1edacac1ab0a,OP,fb2a3d1b360f599abab99db8669f8308,5
SET 120 subscriber.by-imsi-901991234567891.aud3g milenage,c01ffedc1cadaeac1d1f1edacac1ab0a,OPC,FB2A3D1B360F599ABAB99DB8669F8308,7
SET_REPLY 120 subscriber.by-imsi-901991234567891.aud3g OK
GET 121 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 121 subscriber.by-imsi-901991234567891.aud3g MILENAGE,c01ffedc1cadaeac1d1f1edacac1ab0a,OPC,fb2a3d1b360f599abab99db8669f8308,7
SET 122 subscriber.by-imsi-901991234567891.aud3g none
SET_REPLY 122 subscriber.by-imsi-901991234567891.aud3g OK
GET 123 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 123 subscriber.by-imsi-901991234567891.aud3g none

View File

@@ -0,0 +1,8 @@
GET 1 subscriber.by-imsi-901991234567891.msisdn
GET_REPLY 1 subscriber.by-imsi-901991234567891.msisdn none
SET 2 subscriber.by-imsi-901991234567891.msisdn 555666
SET_REPLY 2 subscriber.by-imsi-901991234567891.msisdn OK
GET 3 subscriber.by-imsi-901991234567891.msisdn
GET_REPLY 3 subscriber.by-imsi-901991234567891.msisdn 555666

View File

@@ -28,6 +28,8 @@ include::{srcdir}/chapters/dgsm.adoc[]
include::./common/chapters/gsup.adoc[]
include::./common/chapters/vty_cpu_sched.adoc[]
include::./common/chapters/port_numbers.adoc[]
include::./common/chapters/bibliography.adoc[]
@@ -35,4 +37,3 @@ include::./common/chapters/bibliography.adoc[]
include::./common/chapters/glossary.adoc[]
include::./common/chapters/gfdl.adoc[]

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,7 @@ SUBDIRS = osmocom
nobase_include_HEADERS = \
osmocom/gsupclient/cni_peer_id.h \
osmocom/gsupclient/gsup_client.h \
osmocom/gsupclient/gsup_client_mux.h \
osmocom/gsupclient/gsup_req.h \
osmocom/mslookup/mdns.h \
osmocom/mslookup/mdns_sock.h \

View File

@@ -20,6 +20,9 @@
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <osmocom/core/timer.h>
#include <osmocom/gsm/oap_client.h>
#include <osmocom/gsm/ipa.h>
@@ -40,6 +43,7 @@ typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct
typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up);
/* NOTE: THIS STRUCT IS CONSIDERED PRIVATE, AVOID ACCESSING ITS FIELDS! */
struct osmo_gsup_client {
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
@@ -99,3 +103,12 @@ 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);
void *osmo_gsup_client_get_data(const struct osmo_gsup_client *gsupc);
void osmo_gsup_client_set_data(struct osmo_gsup_client *gsupc, void *data);
const char *osmo_gsup_client_get_rem_addr(const struct osmo_gsup_client *gsupc);
uint16_t osmo_gsup_client_get_rem_port(const struct osmo_gsup_client *gsupc);
bool osmo_gsup_client_is_connected(const struct osmo_gsup_client *gsupc);
const struct ipaccess_unit *osmo_gsup_client_get_ipaccess_unit(const struct osmo_gsup_client *gsupc);

View File

@@ -0,0 +1,56 @@
/*
* (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <osmocom/gsm/gsup.h>
struct gsup_client_mux;
struct ipaccess_unit;
struct gsup_client_mux_rx_cb {
int (*func)(struct gsup_client_mux *gcm, void *data, const struct osmo_gsup_message *gsup_msg);
void *data;
};
/* A GSUP client shared between code paths for various GSUP Message Classes.
* The main task is to dispatch GSUP messages to code paths corresponding to the respective Message Class, i.e.
* subscriber management, SMS, SS/USSD and inter-MSC messaging.
* If a GSUP Message Class IE is present in the message, the received message is dispatched directly to the rx_cb entry
* for that Message Class. Otherwise, the Message Class is determined by a switch() on the Message Type.*/
struct gsup_client_mux {
struct osmo_gsup_client *gsup_client;
/* Target clients by enum osmo_gsup_message_class */
struct gsup_client_mux_rx_cb rx_cb[OSMO_GSUP_MESSAGE_CLASS_ARRAYSIZE];
};
struct gsup_client_mux *gsup_client_mux_alloc(void *talloc_ctx);
int gsup_client_mux_start(struct gsup_client_mux *gcm, const char *gsup_server_addr_str, uint16_t gsup_server_port,
struct ipaccess_unit *ipa_dev);
int gsup_client_mux_tx(struct gsup_client_mux *gcm, const struct osmo_gsup_message *gsup_msg);
void gsup_client_mux_tx_set_source(const struct gsup_client_mux *gcm, struct osmo_gsup_message *gsup_msg);
void gsup_client_mux_tx_error_reply(struct gsup_client_mux *gcm, const struct osmo_gsup_message *gsup_orig,
enum gsm48_gmm_cause cause);
int gsup_client_mux_rx(struct osmo_gsup_client *gsup_client, struct msgb *msg);

View File

@@ -6,6 +6,7 @@ noinst_HEADERS = \
gsup_router.h \
gsup_server.h \
hlr.h \
hlr_sms.h \
hlr_ussd.h \
hlr_vty.h \
hlr_vty_subscr.h \

View File

@@ -3,6 +3,6 @@
#include <osmocom/crypt/auth.h>
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,
struct osmo_sub_auth_data2 *aud2g,
struct osmo_sub_auth_data2 *aud3g,
const uint8_t *rand_auts, const uint8_t *auts);

View File

@@ -30,5 +30,4 @@ enum hlr_ctrl_node {
_LAST_CTRL_NODE_HLR
};
int hlr_ctrl_cmds_install();
struct ctrl_handle *hlr_controlif_setup(struct hlr *hlr);

View File

@@ -4,10 +4,18 @@
#include <sqlite3.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsm/gsup.h>
struct hlr;
enum stmt_idx {
DB_STMT_SEL_ALL,
DB_STMT_SEL_ALL_ORDER_LAST_SEEN,
DB_STMT_SEL_FILTER_MSISDN,
DB_STMT_SEL_FILTER_IMSI,
DB_STMT_SEL_FILTER_IMEI,
DB_STMT_SEL_FILTER_CS,
DB_STMT_SEL_FILTER_PS,
DB_STMT_SEL_BY_IMSI,
DB_STMT_SEL_BY_MSISDN,
DB_STMT_SEL_BY_ID,
@@ -33,6 +41,9 @@ enum stmt_idx {
DB_STMT_SET_LAST_LU_SEEN_PS,
DB_STMT_EXISTS_BY_IMSI,
DB_STMT_EXISTS_BY_MSISDN,
DB_STMT_IND_ADD,
DB_STMT_IND_SELECT,
DB_STMT_IND_DEL,
_NUM_DB_STMT
};
@@ -59,8 +70,8 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite3_log
/* obtain the authentication data for a given imsi */
int db_get_auth_data(struct db_context *dbc, const char *imsi,
struct osmo_sub_auth_data *aud2g,
struct osmo_sub_auth_data *aud3g,
struct osmo_sub_auth_data2 *aud2g,
struct osmo_sub_auth_data2 *aud3g,
int64_t *subscr_id);
int db_update_sqn(struct db_context *dbc, int64_t id,
@@ -110,7 +121,7 @@ struct hlr_subscriber {
* 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.
/* Like struct osmo_sub_auth_data2, 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
* with. In the binary format, a VTY command would first need to hexparse,
@@ -148,6 +159,9 @@ int db_subscr_update_imei_by_imsi(struct db_context *dbc, const char* imsi, cons
int db_subscr_exists_by_imsi(struct db_context *dbc, const char *imsi);
int db_subscr_exists_by_msisdn(struct db_context *dbc, const char *msisdn);
int db_subscrs_get(struct db_context *dbc, const char *filter_type, const char *filter,
void (*get_cb)(struct hlr_subscriber *subscr, void *data), void *data,
int *count, const char **err);
int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
struct hlr_subscriber *subscr);
int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
@@ -163,6 +177,9 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
int db_subscr_purge(struct db_context *dbc, const char *by_imsi,
bool purge_val, bool is_ps);
int db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr, unsigned int *ind);
int db_ind_del(struct db_context *dbc, const struct osmo_cni_peer_id *vlr);
/*! Call sqlite3_column_text() and copy result to a char[].
* \param[out] buf A char[] used as sizeof() arg(!) and osmo_strlcpy() target.
* \param[in] stmt An sqlite3_stmt*.

View File

@@ -25,6 +25,7 @@
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
#define OSMO_DGSM_DEFAULT_RESULT_TIMEOUT_MS 2000
#define LOG_DGSM(imsi, level, fmt, args...) \
LOGP(DDGSM, level, "(IMSI-%s) " fmt, imsi, ##args)

View File

@@ -2,9 +2,9 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/msgb.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/abis/ipaccess.h>
#include <osmocom/gsm/gsup.h>
#include <osmocom/gsm/protocol/ipaccess.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
@@ -42,8 +42,6 @@ struct osmo_gsup_conn {
//struct oap_state oap_state;
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 */
@@ -71,8 +69,6 @@ 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);
enum osmo_gsup_cn_domain cn_domain, void *talloc_ctx);
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_cni_peer_id *to_peer,
struct osmo_gsup_req *req, struct osmo_gsup_message *modified_gsup);

View File

@@ -23,6 +23,7 @@
#pragma once
#include <stdbool.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/gsm/ipa.h>
#include <osmocom/core/tdef.h>
@@ -38,6 +39,13 @@ enum osmo_gsup_message_type;
extern struct osmo_tdef g_hlr_tdefs[];
enum subscr_create_on_demand_mode {
SUBSCR_COD_MODE_DISABLED = 0,
SUBSCR_COD_MODE_NO_MSISDN,
SUBSCR_COD_MODE_RAND_MSISDN,
SUBSCR_COD_MODE_MSISDN_FROM_IMSI,
};
struct hlr {
/* GSUP server pointer */
struct osmo_gsup_server *gs;
@@ -48,7 +56,6 @@ struct hlr {
/* Control Interface */
struct ctrl_handle *ctrl;
const char *ctrl_bind_addr;
/* Local bind addr */
char *gsup_bind_addr;
@@ -56,6 +63,16 @@ struct hlr {
struct llist_head euse_list;
struct hlr_euse *euse_default;
enum gsm48_gmm_cause reject_cause;
enum gsm48_gmm_cause no_proxy_reject_cause;
/* PS: APN default configuration used by Subscription Data on ISR */
struct {
struct {
bool enabled;
struct osmo_gsup_pdp_info pdp_infos[OSMO_GSUP_MAX_NUM_PDP_INFO];
size_t num_pdp_infos;
} pdp_profile;
} ps;
/* NCSS (call independent) session guard timeout value */
int ncss_guard_timeout;
@@ -64,12 +81,18 @@ struct hlr {
struct llist_head ss_sessions;
struct llist_head smsc_list;
struct llist_head smsc_routes;
struct hlr_smsc *smsc_default;
bool store_imei;
bool subscr_create_on_demand;
/* Bitmask of DB_SUBSCR_FLAG_* */
uint8_t subscr_create_on_demand_flags;
unsigned int subscr_create_on_demand_rand_msisdn_len;
struct {
enum subscr_create_on_demand_mode mode;
unsigned int rand_msisdn_len;
/* Bitmask of DB_SUBSCR_FLAG_* */
uint8_t flags;
} subscr_create_on_demand;
struct {
bool allow_startup;

View File

@@ -0,0 +1,33 @@
#pragma once
#include <osmocom/core/linuxlist.h>
struct hlr_smsc {
/* g_hlr->smsc_list */
struct llist_head list;
struct hlr *hlr;
/* name (must match the IPA ID tag) */
const char *name;
/* human-readable description */
const char *description;
};
struct hlr_smsc *smsc_find(struct hlr *hlr, const char *name);
struct hlr_smsc *smsc_alloc(struct hlr *hlr, const char *name);
void smsc_free(struct hlr_smsc *smsc);
struct hlr_smsc_route {
/* g_hlr->smsc_routes */
struct llist_head list;
const char *num_addr;
struct hlr_smsc *smsc;
};
struct hlr_smsc_route *smsc_route_find(struct hlr *hlr, const char *num_addr);
struct hlr_smsc_route *smsc_route_alloc(struct hlr *hlr, const char *num_addr,
struct hlr_smsc *smsc);
void smsc_route_free(struct hlr_smsc_route *rt);
void forward_mo_sms(struct osmo_gsup_req *req);
void forward_mt_sms(struct osmo_gsup_req *req);
void rx_ready_for_sm_req(struct osmo_gsup_req *req);

View File

@@ -31,13 +31,23 @@ enum hlr_vty_node {
HLR_NODE = _LAST_OSMOVTY_NODE + 1,
GSUP_NODE,
EUSE_NODE,
SMSC_NODE,
MSLOOKUP_NODE,
MSLOOKUP_SERVER_NODE,
MSLOOKUP_SERVER_MSC_NODE,
MSLOOKUP_CLIENT_NODE,
PS_NODE,
PS_PDP_PROFILES_NODE,
PS_PDP_PROFILES_PROFILE_NODE,
};
int hlr_vty_is_config_node(struct vty *vty, int node);
#define A38_XOR_MIN_KEY_LEN 12
#define A38_XOR_MAX_KEY_LEN 16
#define A38_XOR2G_KEY_LEN 16
#define A38_COMP128_KEY_LEN 16
#define MILENAGE_KEY_LEN 16
int hlr_vty_go_parent(struct vty *vty);
void hlr_vty_init(void);
void hlr_vty_init(void *hlr_ctx);
void dgsm_vty_init(void);

View File

@@ -11,6 +11,7 @@ enum {
DMSLOOKUP,
DLU,
DDGSM,
DCTRL,
};
extern const struct log_info hlr_log_info;

View File

@@ -71,7 +71,7 @@ struct osmo_mdns_rfc_header {
uint16_t nscount; /* Number of authority records */
uint16_t arcount; /* Number of additional records */
#elif OSMO_IS_BIG_ENDIAN
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
uint16_t id;
uint8_t qr:1, opcode:4, aa:1, tc:1, rd:1;
uint8_t ra:1, z:3, rcode:4;
@@ -99,15 +99,12 @@ struct osmo_mdns_rfc_record {
uint8_t *rdata;
};
char *osmo_mdns_rfc_qname_encode(void *ctx, const char *domain);
char *osmo_mdns_rfc_qname_decode(void *ctx, const char *qname, size_t qname_len);
void osmo_mdns_rfc_header_encode(struct msgb *msg, const struct osmo_mdns_rfc_header *hdr);
int osmo_mdns_rfc_header_decode(const uint8_t *data, size_t data_len, struct osmo_mdns_rfc_header *hdr);
int osmo_mdns_rfc_question_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_question *qst);
int osmo_mdns_rfc_question_encode(struct msgb *msg, const struct osmo_mdns_rfc_question *qst);
struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const uint8_t *data, size_t data_len);
int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_record *rec);
int osmo_mdns_rfc_record_encode(struct msgb *msg, const struct osmo_mdns_rfc_record *rec);
struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_t *data, size_t data_len,
size_t *record_len);

View File

@@ -71,16 +71,24 @@ CREATE TABLE auc_2g (
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)
op VARCHAR(32), -- hex string: operator's secret key (128bit)
opc VARCHAR(32), -- hex string: derived from OP and K (128bit)
k VARCHAR(64) NOT NULL, -- hex string: subscriber's secret key (128/256bit)
op VARCHAR(64), -- hex string: operator's secret key (128/256bit)
opc VARCHAR(64), -- hex string: derived from OP and K (128/256bit)
sqn INTEGER NOT NULL DEFAULT 0, -- sequence number of key usage
-- nr of index bits at lower SQN end
ind_bitlen INTEGER NOT NULL DEFAULT 5
);
CREATE TABLE ind (
-- 3G auth IND pool to be used for this VLR
ind INTEGER PRIMARY KEY,
-- VLR identification, usually the GSUP source_name
vlr TEXT NOT NULL,
UNIQUE (vlr)
);
CREATE 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 = 5;
PRAGMA user_version = 7;

View File

@@ -52,6 +52,7 @@ osmo_hlr_SOURCES = \
hlr_vty.c \
hlr_vty_subscr.c \
gsup_send.c \
hlr_sms.c \
hlr_ussd.c \
proxy.c \
dgsm.c \
@@ -111,7 +112,7 @@ BOOTSTRAP_SQL = $(top_srcdir)/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[] = {" >> "$@"
echo "static const char * const stmt_bootstrap_sql[] = {" >> "$@"
cat "$(BOOTSTRAP_SQL)" \
| sed -f "$(srcdir)/db_sql2c.sed" \
>> "$@"

View File

@@ -1,4 +1,4 @@
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
/* (C) 2015-2023 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -32,8 +32,8 @@
/* compute given number of vectors using either aud2g or aud2g or a combination
* of both. Handles re-synchronization if rand_auts and auts are set */
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,
struct osmo_sub_auth_data2 *aud2g,
struct osmo_sub_auth_data2 *aud3g,
const uint8_t *rand_auts, const uint8_t *auts)
{
unsigned int i;
@@ -93,10 +93,10 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
: "2G only",
auts? ", with AUTS resync" : "");
if (aud3g) {
DBGP("3G: k = %s\n", hexb(aud3g->u.umts.k));
DBGP("3G: k = %s\n", hex(aud3g->u.umts.k, aud3g->u.umts.k_len));
DBGP("3G: %s = %s\n",
aud3g->u.umts.opc_is_op? "OP" : "opc",
hexb(aud3g->u.umts.opc));
hex(aud3g->u.umts.opc, aud3g->u.umts.opc_len));
DBGP("3G: for sqn ind %u, previous sqn was %" PRIu64 "\n",
aud3g->u.umts.ind, aud3g->u.umts.sqn);
}
@@ -115,6 +115,9 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
if (aud3g) {
/* 3G or 3G + 2G case */
/* backwards-compatibiliy: We assume all RES are 8 bytes long */
vec[i].res_len = 8;
/* Do AUTS only for the first vector or we would use
* the same SQN for each following key. */
if ((i == 0) && auts) {
@@ -123,10 +126,10 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
DBGP("vector [%u]: resync: rand_auts = %s\n",
i, hex(rand_auts, 16));
rc = osmo_auth_gen_vec_auts(vec+i, aud3g, auts,
rc = osmo_auth_gen_vec_auts2(vec+i, aud3g, auts,
rand_auts, rand);
} else {
rc = osmo_auth_gen_vec(vec+i, aud3g, rand);
rc = osmo_auth_gen_vec2(vec+i, aud3g, rand);
}
if (rc < 0) {
LOGP(DAUC, LOGL_ERROR, "Error in 3G vector "
@@ -154,7 +157,7 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
DBGP("vector [%u]: calculating 2G separately\n", i);
rc = osmo_auth_gen_vec(&vtmp, aud2g, rand);
rc = osmo_auth_gen_vec2(&vtmp, aud2g, rand);
if (rc < 0) {
LOGP(DAUC, LOGL_ERROR, "Error in 2G vector"
"generation: [%u]: rc = %d\n", i, rc);
@@ -165,7 +168,7 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
vec[i].auth_types |= OSMO_AUTH_TYPE_GSM;
} else {
/* 2G only case */
rc = osmo_auth_gen_vec(vec+i, aud2g, rand);
rc = osmo_auth_gen_vec2(vec+i, aud2g, rand);
if (rc < 0) {
LOGP(DAUC, LOGL_ERROR, "Error in 2G vector "
"generation: [%u]: rc = %d\n", i, rc);

View File

@@ -1,6 +1,6 @@
/* OsmoHLR Control Interface implementation */
/* (C) 2017 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
/* (C) 2017-2023 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Max Suraev <msuraev@sysmocom.de>
@@ -31,12 +31,16 @@
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/ctrl.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/hlr_vty.h>
#define SEL_BY "by-"
#define SEL_BY_IMSI SEL_BY "imsi-"
#define SEL_BY_MSISDN SEL_BY "msisdn-"
#define SEL_BY_ID SEL_BY "id-"
extern bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
int *minlen, int *maxlen, int *minlen_opc, int *maxlen_opc);
#define hexdump_buf(buf) osmo_hexdump_nospc((void*)buf, sizeof(buf))
static bool startswith(const char *str, const char *start)
@@ -162,7 +166,7 @@ static void print_subscr_info(struct ctrl_cmd *cmd,
);
}
static void print_subscr_info_aud2g(struct ctrl_cmd *cmd, struct osmo_sub_auth_data *aud)
static void print_subscr_info_aud2g(struct ctrl_cmd *cmd, struct osmo_sub_auth_data2 *aud)
{
if (aud->algo == OSMO_AUTH_ALG_NONE)
return;
@@ -174,7 +178,7 @@ static void print_subscr_info_aud2g(struct ctrl_cmd *cmd, struct osmo_sub_auth_d
hexdump_buf(aud->u.gsm.ki));
}
static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_data *aud)
static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_data2 *aud)
{
if (aud->algo == OSMO_AUTH_ALG_NONE)
return;
@@ -183,7 +187,7 @@ static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_d
"\naud3g.k\t%s"
,
osmo_auth_alg_name(aud->algo),
hexdump_buf(aud->u.umts.k));
osmo_hexdump_nospc(aud->u.umts.k, aud->u.umts.k_len));
/* hexdump uses a static string buffer, hence only one hexdump per
* printf(). */
ctrl_cmd_reply_printf(cmd,
@@ -192,11 +196,82 @@ static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_d
"\naud3g.sqn\t%" PRIu64
,
aud->u.umts.opc_is_op? "op" : "opc",
hexdump_buf(aud->u.umts.opc),
osmo_hexdump_nospc(aud->u.umts.opc, aud->u.umts.opc_len),
aud->u.umts.ind_bitlen,
aud->u.umts.sqn);
}
CTRL_CMD_DEFINE_WO_NOVRF(subscr_create, "create");
static int set_subscr_create(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *imsi = cmd->value;
int rc;
if (!osmo_imsi_str_valid(imsi)) {
cmd->reply = "Invalid IMSI value.";
return CTRL_CMD_ERROR;
}
/* Create the subscriber in the DB */
rc = db_subscr_create(g_hlr->dbc, imsi, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS);
if (rc) {
if (rc == -EEXIST)
cmd->reply = "Subscriber already exists.";
else
cmd->reply = "Cannot create subscriber.";
return CTRL_CMD_ERROR;
}
LOGP(DCTRL, LOGL_INFO, "Created subscriber IMSI='%s'\n",
imsi);
/* Retrieve data of newly created subscriber: */
rc = db_subscr_get_by_imsi(hlr->dbc, imsi, &subscr);
if (rc < 0) {
cmd->reply = "Failed retrieving ID of newly created subscriber.";
return CTRL_CMD_ERROR;
}
cmd->reply = talloc_asprintf(cmd, "%" PRIu64, subscr.id);
return CTRL_CMD_REPLY;
}
CTRL_CMD_DEFINE_WO_NOVRF(subscr_delete, "delete");
static int set_subscr_delete(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *imsi = cmd->value;
int rc;
if (!osmo_imsi_str_valid(imsi)) {
cmd->reply = "Invalid IMSI value.";
return CTRL_CMD_ERROR;
}
/* Retrieve data of newly created subscriber: */
rc = db_subscr_get_by_imsi(hlr->dbc, imsi, &subscr);
if (rc < 0) {
cmd->reply = "Subscriber doesn't exist.";
return CTRL_CMD_ERROR;
}
/* Create the subscriber in the DB */
rc = db_subscr_delete_by_id(g_hlr->dbc, subscr.id);
if (rc) {
cmd->reply = "Cannot delete subscriber.";
return CTRL_CMD_ERROR;
}
LOGP(DCTRL, LOGL_INFO, "Deleted subscriber IMSI='%s'\n",
imsi);
cmd->reply = talloc_asprintf(cmd, "%" PRIu64, subscr.id);
return CTRL_CMD_REPLY;
}
CTRL_CMD_DEFINE_RO(subscr_info, "info");
static int get_subscr_info(struct ctrl_cmd *cmd, void *data)
{
@@ -216,8 +291,8 @@ CTRL_CMD_DEFINE_RO(subscr_info_aud, "info-aud");
static int get_subscr_info_aud(struct ctrl_cmd *cmd, void *data)
{
const char *imsi;
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
int rc;
@@ -252,8 +327,8 @@ CTRL_CMD_DEFINE_RO(subscr_info_all, "info-all");
static int get_subscr_info_all(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
int rc;
@@ -351,17 +426,316 @@ static int set_subscr_cs_enabled(struct ctrl_cmd *cmd, void *data)
return set_subscr_cs_ps_enabled(cmd, data, false);
}
int hlr_ctrl_cmds_install()
CTRL_CMD_DEFINE_RO(subscr_imsi, "imsi");
static int get_subscr_imsi(struct ctrl_cmd *cmd, void *data)
{
int rc = 0;
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_aud);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_ps_enabled);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_cs_enabled);
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
return rc;
cmd->reply = talloc_strdup(cmd, subscr.imsi);
return CTRL_CMD_REPLY;
}
CTRL_CMD_DEFINE(subscr_msisdn, "msisdn");
static int verify_subscr_msisdn(struct ctrl_cmd *cmd, const char *value, void *data)
{
struct hlr_subscriber subscr;
if (!value)
return 1;
if (strlen(value) > sizeof(subscr.msisdn) - 1)
return 1;
if (strcmp(value, "none") != 0 && !osmo_msisdn_str_valid(value))
return 1;
return 0;
}
static int get_subscr_msisdn(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
if (strlen(subscr.msisdn) == 0)
snprintf(subscr.msisdn, sizeof(subscr.msisdn), "none");
cmd->reply = talloc_asprintf(cmd, "%s", subscr.msisdn);
return CTRL_CMD_REPLY;
}
static int set_subscr_msisdn(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
const char *msisdn;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
if (strcmp(cmd->value, "none") == 0)
msisdn = NULL;
else
msisdn = cmd->value;
if (db_subscr_update_msisdn_by_imsi(g_hlr->dbc, subscr.imsi, msisdn)) {
cmd->reply = "Update MSISDN failed";
return CTRL_CMD_ERROR;
}
cmd->reply = "OK";
return CTRL_CMD_REPLY;
}
/* value format: <algo[,KI]> */
CTRL_CMD_DEFINE(subscr_aud2g, "aud2g");
static int verify_subscr_aud2g(struct ctrl_cmd *cmd, const char *value, void *data)
{
if (!value)
return 1;
if (strcasecmp(value, "none") != 0 && !strchr(value, ','))
return 1;
return 0;
}
static int get_subscr_aud2g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g_unused;
int rc;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
rc = db_get_auth_data(hlr->dbc, subscr.imsi, &aud2g, &aud3g_unused, NULL);
switch (rc) {
case 0:
break;
case -ENOENT:
case -ENOKEY:
aud2g.algo = OSMO_AUTH_ALG_NONE;
break;
default:
cmd->reply = "Error retrieving data from database.";
return CTRL_CMD_ERROR;
}
if (aud2g.algo == OSMO_AUTH_ALG_NONE) {
cmd->reply = "none";
return CTRL_CMD_REPLY;
}
cmd->reply = talloc_asprintf(cmd, "%s,%s", osmo_auth_alg_name(aud2g.algo),
hexdump_buf(aud2g.u.gsm.ki));
return CTRL_CMD_REPLY;
}
static int set_subscr_aud2g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
char *tmp = NULL, *tok, *saveptr;
int minlen = 0;
int maxlen = 0;
struct sub_auth_data_str aud2g = {
.type = OSMO_AUTH_TYPE_GSM
};
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
tmp = talloc_strdup(cmd, cmd->value);
if (!tmp) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
}
/* Parse alg_type: */
tok = strtok_r(tmp, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format";
return CTRL_CMD_ERROR;
}
if (strcmp(tok, "none") == 0) {
aud2g.algo = OSMO_AUTH_ALG_NONE;
} else if (!auth_algo_parse(tok, &aud2g.algo, &minlen, &maxlen, NULL, NULL)) {
cmd->reply = "Unknown auth algorithm.";
return CTRL_CMD_ERROR;
}
if (aud2g.algo != OSMO_AUTH_ALG_NONE) {
tok = strtok_r(NULL, "\0", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud2g.u.gsm.ki = tok;
if (!osmo_is_hexstr(aud2g.u.gsm.ki, minlen * 2, maxlen * 2, true)) {
cmd->reply = "Invalid KI.";
return CTRL_CMD_ERROR;
}
}
if (db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud2g)) {
cmd->reply = "Update aud2g failed.";
return CTRL_CMD_ERROR;
}
cmd->reply = "OK";
return CTRL_CMD_REPLY;
}
/* value format: <algo[,KI,(op|opc),OP_C[,ind_bitlen]]> */
CTRL_CMD_DEFINE(subscr_aud3g, "aud3g");
static int verify_subscr_aud3g(struct ctrl_cmd *cmd, const char *value, void *data)
{
if (!value)
return 1;
if (strcasecmp(value, "none") != 0 && !strchr(value, ','))
return 1;
return 0;
}
static int get_subscr_aud3g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
struct osmo_sub_auth_data2 aud2g_unused;
struct osmo_sub_auth_data2 aud3g;
int rc;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
rc = db_get_auth_data(hlr->dbc, subscr.imsi, &aud2g_unused, &aud3g, NULL);
switch (rc) {
case 0:
break;
case -ENOENT:
case -ENOKEY:
aud3g.algo = OSMO_AUTH_ALG_NONE;
break;
default:
cmd->reply = "Error retrieving data from database.";
return CTRL_CMD_ERROR;
}
if (aud3g.algo == OSMO_AUTH_ALG_NONE) {
cmd->reply = "none";
return CTRL_CMD_REPLY;
}
cmd->reply = talloc_asprintf(cmd, "%s,%s,%s,%s,%u", osmo_auth_alg_name(aud3g.algo),
osmo_hexdump_nospc_c(cmd, aud3g.u.umts.k, aud3g.u.umts.k_len),
aud3g.u.umts.opc_is_op ? "OP" : "OPC",
osmo_hexdump_nospc_c(cmd, aud3g.u.umts.opc, aud3g.u.umts.opc_len),
aud3g.u.umts.ind_bitlen);
return CTRL_CMD_REPLY;
}
static int set_subscr_aud3g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
char *tmp = NULL, *tok, *saveptr;
int minlen = 0, minlen_opc = 0;
int maxlen = 0, maxlen_opc = 0;
struct sub_auth_data_str aud3g = {
.type = OSMO_AUTH_TYPE_UMTS,
.u.umts = {
.ind_bitlen = 5,
},
};
bool ind_bitlen_present;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
tmp = talloc_strdup(cmd, cmd->value);
if (!tmp) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
}
/* Parse alg_type: */
tok = strtok_r(tmp, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
if (strcmp(tok, "none") == 0) {
aud3g.algo = OSMO_AUTH_ALG_NONE;
} else if (!auth_algo_parse(tok, &aud3g.algo, &minlen, &maxlen, &minlen_opc, &maxlen_opc)) {
cmd->reply = "Unknown auth algorithm.";
return CTRL_CMD_ERROR;
}
if (aud3g.algo != OSMO_AUTH_ALG_NONE) {
/* Parse K */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud3g.u.umts.k = tok;
if (!osmo_is_hexstr(aud3g.u.umts.k, minlen * 2, maxlen * 2, true)) {
cmd->reply = "Invalid KI.";
return CTRL_CMD_ERROR;
}
/* Parse OP/OPC choice */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
if (strcasecmp(tok, "op") == 0) {
aud3g.u.umts.opc_is_op = true;
} else if (strcasecmp(tok, "opc") == 0) {
aud3g.u.umts.opc_is_op = false;
} else {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
/* Parse OP/OPC value */
ind_bitlen_present = !!strchr(saveptr, ',');
tok = strtok_r(NULL, ind_bitlen_present ? "," : "\0", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud3g.u.umts.opc = tok;
if (!osmo_is_hexstr(aud3g.u.umts.opc, minlen_opc * 2, maxlen_opc * 2, true)) {
cmd->reply = talloc_asprintf(cmd, "Invalid OP/OPC.");
return CTRL_CMD_ERROR;
}
if (ind_bitlen_present) {
/* Parse bitlen_ind */
tok = strtok_r(NULL, "\0", &saveptr);
if (!tok || tok[0] == '\0') {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud3g.u.umts.ind_bitlen = atoi(tok);
}
}
if (db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud3g)) {
cmd->reply = "Update aud3g failed.";
return CTRL_CMD_ERROR;
}
cmd->reply = "OK";
return CTRL_CMD_REPLY;
}
static int hlr_ctrl_node_lookup(void *data, vector vline, int *node_type,
@@ -389,14 +763,31 @@ static int hlr_ctrl_node_lookup(void *data, vector vline, int *node_type,
return 1;
}
static int hlr_ctrl_cmds_install(void)
{
int rc = 0;
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR, &cmd_subscr_create);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR, &cmd_subscr_delete);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_aud);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_ps_enabled);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_cs_enabled);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_imsi);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_msisdn);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_aud2g);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_aud3g);
return rc;
}
struct ctrl_handle *hlr_controlif_setup(struct hlr *hlr)
{
int rc;
struct ctrl_handle *hdl = ctrl_interface_setup_dynip2(hlr,
hlr->ctrl_bind_addr,
OSMO_CTRL_PORT_HLR,
hlr_ctrl_node_lookup,
_LAST_CTRL_NODE_HLR);
struct ctrl_handle *hdl = ctrl_interface_setup2(hlr, OSMO_CTRL_PORT_HLR, hlr_ctrl_node_lookup,
_LAST_CTRL_NODE_HLR);
if (!hdl)
return NULL;

103
src/db.c
View File

@@ -1,4 +1,4 @@
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
/* (C) 2015-2023 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -28,7 +28,7 @@
#include "db_bootstrap.h"
/* This constant is currently duplicated in sql/hlr.sql and must be kept in sync! */
#define CURRENT_SCHEMA_VERSION 5
#define CURRENT_SCHEMA_VERSION 7
#define SEL_COLUMNS \
"id," \
@@ -51,6 +51,14 @@
"sgsn_via_proxy"
static const char *stmt_sql[] = {
[DB_STMT_SEL_ALL] = "SELECT " SEL_COLUMNS " FROM subscriber;",
[DB_STMT_SEL_ALL_ORDER_LAST_SEEN] = "SELECT " SEL_COLUMNS " FROM subscriber "
"WHERE last_lu_seen IS NOT NULL ORDER BY last_lu_seen;",
[DB_STMT_SEL_FILTER_MSISDN] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE msisdn LIKE $search ORDER BY msisdn",
[DB_STMT_SEL_FILTER_IMSI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imsi LIKE $search ORDER BY imsi",
[DB_STMT_SEL_FILTER_IMEI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imei LIKE $search ORDER BY imei",
[DB_STMT_SEL_FILTER_CS] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE nam_cs = $search ORDER BY last_lu_seen",
[DB_STMT_SEL_FILTER_PS] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE nam_ps = $search ORDER BY last_lu_seen",
[DB_STMT_SEL_BY_IMSI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imsi = ?",
[DB_STMT_SEL_BY_MSISDN] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE msisdn = ?",
[DB_STMT_SEL_BY_ID] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE id = ?",
@@ -85,6 +93,9 @@ static const char *stmt_sql[] = {
[DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch') WHERE id = $subscriber_id",
[DB_STMT_EXISTS_BY_IMSI] = "SELECT 1 FROM subscriber WHERE imsi = $imsi",
[DB_STMT_EXISTS_BY_MSISDN] = "SELECT 1 FROM subscriber WHERE msisdn = $msisdn",
[DB_STMT_IND_ADD] = "INSERT INTO ind (vlr) VALUES ($vlr)",
[DB_STMT_IND_SELECT] = "SELECT ind FROM ind WHERE vlr = $vlr",
[DB_STMT_IND_DEL] = "DELETE FROM ind WHERE vlr = $vlr",
};
static void sql3_error_log_cb(void *arg, int err_code, const char *msg)
@@ -224,9 +235,9 @@ void db_close(struct db_context *dbc)
talloc_free(dbc);
}
static int db_run_statements(struct db_context *dbc, const char **statements, size_t statements_count)
static int db_run_statements(struct db_context *dbc, const char * const *statements, size_t statements_count)
{
int rc;
int rc = 0;
int i;
for (i = 0; i < statements_count; i++) {
const char *stmt_str = statements[i];
@@ -297,7 +308,7 @@ static int
db_upgrade_v1(struct db_context *dbc)
{
int rc;
const char *statements[] = {
const char * const statements[] = {
"ALTER TABLE subscriber ADD COLUMN last_lu_seen TIMESTAMP default NULL",
"PRAGMA user_version = 1",
};
@@ -313,7 +324,7 @@ db_upgrade_v1(struct db_context *dbc)
static int db_upgrade_v2(struct db_context *dbc)
{
int rc;
const char *statements[] = {
const char * const statements[] = {
"ALTER TABLE subscriber ADD COLUMN imei VARCHAR(14)",
"PRAGMA user_version = 2",
};
@@ -426,7 +437,7 @@ static int db_upgrade_v3(struct db_context *dbc)
"ms_purged_ps," \
"last_lu_seen"
const char *statements[] = {
const char * const statements[] = {
"BEGIN TRANSACTION",
"CREATE TEMPORARY TABLE subscriber_backup" SUBSCR_V3_CREATE,
"INSERT INTO subscriber_backup SELECT " SUBSCR_V2_COLUMN_NAMES " FROM subscriber",
@@ -449,7 +460,7 @@ static int db_upgrade_v3(struct db_context *dbc)
static int db_upgrade_v4(struct db_context *dbc)
{
int rc;
const char *statements[] = {
const char * const statements[] = {
"ALTER TABLE subscriber ADD COLUMN last_lu_seen_ps TIMESTAMP default NULL",
"PRAGMA user_version = 4",
};
@@ -465,7 +476,7 @@ static int db_upgrade_v4(struct db_context *dbc)
static int db_upgrade_v5(struct db_context *dbc)
{
int rc;
const char *statements[] = {
const char * const statements[] = {
"ALTER TABLE subscriber ADD COLUMN vlr_via_proxy VARCHAR",
"ALTER TABLE subscriber ADD COLUMN sgsn_via_proxy VARCHAR",
"PRAGMA user_version = 5",
@@ -479,6 +490,69 @@ static int db_upgrade_v5(struct db_context *dbc)
return rc;
}
static int db_upgrade_v6(struct db_context *dbc)
{
int rc;
const char * const statements[] = {
"CREATE TABLE ind (\n"
" -- 3G auth IND pool to be used for this VLR\n"
" ind INTEGER PRIMARY KEY,\n"
" -- VLR identification, usually the GSUP source_name\n"
" vlr TEXT NOT NULL,\n"
" UNIQUE (vlr)\n"
")"
,
"PRAGMA user_version = 6",
};
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
if (rc != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 6\n");
return rc;
}
return rc;
}
static int db_upgrade_v7(struct db_context *dbc)
{
int rc;
/* SQLite doesn't allow us to change the column type in-place, so we
* first rename the old table, create a new table and then copy
* the data over before deleting the old table */
#define CREATE_AUC_3G_V7 \
"CREATE TABLE auc_3g (\n" \
" subscriber_id INTEGER PRIMARY KEY, -- subscriber.id\n" \
" algo_id_3g INTEGER NOT NULL, -- enum osmo_auth_algo value\n" \
" k VARCHAR(64) NOT NULL, -- hex string: subscriber's secret key (128/256bit)\n" \
" op VARCHAR(64), -- hex string: operator's secret key (128/256bit)\n" \
" opc VARCHAR(64), -- hex string: derived from OP and K (128/256bit)\n" \
" sqn INTEGER NOT NULL DEFAULT 0, -- sequence number of key usage\n" \
" -- nr of index bits at lower SQN end\n" \
" ind_bitlen INTEGER NOT NULL DEFAULT 5\n" \
");"
const char * const statements[] = {
"BEGIN TRANSACTION",
/* rename old table */
"ALTER TABLE auc_3g RENAME TO old_auc_3g",
/* create new table */
CREATE_AUC_3G_V7,
/* copy over old data */
"INSERT INTO auc_3g SELECT subscriber_id, algo_id_3g, k, op, opc,sqn, ind_bitlen FROM old_auc_3g",
/* delete old table */
"DROP TABLE old_auc_3g",
/* update user_version */
"PRAGMA user_version = 7",
"COMMIT",
};
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
if (rc != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 7\n");
return rc;
}
return rc;
}
typedef int (*db_upgrade_func_t)(struct db_context *dbc);
static db_upgrade_func_t db_upgrade_path[] = {
db_upgrade_v1,
@@ -486,6 +560,8 @@ static db_upgrade_func_t db_upgrade_path[] = {
db_upgrade_v3,
db_upgrade_v4,
db_upgrade_v5,
db_upgrade_v6,
db_upgrade_v7,
};
static int db_get_user_version(struct db_context *dbc)
@@ -519,6 +595,7 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
int rc;
bool has_sqlite_config_sqllog = false;
int version;
bool version_changed = false;
LOGP(DDB, LOGL_NOTICE, "using database: %s\n", fname);
LOGP(DDB, LOGL_INFO, "Compiled against SQLite3 lib version %s\n", SQLITE_VERSION);
@@ -596,6 +673,7 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
goto out_free;
}
version = CURRENT_SCHEMA_VERSION;
version_changed = true;
}
LOGP(DDB, LOGL_NOTICE, "Database '%s' has HLR DB schema version %d\n", dbc->fname, version);
@@ -610,6 +688,7 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
}
LOGP(DDB, LOGL_NOTICE, "Database '%s' has been upgraded to HLR DB schema version %d\n",
dbc->fname, version+1);
version_changed = true;
}
if (version != CURRENT_SCHEMA_VERSION) {
@@ -626,6 +705,12 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
goto out_free;
}
/* Flush the cache after changing the version, to make the scenario
* less likely that after an unclean shutdown the DB gets restored
* with the right table layout but wrong version (SYS#7394). */
if (version_changed)
sqlite3_db_cacheflush(dbc->db);
/* prepare all SQL statements */
for (i = 0; i < ARRAY_SIZE(dbc->stmt); i++) {
rc = sqlite3_prepare_v2(dbc->db, stmt_sql[i], -1,

View File

@@ -1,4 +1,4 @@
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
/* (C) 2015-2023 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -74,9 +74,9 @@ out:
}
/* hexparse a specific column of a sqlite prepared statement into dst (with length check)
* returns 0 for success, -EIO on error */
static int hexparse_stmt(uint8_t *dst, size_t dst_len, sqlite3_stmt *stmt, int col, const char *col_name,
const char *imsi)
* returns byte length in case of success, -EIO on error */
static int hexparse_stmt(uint8_t *dst, size_t dst_len_min, size_t dst_len_max, sqlite3_stmt *stmt,
int col, const char *col_name, const char *imsi)
{
const uint8_t *text;
size_t col_len;
@@ -84,9 +84,15 @@ static int hexparse_stmt(uint8_t *dst, size_t dst_len, sqlite3_stmt *stmt, int c
/* Bytes are stored as hex strings in database, hence divide length by two */
col_len = sqlite3_column_bytes(stmt, col) / 2;
if (col_len != dst_len) {
LOGAUC(imsi, LOGL_ERROR, "Error reading %s, expected length %lu but has length %lu\n", col_name,
dst_len, col_len);
if (col_len < dst_len_min) {
LOGAUC(imsi, LOGL_ERROR, "Error reading %s, expected min length %lu but has length %lu\n", col_name,
dst_len_min, col_len);
return -EIO;
}
if (col_len > dst_len_max) {
LOGAUC(imsi, LOGL_ERROR, "Error reading %s, expected max length %lu but has length %lu\n", col_name,
dst_len_max, col_len);
return -EIO;
}
@@ -95,8 +101,11 @@ static int hexparse_stmt(uint8_t *dst, size_t dst_len, sqlite3_stmt *stmt, int c
LOGAUC(imsi, LOGL_ERROR, "Error reading %s\n", col_name);
return -EIO;
}
osmo_hexparse((void *)text, dst, dst_len);
return 0;
if (osmo_hexparse((void *)text, dst, dst_len_max) != col_len)
return -EINVAL;
return col_len;
}
/* obtain the authentication data for a given imsi
@@ -104,8 +113,8 @@ static int hexparse_stmt(uint8_t *dst, size_t dst_len, sqlite3_stmt *stmt, int c
* -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,
struct osmo_sub_auth_data2 *aud2g,
struct osmo_sub_auth_data2 *aud3g,
int64_t *subscr_id)
{
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_AUC_BY_IMSI];
@@ -139,7 +148,8 @@ int db_get_auth_data(struct db_context *dbc, const char *imsi,
/* obtain result values using sqlite3_column_*() */
if (sqlite3_column_type(stmt, 1) == SQLITE_INTEGER) {
/* we do have some 2G authentication data */
if (hexparse_stmt(aud2g->u.gsm.ki, sizeof(aud2g->u.gsm.ki), stmt, 2, "Ki", imsi))
if (hexparse_stmt(aud2g->u.gsm.ki, sizeof(aud2g->u.gsm.ki), sizeof(aud2g->u.gsm.ki),
stmt, 2, "Ki", imsi) < 0)
goto end_2g;
aud2g->algo = sqlite3_column_int(stmt, 1);
aud2g->type = OSMO_AUTH_TYPE_GSM;
@@ -148,24 +158,30 @@ int db_get_auth_data(struct db_context *dbc, const char *imsi,
end_2g:
if (sqlite3_column_type(stmt, 3) == SQLITE_INTEGER) {
/* we do have some 3G authentication data */
if (hexparse_stmt(aud3g->u.umts.k, sizeof(aud3g->u.umts.k), stmt, 4, "K", imsi)) {
rc = hexparse_stmt(aud3g->u.umts.k, 16, sizeof(aud3g->u.umts.k), stmt, 4, "K", imsi);
if (rc < 0) {
ret = -EIO;
goto out;
}
aud3g->u.umts.k_len = rc;
aud3g->algo = sqlite3_column_int(stmt, 3);
/* UMTS Subscribers can have either OP or OPC */
if (sqlite3_column_text(stmt, 5)) {
if (hexparse_stmt(aud3g->u.umts.opc, sizeof(aud3g->u.umts.opc), stmt, 5, "OP", imsi)) {
rc = hexparse_stmt(aud3g->u.umts.opc, 16, sizeof(aud3g->u.umts.opc), stmt, 5, "OP", imsi);
if (rc < 0) {
ret = -EIO;
goto out;
}
aud3g->u.umts.opc_len = rc;
aud3g->u.umts.opc_is_op = 1;
} else {
if (hexparse_stmt(aud3g->u.umts.opc, sizeof(aud3g->u.umts.opc), stmt, 6, "OPC", imsi)) {
rc = hexparse_stmt(aud3g->u.umts.opc, 16, sizeof(aud3g->u.umts.opc), stmt, 6, "OPC", imsi);
if (rc < 0) {
ret = -EIO;
goto out;
}
aud3g->u.umts.opc_len = rc;
aud3g->u.umts.opc_is_op = 0;
}
aud3g->u.umts.sqn = sqlite3_column_int64(stmt, 7);
@@ -191,7 +207,7 @@ int db_get_auc(struct db_context *dbc, const char *imsi,
unsigned int num_vec, const uint8_t *rand_auts,
const uint8_t *auts, bool separation_bit)
{
struct osmo_sub_auth_data aud2g, aud3g;
struct osmo_sub_auth_data2 aud2g, aud3g;
int64_t subscr_id;
int ret = 0;
int rc;

View File

@@ -1,4 +1,4 @@
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
/* (C) 2015-2023 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -45,7 +45,8 @@
* \param[in,out] dbc database context.
* \param[in] imsi ASCII string of IMSI digits, is validated.
* \param[in] flags Bitmask of DB_SUBSCR_FLAG_*.
* \returns 0 on success, -EINVAL on invalid IMSI, -EIO on database error.
* \returns 0 on success, -EINVAL on invalid IMSI, -EEXIST if subscriber with
* provided imsi already exists, -EIO on other database errors.
*/
int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags)
{
@@ -73,6 +74,8 @@ int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags)
if (rc != SQLITE_DONE) {
LOGHLR(imsi, LOGL_ERROR, "Cannot create subscriber: SQL error: (%d) %s\n",
rc, sqlite3_errmsg(dbc->db));
if (rc == SQLITE_CONSTRAINT_UNIQUE)
return -EEXIST;
return -EIO;
}
@@ -235,8 +238,9 @@ int db_subscr_update_aud_by_id(struct db_context *dbc, int64_t subscr_id,
case OSMO_AUTH_ALG_COMP128v1:
case OSMO_AUTH_ALG_COMP128v2:
case OSMO_AUTH_ALG_COMP128v3:
case OSMO_AUTH_ALG_XOR:
case OSMO_AUTH_ALG_XOR_2G:
break;
case OSMO_AUTH_ALG_XOR_3G:
case OSMO_AUTH_ALG_MILENAGE:
LOGP(DAUC, LOGL_ERROR, "Cannot update auth tokens:"
" auth algo not suited for 2G: %s\n",
@@ -264,11 +268,12 @@ int db_subscr_update_aud_by_id(struct db_context *dbc, int64_t subscr_id,
switch (aud->algo) {
case OSMO_AUTH_ALG_NONE:
case OSMO_AUTH_ALG_MILENAGE:
case OSMO_AUTH_ALG_XOR_3G:
break;
case OSMO_AUTH_ALG_COMP128v1:
case OSMO_AUTH_ALG_COMP128v2:
case OSMO_AUTH_ALG_COMP128v3:
case OSMO_AUTH_ALG_XOR:
case OSMO_AUTH_ALG_XOR_2G:
LOGP(DAUC, LOGL_ERROR, "Cannot update auth tokens:"
" auth algo not suited for 3G: %s\n",
osmo_auth_alg_name(aud->algo));
@@ -281,12 +286,12 @@ int db_subscr_update_aud_by_id(struct db_context *dbc, int64_t subscr_id,
if (aud->algo == OSMO_AUTH_ALG_NONE)
break;
if (!osmo_is_hexstr(aud->u.umts.k, 32, 32, true)) {
if (!osmo_is_hexstr(aud->u.umts.k, 32, 64, true)) {
LOGP(DAUC, LOGL_ERROR, "Cannot update auth tokens:"
" Invalid K: '%s'\n", aud->u.umts.k);
return -EINVAL;
}
if (!osmo_is_hexstr(aud->u.umts.opc, 32, 32, true)) {
if (!osmo_is_hexstr(aud->u.umts.opc, 32, 64, true)) {
LOGP(DAUC, LOGL_ERROR, "Cannot update auth tokens:"
" Invalid OP/OPC: '%s'\n", aud->u.umts.opc);
return -EINVAL;
@@ -625,6 +630,94 @@ int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
return rc;
}
/*! Retrieve subscriber data from the HLR database.
* \param[in,out] dbc database context.
* \param[in] filter_type ASCII string of identifier type to search.
* \param[in] filter ASCII string to search.
* \param[in] get_cb pointer to call back function for data.
* \param[in,out] data pointer to pass to callback function.
* \param[in,out] count counter for number of matched subscribers.
* \param[in,our] err
* \returns 0 on success, -ENOENT if no subscriber was found, -EIO on
* database error.
*/
int db_subscrs_get(struct db_context *dbc, const char *filter_type, const char *filter,
void (*get_cb)(struct hlr_subscriber *subscr, void *data), void *data,
int *count, const char **err)
{
sqlite3_stmt *stmt;
char search[256];
int rc;
struct hlr_subscriber subscr;
bool show_ls = false;
if (!filter_type) {
stmt = dbc->stmt[DB_STMT_SEL_ALL];
} else if (strcmp(filter_type, "imei") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_IMEI];
} else if (strcmp(filter_type, "imsi") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_IMSI];
} else if (strcmp(filter_type, "msisdn") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_MSISDN];
} else if (strcmp(filter_type, "cs") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_CS];
} else if (strcmp(filter_type, "ps") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_PS];
} else if (strcmp(filter_type, "last_lu_seen") == 0) {
show_ls = true;
stmt = dbc->stmt[DB_STMT_SEL_ALL_ORDER_LAST_SEEN];
} else {
return -EIO;
}
if (filter_type && filter && strcmp(filter_type, "last_lu_seen") != 0) {
if (strcmp(filter, "on") == 0) {
sprintf(search, "%s", "1");
} else if (strcmp(filter, "off") == 0) {
sprintf(search, "%s", "0");
} else {
sprintf(search, "%%%s%%", filter);
}
if (!db_bind_text(stmt, "$search", search)) {
*err = sqlite3_errmsg(dbc->db);
return -EIO;
}
}
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE) {
db_remove_reset(stmt);
*err = "No matching subscriber(s)";
return -ENOENT;
}
while (rc == SQLITE_ROW) {
subscr = (struct hlr_subscriber){
.id = sqlite3_column_int64(stmt, 0),};
copy_sqlite3_text_to_buf(subscr.imsi, stmt, 1);
copy_sqlite3_text_to_buf(subscr.msisdn, stmt, 2);
copy_sqlite3_text_to_buf(subscr.imei, stmt, 3);
subscr.nam_cs = sqlite3_column_int(stmt, 9);
subscr.nam_ps = sqlite3_column_int(stmt, 10);
if (show_ls)
parse_last_lu_seen(&subscr.last_lu_seen, (const char *)sqlite3_column_text(stmt, 14),
subscr.imsi, "CS");
get_cb(&subscr, data);
rc = sqlite3_step(stmt);
(*count)++;
}
db_remove_reset(stmt);
if (rc != SQLITE_DONE) {
*err = sqlite3_errmsg(dbc->db);
LOGP(DAUC, LOGL_ERROR, "Cannot read subscribers from db:: %s\n", *err);
return rc;
}
*err = NULL;
return 0;
}
/*! Retrieve subscriber data from the HLR database.
* \param[in,out] dbc database context.
* \param[in] id ID of the subscriber in the HLR db.
@@ -884,3 +977,106 @@ out:
return ret;
}
static int _db_ind_run(struct db_context *dbc, sqlite3_stmt *stmt, const char *vlr, bool reset)
{
int rc;
if (!db_bind_text(stmt, "$vlr", vlr))
return -EIO;
/* execute the statement */
rc = sqlite3_step(stmt);
if (reset)
db_remove_reset(stmt);
return rc;
}
static int _db_ind_add(struct db_context *dbc, const char *vlr)
{
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_ADD];
if (_db_ind_run(dbc, stmt, vlr, true) != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Cannot create IND entry for %s\n", osmo_quote_str_c(OTC_SELECT, vlr, -1));
return -EIO;
}
return 0;
}
static int _db_ind_del(struct db_context *dbc, const char *vlr)
{
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_DEL];
_db_ind_run(dbc, stmt, vlr, true);
/* We don't really care about the result. If it didn't exist, then that was the goal anyway. */
return 0;
}
static int _db_ind_get(struct db_context *dbc, const char *vlr, unsigned int *ind)
{
int ret = 0;
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_SELECT];
int rc = _db_ind_run(dbc, stmt, vlr, false);
if (rc == SQLITE_DONE) {
/* Does not exist yet */
ret = -ENOENT;
goto out;
} else if (rc != SQLITE_ROW) {
LOGP(DDB, LOGL_ERROR, "Error executing SQL: %d\n", rc);
ret = -EIO;
goto out;
}
OSMO_ASSERT(ind);
*ind = sqlite3_column_int64(stmt, 0);
out:
db_remove_reset(stmt);
return ret;
}
int _db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr,
unsigned int *ind, bool del)
{
const char *vlr_name = NULL;
int rc;
switch (vlr->type) {
case OSMO_CNI_PEER_ID_IPA_NAME:
if (vlr->ipa_name.len < 2 || vlr->ipa_name.val[vlr->ipa_name.len - 1] != '\0') {
LOGP(DDB, LOGL_ERROR, "Expecting VLR ipa_name to be zero terminated; found %s\n",
osmo_ipa_name_to_str(&vlr->ipa_name));
return -ENOTSUP;
}
vlr_name = (const char*)vlr->ipa_name.val;
break;
default:
LOGP(DDB, LOGL_ERROR, "Unsupported osmo_cni_peer_id type: %s\n",
osmo_cni_peer_id_type_name(vlr->type));
return -ENOTSUP;
}
if (del)
return _db_ind_del(dbc, vlr_name);
rc = _db_ind_get(dbc, vlr_name, ind);
if (!rc)
return 0;
/* Does not exist yet, create. */
rc = _db_ind_add(dbc, vlr_name);
if (rc) {
LOGP(DDB, LOGL_ERROR, "Error creating IND entry for %s\n", osmo_quote_str_c(OTC_SELECT, vlr_name, -1));
return rc;
}
/* To be sure, query again from scratch. */
return _db_ind_get(dbc, vlr_name, ind);
}
int db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr, unsigned int *ind)
{
return _db_ind(dbc, vlr, ind, false);
}
int db_ind_del(struct db_context *dbc, const struct osmo_cni_peer_id *vlr)
{
return _db_ind(dbc, vlr, NULL, true);
}

View File

@@ -18,10 +18,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: dbd_helper.c,v 1.44 2011/08/09 11:14:14 mhoenicka Exp $
*/

View File

@@ -170,7 +170,7 @@ void dgsm_init(void *ctx)
g_hlr->mslookup.server.local_attach_max_age = 60 * 60;
g_hlr->mslookup.client.result_timeout_milliseconds = 2000;
g_hlr->mslookup.client.result_timeout_milliseconds = OSMO_DGSM_DEFAULT_RESULT_TIMEOUT_MS;
g_hlr->gsup_unit_name.unit_name = "HLR";
g_hlr->gsup_unit_name.serno = "unnamed-HLR";
@@ -191,7 +191,7 @@ void dgsm_start(void *ctx)
dgsm_mdns_client_config_apply();
}
void dgsm_stop()
void dgsm_stop(void)
{
g_hlr->mslookup.allow_startup = false;
mslookup_server_mdns_config_apply();

View File

@@ -442,13 +442,13 @@ int config_write_mslookup(struct vty *vty)
msc = mslookup_server_msc_get(&mslookup_server_msc_wildcard, false);
if (msc)
config_write_msc_services(vty, " ", msc);
config_write_msc_services(vty, " ", msc);
llist_for_each_entry(msc, &g_hlr->mslookup.server.local_site_services, entry) {
if (!osmo_ipa_name_cmp(&mslookup_server_msc_wildcard, &msc->name))
continue;
vty_out(vty, " msc %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
config_write_msc_services(vty, " ", msc);
vty_out(vty, " msc ipa-name %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
config_write_msc_services(vty, " ", msc);
}
/* If the server is disabled, still output the above to not lose the service config. */
@@ -475,6 +475,10 @@ int config_write_mslookup(struct vty *vty)
vty_out(vty, " mdns domain-suffix %s%s",
g_hlr->mslookup.client.mdns.domain_suffix,
VTY_NEWLINE);
if (g_hlr->mslookup.client.result_timeout_milliseconds != OSMO_DGSM_DEFAULT_RESULT_TIMEOUT_MS)
vty_out(vty, " timeout %u%s",
g_hlr->mslookup.client.result_timeout_milliseconds,
VTY_NEWLINE);
}
return CMD_SUCCESS;

View File

@@ -18,18 +18,22 @@
*/
#include <errno.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
#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 <osmocom/gsm/protocol/ipaccess.h>
#include <osmocom/gsm/ipa.h>
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/hlr/gsup_server.h>
#include <osmocom/hlr/gsup_router.h>
#include <osmocom/hlr/hlr.h>
#define LOG_GSUP_CONN(conn, level, fmt, args...) \
LOGP(DLGSUP, level, "GSUP peer %s: " fmt, \
@@ -46,7 +50,7 @@ static void osmo_gsup_server_send(struct osmo_gsup_conn *conn,
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_prepend_header(msg_tx, IPAC_PROTO_OSMO);
ipa_server_conn_send(conn->conn, msg_tx);
}
@@ -177,11 +181,9 @@ static int osmo_gsup_server_read_cb(struct ipa_server_conn *conn,
if (hh->proto == IPAC_PROTO_IPACCESS) {
rc = ipa_server_conn_ccm(conn, msg);
if (rc < 0) {
/* conn is already invalid here! */
return -1;
}
msgb_free(msg);
if (rc < 0) /* conn is already invalid here! */
return -1;
return 0;
}
@@ -274,7 +276,7 @@ static int osmo_gsup_server_ccm_cb(struct ipa_server_conn *conn,
{
struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data;
uint8_t *addr = NULL;
size_t addr_len;
int addr_len;
LOGP(DLGSUP, LOGL_INFO, "CCM Callback\n");
@@ -315,41 +317,17 @@ static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn)
return 0;
}
/* Add conn to the clients list in a way that conn->auc_3g_ind takes the lowest
* unused integer and the list of clients remains sorted by auc_3g_ind.
* Keep this function non-static to allow linking in a unit test. */
void osmo_gsup_server_add_conn(struct llist_head *clients,
struct osmo_gsup_conn *conn)
static void update_fd_settings(int fd)
{
struct osmo_gsup_conn *c;
struct osmo_gsup_conn *prev_conn;
int ret;
int val;
c = llist_first_entry_or_null(clients, struct osmo_gsup_conn, list);
/*TODO: Set keepalive settings here. See OS#4312 */
/* Is the first index, 0, unused? */
if (!c || c->auc_3g_ind > 0) {
conn->auc_3g_ind = 0;
llist_add(&conn->list, clients);
return;
}
/* Look for a gap later on */
prev_conn = NULL;
llist_for_each_entry(c, clients, list) {
/* skip first item, we know it has auc_3g_ind == 0. */
if (!prev_conn) {
prev_conn = c;
continue;
}
if (c->auc_3g_ind > prev_conn->auc_3g_ind + 1)
break;
prev_conn = c;
}
OSMO_ASSERT(prev_conn);
conn->auc_3g_ind = prev_conn->auc_3g_ind + 1;
llist_add(&conn->list, &prev_conn->list);
val = 1;
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
if (ret < 0)
LOGP(DLGSUP, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
}
/* a client has connected to the server socket and we have accept()ed it */
@@ -371,10 +349,11 @@ static int osmo_gsup_server_accept_cb(struct ipa_server_link *link, int fd)
/* link data structure with server structure */
conn->server = gsups;
osmo_gsup_server_add_conn(&gsups->clients, conn);
llist_add_tail(&conn->list, &gsups->clients);
LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d (IND=%u)\n",
conn->conn->addr, conn->conn->port, conn->auc_3g_ind);
LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d\n", conn->conn->addr, conn->conn->port);
update_fd_settings(fd);
/* request the identity of the client */
rc = ipa_ccm_send_id_req(fd);
@@ -461,25 +440,22 @@ int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup,
/**
* 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
* All required memory buffers for data pointed to by pointers in struct osmo_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.
* \param[in] talloc_ctx To allocation memory for dynamic fields (msisdn, apn) in the gsup field
* \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)
enum osmo_gsup_cn_domain cn_domain,
void *talloc_ctx)
{
int len;
uint8_t *msisdn_buf = talloc_size(talloc_ctx, OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN);
OSMO_ASSERT(gsup);
*gsup = (struct osmo_gsup_message){
@@ -488,27 +464,29 @@ int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup,
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);
len = gsm48_encode_bcd_number(msisdn_buf, OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN, 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 = msisdn_buf;
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);
if (g_hlr->ps.pdp_profile.enabled) {
OSMO_ASSERT(g_hlr->ps.pdp_profile.num_pdp_infos <= ARRAY_SIZE(g_hlr->ps.pdp_profile.pdp_infos));
OSMO_ASSERT(g_hlr->ps.pdp_profile.num_pdp_infos <= ARRAY_SIZE(gsup->pdp_infos));
memcpy(gsup->pdp_infos,
g_hlr->ps.pdp_profile.pdp_infos,
sizeof(struct osmo_gsup_pdp_info) * g_hlr->ps.pdp_profile.num_pdp_infos);
gsup->num_pdp_infos = g_hlr->ps.pdp_profile.num_pdp_infos;
} else {
uint8_t *apn_buf = talloc_size(talloc_ctx, APN_MAXLEN);
osmo_gsup_configure_wildcard_apn(gsup, apn_buf, APN_MAXLEN);
}
}
return 0;

View File

@@ -1,7 +1,7 @@
# 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
LIBVERSION=2:0:2
AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include \
$(TALLOC_CFLAGS) $(LIBOSMOCORE_CFLAGS) $(LIBOSMOABIS_CFLAGS)
@@ -11,6 +11,7 @@ lib_LTLIBRARIES = libosmo-gsup-client.la
libosmo_gsup_client_la_SOURCES = \
cni_peer_id.c \
gsup_client.c \
gsup_client_mux.c \
gsup_req.c \
$(NULL)

View File

@@ -2,6 +2,8 @@
*
* All Rights Reserved
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* 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
@@ -154,6 +156,12 @@ int osmo_cni_peer_id_set_str(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni
int osmo_cni_peer_id_cmp(const struct osmo_cni_peer_id *a, const struct osmo_cni_peer_id *b)
{
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
if (a->type != b->type)
return OSMO_CMP(a->type, b->type);
switch (a->type) {

View File

@@ -6,6 +6,8 @@
* Author: Jacob Erlbeck
* Author: Neels Hofmeyr
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* 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
@@ -24,6 +26,7 @@
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/gsm/ipa.h>
#include <osmocom/gsm/oap_client.h>
#include <osmocom/gsm/protocol/ipaccess.h>
#include <osmocom/core/msgb.h>
@@ -31,6 +34,8 @@
#include <errno.h>
#include <string.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
static void start_test_procedure(struct osmo_gsup_client *gsupc);
@@ -40,7 +45,7 @@ static void gsup_client_send_ping(struct osmo_gsup_client *gsupc)
msg->l2h = msgb_put(msg, 1);
msg->l2h[0] = IPAC_MSGT_PING;
ipa_msg_push_header(msg, IPAC_PROTO_IPACCESS);
ipa_prepend_header(msg, IPAC_PROTO_IPACCESS);
ipa_client_conn_send(gsupc->link, msg);
}
@@ -110,7 +115,7 @@ 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_prepend_header(msg_tx, IPAC_PROTO_OSMO);
ipa_client_conn_send(gsupc->link, msg_tx);
/* msg_tx is now queued and will be freed. */
}
@@ -129,6 +134,19 @@ static void gsup_client_oap_register(struct osmo_gsup_client *gsupc)
client_send(gsupc, IPAC_PROTO_EXT_OAP, msg_tx);
}
static void update_fd_settings(int fd)
{
int ret;
int val;
/*TODO: Set keepalive settings here. See OS#4312 */
val = 1;
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
if (ret < 0)
LOGP(DLGSUP, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
}
static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
{
struct osmo_gsup_client *gsupc = link->data;
@@ -139,6 +157,7 @@ static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
gsupc->is_connected = up;
if (up) {
update_fd_settings(link->ofd->fd);
start_test_procedure(gsupc);
if (gsupc->oap_state.state == OSMO_OAP_INITIALIZED)
@@ -288,7 +307,7 @@ struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx, struct osmo_
OSMO_ASSERT(config->ipa_dev->unit_name);
gsupc = talloc_zero(talloc_ctx, struct osmo_gsup_client);
gsupc = talloc(talloc_ctx, struct osmo_gsup_client);
OSMO_ASSERT(gsupc);
*gsupc = (struct osmo_gsup_client){
.unit_name = (const char *)config->ipa_dev->unit_name, /* API backwards compat */
@@ -431,3 +450,36 @@ struct msgb *osmo_gsup_client_msgb_alloc(void)
{
return msgb_alloc_headroom(4000, 64, __func__);
}
void *osmo_gsup_client_get_data(const struct osmo_gsup_client *gsupc)
{
return gsupc->data;
}
void osmo_gsup_client_set_data(struct osmo_gsup_client *gsupc, void *data)
{
gsupc->data = data;
}
const char *osmo_gsup_client_get_rem_addr(const struct osmo_gsup_client *gsupc)
{
if (!gsupc->link)
return NULL;
return gsupc->link->addr;
}
uint16_t osmo_gsup_client_get_rem_port(const struct osmo_gsup_client *gsupc)
{
if (!gsupc->link)
return 0;
return gsupc->link->port;
}
bool osmo_gsup_client_is_connected(const struct osmo_gsup_client *gsupc)
{
return gsupc->is_connected;
}
const struct ipaccess_unit *osmo_gsup_client_get_ipaccess_unit(const struct osmo_gsup_client *gsupc)
{
return gsupc->ipa_dev;
}

View File

@@ -0,0 +1,196 @@
/* Directing individual GSUP messages to their respective handlers. */
/*
* (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <osmocom/core/logging.h>
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/gsupclient/gsup_client_mux.h>
static enum osmo_gsup_message_class gsup_client_mux_classify(struct gsup_client_mux *gcm,
const struct osmo_gsup_message *gsup_msg)
{
if (gsup_msg->message_class)
return gsup_msg->message_class;
LOGP(DLGSUP, LOGL_DEBUG, "No explicit GSUP Message Class, trying to guess from message type %s\n",
osmo_gsup_message_type_name(gsup_msg->message_type));
switch (gsup_msg->message_type) {
case OSMO_GSUP_MSGT_PROC_SS_REQUEST:
case OSMO_GSUP_MSGT_PROC_SS_RESULT:
case OSMO_GSUP_MSGT_PROC_SS_ERROR:
return OSMO_GSUP_MESSAGE_CLASS_USSD;
/* GSM 04.11 code implementing MO SMS */
case OSMO_GSUP_MSGT_MO_FORWARD_SM_ERROR:
case OSMO_GSUP_MSGT_MO_FORWARD_SM_RESULT:
case OSMO_GSUP_MSGT_READY_FOR_SM_ERROR:
case OSMO_GSUP_MSGT_READY_FOR_SM_RESULT:
case OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST:
return OSMO_GSUP_MESSAGE_CLASS_SMS;
default:
return OSMO_GSUP_MESSAGE_CLASS_SUBSCRIBER_MANAGEMENT;
}
}
/* Non-static for unit tests */
int gsup_client_mux_rx(struct osmo_gsup_client *gsup_client, struct msgb *msg)
{
struct gsup_client_mux *gcm = osmo_gsup_client_get_data(gsup_client);
struct osmo_gsup_message gsup;
enum osmo_gsup_message_class message_class;
int rc;
rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup);
if (rc < 0) {
LOGP(DLGSUP, LOGL_ERROR, "Failed to decode GSUP message: '%s' (%d) [ %s]\n",
get_value_string(gsm48_gmm_cause_names, -rc), -rc, osmo_hexdump(msg->data, msg->len));
goto msgb_free_and_return;
}
if (!gsup.imsi[0]) {
LOGP(DLGSUP, LOGL_ERROR, "Failed to decode GSUP message: missing IMSI\n");
if (OSMO_GSUP_IS_MSGT_REQUEST(gsup.message_type))
gsup_client_mux_tx_error_reply(gcm, &gsup, GMM_CAUSE_INV_MAND_INFO);
rc = -GMM_CAUSE_INV_MAND_INFO;
goto msgb_free_and_return;
}
message_class = gsup_client_mux_classify(gcm, &gsup);
if (message_class <= OSMO_GSUP_MESSAGE_CLASS_UNSET || message_class >= ARRAY_SIZE(gcm->rx_cb)) {
LOGP(DLGSUP, LOGL_ERROR, "Failed to classify GSUP message target\n");
rc = -EINVAL;
goto msgb_free_and_return;
}
if (!gcm->rx_cb[message_class].func) {
LOGP(DLGSUP, LOGL_ERROR, "No receiver set up for GSUP Message Class %s\n", osmo_gsup_message_class_name(message_class));
rc = -ENOTSUP;
goto msgb_free_and_return;
}
rc = gcm->rx_cb[message_class].func(gcm, gcm->rx_cb[message_class].data, &gsup);
msgb_free_and_return:
msgb_free(msg);
return rc;
}
/* Make it clear that struct gsup_client_mux should be talloc allocated, so that it can be used as talloc parent. */
struct gsup_client_mux *gsup_client_mux_alloc(void *talloc_ctx)
{
return talloc_zero(talloc_ctx, struct gsup_client_mux);
}
/* Start a GSUP client to serve this gsup_client_mux. */
int gsup_client_mux_start(struct gsup_client_mux *gcm, const char *gsup_server_addr_str, uint16_t gsup_server_port,
struct ipaccess_unit *ipa_dev)
{
gcm->gsup_client = osmo_gsup_client_create2(gcm, ipa_dev,
gsup_server_addr_str,
gsup_server_port,
&gsup_client_mux_rx, NULL);
if (!gcm->gsup_client)
return -ENOMEM;
osmo_gsup_client_set_data(gcm->gsup_client, gcm);
return 0;
}
int gsup_client_mux_tx(struct gsup_client_mux *gcm, const struct osmo_gsup_message *gsup_msg)
{
struct msgb *msg;
int rc;
if (!gcm || !gcm->gsup_client) {
LOGP(DLGSUP, LOGL_ERROR, "GSUP link is down, cannot send GSUP message\n");
return -ENOTSUP;
}
msg = osmo_gsup_client_msgb_alloc();
rc = osmo_gsup_encode(msg, gsup_msg);
if (rc < 0) {
LOGP(DLGSUP, LOGL_ERROR, "Failed to encode GSUP message: '%s'\n", strerror(-rc));
return rc;
}
return osmo_gsup_client_send(gcm->gsup_client, msg);
}
/* Set GSUP source_name to our local IPA name */
void gsup_client_mux_tx_set_source(const struct gsup_client_mux *gcm,
struct osmo_gsup_message *gsup_msg)
{
const char *local_msc_name;
const struct ipaccess_unit *ipa_dev;
if (!gcm)
return;
if (!gcm->gsup_client)
return;
ipa_dev = osmo_gsup_client_get_ipaccess_unit(gcm->gsup_client);
if (!ipa_dev)
return;
local_msc_name = ipa_dev->serno;
if (!local_msc_name)
return;
gsup_msg->source_name = (const uint8_t *) local_msc_name;
gsup_msg->source_name_len = strlen(local_msc_name) + 1;
}
/* Transmit GSUP error in response to original message */
void gsup_client_mux_tx_error_reply(struct gsup_client_mux *gcm, const struct osmo_gsup_message *gsup_orig,
enum gsm48_gmm_cause cause)
{
struct osmo_gsup_message gsup_reply;
/* No need to answer if we couldn't parse an ERROR message type, only REQUESTs need an error reply. */
if (!OSMO_GSUP_IS_MSGT_REQUEST(gsup_orig->message_type))
return;
gsup_reply = (struct osmo_gsup_message){
.cause = cause,
.message_type = OSMO_GSUP_TO_MSGT_ERROR(gsup_orig->message_type),
.message_class = gsup_orig->message_class,
.destination_name = gsup_orig->source_name,
.destination_name_len = gsup_orig->source_name_len,
/* RP-Message-Reference is mandatory for SM Service */
.sm_rp_mr = gsup_orig->sm_rp_mr,
};
OSMO_STRLCPY_ARRAY(gsup_reply.imsi, gsup_orig->imsi);
gsup_client_mux_tx_set_source(gcm, &gsup_reply);
/* For SS/USSD, it's important to keep both session state and ID IEs */
if (gsup_orig->session_state != OSMO_GSUP_SESSION_STATE_NONE) {
gsup_reply.session_state = OSMO_GSUP_SESSION_STATE_END;
gsup_reply.session_id = gsup_orig->session_id;
}
if (osmo_gsup_client_enc_send(gcm->gsup_client, &gsup_reply))
LOGP(DLGSUP, LOGL_ERROR, "Failed to send Error reply (imsi=%s)\n",
osmo_quote_str(gsup_orig->imsi, -1));
}

View File

@@ -2,6 +2,8 @@
*
* All Rights Reserved
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* 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
@@ -107,6 +109,12 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_cni_peer_id
struct osmo_gsup_req *req;
int rc;
if (!from_peer) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from NULL peer is not allowed\n");
msgb_free(msg);
return NULL;
}
if (!msgb_l2(msg) || !msgb_l2len(msg)) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: missing or empty L2 data\n",
osmo_cni_peer_id_to_str(from_peer));
@@ -121,8 +129,7 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_cni_peer_id
req->msg = msg;
req->send_response_cb = send_response_cb;
req->cb_data = cb_data;
if (from_peer)
req->source_name = *from_peer;
req->source_name = *from_peer;
rc = osmo_gsup_decode(msgb_l2(req->msg), msgb_l2len(req->msg), (struct osmo_gsup_message*)&req->gsup);
if (rc < 0) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: cannot decode (rc=%d)\n", osmo_cni_peer_id_to_str(from_peer), rc);

114
src/hlr.c
View File

@@ -31,6 +31,7 @@
#include <osmocom/vty/command.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/ports.h>
#include <osmocom/vty/cpu_sched_vty.h>
#include <osmocom/ctrl/control_vty.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/gsm/gsm48_ie.h>
@@ -48,6 +49,7 @@
#include <osmocom/hlr/rand.h>
#include <osmocom/hlr/hlr_vty.h>
#include <osmocom/hlr/hlr_ussd.h>
#include <osmocom/hlr/hlr_sms.h>
#include <osmocom/hlr/dgsm.h>
#include <osmocom/hlr/proxy.h>
#include <osmocom/hlr/lu_fsm.h>
@@ -84,8 +86,6 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
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;
@@ -130,8 +130,7 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
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) {
if (osmo_gsup_create_insert_subscriber_data_msg(&gsup, subscr->imsi, subscr->msisdn, cn_domain, OTC_SELECT) != 0) {
LOGP(DLGSUP, LOGL_ERROR,
"IMSI='%s': Cannot notify GSUP client; could not create gsup message "
"for %s:%u\n", subscr->imsi,
@@ -205,23 +204,34 @@ static int subscr_create_on_demand(const char *imsi)
{
char msisdn[GSM23003_MSISDN_MAX_DIGITS + 1];
int rc;
unsigned int rand_msisdn_len = g_hlr->subscr_create_on_demand_rand_msisdn_len;
if (!g_hlr->subscr_create_on_demand)
return -1;
if (db_subscr_exists_by_imsi(g_hlr->dbc, imsi) == 0)
return -1;
if (rand_msisdn_len && generate_new_msisdn(msisdn, imsi, rand_msisdn_len) != 0)
switch (g_hlr->subscr_create_on_demand.mode) {
case SUBSCR_COD_MODE_MSISDN_FROM_IMSI:
OSMO_STRLCPY_ARRAY(msisdn, imsi);
break;
case SUBSCR_COD_MODE_RAND_MSISDN:
if (generate_new_msisdn(msisdn, imsi, g_hlr->subscr_create_on_demand.rand_msisdn_len) != 0)
return -1;
break;
case SUBSCR_COD_MODE_NO_MSISDN:
msisdn[0] = '\0';
break;
case SUBSCR_COD_MODE_DISABLED:
default:
return -1;
}
LOGP(DMAIN, LOGL_INFO, "IMSI='%s': Creating subscriber on demand\n", imsi);
rc = db_subscr_create(g_hlr->dbc, imsi, g_hlr->subscr_create_on_demand_flags);
rc = db_subscr_create(g_hlr->dbc, imsi, g_hlr->subscr_create_on_demand.flags);
if (rc) {
LOGP(DMAIN, LOGL_ERROR, "Failed to create subscriber on demand (rc=%d): IMSI='%s'\n", rc, imsi);
return rc;
}
if (!rand_msisdn_len)
if (msisdn[0] == '\0')
return 0;
/* Update MSISDN of the new (just allocated) subscriber */
@@ -268,9 +278,9 @@ int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val,
if (nam_val)
return 0;
if (subscr->vlr_number && osmo_ipa_name_set_str(&vlr_name, subscr->vlr_number))
if (subscr->vlr_number[0] && !osmo_ipa_name_set_str(&vlr_name, subscr->vlr_number))
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &vlr_name, &gsup_del_data);
if (subscr->sgsn_number && osmo_ipa_name_set_str(&vlr_name, subscr->sgsn_number))
if (subscr->sgsn_number[0] && !osmo_ipa_name_set_str(&vlr_name, subscr->sgsn_number))
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &vlr_name, &gsup_del_data);
return 0;
}
@@ -280,13 +290,14 @@ int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val,
***********************************************************************/
/* process an incoming SAI request */
static int rx_send_auth_info(unsigned int auc_3g_ind, struct osmo_gsup_req *req)
static int rx_send_auth_info(struct osmo_gsup_req *req)
{
struct osmo_gsup_message gsup_out = {
.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT,
};
bool separation_bit = false;
int num_auth_vectors = OSMO_GSUP_MAX_NUM_AUTH_INFO;
unsigned int auc_3g_ind;
int rc;
subscr_create_on_demand(req->gsup.imsi);
@@ -297,6 +308,14 @@ static int rx_send_auth_info(unsigned int auc_3g_ind, struct osmo_gsup_req *req)
if (req->gsup.num_auth_vectors > 0 &&
req->gsup.num_auth_vectors <= OSMO_GSUP_MAX_NUM_AUTH_INFO)
num_auth_vectors = req->gsup.num_auth_vectors;
rc = db_ind(g_hlr->dbc, &req->source_name, &auc_3g_ind);
if (rc) {
LOG_GSUP_REQ(req, LOGL_ERROR,
"Unable to determine 3G auth IND for source %s (rc=%d),"
" generating tuples with IND = 0\n",
osmo_cni_peer_id_to_str(&req->source_name), rc);
auc_3g_ind = 0;
}
rc = db_get_auc(g_hlr->dbc, req->gsup.imsi, auc_3g_ind,
gsup_out.auth_vectors,
@@ -314,7 +333,7 @@ static int rx_send_auth_info(unsigned int auc_3g_ind, struct osmo_gsup_req *req)
" Returning slightly inaccurate cause 'IMSI Unknown' via GSUP");
return rc;
case -ENOENT:
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN, "IMSI unknown");
osmo_gsup_req_respond_err(req, g_hlr->reject_cause, "IMSI unknown");
return rc;
default:
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "failure to look up IMSI in db");
@@ -516,7 +535,7 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
switch (req->gsup.message_type) {
/* requests sent to us */
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
rx_send_auth_info(conn->auc_3g_ind, req);
rx_send_auth_info(req);
break;
case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
rx_upd_loc_req(conn, req);
@@ -549,6 +568,15 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
case OSMO_GSUP_MSGT_CHECK_IMEI_REQUEST:
rx_check_imei_req(req);
break;
case OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST:
forward_mo_sms(req);
break;
case OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST:
forward_mt_sms(req);
break;
case OSMO_GSUP_MSGT_READY_FOR_SM_REQUEST:
rx_ready_for_sm_req(req);
break;
default:
LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n",
osmo_gsup_message_type_name(req->gsup.message_type));
@@ -558,12 +586,12 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
return 0;
}
static void print_usage()
static void print_usage(void)
{
printf("Usage: osmo-hlr\n");
}
static void print_help()
static void print_help(void)
{
printf(" -h --help This text.\n");
printf(" -c --config-file filename The config file to use.\n");
@@ -576,6 +604,10 @@ static void print_help()
printf(" -U --db-upgrade Allow HLR database schema upgrades.\n");
printf(" -C --db-check Quit after opening (and upgrading) the database.\n");
printf(" -V --version Print the version of OsmoHLR.\n");
printf("\nVTY reference generation:\n");
printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n");
printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n");
}
static struct {
@@ -591,10 +623,37 @@ static struct {
.db_upgrade = false,
};
static void handle_long_options(const char *prog_name, const int long_option)
{
static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT;
switch (long_option) {
case 1:
vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
if (vty_ref_mode < 0) {
fprintf(stderr, "%s: Unknown VTY reference generation "
"mode '%s'\n", prog_name, optarg);
exit(2);
}
break;
case 2:
fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
exit(0);
default:
fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
exit(2);
}
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
static int long_option = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"config-file", 1, 0, 'c'},
@@ -607,6 +666,8 @@ static void handle_options(int argc, char **argv)
{"db-upgrade", 0, 0, 'U' },
{"db-check", 0, 0, 'C' },
{"version", 0, 0, 'V' },
{"vty-ref-mode", 1, &long_option, 1},
{"vty-ref-xml", 0, &long_option, 2},
{0, 0, 0, 0}
};
@@ -616,6 +677,9 @@ static void handle_options(int argc, char **argv)
break;
switch (c) {
case 0:
handle_long_options(argv[0], long_option);
break;
case 'h':
print_usage();
print_help();
@@ -681,7 +745,7 @@ static void signal_hdlr(int signal)
}
static const char vlr_copyright[] =
"Copyright (C) 2016, 2017 by Harald Welte, sysmocom s.f.m.c. GmbH\r\n"
"Copyright (C) 2016-2023 by Harald Welte, sysmocom s.f.m.c. GmbH\r\n"
"License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
"This is free software: you are free to change and redistribute it.\r\n"
"There is NO WARRANTY, to the extent permitted by law.\r\n";
@@ -690,7 +754,6 @@ static struct vty_app_info vty_info = {
.name = "OsmoHLR",
.version = PACKAGE_VERSION,
.copyright = vlr_copyright,
.is_config_node = hlr_vty_is_config_node,
.go_parent_cb = hlr_vty_go_parent,
};
@@ -707,12 +770,16 @@ int main(int argc, char **argv)
g_hlr = talloc_zero(hlr_ctx, struct hlr);
INIT_LLIST_HEAD(&g_hlr->euse_list);
INIT_LLIST_HEAD(&g_hlr->smsc_list);
INIT_LLIST_HEAD(&g_hlr->ss_sessions);
INIT_LLIST_HEAD(&g_hlr->ussd_routes);
INIT_LLIST_HEAD(&g_hlr->smsc_routes);
INIT_LLIST_HEAD(&g_hlr->mslookup.server.local_site_services);
g_hlr->db_file_path = talloc_strdup(g_hlr, HLR_DEFAULT_DB_FILE_PATH);
g_hlr->mslookup.server.mdns.domain_suffix = talloc_strdup(g_hlr, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT);
g_hlr->mslookup.client.mdns.domain_suffix = talloc_strdup(g_hlr, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT);
g_hlr->reject_cause = GMM_CAUSE_PLMN_NOTALLOWED;
g_hlr->no_proxy_reject_cause = GMM_CAUSE_NET_FAIL;
/* Init default (call independent) SS session guard timeout value */
g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT;
@@ -729,9 +796,10 @@ int main(int argc, char **argv)
osmo_stats_init(hlr_ctx);
vty_init(&vty_info);
ctrl_vty_init(hlr_ctx);
handle_options(argc, argv);
hlr_vty_init();
hlr_vty_init(hlr_ctx);
dgsm_vty_init();
osmo_cpu_sched_vty_init(hlr_ctx);
handle_options(argc, argv);
rc = vty_read_config_file(cmdline_opts.config_file, NULL);
if (rc < 0) {
@@ -769,8 +837,7 @@ int main(int argc, char **argv)
}
/* start telnet after reading config for vty_get_bind_addr() */
rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(),
OSMO_VTY_PORT_HLR);
rc = telnet_init_default(hlr_ctx, NULL, OSMO_VTY_PORT_HLR);
if (rc < 0)
return rc;
@@ -783,7 +850,6 @@ int main(int argc, char **argv)
}
proxy_init(g_hlr->gs);
g_hlr->ctrl_bind_addr = ctrl_vty_get_bind_addr();
g_hlr->ctrl = hlr_controlif_setup(g_hlr);
dgsm_start(hlr_ctx);

View File

@@ -25,6 +25,7 @@
#include <getopt.h>
#include <inttypes.h>
#include <string.h>
#include <errno.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
@@ -50,7 +51,7 @@ static struct {
.db_upgrade = false,
};
static void print_help()
static void print_help(void)
{
printf("\n");
printf("Usage: osmo-hlr-db-tool [-l <hlr.db>] [create|import-nitb-db <nitb.db>]\n");
@@ -70,8 +71,9 @@ static void print_help()
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");
printf(" Be aware that the import is somewhat lossy, only the IMSI,\n");
printf(" MSISDN, IMEI, nam_cs/ps, 2G auth data and last seen LU are set.\n");
printf(" The most recently associated IMEI from the Equipment table is used.\n");
}
static void print_version(int print_copyright)
@@ -212,9 +214,15 @@ enum nitb_stmt {
static const char *nitb_stmt_sql[] = {
[NITB_SELECT_SUBSCR] =
"SELECT imsi, id, extension, authorized"
" FROM Subscriber"
" ORDER BY id",
"SELECT s.imsi, s.id, s.extension, s.authorized,"
" SUBSTR(e.imei,0,15), STRFTIME('%s', s.expire_lu)"
" FROM Subscriber s LEFT JOIN"
" (SELECT imei, subscriber_id, MAX(Equipment.updated) AS updated"
" FROM Equipment,EquipmentWatch"
" WHERE Equipment.id = EquipmentWatch.equipment_id"
" GROUP BY EquipmentWatch.subscriber_id) e"
" ON e.subscriber_id = s.id"
" ORDER by s.id",
[NITB_SELECT_AUTH_KEYS] =
"SELECT algorithm_id, a3a8_ki from authkeys"
" WHERE subscriber_id = $subscr_id",
@@ -222,8 +230,65 @@ static const char *nitb_stmt_sql[] = {
sqlite3_stmt *nitb_stmt[ARRAY_SIZE(nitb_stmt_sql)] = {};
enum hlr_db_stmt {
HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI,
};
static const char *hlr_db_stmt_sql[] = {
[HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI] =
"UPDATE subscriber SET last_lu_seen = datetime($last_lu, 'unixepoch') WHERE imsi = $imsi",
};
sqlite3_stmt *hlr_db_stmt[ARRAY_SIZE(hlr_db_stmt_sql)] = {};
size_t _dbd_decode_binary(const unsigned char *in, unsigned char *out);
/*! Set a subscriber's LU timestamp in the HLR database.
* In normal operations there is never any need to explicitly
* update the value of last_lu_seen, so this function can live here.
*
* \param[in,out] dbc database context.
* \param[in] imsi ASCII string of IMSI digits
* \param[in] imei ASCII string of identifier digits, or NULL to remove the IMEI.
* \returns 0 on success, -ENOENT when the given subscriber does not exist,
* -EIO on database errors.
*/
int db_subscr_update_lu_by_imsi(struct db_context *dbc, const char* imsi, const int last_lu)
{
int rc, ret = 0;
sqlite3_stmt *stmt = hlr_db_stmt[HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI];
if (!db_bind_text(stmt, "$imsi", imsi))
return -EIO;
if (last_lu && !db_bind_int(stmt, "$last_lu", last_lu))
return -EIO;
/* execute the statement */
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
LOGP(DAUC, LOGL_ERROR, "Update last_lu_seen for subscriber IMSI='%s': SQL Error: %s\n", imsi,
sqlite3_errmsg(dbc->db));
ret = -EIO;
goto out;
}
/* verify execution result */
rc = sqlite3_changes(dbc->db);
if (!rc) {
LOGP(DAUC, LOGL_ERROR, "Cannot update last_lu_seen for subscriber IMSI='%s': no such subscriber\n", imsi);
ret = -ENOENT;
} else if (rc != 1) {
LOGP(DAUC, LOGL_ERROR, "Update last_lu_seen for subscriber IMSI='%s': SQL modified %d rows (expected 1)\n",
imsi, rc);
ret = -EIO;
}
out:
db_remove_reset(stmt);
return ret;
}
void import_nitb_subscr_aud(sqlite3 *nitb_db, const char *imsi, int64_t nitb_id, int64_t hlr_id)
{
int rc;
@@ -297,6 +362,7 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
int64_t imsi;
char imsi_str[32];
bool authorized;
int last_lu_int;
imsi = sqlite3_column_int64(stmt, 0);
@@ -315,8 +381,18 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
nitb_id = sqlite3_column_int64(stmt, 1);
copy_sqlite3_text_to_buf(subscr.msisdn, stmt, 2);
authorized = sqlite3_column_int(stmt, 3) ? true : false;
copy_sqlite3_text_to_buf(subscr.imei, stmt, 4);
/* Default periodic LU was 30 mins and the expire_lu
* was twice that + 1 min
*/
last_lu_int = sqlite3_column_int(stmt, 5) - 3660;
db_subscr_update_msisdn_by_imsi(dbc, imsi_str, subscr.msisdn);
/* In case the subscriber was somehow never seen, invent an IMEI */
if (strlen(subscr.imei) == 14)
db_subscr_update_imei_by_imsi(dbc, imsi_str, subscr.imei);
db_subscr_update_lu_by_imsi(dbc, imsi_str, last_lu_int);
db_subscr_nam(dbc, imsi_str, authorized, true);
db_subscr_nam(dbc, imsi_str, authorized, false);
@@ -361,6 +437,17 @@ int import_nitb_db(void)
}
}
for (i = 0; i < ARRAY_SIZE(hlr_db_stmt_sql); i++) {
sql = hlr_db_stmt_sql[i];
rc = sqlite3_prepare_v2(g_hlr_db_tool_ctx->dbc->db, hlr_db_stmt_sql[i], -1,
&hlr_db_stmt[i], NULL);
if (rc != SQLITE_OK) {
LOGP(DDB, LOGL_ERROR, "OsmoHLR DB: Unable to prepare SQL statement '%s'\n", sql);
ret = -1;
goto out_free;
}
}
stmt = nitb_stmt[NITB_SELECT_SUBSCR];
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
@@ -387,6 +474,7 @@ int main(int argc, char **argv)
{
int rc;
int (*main_action)(void);
int i;
main_action = NULL;
g_hlr_db_tool_ctx = talloc_zero(NULL, struct hlr_db_tool_ctx);
@@ -430,6 +518,11 @@ int main(int argc, char **argv)
if (main_action)
rc = (*main_action)();
/* db_close will only finalize statments in g_hlr_db_tool_ctx->dbc->stmt
* it is ok to call finalize on NULL */
for (i = 0; i < ARRAY_SIZE(hlr_db_stmt); i++) {
sqlite3_finalize(hlr_db_stmt[i]);
}
db_close(g_hlr_db_tool_ctx->dbc);
log_fini();
exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);

276
src/hlr_sms.c Normal file
View File

@@ -0,0 +1,276 @@
/* OsmoHLR SMS-over-GSUP routing implementation */
/* Author: Mychaela N. Falconia <falcon@freecalypso.org>, 2023 - however,
* Mother Mychaela's contributions are NOT subject to copyright.
* No rights reserved, all rights relinquished.
*
* Based on earlier unmerged work by Vadim Yanitskiy, 2019.
*
* 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 <stdint.h>
#include <string.h>
#include <errno.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gsm/gsup.h>
#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsm/protocol/gsm_04_11.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/hlr_sms.h>
#include <osmocom/hlr/gsup_server.h>
#include <osmocom/hlr/gsup_router.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/db.h>
/***********************************************************************
* core data structures expressing config from VTY
***********************************************************************/
struct hlr_smsc *smsc_find(struct hlr *hlr, const char *name)
{
struct hlr_smsc *smsc;
llist_for_each_entry(smsc, &hlr->smsc_list, list) {
if (!strcmp(smsc->name, name))
return smsc;
}
return NULL;
}
struct hlr_smsc *smsc_alloc(struct hlr *hlr, const char *name)
{
struct hlr_smsc *smsc = smsc_find(hlr, name);
if (smsc)
return NULL;
smsc = talloc_zero(hlr, struct hlr_smsc);
smsc->name = talloc_strdup(smsc, name);
smsc->hlr = hlr;
llist_add_tail(&smsc->list, &hlr->smsc_list);
return smsc;
}
void smsc_free(struct hlr_smsc *smsc)
{
llist_del(&smsc->list);
talloc_free(smsc);
}
struct hlr_smsc_route *smsc_route_find(struct hlr *hlr, const char *num_addr)
{
struct hlr_smsc_route *rt;
llist_for_each_entry(rt, &hlr->smsc_routes, list) {
if (!strcmp(rt->num_addr, num_addr))
return rt;
}
return NULL;
}
struct hlr_smsc_route *smsc_route_alloc(struct hlr *hlr, const char *num_addr,
struct hlr_smsc *smsc)
{
struct hlr_smsc_route *rt;
if (smsc_route_find(hlr, num_addr))
return NULL;
rt = talloc_zero(hlr, struct hlr_smsc_route);
rt->num_addr = talloc_strdup(rt, num_addr);
rt->smsc = smsc;
llist_add_tail(&rt->list, &hlr->smsc_routes);
return rt;
}
void smsc_route_free(struct hlr_smsc_route *rt)
{
llist_del(&rt->list);
talloc_free(rt);
}
/***********************************************************************
* forwarding of MO SMS to SMSCs based on SM-RP-DA
***********************************************************************/
static const struct hlr_smsc *find_smsc_route(const char *smsc_addr)
{
const struct hlr_smsc_route *rt;
rt = smsc_route_find(g_hlr, smsc_addr);
if (rt)
return rt->smsc;
return g_hlr->smsc_default;
}
static void respond_with_sm_rp_cause(struct osmo_gsup_req *req,
uint8_t sm_rp_cause)
{
struct osmo_gsup_message rsp_msg = { };
rsp_msg.sm_rp_cause = &sm_rp_cause;
osmo_gsup_req_respond(req, &rsp_msg, true, true);
}
/* Short Message from MSC/VLR towards SMSC */
void forward_mo_sms(struct osmo_gsup_req *req)
{
uint8_t gsm48_decode_buffer[GSM411_SMSC_ADDR_MAX_OCTETS];
char smsc_addr[GSM411_SMSC_ADDR_MAX_DIGITS+1];
const struct hlr_smsc *smsc;
struct osmo_cni_peer_id dest_peer;
/* Make sure SM-RP-DA (SMSC address) is present */
if (req->gsup.sm_rp_da == NULL || !req->gsup.sm_rp_da_len) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO,
"missing SM-RP-DA");
return;
}
if (req->gsup.sm_rp_da_type != OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO,
"SM-RP-DA type is not SMSC");
return;
}
/* Enforce the length constrainst on SM-RP-DA, as specified in
* GSM 04.11 section 8.2.5.2. Also enforce absence of ToN/NPI
* extension octets at the same time. */
if (req->gsup.sm_rp_da_len < GSM411_SMSC_ADDR_MIN_OCTETS ||
req->gsup.sm_rp_da_len > GSM411_SMSC_ADDR_MAX_OCTETS ||
!(req->gsup.sm_rp_da[0] & 0x80)) {
/* This form of bogosity originates from the MS,
* not from OsmoMSC or any other Osmocom network elements! */
LOGP(DLSMS, LOGL_NOTICE,
"Rx '%s' (IMSI-%s) contains invalid SM-RP-DA from MS\n",
osmo_gsup_message_type_name(req->gsup.message_type),
req->gsup.imsi);
respond_with_sm_rp_cause(req, GSM411_RP_CAUSE_SEMANT_INC_MSG);
return;
}
/* Decode SMSC address from SM-RP-DA */
gsm48_decode_buffer[0] = req->gsup.sm_rp_da_len - 1;
memcpy(gsm48_decode_buffer + 1, req->gsup.sm_rp_da + 1,
req->gsup.sm_rp_da_len - 1);
gsm48_decode_bcd_number2(smsc_addr, sizeof(smsc_addr),
gsm48_decode_buffer,
req->gsup.sm_rp_da_len, 0);
/* Look for a route to this SMSC */
smsc = find_smsc_route(smsc_addr);
if (smsc == NULL) {
LOGP(DLSMS, LOGL_NOTICE,
"Failed to find a route for '%s' (IMSI-%s, SMSC-Addr-%s)\n",
osmo_gsup_message_type_name(req->gsup.message_type),
req->gsup.imsi, smsc_addr);
respond_with_sm_rp_cause(req,
GSM411_RP_CAUSE_MO_NUM_UNASSIGNED);
return;
}
/* We got the IPA name of our SMSC - forward the message */
osmo_cni_peer_id_set(&dest_peer, OSMO_CNI_PEER_ID_IPA_NAME,
(const uint8_t *) smsc->name,
strlen(smsc->name) + 1);
osmo_gsup_forward_to_local_peer(req->cb_data, &dest_peer, req, NULL);
}
/***********************************************************************
* forwarding of MT SMS from SMSCs to MSC/VLR based on IMSI
***********************************************************************/
void forward_mt_sms(struct osmo_gsup_req *req)
{
struct hlr_subscriber subscr;
struct osmo_cni_peer_id dest_peer;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, req->gsup.imsi, &subscr);
if (rc < 0) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN,
"IMSI unknown");
return;
}
/* is this subscriber currently attached to a VLR? */
if (!subscr.vlr_number[0]) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMPL_DETACHED,
"subscriber not attached to a VLR");
return;
}
osmo_cni_peer_id_set(&dest_peer, OSMO_CNI_PEER_ID_IPA_NAME,
(const uint8_t *) subscr.vlr_number,
strlen(subscr.vlr_number) + 1);
osmo_gsup_forward_to_local_peer(req->cb_data, &dest_peer, req, NULL);
}
/***********************************************************************
* READY-FOR-SM handling
*
* An MSC indicates that an MS is ready to receive messages. If one
* or more SMSCs have previously tried to send MT SMS to this MS and
* failed, we should pass this READY-FOR-SM message to them so they
* can resend their queued SMS right away. But which SMSC do we
* forward the message to? 3GPP specs call for a complicated system
* where the HLR remembers which SMSCs have tried and failed to deliver
* MT SMS, and those SMSCs then get notified - but that design is too
* much complexity for the current state of Osmocom. So we keep it
* simple: we iterate over all configured SMSCs and forward a copy
* of the READY-FOR-SM.req message to each.
*
* Routing of responses is another problem: the MSC that sent
* READY-FOR-SM.req expects only one response, and one can even argue
* that the operation is a "success" from the perspective of the MS
* irrespective of whether each given SMSC handled the notification
* successfully or not. Hence our approach: we always return success
* to the MS, and when we forward copies of READY-FOR-SM.req to SMSCs,
* we list the HLR as the message source - this way SMSC responses
* will terminate at this HLR and won't be forwarded to the MSC.
***********************************************************************/
static void forward_req_copy_to_smsc(const struct osmo_gsup_req *req,
const struct hlr_smsc *smsc)
{
const char *my_ipa_name = g_hlr->gsup_unit_name.serno;
struct osmo_gsup_message forward = req->gsup;
struct osmo_ipa_name smsc_ipa_name;
/* set the source to this HLR */
forward.source_name = (const uint8_t *) my_ipa_name;
forward.source_name_len = strlen(my_ipa_name) + 1;
/* send it off */
LOG_GSUP_REQ(req, LOGL_INFO, "Forwarding source-reset copy to %s\n",
smsc->name);
osmo_ipa_name_set(&smsc_ipa_name, (const uint8_t *) smsc->name,
strlen(smsc->name) + 1);
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &smsc_ipa_name, &forward);
}
void rx_ready_for_sm_req(struct osmo_gsup_req *req)
{
struct hlr_smsc *smsc;
/* fan request msg out to all SMSCs */
llist_for_each_entry(smsc, &g_hlr->smsc_list, list)
forward_req_copy_to_smsc(req, smsc);
/* send OK response to the MSC and the MS */
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_READY_FOR_SM_RESULT,
true);
}

View File

@@ -122,9 +122,40 @@ void ussd_route_del(struct hlr_ussd_route *rt)
talloc_free(rt);
}
static struct hlr_ussd_route *ussd_route_lookup_7bit(struct hlr *hlr, const char *ussd_code)
static struct hlr_ussd_route *ussd_route_lookup_for_req(struct hlr *hlr, const struct ss_request *req)
{
const uint8_t cgroup = req->ussd_data_dcs >> 4;
const uint8_t lang = req->ussd_data_dcs & 0x0f;
char ussd_code[GSM0480_USSD_7BIT_STRING_LEN];
struct hlr_ussd_route *rt;
ussd_code[0] = '\0';
/* We support only the Coding Group 0 (GSM 7-bit default alphabeet). In fact,
* the USSD request is usually limited to [*#0-9], so we don't really need to
* support other coding groups and languages. */
switch (cgroup) {
case 0:
/* The Language is usually set to '1111'B (unspecified), but some UEs
* are known to indicate '0000'B (German). */
if (lang != 0x0f) {
LOGP(DSS, LOGL_NOTICE, "USSD DataCodingScheme (0x%02x): "
"the Language is usually set to 15 (unspecified), "
"but the request indicates %u - ignoring this\n",
req->ussd_data_dcs, lang);
/* do not abort, attempt to decode as if it was '1111'B */
}
gsm_7bit_decode_n_ussd(&ussd_code[0], sizeof(ussd_code),
req->ussd_data, (req->ussd_data_len * 8) / 7);
break;
default:
LOGP(DSS, LOGL_ERROR, "USSD DataCodingScheme (0x%02x): "
"Coding Group %u is not supported, expecting Coding Group 0\n",
req->ussd_data_dcs, cgroup);
return NULL;
}
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 "
@@ -279,19 +310,20 @@ static int ss_gsup_send_to_ms(struct ss_session *ss, struct osmo_gsup_server *gs
}
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 msgb *ss_msg)
{
struct osmo_gsup_message resp = {0};
struct osmo_gsup_message resp;
int rc;
resp.message_type = gsup_msg_type;
resp = (struct osmo_gsup_message) {
.message_type = gsup_msg_type,
.session_id = ss->session_id,
.session_state = ss->state,
};
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);
@@ -311,7 +343,8 @@ static int ss_tx_reject(struct ss_session *ss, int invoke_id, uint8_t problem_ta
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);
ss->state = OSMO_GSUP_SESSION_STATE_END;
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, msg);
}
#endif
@@ -320,15 +353,16 @@ static int ss_tx_to_ms_error(struct ss_session *ss, uint8_t invoke_id, uint8_t e
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);
ss->state = OSMO_GSUP_SESSION_STATE_END;
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, msg);
}
static int ss_tx_to_ms_ussd_7bit(struct ss_session *ss, bool final, uint8_t invoke_id, const char *text)
static int ss_tx_to_ms_ussd_7bit(struct ss_session *ss, 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);
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, msg);
}
/***********************************************************************
@@ -344,6 +378,8 @@ static int handle_ussd_own_msisdn(struct ss_session *ss,
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
int rc;
ss->state = OSMO_GSUP_SESSION_STATE_END;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
@@ -351,7 +387,7 @@ static int handle_ussd_own_msisdn(struct ss_session *ss,
snprintf(buf, sizeof(buf), "You have no MSISDN!");
else
snprintf(buf, sizeof(buf), "Your extension is %s", subscr.msisdn);
ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf);
ss_tx_to_ms_ussd_7bit(ss, req->invoke_id, buf);
break;
case -ENOENT:
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
@@ -369,7 +405,21 @@ static int handle_ussd_own_imsi(struct ss_session *ss,
{
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
snprintf(buf, sizeof(buf), "Your IMSI is %s", ss->imsi);
ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf);
ss->state = OSMO_GSUP_SESSION_STATE_END;
ss_tx_to_ms_ussd_7bit(ss, req->invoke_id, buf);
return 0;
}
/* This handler just keeps the session idle unless the guard timer expires. */
static int handle_ussd_test_idle(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), "Keeping your session idle, it will expire "
"at most in %u seconds.", g_hlr->ncss_guard_timeout);
ss->state = OSMO_GSUP_SESSION_STATE_CONTINUE;
ss_tx_to_ms_ussd_7bit(ss, req->invoke_id, buf);
return 0;
}
@@ -383,6 +433,10 @@ static const struct hlr_iuse hlr_iuses[] = {
.name = "own-imsi",
.handle_ussd = handle_ussd_own_imsi,
},
{
.name = "test-idle",
.handle_ussd = handle_ussd_test_idle,
},
};
const struct hlr_iuse *iuse_find(const char *name)
@@ -496,8 +550,9 @@ static int handle_ussd(struct ss_session *ss, bool is_euse_originated, const str
} else {
/* Handle internally */
ss->u.iuse->handle_ussd(ss, gsup, req);
/* Release session immediately */
ss_session_free(ss);
/* Release session if the handler has changed its state to END */
if (ss->state == OSMO_GSUP_SESSION_STATE_END)
ss_session_free(ss);
}
}
@@ -579,7 +634,7 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
} 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);
rt = ussd_route_lookup_for_req(hlr, &req);
if (rt) {
if (rt->is_external) {
ss->is_external = true;
@@ -607,7 +662,8 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
if (!ss) {
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: CONTINUE for unknown SS session\n",
gsup->imsi, gsup->session_id);
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "CONTINUE for unknown SS session");
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_MSGT_INCOMP_P_STATE,
"CONTINUE for unknown SS session");
return;
}
@@ -628,6 +684,8 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
if (!ss) {
LOGP(DSS, LOGL_ERROR, "%s/0x%08x: END for unknown SS session\n",
gsup->imsi, gsup->session_id);
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_MSGT_INCOMP_P_STATE,
"END for unknown SS session");
return;
}
@@ -658,4 +716,5 @@ void rx_proc_ss_error(struct osmo_gsup_req *req)
{
LOGP(DSS, LOGL_NOTICE, "%s/0x%08x: Process SS ERROR (%s)\n", req->gsup.imsi, req->gsup.session_id,
osmo_gsup_session_state_name(req->gsup.session_state));
osmo_gsup_req_free(req);
}

View File

@@ -25,7 +25,13 @@
*
*/
#include <errno.h>
#include <string.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/stats.h>
#include <osmocom/vty/command.h>
@@ -38,8 +44,39 @@
#include <osmocom/hlr/hlr_vty.h>
#include <osmocom/hlr/hlr_vty_subscr.h>
#include <osmocom/hlr/hlr_ussd.h>
#include <osmocom/hlr/hlr_sms.h>
#include <osmocom/hlr/gsup_server.h>
static const struct value_string gsm48_gmm_cause_vty_names[] = {
{ GMM_CAUSE_IMSI_UNKNOWN, "imsi-unknown" },
{ GMM_CAUSE_ILLEGAL_MS, "illegal-ms" },
{ GMM_CAUSE_PLMN_NOTALLOWED, "plmn-not-allowed" },
{ GMM_CAUSE_LA_NOTALLOWED, "la-not-allowed" },
{ GMM_CAUSE_ROAMING_NOTALLOWED, "roaming-not-allowed" },
{ GMM_CAUSE_NO_SUIT_CELL_IN_LA, "no-suitable-cell-in-la" },
{ GMM_CAUSE_NET_FAIL, "net-fail" },
{ GMM_CAUSE_CONGESTION, "congestion" },
{ GMM_CAUSE_GSM_AUTH_UNACCEPT, "auth-unacceptable" },
{ GMM_CAUSE_PROTO_ERR_UNSPEC, "proto-error-unspec" },
{ 0, NULL },
};
/* TS 24.008 4.4.4.7 */
static const struct value_string gsm48_gmm_cause_vty_descs[] = {
{ GMM_CAUSE_IMSI_UNKNOWN, " #02: (IMSI unknown in HLR)" },
{ GMM_CAUSE_ILLEGAL_MS, " #03 (Illegal MS)" },
{ GMM_CAUSE_PLMN_NOTALLOWED, " #11: (PLMN not allowed)" },
{ GMM_CAUSE_LA_NOTALLOWED, " #12: (Location Area not allowed)" },
{ GMM_CAUSE_ROAMING_NOTALLOWED, " #13: (Roaming not allowed in this location area)" },
{ GMM_CAUSE_NO_SUIT_CELL_IN_LA, " #15: (No Suitable Cells In Location Area [continue search in PLMN])." },
{ GMM_CAUSE_NET_FAIL, " #17: (Network Failure)" },
{ GMM_CAUSE_CONGESTION, " #22: (Congestion)" },
{ GMM_CAUSE_GSM_AUTH_UNACCEPT, " #23: (GSM authentication unacceptable [UMTS])" },
{ GMM_CAUSE_PROTO_ERR_UNSPEC, "#111: (Protocol error, unspecified)" },
{ 0, NULL },
};
struct cmd_node hlr_node = {
HLR_NODE,
"%s(config-hlr)# ",
@@ -70,30 +107,230 @@ DEFUN(cfg_gsup,
return CMD_SUCCESS;
}
struct cmd_node ps_node = {
PS_NODE,
"%s(config-hlr-ps)# ",
1,
};
DEFUN(cfg_ps,
cfg_ps_cmd,
"ps",
"Configure the PS options")
{
vty->node = PS_NODE;
return CMD_SUCCESS;
}
struct cmd_node ps_pdp_profiles_node = {
PS_PDP_PROFILES_NODE,
"%s(config-hlr-ps-pdp-profiles)# ",
1,
};
DEFUN(cfg_ps_pdp_profiles,
cfg_ps_pdp_profiles_cmd,
"pdp-profiles default",
"Define a PDP profile set.\n"
"Define the global default profile.\n")
{
g_hlr->ps.pdp_profile.enabled = true;
vty->node = PS_PDP_PROFILES_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_no_ps_pdp_profiles,
cfg_no_ps_pdp_profiles_cmd,
"no pdp-profiles default",
NO_STR
"Delete PDP profile.\n"
"Unique identifier for this PDP profile set.\n")
{
g_hlr->ps.pdp_profile.enabled = false;
return CMD_SUCCESS;
}
struct cmd_node ps_pdp_profiles_profile_node = {
PS_PDP_PROFILES_PROFILE_NODE,
"%s(config-hlr-ps-pdp-profile)# ",
1,
};
/* context_id == 0 means the slot is free */
struct osmo_gsup_pdp_info *get_pdp_profile(uint8_t context_id)
{
for (int i = 0; i < OSMO_GSUP_MAX_NUM_PDP_INFO; i++) {
struct osmo_gsup_pdp_info *info = &g_hlr->ps.pdp_profile.pdp_infos[i];
if (info->context_id == context_id)
return info;
}
return NULL;
}
struct osmo_gsup_pdp_info *create_pdp_profile(uint8_t context_id)
{
struct osmo_gsup_pdp_info *info = get_pdp_profile(0);
if (!info)
return NULL;
memset(info, 0, sizeof(*info));
info->context_id = context_id;
info->have_info = 1;
g_hlr->ps.pdp_profile.num_pdp_infos++;
return info;
}
void destroy_pdp_profile(struct osmo_gsup_pdp_info *info)
{
info->context_id = 0;
if (info->apn_enc)
talloc_free((void *) info->apn_enc);
g_hlr->ps.pdp_profile.num_pdp_infos--;
memset(info, 0, sizeof(*info));
}
DEFUN(cfg_ps_pdp_profiles_profile,
cfg_ps_pdp_profiles_profile_cmd,
"profile <1-10>",
"Configure a PDP profile\n"
"Unique PDP context identifier. The lowest profile will be used as default context.\n")
{
struct osmo_gsup_pdp_info *info;
uint8_t context_id = atoi(argv[0]);
info = get_pdp_profile(context_id);
if (!info) {
info = create_pdp_profile(context_id);
if (!info) {
vty_out(vty, "Failed to create profile %d!%s", context_id, VTY_NEWLINE);
return CMD_ERR_INCOMPLETE;
}
}
vty->node = PS_PDP_PROFILES_PROFILE_NODE;
vty->index = info;
return CMD_SUCCESS;
}
DEFUN(cfg_no_ps_pdp_profiles_profile,
cfg_no_ps_pdp_profiles_profile_cmd,
"no profile <1-10>",
NO_STR
"Delete a PDP profile\n"
"Unique PDP context identifier. The lowest profile will be used as default context.\n")
{
struct osmo_gsup_pdp_info *info;
uint8_t context_id = atoi(argv[0]);
info = get_pdp_profile(context_id);
if (info)
destroy_pdp_profile(info);
return CMD_SUCCESS;
}
DEFUN(cfg_ps_pdp_profile_apn, cfg_ps_pdp_profile_apn_cmd,
"apn ID",
"Configure the APN.\n"
"APN name or * for wildcard apn.\n")
{
struct osmo_gsup_pdp_info *info = vty->index;
const char *apn_name = argv[0];
/* apn encoded takes one more byte than strlen() */
size_t apn_enc_len = strlen(apn_name) + 1;
uint8_t *apn_enc;
int ret;
if (apn_enc_len > APN_MAXLEN) {
vty_out(vty, "APN name is too long '%s'. Max is %d!%s", apn_name, APN_MAXLEN, VTY_NEWLINE);
return CMD_ERR_INCOMPLETE;
}
info->apn_enc = apn_enc = (uint8_t *) talloc_zero_size(g_hlr, apn_enc_len);
ret = info->apn_enc_len = osmo_apn_from_str(apn_enc, apn_enc_len, apn_name);
if (ret < 0) {
talloc_free(apn_enc);
info->apn_enc = NULL;
info->apn_enc_len = 0;
vty_out(vty, "Invalid APN name %s!", apn_name);
return CMD_WARNING;
}
return CMD_SUCCESS;
}
DEFUN(cfg_no_ps_pdp_profile_apn, cfg_no_ps_pdp_profile_apn_cmd,
"no apn",
NO_STR
"Delete the APN.\n")
{
struct osmo_gsup_pdp_info *info = vty->index;
if (info->apn_enc) {
talloc_free((void *) info->apn_enc);
info->apn_enc = NULL;
info->apn_enc_len = 0;
}
return CMD_SUCCESS;
}
static void config_write_subscr_create_on_demand(struct vty *vty)
{
const uint8_t flags = g_hlr->subscr_create_on_demand.flags;
const char *flags_str;
switch (g_hlr->subscr_create_on_demand.mode) {
case SUBSCR_COD_MODE_MSISDN_FROM_IMSI:
vty_out(vty, " subscriber-create-on-demand msisdn-from-imsi");
break;
case SUBSCR_COD_MODE_RAND_MSISDN:
vty_out(vty, " subscriber-create-on-demand %u",
g_hlr->subscr_create_on_demand.rand_msisdn_len);
break;
case SUBSCR_COD_MODE_NO_MSISDN:
vty_out(vty, " subscriber-create-on-demand no-msisdn");
break;
case SUBSCR_COD_MODE_DISABLED:
default:
vty_out(vty, " no subscriber-create-on-demand%s", VTY_NEWLINE);
return;
}
if ((flags & DB_SUBSCR_FLAG_NAM_CS) && (flags & DB_SUBSCR_FLAG_NAM_PS))
flags_str = "cs+ps";
else if (flags & DB_SUBSCR_FLAG_NAM_CS)
flags_str = "cs";
else if (flags & DB_SUBSCR_FLAG_NAM_PS)
flags_str = "ps";
else
flags_str = "none";
vty_out(vty, " %s%s", flags_str, VTY_NEWLINE);
}
static int config_write_hlr(struct vty *vty)
{
vty_out(vty, "hlr%s", VTY_NEWLINE);
vty_out(vty, " reject-cause not-found %s%s",
get_value_string_or_null(gsm48_gmm_cause_vty_names,
(uint32_t) g_hlr->reject_cause), VTY_NEWLINE);
vty_out(vty, " reject-cause no-proxy %s%s",
get_value_string_or_null(gsm48_gmm_cause_vty_names,
(uint32_t) g_hlr->no_proxy_reject_cause), VTY_NEWLINE);
if (g_hlr->store_imei)
vty_out(vty, " store-imei%s", VTY_NEWLINE);
if (g_hlr->db_file_path && strcmp(g_hlr->db_file_path, HLR_DEFAULT_DB_FILE_PATH))
vty_out(vty, " database %s%s", g_hlr->db_file_path, VTY_NEWLINE);
if (g_hlr->subscr_create_on_demand) {
const char *flags_str = "none";
uint8_t flags = g_hlr->subscr_create_on_demand_flags;
unsigned int rand_msisdn_len = g_hlr->subscr_create_on_demand_rand_msisdn_len;
if ((flags & DB_SUBSCR_FLAG_NAM_CS) && (flags & DB_SUBSCR_FLAG_NAM_PS))
flags_str = "cs+ps";
else if (flags & DB_SUBSCR_FLAG_NAM_CS)
flags_str = "cs";
else if (flags & DB_SUBSCR_FLAG_NAM_PS)
flags_str = "ps";
if (rand_msisdn_len)
vty_out(vty, " subscriber-create-on-demand %i %s%s", rand_msisdn_len, flags_str, VTY_NEWLINE);
else
vty_out(vty, " subscriber-create-on-demand no-msisdn %s%s", flags_str, VTY_NEWLINE);
}
config_write_subscr_create_on_demand(vty);
return CMD_SUCCESS;
}
@@ -102,6 +339,39 @@ static int config_write_hlr_gsup(struct vty *vty)
vty_out(vty, " gsup%s", VTY_NEWLINE);
if (g_hlr->gsup_bind_addr)
vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
if (g_hlr->gsup_unit_name.serno)
vty_out(vty, " ipa-name %s%s", g_hlr->gsup_unit_name.serno, VTY_NEWLINE);
return CMD_SUCCESS;
}
static int config_write_hlr_ps(struct vty *vty)
{
vty_out(vty, " ps%s", VTY_NEWLINE);
return CMD_SUCCESS;
}
static int config_write_hlr_ps_pdp_profiles(struct vty *vty)
{
char apn[APN_MAXLEN + 1] = {};
if (!g_hlr->ps.pdp_profile.enabled)
return CMD_SUCCESS;
vty_out(vty, " pdp-profiles default%s", VTY_NEWLINE);
for (int i = 0; i < g_hlr->ps.pdp_profile.num_pdp_infos; i++) {
struct osmo_gsup_pdp_info *pdp_info = &g_hlr->ps.pdp_profile.pdp_infos[i];
if (!pdp_info->context_id)
continue;
vty_out(vty, " profile %d%s", pdp_info->context_id, VTY_NEWLINE);
if (!pdp_info->have_info)
continue;
if (pdp_info->apn_enc && pdp_info->apn_enc_len) {
osmo_apn_to_str(apn, pdp_info->apn_enc, pdp_info->apn_enc_len);
vty_out(vty, " apn %s%s", apn, VTY_NEWLINE);
}
}
return CMD_SUCCESS;
}
@@ -114,8 +384,8 @@ static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
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_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u%s",
name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps,
VTY_NEWLINE);
}
@@ -156,7 +426,7 @@ DEFUN(cfg_hlr_gsup_ipa_name,
{
if (vty->type != VTY_FILE) {
vty_out(vty, "gsup/ipa-name: The GSUP IPA name cannot be changed at run-time; "
"It can only be set in the configuraton file.%s", VTY_NEWLINE);
"It can only be set in the configuration file.%s", VTY_NEWLINE);
return CMD_WARNING;
}
@@ -168,16 +438,15 @@ DEFUN(cfg_hlr_gsup_ipa_name,
* USSD Entity
***********************************************************************/
#include <osmocom/hlr/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_CHOICE "(own-msisdn|own-imsi|test-idle)"
#define INT_STR "Internal USSD Handler\n" \
"Respond with subscribers' own MSISDN\n" \
"Respond with subscribers' own IMSI\n"
"Respond with subscribers' own IMSI\n" \
"Keep the session idle (useful for testing)\n"
#define EXT_STR "External USSD Handler\n" \
"Name of External USSD Handler (IPA CCM ID)\n"
@@ -305,7 +574,7 @@ DEFUN(cfg_no_euse, cfg_no_euse_cmd,
{
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);
vty_out(vty, "%% Cannot remove non-existent EUSE %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (g_hlr->euse_default == euse) {
@@ -355,6 +624,175 @@ DEFUN(cfg_ncss_guard_timeout, cfg_ncss_guard_timeout_cmd,
return CMD_SUCCESS;
}
/***********************************************************************
* Routing of SM-RL to GSUP-attached SMSCs
***********************************************************************/
#define SMSC_STR "Configuration of GSUP routing to SMSCs\n"
struct cmd_node smsc_node = {
SMSC_NODE,
"%s(config-hlr-smsc)# ",
1,
};
DEFUN(cfg_smsc_entity, cfg_smsc_entity_cmd,
"smsc entity NAME",
SMSC_STR
"Configure a particular external SMSC\n"
"IPA name of the external SMSC\n")
{
struct hlr_smsc *smsc;
const char *id = argv[0];
smsc = smsc_find(g_hlr, id);
if (!smsc) {
smsc = smsc_alloc(g_hlr, id);
if (!smsc)
return CMD_WARNING;
}
vty->index = smsc;
vty->index_sub = &smsc->description;
vty->node = SMSC_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_no_smsc_entity, cfg_no_smsc_entity_cmd,
"no smsc entity NAME",
NO_STR SMSC_STR "Remove a particular external SMSC\n"
"IPA name of the external SMSC\n")
{
struct hlr_smsc *smsc = smsc_find(g_hlr, argv[0]);
if (!smsc) {
vty_out(vty, "%% Cannot remove non-existent SMSC %s%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (g_hlr->smsc_default == smsc) {
vty_out(vty,
"%% Cannot remove SMSC %s, it is the default route%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
smsc_free(smsc);
return CMD_SUCCESS;
}
DEFUN(cfg_smsc_route, cfg_smsc_route_cmd,
"smsc route NUMBER NAME",
SMSC_STR
"Configure GSUP route to a particular SMSC\n"
"Numeric address of this SMSC, must match EF.SMSP programming in SIMs\n"
"IPA name of the external SMSC\n")
{
struct hlr_smsc *smsc = smsc_find(g_hlr, argv[1]);
struct hlr_smsc_route *rt = smsc_route_find(g_hlr, argv[0]);
if (rt) {
vty_out(vty,
"%% Cannot add [another?] route for SMSC address %s%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (!smsc) {
vty_out(vty, "%% Cannot find SMSC '%s'%s", argv[1],
VTY_NEWLINE);
return CMD_WARNING;
}
smsc_route_alloc(g_hlr, argv[0], smsc);
return CMD_SUCCESS;
}
DEFUN(cfg_no_smsc_route, cfg_no_smsc_route_cmd,
"no smsc route NUMBER",
NO_STR SMSC_STR "Remove GSUP route to a particular SMSC\n"
"Numeric address of the SMSC\n")
{
struct hlr_smsc_route *rt = smsc_route_find(g_hlr, argv[0]);
if (!rt) {
vty_out(vty, "%% Cannot find route for SMSC address %s%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
smsc_route_free(rt);
return CMD_SUCCESS;
}
DEFUN(cfg_smsc_defroute, cfg_smsc_defroute_cmd,
"smsc default-route NAME",
SMSC_STR
"Configure default SMSC route for unknown SMSC numeric addresses\n"
"IPA name of the external SMSC\n")
{
struct hlr_smsc *smsc;
smsc = smsc_find(g_hlr, argv[0]);
if (!smsc) {
vty_out(vty, "%% Cannot find SMSC %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (g_hlr->smsc_default != smsc) {
vty_out(vty, "Switching default route from %s to %s%s",
g_hlr->smsc_default ? g_hlr->smsc_default->name : "<none>",
smsc->name, VTY_NEWLINE);
g_hlr->smsc_default = smsc;
}
return CMD_SUCCESS;
}
DEFUN(cfg_no_smsc_defroute, cfg_no_smsc_defroute_cmd,
"no smsc default-route",
NO_STR SMSC_STR
"Remove default SMSC route for unknown SMSC numeric addresses\n")
{
g_hlr->smsc_default = NULL;
return CMD_SUCCESS;
}
static void dump_one_smsc(struct vty *vty, struct hlr_smsc *smsc)
{
vty_out(vty, " smsc entity %s%s", smsc->name, VTY_NEWLINE);
}
static int config_write_smsc(struct vty *vty)
{
struct hlr_smsc *smsc;
struct hlr_smsc_route *rt;
llist_for_each_entry(smsc, &g_hlr->smsc_list, list)
dump_one_smsc(vty, smsc);
llist_for_each_entry(rt, &g_hlr->smsc_routes, list) {
vty_out(vty, " smsc route %s %s%s", rt->num_addr,
rt->smsc->name, VTY_NEWLINE);
}
if (g_hlr->smsc_default)
vty_out(vty, " smsc default-route %s%s",
g_hlr->smsc_default->name, VTY_NEWLINE);
return 0;
}
DEFUN(cfg_reject_cause, cfg_reject_cause_cmd,
"reject-cause TYPE CAUSE", "") /* Dynamically Generated */
{
int cause_code = get_string_value(gsm48_gmm_cause_vty_names, argv[1]);
OSMO_ASSERT(cause_code >= 0);
if (strcmp(argv[0], "not-found") == 0)
g_hlr->reject_cause = (enum gsm48_gmm_cause) cause_code;
if (strcmp(argv[0], "no-proxy") == 0)
g_hlr->no_proxy_reject_cause = (enum gsm48_gmm_cause) cause_code;
return CMD_SUCCESS;
}
DEFUN(cfg_store_imei, cfg_store_imei_cmd,
"store-imei",
"Save the IMEI in the database when receiving Check IMEI requests. Note that an MSC does not necessarily send"
@@ -373,29 +811,37 @@ DEFUN(cfg_no_store_imei, cfg_no_store_imei_cmd,
}
DEFUN(cfg_subscr_create_on_demand, cfg_subscr_create_on_demand_cmd,
"subscriber-create-on-demand (no-msisdn|<3-15>) (none|cs|ps|cs+ps)",
"subscriber-create-on-demand (no-msisdn|msisdn-from-imsi|<3-15>) (none|cs|ps|cs+ps)",
"Make a new record when a subscriber is first seen.\n"
"Do not automatically assign MSISDN.\n"
"Assign MSISDN identical to subscriber's IMSI.\n"
"Length of an automatically assigned MSISDN.\n"
"Do not allow any NAM (Network Access Mode) by default.\n"
"Allow access to circuit switched NAM by default.\n"
"Allow access to packet switched NAM by default.\n"
"Allow access to circuit and packet switched NAM by default.\n")
{
enum subscr_create_on_demand_mode mode;
unsigned int rand_msisdn_len = 0;
uint8_t flags = 0x00;
if (strcmp(argv[0], "no-msisdn") != 0)
if (strcmp(argv[0], "no-msisdn") == 0) {
mode = SUBSCR_COD_MODE_NO_MSISDN;
} else if (strcmp(argv[0], "msisdn-from-imsi") == 0) {
mode = SUBSCR_COD_MODE_MSISDN_FROM_IMSI;
} else { /* random MSISDN */
mode = SUBSCR_COD_MODE_RAND_MSISDN;
rand_msisdn_len = atoi(argv[0]);
}
if (strstr(argv[1], "cs"))
flags |= DB_SUBSCR_FLAG_NAM_CS;
if (strstr(argv[1], "ps"))
flags |= DB_SUBSCR_FLAG_NAM_PS;
g_hlr->subscr_create_on_demand = true;
g_hlr->subscr_create_on_demand_rand_msisdn_len = rand_msisdn_len;
g_hlr->subscr_create_on_demand_flags = flags;
g_hlr->subscr_create_on_demand.mode = mode;
g_hlr->subscr_create_on_demand.rand_msisdn_len = rand_msisdn_len;
g_hlr->subscr_create_on_demand.flags = flags;
return CMD_SUCCESS;
}
@@ -404,7 +850,7 @@ DEFUN(cfg_no_subscr_create_on_demand, cfg_no_subscr_create_on_demand_cmd,
"no subscriber-create-on-demand",
"Do not make a new record when a subscriber is first seen.\n")
{
g_hlr->subscr_create_on_demand = false;
g_hlr->subscr_create_on_demand.mode = SUBSCR_COD_MODE_DISABLED;
return CMD_SUCCESS;
}
@@ -435,20 +881,22 @@ int hlr_vty_go_parent(struct vty *vty)
return vty->node;
}
int hlr_vty_is_config_node(struct vty *vty, int node)
void hlr_vty_init(void *hlr_ctx)
{
switch (node) {
/* add items that are not config */
case CONFIG_NODE:
return 0;
cfg_reject_cause_cmd.string =
vty_cmd_string_from_valstr(hlr_ctx,
gsm48_gmm_cause_vty_names,
"reject-cause (not-found|no-proxy) (", "|", ")",
VTY_DO_LOWER);
default:
return 1;
}
}
cfg_reject_cause_cmd.doc =
vty_cmd_string_from_valstr(hlr_ctx,
gsm48_gmm_cause_vty_descs,
"GSUP/GMM cause to be sent\n"
"in the case the IMSI could not be found in the database\n"
"in the case no remote HLR reponded to mslookup GSUP request\n",
"\n", "", 0);
void hlr_vty_init(void)
{
logging_vty_add_cmds();
osmo_talloc_vty_add_cmds();
osmo_stats_vty_add_cmds();
@@ -464,6 +912,20 @@ void hlr_vty_init(void)
install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
install_element(GSUP_NODE, &cfg_hlr_gsup_ipa_name_cmd);
/* PS */
install_node(&ps_node, config_write_hlr_ps);
install_element(HLR_NODE, &cfg_ps_cmd);
install_node(&ps_pdp_profiles_node, config_write_hlr_ps_pdp_profiles);
install_element(PS_NODE, &cfg_ps_pdp_profiles_cmd);
install_element(PS_NODE, &cfg_no_ps_pdp_profiles_cmd);
install_node(&ps_pdp_profiles_profile_node, NULL);
install_element(PS_PDP_PROFILES_NODE, &cfg_ps_pdp_profiles_profile_cmd);
install_element(PS_PDP_PROFILES_NODE, &cfg_no_ps_pdp_profiles_profile_cmd);
install_element(PS_PDP_PROFILES_PROFILE_NODE, &cfg_ps_pdp_profile_apn_cmd);
install_element(PS_PDP_PROFILES_PROFILE_NODE, &cfg_no_ps_pdp_profile_apn_cmd);
install_element(HLR_NODE, &cfg_database_cmd);
install_element(HLR_NODE, &cfg_euse_cmd);
@@ -475,6 +937,16 @@ void hlr_vty_init(void)
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);
install_node(&smsc_node, config_write_smsc);
install_element(HLR_NODE, &cfg_smsc_entity_cmd);
install_element(HLR_NODE, &cfg_no_smsc_entity_cmd);
install_element(HLR_NODE, &cfg_smsc_route_cmd);
install_element(HLR_NODE, &cfg_no_smsc_route_cmd);
install_element(HLR_NODE, &cfg_smsc_defroute_cmd);
install_element(HLR_NODE, &cfg_no_smsc_defroute_cmd);
install_element(HLR_NODE, &cfg_reject_cause_cmd);
install_element(HLR_NODE, &cfg_store_imei_cmd);
install_element(HLR_NODE, &cfg_no_store_imei_cmd);
install_element(HLR_NODE, &cfg_subscr_create_on_demand_cmd);

View File

@@ -1,5 +1,5 @@
/* OsmoHLR subscriber management VTY implementation */
/* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
/* (C) 2017-2023 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
@@ -31,6 +31,7 @@
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/timestamp.h>
#include <osmocom/hlr/hlr_vty.h>
struct vty;
@@ -44,13 +45,14 @@ static char *get_datestr(const time_t *t, char *buf, size_t bufsize)
return buf;
}
static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t last_lu_seen)
static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t last_lu_seen, bool only_age)
{
uint32_t age;
char datebuf[32];
if (!last_lu_seen)
return;
vty_out(vty, " last LU seen on %s: %s", domain_label, get_datestr(&last_lu_seen, datebuf, sizeof(datebuf)));
if (!only_age)
vty_out(vty, " last LU seen on %s: %s", domain_label, get_datestr(&last_lu_seen, datebuf, sizeof(datebuf)));
if (!timestamp_age(&last_lu_seen, &age))
vty_out(vty, " (invalid timestamp)%s", VTY_NEWLINE);
else {
@@ -64,7 +66,10 @@ static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t
UNIT_AGO("h", 60*60);
UNIT_AGO("m", 60);
UNIT_AGO("s", 1);
vty_out(vty, " ago)%s", VTY_NEWLINE);
if (!only_age)
vty_out(vty, " ago)%s", VTY_NEWLINE);
else
vty_out(vty, " ago)");
#undef UNIT_AGO
}
}
@@ -72,8 +77,8 @@ static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t
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;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
vty_out(vty, " ID: %"PRIu64"%s", subscr->id, VTY_NEWLINE);
@@ -108,8 +113,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);
dump_last_lu_seen(vty, "CS", subscr->last_lu_seen);
dump_last_lu_seen(vty, "PS", subscr->last_lu_seen_ps);
dump_last_lu_seen(vty, "CS", subscr->last_lu_seen, false);
dump_last_lu_seen(vty, "PS", subscr->last_lu_seen_ps, false);
if (!*subscr->imsi)
return;
@@ -132,12 +137,12 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
if (aud2g.type != OSMO_AUTH_TYPE_NONE && aud2g.type != OSMO_AUTH_TYPE_GSM) {
vty_out(vty, "%% Error: 2G auth data is not of type 'GSM'%s", VTY_NEWLINE);
aud2g = (struct osmo_sub_auth_data){};
aud2g = (struct osmo_sub_auth_data2){};
}
if (aud3g.type != OSMO_AUTH_TYPE_NONE && aud3g.type != OSMO_AUTH_TYPE_UMTS) {
vty_out(vty, "%% Error: 3G auth data is not of type 'UMTS'%s", VTY_NEWLINE);
aud3g = (struct osmo_sub_auth_data){};
aud3g = (struct osmo_sub_auth_data2){};
}
if (aud2g.algo != OSMO_AUTH_ALG_NONE && aud2g.type != OSMO_AUTH_TYPE_NONE) {
@@ -149,9 +154,10 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
if (aud3g.algo != OSMO_AUTH_ALG_NONE && aud3g.type != OSMO_AUTH_TYPE_NONE) {
vty_out(vty, " 3G auth: %s%s", osmo_auth_alg_name(aud3g.algo), VTY_NEWLINE);
vty_out(vty, " K=%s%s", hexdump_buf(aud3g.u.umts.k), VTY_NEWLINE);
vty_out(vty, " K=%s%s",
osmo_hexdump_nospc(aud3g.u.umts.k, aud3g.u.umts.k_len), VTY_NEWLINE);
vty_out(vty, " %s=%s%s", aud3g.u.umts.opc_is_op? "OP" : "OPC",
hexdump_buf(aud3g.u.umts.opc), VTY_NEWLINE);
osmo_hexdump_nospc(aud3g.u.umts.opc, aud3g.u.umts.opc_len), VTY_NEWLINE);
vty_out(vty, " IND-bitlen=%u", aud3g.u.umts.ind_bitlen);
if (aud3g.u.umts.sqn)
vty_out(vty, " last-SQN=%"PRIu64, aud3g.u.umts.sqn);
@@ -159,6 +165,28 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
}
}
static void subscr_dump_summary_vty(struct hlr_subscriber *subscr, void *data)
{
struct vty *vty = data;
vty_out(vty, "%-5"PRIu64" %-12s %-16s", subscr->id,
*subscr->msisdn ? subscr->msisdn : "none",
*subscr->imsi ? subscr->imsi : "none");
if (*subscr->imei) {
char checksum = osmo_luhn(subscr->imei, 14);
if (checksum == -EINVAL)
vty_out(vty, " %-14s (INVALID LENGTH!)", subscr->imei);
else
vty_out(vty, " %-14s%c", subscr->imei, checksum);
} else {
vty_out(vty," ------------- ");
}
vty_out(vty, " %-2s%-2s ", subscr->nam_cs ? "CS" : "", subscr->nam_ps ? "PS" : "");
if (subscr->last_lu_seen)
dump_last_lu_seen(vty, "CS", subscr->last_lu_seen, true);
vty_out_newline(vty);
}
static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id, struct hlr_subscriber *subscr)
{
char imei_buf[GSM23003_IMEI_NUM_DIGITS_NO_CHK+1];
@@ -186,10 +214,52 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id,
return rc;
}
static void dump_summary_table_vty(struct vty *vty, bool header, bool show_ls)
{
const char *texts = "ID MSISDN IMSI IMEI NAM";
const char *lines = "----- ------------ ---------------- ---------------- -----";
const char *ls_text = " LAST SEEN";
const char *ls_line = " ------------";
if (header) {
if (!show_ls)
vty_out(vty, "%s%s%s%s", texts, VTY_NEWLINE, lines, VTY_NEWLINE);
else
vty_out(vty, "%s%s%s%s%s%s", texts, ls_text, VTY_NEWLINE, lines, ls_line, VTY_NEWLINE);
} else {
if (!show_ls)
vty_out(vty, "%s%s%s%s", lines, VTY_NEWLINE, texts, VTY_NEWLINE);
else
vty_out(vty, "%s%s%s%s%s%s", lines, ls_line, VTY_NEWLINE, texts, ls_text, VTY_NEWLINE);
}
}
static int get_subscrs(struct vty *vty, const char *filter_type, const char *filter)
{
int rc = -1;
int count = 0;
const char *err;
bool show_ls = (filter_type && strcmp(filter_type, "last_lu_seen") == 0);
dump_summary_table_vty(vty, true, show_ls);
rc = db_subscrs_get(g_hlr->dbc, filter_type, filter, subscr_dump_summary_vty, vty, &count, &err);
if (count > 40) {
dump_summary_table_vty(vty, false, show_ls);
}
if (count > 0)
vty_out(vty, " Subscribers Shown: %d%s", count, VTY_NEWLINE);
if (rc)
vty_out(vty, "%% %s%s", err, VTY_NEWLINE);
return rc;
}
#define SUBSCR_CMD "subscriber "
#define SUBSCR_CMD_HELP "Subscriber management commands\n"
#define SUBSCR_SHOW_HELP "Show subscriber information\n"
#define SUBSCRS_SHOW_HELP "Show all subscribers (with filter possibility)\n"
#define SUBSCR_ID "(imsi|msisdn|id|imei) IDENT"
#define SUBSCR_FILTER "(imei|imsi|msisdn) FILTER"
#define SUBSCR_ID_HELP \
"Identify subscriber by IMSI\n" \
"Identify subscriber by MSISDN (phone number)\n" \
@@ -207,7 +277,7 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id,
DEFUN(subscriber_show,
subscriber_show_cmd,
SUBSCR "show",
SUBSCR_HELP "Show subscriber information\n")
SUBSCR_HELP SUBSCR_SHOW_HELP)
{
struct hlr_subscriber subscr;
const char *id_type = argv[0];
@@ -222,7 +292,50 @@ DEFUN(subscriber_show,
ALIAS(subscriber_show, show_subscriber_cmd,
"show " SUBSCR_CMD SUBSCR_ID,
SHOW_STR SUBSCR_CMD_HELP SUBSCR_ID_HELP);
SHOW_STR SUBSCR_SHOW_HELP SUBSCR_ID_HELP);
DEFUN(show_subscriber_all,
show_subscriber_all_cmd,
"show subscribers all",
SHOW_STR SUBSCRS_SHOW_HELP "Show summary of all subscribers\n")
{
if (get_subscrs(vty, NULL, NULL))
return CMD_WARNING;
return CMD_SUCCESS;
}
DEFUN(show_subscriber_filtered,
show_subscriber_filtered_cmd,
"show subscribers " SUBSCR_FILTER,
SHOW_STR SUBSCRS_SHOW_HELP
"Filter Subscribers by IMEI\n" "Filter Subscribers by IMSI\n" "Filter Subscribers by MSISDN\n"
"String to match in imei, imsi or msisdn\n")
{
const char *filter_type = argv[0];
const char *filter = argv[1];
if (get_subscrs(vty, filter_type, filter))
return CMD_WARNING;
return CMD_SUCCESS;
}
ALIAS(show_subscriber_filtered, show_subscriber_filtered_cmd2,
"show subscribers (cs|ps) (on|off)",
SHOW_STR SUBSCR_SHOW_HELP
"Filter Subscribers by CS Network Access Mode\n" "Filter Subscribers by PS Network Access Mode\n"
"Authorised\n" "Not Authorised\n");
DEFUN(show_subscriber_order_last_seen, show_subscriber_order_last_seen_cmd,
"show subscribers last-seen",
SHOW_STR SUBSCR_SHOW_HELP "Show Subscribers Ordered by Last Seen Time\n")
{
if (get_subscrs(vty, "last_lu_seen", NULL))
return CMD_WARNING;
return CMD_SUCCESS;
}
DEFUN(subscriber_create,
subscriber_create_cmd,
@@ -235,7 +348,7 @@ DEFUN(subscriber_create,
int rc;
struct hlr_subscriber subscr;
const char *imsi = argv[0];
if (!osmo_imsi_str_valid(imsi)) {
vty_out(vty, "%% Not a valid IMSI: %s%s", imsi, VTY_NEWLINE);
return CMD_WARNING;
@@ -348,26 +461,27 @@ static bool is_hexkey_valid(struct vty *vty, const char *label,
return false;
}
#define AUTH_ALG_TYPES_2G "(comp128v1|comp128v2|comp128v3|xor)"
#define AUTH_ALG_TYPES_2G "(comp128v1|comp128v2|comp128v3|xor-2g)"
#define AUTH_ALG_TYPES_2G_HELP \
"Use COMP128v1 algorithm\n" \
"Use COMP128v2 algorithm\n" \
"Use COMP128v3 algorithm\n" \
"Use XOR algorithm\n"
"Use XOR-2G algorithm\n"
#define AUTH_ALG_TYPES_3G "milenage"
#define AUTH_ALG_TYPES_3G "(milenage|tuak)"
#define AUTH_ALG_TYPES_3G_HELP \
"Use Milenage algorithm\n"
"Use Milenage algorithm\n" \
"Use TUAK algorithm\n"
#define A38_XOR_MIN_KEY_LEN 12
#define A38_XOR_MAX_KEY_LEN 16
#define A38_COMP128_KEY_LEN 16
#define MILENAGE_KEY_LEN 16
static bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
int *minlen, int *maxlen)
bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
int *minlen, int *maxlen, int *minlen_opc, int *maxlen_opc)
{
/* Default: no OP[c]. True for all 2G algorithms, and 3G-XOR. Overridden below for real 3G AKA algorithms. */
if (minlen_opc)
*minlen_opc = 0;
if (maxlen_opc)
*maxlen_opc = 0;
if (!strcasecmp(alg_str, "none")) {
*algo = OSMO_AUTH_ALG_NONE;
*minlen = *maxlen = 0;
@@ -380,13 +494,28 @@ static bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
} else if (!strcasecmp(alg_str, "comp128v3")) {
*algo = OSMO_AUTH_ALG_COMP128v3;
*minlen = *maxlen = A38_COMP128_KEY_LEN;
} else if (!strcasecmp(alg_str, "xor")) {
*algo = OSMO_AUTH_ALG_XOR;
} else if (!strcasecmp(alg_str, "xor-3g")) {
*algo = OSMO_AUTH_ALG_XOR_3G;
*minlen = A38_XOR_MIN_KEY_LEN;
*maxlen = A38_XOR_MAX_KEY_LEN;
} else if (!strcasecmp(alg_str, "xor-2g")) {
*algo = OSMO_AUTH_ALG_XOR_2G;
*minlen = *maxlen = A38_XOR2G_KEY_LEN;
} else if (!strcasecmp(alg_str, "milenage")) {
*algo = OSMO_AUTH_ALG_MILENAGE;
*minlen = *maxlen = MILENAGE_KEY_LEN;
if (minlen_opc)
*minlen_opc = MILENAGE_KEY_LEN;
if (maxlen_opc)
*maxlen_opc = MILENAGE_KEY_LEN;
} else if (!strcasecmp(alg_str, "tuak")) {
*algo = OSMO_AUTH_ALG_TUAK;
*minlen = 16;
*maxlen = 32;
if (minlen_opc)
*minlen_opc = 32;
if (maxlen_opc)
*maxlen_opc = 32;
} else
return false;
return true;
@@ -442,7 +571,7 @@ DEFUN(subscriber_aud2g,
.u.gsm.ki = ki,
};
if (!auth_algo_parse(alg_type, &aud2g.algo, &minlen, &maxlen)) {
if (!auth_algo_parse(alg_type, &aud2g.algo, &minlen, &maxlen, NULL, NULL)) {
vty_out(vty, "%% Unknown auth algorithm: '%s'%s", alg_type, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -501,21 +630,21 @@ DEFUN(subscriber_aud3g,
SUBSCR_UPDATE_HELP
"Set UMTS authentication data (3G, and 2G with UMTS AKA)\n"
AUTH_ALG_TYPES_3G_HELP
"Set Encryption Key K\n" "K as 32 hexadecimal characters\n"
"Set OP key\n" "Set OPC key\n" "OP or OPC as 32 hexadecimal characters\n"
"Set Encryption Key K\n" "K as 32/64 hexadecimal characters\n"
"Set OP key\n" "Set OPC key\n" "OP or OPC as 32/64 hexadecimal characters\n"
"Set IND bit length\n" "IND bit length value (default: 5)\n")
{
struct hlr_subscriber subscr;
int minlen = 0;
int maxlen = 0;
int minlen = 0, minlen_opc = 0;
int maxlen = 0, maxlen_opc = 0;
int rc;
const char *id_type = argv[0];
const char *id = argv[1];
const char *alg_type = AUTH_ALG_TYPES_3G;
const char *k = argv[2];
bool opc_is_op = (strcasecmp("op", argv[3]) == 0);
const char *op_opc = argv[4];
int ind_bitlen = argc > 6? atoi(argv[6]) : 5;
const char *alg_type = argv[2];
const char *k = argv[3];
bool opc_is_op = (strcasecmp("op", argv[4]) == 0);
const char *op_opc = argv[5];
int ind_bitlen = argc > 7 ? atoi(argv[7]) : 5;
struct sub_auth_data_str aud3g = {
.type = OSMO_AUTH_TYPE_UMTS,
.u.umts = {
@@ -525,8 +654,8 @@ DEFUN(subscriber_aud3g,
.ind_bitlen = ind_bitlen,
},
};
if (!auth_algo_parse(alg_type, &aud3g.algo, &minlen, &maxlen)) {
if (!auth_algo_parse(alg_type, &aud3g.algo, &minlen, &maxlen, &minlen_opc, &maxlen_opc)) {
vty_out(vty, "%% Unknown auth algorithm: '%s'%s", alg_type, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -534,8 +663,56 @@ DEFUN(subscriber_aud3g,
if (!is_hexkey_valid(vty, "K", aud3g.u.umts.k, minlen, maxlen))
return CMD_WARNING;
if (!is_hexkey_valid(vty, opc_is_op ? "OP" : "OPC", aud3g.u.umts.opc,
MILENAGE_KEY_LEN, MILENAGE_KEY_LEN))
if (!is_hexkey_valid(vty, opc_is_op ? "OP" : "OPC", aud3g.u.umts.opc, minlen_opc, maxlen_opc))
return CMD_WARNING;
if (get_subscr_by_argv(vty, id_type, id, &subscr))
return CMD_WARNING;
rc = db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud3g);
if (rc) {
vty_out(vty, "%% Error: cannot set 3G auth data for IMSI='%s'%s",
subscr.imsi, VTY_NEWLINE);
return CMD_WARNING;
}
return CMD_SUCCESS;
}
DEFUN(subscriber_aud3g_xor,
subscriber_aud3g_xor_cmd,
SUBSCR_UPDATE "aud3g xor-3g k K"
" [ind-bitlen] [<0-28>]",
SUBSCR_UPDATE_HELP
"Set UMTS authentication data (3G, and 2G with UMTS AKA)\n"
"Use XOR-3G algorithm\n"
"Set Encryption Key K\n" "K as 32 hexadecimal characters\n"
"Set IND bit length\n" "IND bit length value (default: 5)\n")
{
struct hlr_subscriber subscr;
int minlen = 0;
int maxlen = 0;
int rc;
const char *id_type = argv[0];
const char *id = argv[1];
const char *k = argv[2];
int ind_bitlen = argc > 4? atoi(argv[4]) : 5;
struct sub_auth_data_str aud3g = {
.type = OSMO_AUTH_TYPE_UMTS,
.u.umts = {
.k = k,
.opc_is_op = 0,
.opc = "00000000000000000000000000000000",
.ind_bitlen = ind_bitlen,
},
};
if (!auth_algo_parse("xor-3g", &aud3g.algo, &minlen, &maxlen, NULL, NULL)) {
vty_out(vty, "%% Unknown auth algorithm: '%s'%s", "xor-3g", VTY_NEWLINE);
return CMD_WARNING;
}
if (!is_hexkey_valid(vty, "K", aud3g.u.umts.k, minlen, maxlen))
return CMD_WARNING;
if (get_subscr_by_argv(vty, id_type, id, &subscr))
@@ -628,6 +805,10 @@ DEFUN(subscriber_nam,
void hlr_vty_subscriber_init(void)
{
install_element_ve(&show_subscriber_all_cmd);
install_element_ve(&show_subscriber_filtered_cmd);
install_element_ve(&show_subscriber_filtered_cmd2);
install_element_ve(&show_subscriber_order_last_seen_cmd);
install_element_ve(&subscriber_show_cmd);
install_element_ve(&show_subscriber_cmd);
install_element(ENABLE_NODE, &subscriber_create_cmd);
@@ -637,6 +818,7 @@ void hlr_vty_subscriber_init(void)
install_element(ENABLE_NODE, &subscriber_aud2g_cmd);
install_element(ENABLE_NODE, &subscriber_no_aud3g_cmd);
install_element(ENABLE_NODE, &subscriber_aud3g_cmd);
install_element(ENABLE_NODE, &subscriber_aud3g_xor_cmd);
install_element(ENABLE_NODE, &subscriber_imei_cmd);
install_element(ENABLE_NODE, &subscriber_nam_cmd);
}

View File

@@ -43,6 +43,12 @@ const struct log_info_cat hlr_log_info_cat[] = {
.color = "\033[1;35m",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
[DCTRL] = {
.name = "DCTRL",
.description = "Osmocom CTRL interface",
.color = "\033[1;30m",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
};
const struct log_info hlr_log_info = {

View File

@@ -136,7 +136,7 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
}
if (db_subscr_get_by_imsi(g_hlr->dbc, update_location_req->gsup.imsi, &lu->subscr) < 0) {
lu_failure(lu, GMM_CAUSE_IMSI_UNKNOWN, "Subscriber does not exist");
lu_failure(lu, g_hlr->reject_cause, "Subscriber does not exist");
return;
}
@@ -241,13 +241,11 @@ static void lu_fsm_wait_insert_data_result_onenter(struct osmo_fsm_inst *fi, uin
struct lu *lu = fi->priv;
struct hlr_subscriber *subscr = &lu->subscr;
struct osmo_gsup_message gsup;
uint8_t msisdn_enc[OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN];
uint8_t apn[APN_MAXLEN];
if (osmo_gsup_create_insert_subscriber_data_msg(&gsup, subscr->imsi,
subscr->msisdn, msisdn_enc, sizeof(msisdn_enc),
apn, sizeof(apn),
lu->is_ps? OSMO_GSUP_CN_DOMAIN_PS : OSMO_GSUP_CN_DOMAIN_CS)) {
subscr->msisdn,
lu->is_ps ? OSMO_GSUP_CN_DOMAIN_PS : OSMO_GSUP_CN_DOMAIN_CS,
OTC_SELECT)) {
lu_failure(lu, GMM_CAUSE_NET_FAIL, "cannot encode Insert Subscriber Data message");
return;
}
@@ -277,6 +275,7 @@ void lu_fsm_wait_insert_data_result(struct osmo_fsm_inst *fi, uint32_t event, vo
case OSMO_GSUP_MSGT_INSERT_DATA_ERROR:
lu_failure(lu, GMM_CAUSE_NET_FAIL, "Rx %s", osmo_gsup_message_type_name(req->gsup.message_type));
osmo_gsup_req_free(req);
break;
default:
@@ -314,7 +313,7 @@ static struct osmo_fsm lu_fsm = {
.cleanup = lu_fsm_cleanup,
};
static __attribute__((constructor)) void lu_fsm_init()
static __attribute__((constructor)) void lu_fsm_init(void)
{
OSMO_ASSERT(osmo_fsm_register(&lu_fsm) == 0);
}

View File

@@ -1,7 +1,7 @@
# 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
LIBVERSION=1:1:0
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include
AM_CFLAGS = -fPIC -Wall $(PCSC_CFLAGS) $(TALLOC_CFLAGS) $(LIBOSMOCORE_CFLAGS)

View File

@@ -40,7 +40,7 @@ int osmo_mdns_msg_request_encode(void *ctx, struct msgb *msg, const struct osmo_
qst.domain = req->domain;
qst.qtype = req->type;
qst.qclass = OSMO_MDNS_RFC_CLASS_IN;
if (osmo_mdns_rfc_question_encode(ctx, msg, &qst) != 0)
if (osmo_mdns_rfc_question_encode(msg, &qst) != 0)
return -EINVAL;
return 0;
@@ -106,7 +106,7 @@ int osmo_mdns_msg_answer_encode(void *ctx, struct msgb *msg, const struct osmo_m
rec.rdlength = ans_record->length;
rec.rdata = ans_record->data;
if (osmo_mdns_rfc_record_encode(ctx, msg, &rec) != 0)
if (osmo_mdns_rfc_record_encode(msg, &rec) != 0)
return -EINVAL;
}

View File

@@ -27,91 +27,9 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/bitvec.h>
#include <osmocom/core/logging.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/mslookup/mdns_rfc.h>
/*
* Encode/decode IEs
*/
/*! Encode a domain string as qname (RFC 1035 4.1.2).
* \param[in] domain multiple labels separated by dots, e.g. "sip.voice.1234.msisdn".
* \returns allocated buffer with length-value pairs for each label (e.g. 0x03 "sip" 0x05 "voice" ...), NULL on error.
*/
char *osmo_mdns_rfc_qname_encode(void *ctx, const char *domain)
{
char *domain_dup;
char *domain_iter;
char buf[OSMO_MDNS_RFC_MAX_NAME_LEN + 2] = ""; /* len(qname) is len(domain) +1 */
struct osmo_strbuf sb = { .buf = buf, .len = sizeof(buf) };
char *label;
if (strlen(domain) > OSMO_MDNS_RFC_MAX_NAME_LEN)
return NULL;
domain_iter = domain_dup = talloc_strdup(ctx, domain);
while ((label = strsep(&domain_iter, "."))) {
size_t len = strlen(label);
/* Empty domain, dot at start, two dots in a row, or ending with a dot */
if (!len)
goto error;
OSMO_STRBUF_PRINTF(sb, "%c%s", (char)len, label);
}
talloc_free(domain_dup);
return talloc_strdup(ctx, buf);
error:
talloc_free(domain_dup);
return NULL;
}
/*! Decode a domain string from a qname (RFC 1035 4.1.2).
* \param[in] qname buffer with length-value pairs for each label (e.g. 0x03 "sip" 0x05 "voice" ...)
* \param[in] qname_max_len amount of bytes that can be read at most from the memory location that qname points to.
* \returns allocated buffer with domain string, multiple labels separated by dots (e.g. "sip.voice.1234.msisdn"),
* NULL on error.
*/
char *osmo_mdns_rfc_qname_decode(void *ctx, const char *qname, size_t qname_max_len)
{
const char *next_label, *qname_end = qname + qname_max_len;
char buf[OSMO_MDNS_RFC_MAX_NAME_LEN + 1];
int i = 0;
if (qname_max_len < 1)
return NULL;
while (*qname) {
size_t len;
if (i >= qname_max_len)
return NULL;
len = *qname;
next_label = qname + len + 1;
if (next_label >= qname_end || i + len > OSMO_MDNS_RFC_MAX_NAME_LEN)
return NULL;
if (i) {
/* Two dots in a row is not allowed */
if (buf[i - 1] == '.')
return NULL;
buf[i] = '.';
i++;
}
memcpy(buf + i, qname + 1, len);
i += len;
qname = next_label;
}
buf[i] = '\0';
return talloc_strdup(ctx, buf);
}
/*
* Encode/decode message sections
*/
@@ -151,20 +69,17 @@ int osmo_mdns_rfc_header_decode(const uint8_t *data, size_t data_len, struct osm
/*! Encode question section (RFC 1035 4.1.2).
* \param[in] msgb mesage buffer to which the encoded data will be appended.
*/
int osmo_mdns_rfc_question_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_question *qst)
int osmo_mdns_rfc_question_encode(struct msgb *msg, const struct osmo_mdns_rfc_question *qst)
{
char *qname;
size_t qname_len;
uint8_t *qname_buf;
uint8_t *buf;
size_t buf_len;
/* qname */
qname = osmo_mdns_rfc_qname_encode(ctx, qst->domain);
if (!qname)
buf_len = strlen(qst->domain) + 1;
buf = msgb_put(msg, buf_len);
if (osmo_apn_from_str(buf, buf_len, qst->domain) < 0)
return -EINVAL;
qname_len = strlen(qname) + 1;
qname_buf = msgb_put(msg, qname_len);
memcpy(qname_buf, qname, qname_len);
talloc_free(qname);
msgb_put_u8(msg, 0x00);
/* qtype and qclass */
msgb_put_u16(msg, qst->qtype);
@@ -182,21 +97,25 @@ struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const ui
if (data_len < 6)
return NULL;
/* qname */
ret = talloc_zero(ctx, struct osmo_mdns_rfc_question);
if (!ret)
return NULL;
ret->domain = osmo_mdns_rfc_qname_decode(ret, (const char *)data, qname_len);
if (!ret->domain) {
talloc_free(ret);
return NULL;
}
/* qname */
ret->domain = talloc_size(ret, qname_len - 1);
if (!ret->domain)
goto error;
if (!osmo_apn_to_str(ret->domain, data, qname_len - 1))
goto error;
/* qtype and qclass */
ret->qtype = osmo_load16be(data + qname_len);
ret->qclass = osmo_load16be(data + qname_len + 2);
return ret;
error:
talloc_free(ret);
return NULL;
}
/*
@@ -206,20 +125,17 @@ struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const ui
/*! Encode one resource record (RFC 1035 4.1.3).
* \param[in] msgb mesage buffer to which the encoded data will be appended.
*/
int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_record *rec)
int osmo_mdns_rfc_record_encode(struct msgb *msg, const struct osmo_mdns_rfc_record *rec)
{
char *name;
size_t name_len;
uint8_t *buf;
size_t buf_len;
/* name */
name = osmo_mdns_rfc_qname_encode(ctx, rec->domain);
if (!name)
buf_len = strlen(rec->domain) + 1;
buf = msgb_put(msg, buf_len);
if (osmo_apn_from_str(buf, buf_len, rec->domain) < 0)
return -EINVAL;
name_len = strlen(name) + 1;
buf = msgb_put(msg, name_len);
memcpy(buf, name, name_len);
talloc_free(name);
msgb_put_u8(msg, 0x00);
/* type, class, ttl, rdlength */
msgb_put_u16(msg, rec->type);
@@ -237,15 +153,26 @@ int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_m
struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_t *data, size_t data_len,
size_t *record_len)
{
struct osmo_mdns_rfc_record *ret = talloc_zero(ctx, struct osmo_mdns_rfc_record);
struct osmo_mdns_rfc_record *ret;
size_t name_len;
/* name */
ret->domain = osmo_mdns_rfc_qname_decode(ret, (const char *)data, data_len - 10);
/* name length: represented as a series of labels, and terminated by a
* label with zero length (RFC 1035 3.3). A label with zero length is a
* NUL byte. */
name_len = strnlen((const char *)data, data_len - 10) + 1;
if (data[name_len])
return NULL;
/* allocate ret + ret->domain */
ret = talloc_zero(ctx, struct osmo_mdns_rfc_record);
if (!ret)
return NULL;
ret->domain = talloc_size(ctx, name_len - 1);
if (!ret->domain)
goto error;
name_len = strlen(ret->domain) + 2;
if (name_len + 10 > data_len)
/* name */
if (!osmo_apn_to_str(ret->domain, data, name_len - 1))
goto error;
/* type, class, ttl, rdlength */
@@ -259,7 +186,7 @@ struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_
/* rdata */
ret->rdata = talloc_memdup(ret, data + name_len + 10, ret->rdlength);
if (!ret->rdata)
return NULL;
goto error;
*record_len = name_len + 10 + ret->rdlength;
return ret;

View File

@@ -53,7 +53,7 @@ static void print_version(void)
"\n");
}
static void print_help()
static void print_help(void)
{
print_version();
printf(
@@ -419,9 +419,9 @@ static void socket_client_close(struct socket_client *c)
{
struct osmo_fd *ofd = &c->ofd;
osmo_fd_unregister(ofd);
close(ofd->fd);
ofd->fd = -1;
osmo_fd_unregister(ofd);
llist_del(&c->entry);
talloc_free(c);
@@ -429,7 +429,11 @@ static void socket_client_close(struct socket_client *c)
void socket_client_respond_result(struct socket_client *c, const char *response)
{
write(c->ofd.fd, response, strlen(response));
size_t len = strlen(response);
int rc = write(c->ofd.fd, response, len);
if (rc != len)
print_error("%s: write() returned %d instead of %zu\n", __func__, rc, len);
}
static int socket_read_cb(struct osmo_fd *ofd)
@@ -487,7 +491,7 @@ static int socket_cb(struct osmo_fd *ofd, unsigned int flags)
{
int rc = 0;
if (flags & BSC_FD_READ)
if (flags & OSMO_FD_READ)
rc = socket_read_cb(ofd);
if (rc < 0)
return rc;
@@ -512,7 +516,7 @@ int socket_accept(struct osmo_fd *ofd, unsigned int flags)
c = talloc_zero(globals.ctx, struct socket_client);
OSMO_ASSERT(c);
c->ofd.fd = rc;
c->ofd.when = BSC_FD_READ;
c->ofd.when = OSMO_FD_READ;
c->ofd.cb = socket_cb;
c->ofd.data = c;
@@ -526,8 +530,13 @@ int socket_accept(struct osmo_fd *ofd, unsigned int flags)
llist_add(&c->entry, &globals.socket_clients);
if (globals.format == FORMAT_CSV && cmdline_opts.csv_headers)
write(c->ofd.fd, CSV_HEADERS, strlen(CSV_HEADERS));
if (globals.format == FORMAT_CSV && cmdline_opts.csv_headers) {
size_t len = strlen(CSV_HEADERS);
int rc = write(c->ofd.fd, CSV_HEADERS, strlen(CSV_HEADERS));
if (rc != len)
print_error("%s: write() returned %d instead of %zu\n", __func__, rc, len);
}
return 0;
}
@@ -543,7 +552,7 @@ int socket_init(const char *sock_path)
return -1;
}
ofd->when = BSC_FD_READ;
ofd->when = OSMO_FD_READ;
ofd->cb = socket_accept;
rc = osmo_fd_register(ofd);
@@ -555,15 +564,15 @@ int socket_init(const char *sock_path)
return 0;
}
void socket_close()
void socket_close(void)
{
struct socket_client *c, *n;
llist_for_each_entry_safe(c, n, &globals.socket_clients, entry)
socket_client_close(c);
if (osmo_fd_is_registered(&globals.socket_ofd)) {
osmo_fd_unregister(&globals.socket_ofd);
close(globals.socket_ofd.fd);
globals.socket_ofd.fd = -1;
osmo_fd_unregister(&globals.socket_ofd);
}
}
@@ -584,11 +593,11 @@ void respond_result(const char *query_str, const struct osmo_mslookup_result *r)
llist_for_each_entry_safe(c, n, &globals.socket_clients, entry) {
if (!strcmp(query_str, c->query_str)) {
socket_client_respond_result(c, g_buf);
if (r->last)
if (!r || r->last)
socket_client_close(c);
}
}
if (r->last)
if (!r || r->last)
globals.requests_handled++;
}

View File

@@ -49,7 +49,7 @@ static void set_result(struct osmo_mslookup_result *result,
result->age = age;
}
const struct mslookup_service_host *mslookup_server_get_local_gsup_addr()
const struct mslookup_service_host *mslookup_server_get_local_gsup_addr(void)
{
static struct mslookup_service_host gsup_bind = {};
struct mslookup_service_host *host;

View File

@@ -71,7 +71,7 @@ static int osmo_mslookup_server_mdns_rx(struct osmo_fd *osmo_fd, unsigned int wh
/* Parse the message and print it */
n = read(osmo_fd->fd, buffer, sizeof(buffer));
if (n < 0)
if (n <= 0)
return n;
ctx = talloc_named_const(server, 0, __func__);
@@ -121,7 +121,7 @@ void osmo_mslookup_server_mdns_stop(struct osmo_mslookup_server_mdns *server)
talloc_free(server);
}
void mslookup_server_mdns_config_apply()
void mslookup_server_mdns_config_apply(void)
{
/* Check whether to start/stop/restart mDNS server */
bool should_run;

View File

@@ -29,6 +29,7 @@
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/gsupclient/gsup_req.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/proxy.h>
#include <osmocom/hlr/remote_hlr.h>
@@ -80,7 +81,19 @@ static void proxy_deferred_gsup_req_add(struct proxy *proxy, struct osmo_gsup_re
static void proxy_pending_req_remote_hlr_connect_result(struct osmo_gsup_req *req, struct remote_hlr *remote_hlr)
{
if (!remote_hlr || !remote_hlr_is_up(remote_hlr)) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN, "Proxy: Failed to connect to home HLR");
/* Do not respond with an error to a CHECK_IMEI_REQUEST as osmo-msc will send a LU Reject Cause #6
* Just respond ACK and deal with the IMSI check that comes next. */
if (req->gsup.message_type == OSMO_GSUP_MSGT_CHECK_IMEI_REQUEST) {
/* Accept all IMEIs */
struct osmo_gsup_message gsup_reply = (struct osmo_gsup_message){
.message_type = OSMO_GSUP_MSGT_CHECK_IMEI_RESULT,
.imei_result = OSMO_GSUP_IMEI_RESULT_ACK,
};
osmo_gsup_req_respond(req, &gsup_reply, false, true);
return;
}
osmo_gsup_req_respond_err(req, g_hlr->no_proxy_reject_cause,
"Proxy: Failed to connect to home HLR");
return;
}
@@ -190,6 +203,7 @@ int proxy_subscr_create_or_update(struct proxy *proxy, const struct proxy_subscr
int _proxy_subscr_del(struct proxy_subscr_listentry *e)
{
llist_del(&e->entry);
talloc_free(e);
return 0;
}

View File

@@ -20,7 +20,7 @@
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/gsm/gsup.h>
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/gsm/ipa.h>
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/hlr.h>
@@ -66,7 +66,7 @@ static void remote_hlr_err_reply(struct remote_hlr *rh, const struct osmo_gsup_m
* The local MSC shall be indicated by gsup.destination_name. */
static int remote_hlr_rx(struct osmo_gsup_client *gsupc, struct msgb *msg)
{
struct remote_hlr *rh = gsupc->data;
struct remote_hlr *rh = osmo_gsup_client_get_data(gsupc);
struct proxy_subscr proxy_subscr;
struct osmo_gsup_message gsup;
int rc;
@@ -108,7 +108,7 @@ struct remote_hlr_pending_up {
static bool remote_hlr_up_down(struct osmo_gsup_client *gsupc, bool up)
{
struct remote_hlr *remote_hlr = gsupc->data;
struct remote_hlr *remote_hlr = osmo_gsup_client_get_data(gsupc);
struct remote_hlr_pending_up *p, *n;
if (!up) {
LOG_REMOTE_HLR(remote_hlr, LOGL_NOTICE, "link to remote HLR is down, removing GSUP client\n");
@@ -127,7 +127,7 @@ static bool remote_hlr_up_down(struct osmo_gsup_client *gsupc, bool up)
bool remote_hlr_is_up(struct remote_hlr *remote_hlr)
{
return remote_hlr && remote_hlr->gsupc && remote_hlr->gsupc->is_connected;
return remote_hlr && remote_hlr->gsupc && osmo_gsup_client_is_connected(remote_hlr->gsupc);
}
struct remote_hlr *remote_hlr_get_or_connect(const struct osmo_sockaddr_str *addr, bool connect,
@@ -180,7 +180,7 @@ struct remote_hlr *remote_hlr_get_or_connect(const struct osmo_sockaddr_str *add
return NULL;
}
rh->gsupc->data = rh;
osmo_gsup_client_set_data(rh->gsupc, rh);
llist_add(&rh->entry, &remote_hlrs);
add_result_cb:

View File

@@ -1,6 +1,5 @@
SUBDIRS = \
auc \
gsup_server \
db \
gsup \
db_upgrade \
@@ -70,6 +69,9 @@ vty-test:
CTRL_TEST_DB = hlr_ctrl_test.db
# Run a specific test with: 'make ctrl-test CTRL_TEST=test_subscriber.ctrl'
CTRL_TEST ?= *.ctrl
# To update the CTRL script from current application behavior,
# pass -u to ctrl_script_runner.py by doing:
# make ctrl-test U=-u
@@ -80,7 +82,7 @@ ctrl-test:
osmo_verify_transcript_ctrl.py -v \
-p 4259 \
-r "$(top_builddir)/src/osmo-hlr -c $(top_srcdir)/doc/examples/osmo-hlr.cfg -l $(CTRL_TEST_DB)" \
$(U) $(srcdir)/*.ctrl
$(U) $(srcdir)/$(CTRL_TEST)
-rm -f $(CTRL_TEST_DB)
-rm $(CTRL_TEST_DB)-*

View File

@@ -2,12 +2,12 @@ SUBDIRS = gen_ts_55_205_test_sets
AM_CPPFLAGS = \
$(all_includes) \
-I$(top_srcdir)/include \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(NULL)
@@ -23,17 +23,15 @@ EXTRA_DIST = \
auc_ts_55_205_test_sets.err \
$(NULL)
check_PROGRAMS = auc_ts_55_205_test_sets
noinst_PROGRAMS = auc_test
check_PROGRAMS = auc_test auc_ts_55_205_test_sets
auc_test_SOURCES = \
auc_test.c \
$(NULL)
auc_test_LDADD = \
$(top_srcdir)/src/auc.c \
$(top_srcdir)/src/logging.c \
$(top_builddir)/src/auc.o \
$(top_builddir)/src/logging.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(NULL)
@@ -43,8 +41,8 @@ auc_ts_55_205_test_sets_SOURCES = \
$(NULL)
auc_ts_55_205_test_sets_LDADD = \
$(top_srcdir)/src/auc.c \
$(top_srcdir)/src/logging.c \
$(top_builddir)/src/auc.o \
$(top_builddir)/src/logging.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(NULL)

View File

@@ -113,16 +113,17 @@ int rand_get(uint8_t *rand, unsigned int len)
return len;
}
/* Subscriber with 2G-only (COMP128v1) authentication data */
static void test_gen_vectors_2g_only(void)
{
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct osmo_auth_vector vec;
int rc;
comment_start();
aud2g = (struct osmo_sub_auth_data){
aud2g = (struct osmo_sub_auth_data2){
.type = OSMO_AUTH_TYPE_GSM,
.algo = OSMO_AUTH_ALG_COMP128v1,
};
@@ -130,7 +131,7 @@ static void test_gen_vectors_2g_only(void)
osmo_hexparse("EB215756028D60E3275E613320AEC880",
aud2g.u.gsm.ki, sizeof(aud2g.u.gsm.ki));
aud3g = (struct osmo_sub_auth_data){ 0 };
aud3g = (struct osmo_sub_auth_data2){ 0 };
next_rand("39fa2f4e3d523d8619a73b4f65c3e14d", true);
@@ -174,16 +175,18 @@ static void test_gen_vectors_2g_only(void)
comment_end();
}
/* Subscriber with separate 2G (COMP128v1) and 3G (MILENAGE) authentication data,
* reflects the default configuration of sysmoUSIM-SJS1 */
static void test_gen_vectors_2g_plus_3g(void)
{
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct osmo_auth_vector vec;
int rc;
comment_start();
aud2g = (struct osmo_sub_auth_data){
aud2g = (struct osmo_sub_auth_data2){
.type = OSMO_AUTH_TYPE_GSM,
.algo = OSMO_AUTH_ALG_COMP128v1,
};
@@ -191,9 +194,11 @@ static void test_gen_vectors_2g_plus_3g(void)
osmo_hexparse("EB215756028D60E3275E613320AEC880",
aud2g.u.gsm.ki, sizeof(aud2g.u.gsm.ki));
aud3g = (struct osmo_sub_auth_data){
aud3g = (struct osmo_sub_auth_data2){
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_MILENAGE,
.u.umts.k_len = 16,
.u.umts.opc_len = 16,
.u.umts.sqn = 31,
};
@@ -284,10 +289,13 @@ void _test_gen_vectors_3g_only__expect_vecs(struct osmo_auth_vector vecs[3])
);
}
/* Subscriber with only 3G (MILENAGE) authentication data,
* reflects the default configuration of sysmoISIM-SJA2. Resulting
* tuples are suitable for both 2G and 3G authentication */
static void test_gen_vectors_3g_only(void)
{
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct osmo_auth_vector vec;
struct osmo_auth_vector vecs[3];
uint8_t auts[14];
@@ -296,11 +304,13 @@ static void test_gen_vectors_3g_only(void)
comment_start();
aud2g = (struct osmo_sub_auth_data){ 0 };
aud2g = (struct osmo_sub_auth_data2){ 0 };
aud3g = (struct osmo_sub_auth_data){
aud3g = (struct osmo_sub_auth_data2){
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_MILENAGE,
.u.umts.k_len = 16,
.u.umts.opc_len = 16,
.u.umts.sqn = 31,
};
@@ -454,7 +464,58 @@ static void test_gen_vectors_3g_only(void)
comment_end();
}
void test_gen_vectors_bad_args()
/* Subscriber with only 3G (XOR) authentication data,
* reflects the default configuration of sysmoTSIM-SJAx as well
* as many "Test USIM" cards. Resulting tuples are suitable for both
* 2G and 3G authentication */
static void test_gen_vectors_3g_xor(void)
{
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct osmo_auth_vector vec;
int rc;
comment_start();
aud2g = (struct osmo_sub_auth_data2){ 0 };
aud3g = (struct osmo_sub_auth_data2){
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_XOR_3G,
.u.umts.k_len = 16,
.u.umts.opc_len = 16,
.u.umts.sqn = 0,
};
osmo_hexparse("000102030405060708090a0b0c0d0e0f",
aud3g.u.umts.k, sizeof(aud3g.u.umts.k));
osmo_hexparse("00000000000000000000000000000000",
aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc));
next_rand("b5039c57e4a75051551d1a390a71ce48", true);
vec = (struct osmo_auth_vector){ {0} };
VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%"PRIu64);
rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
VERBOSE_ASSERT(rc, == 1, "%d");
VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%"PRIu64);
VEC_IS(&vec,
" rand: b5039c57e4a75051551d1a390a71ce48\n"
" autn: 54e0a256565d0000b5029e54e0a25656\n"
" ck: 029e54e0a256565d141032067cc047b5\n"
" ik: 9e54e0a256565d141032067cc047b502\n"
" res: b5029e54e0a256565d141032067cc047\n"
" res_len: 10\n"
" kc: 98e880384887f9fe\n"
" sres: 0ec81877\n"
" auth_types: 03000000\n"
);
comment_end();
}
/* Test a variety of invalid authentication data combinations */
void test_gen_vectors_bad_args(void)
{
struct osmo_auth_vector vec;
uint8_t auts[14];
@@ -462,39 +523,43 @@ void test_gen_vectors_bad_args()
int rc;
int i;
struct osmo_sub_auth_data aud2g = {
struct osmo_sub_auth_data2 aud2g = {
.type = OSMO_AUTH_TYPE_GSM,
.algo = OSMO_AUTH_ALG_COMP128v1,
};
struct osmo_sub_auth_data aud3g = {
struct osmo_sub_auth_data2 aud3g = {
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_MILENAGE,
.u.umts.k_len = 16,
.u.umts.opc_len = 16,
};
struct osmo_sub_auth_data aud2g_noalg = {
struct osmo_sub_auth_data2 aud2g_noalg = {
.type = OSMO_AUTH_TYPE_GSM,
.algo = OSMO_AUTH_ALG_NONE,
};
struct osmo_sub_auth_data aud3g_noalg = {
struct osmo_sub_auth_data2 aud3g_noalg = {
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_NONE,
.u.umts.k_len = 16,
.u.umts.opc_len = 16,
};
struct osmo_sub_auth_data aud_notype = {
struct osmo_sub_auth_data2 aud_notype = {
.type = OSMO_AUTH_TYPE_NONE,
.algo = OSMO_AUTH_ALG_MILENAGE,
};
struct osmo_sub_auth_data no_aud = {
struct osmo_sub_auth_data2 no_aud = {
.type = OSMO_AUTH_TYPE_NONE,
.algo = OSMO_AUTH_ALG_NONE,
};
struct {
struct osmo_sub_auth_data *aud2g;
struct osmo_sub_auth_data *aud3g;
struct osmo_sub_auth_data2 *aud2g;
struct osmo_sub_auth_data2 *aud3g;
uint8_t *rand_auts;
uint8_t *auts;
const char *label;
@@ -613,15 +678,20 @@ int main(int argc, char **argv)
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_filename2(osmo_stderr_target,
cmdline_opts.verbose ?
LOG_FILENAME_BASENAME :
LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");
test_gen_vectors_2g_only();
test_gen_vectors_2g_plus_3g();
test_gen_vectors_3g_only();
test_gen_vectors_3g_xor();
test_gen_vectors_bad_args();
printf("Done\n");

View File

@@ -217,6 +217,29 @@ DAUC vector [2]: auth_types = 0x3
===== test_gen_vectors_3g_only: SUCCESS
===== test_gen_vectors_3g_xor
aud3g.u.umts.sqn == 0
DAUC Computing 1 auth vector: 3G only (2G derived from 3G keys)
DAUC 3G: k = 000102030405060708090a0b0c0d0e0f
DAUC 3G: opc = 00000000000000000000000000000000
DAUC 3G: for sqn ind 0, previous sqn was 0
DAUC vector [0]: rand = b5039c57e4a75051551d1a390a71ce48
DAUC vector [0]: sqn = 0
DAUC vector [0]: autn = 54e0a256565d0000b5029e54e0a25656
DAUC vector [0]: ck = 029e54e0a256565d141032067cc047b5
DAUC vector [0]: ik = 9e54e0a256565d141032067cc047b502
DAUC vector [0]: res = b5029e54e0a256565d141032067cc047
DAUC vector [0]: res_len = 16
DAUC vector [0]: deriving 2G from 3G
DAUC vector [0]: kc = 98e880384887f9fe
DAUC vector [0]: sres = 0ec81877
DAUC vector [0]: auth_types = 0x3
rc == 1
aud3g.u.umts.sqn == 0
vector matches expectations
===== test_gen_vectors_3g_xor: SUCCESS
===== test_gen_vectors_bad_args
- no auth data (a)

View File

@@ -24,43 +24,46 @@
static void {func_name}(void)
{{
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_auth_vector vec;
int rc;
struct osmo_sub_auth_data2 aud2g;
struct osmo_sub_auth_data2 aud3g;
struct osmo_auth_vector vec;
int rc;
comment_start();
comment_start();
aud2g = (struct osmo_sub_auth_data){{ 0 }};
aud2g = (struct osmo_sub_auth_data2){{ 0 }};
aud3g = (struct osmo_sub_auth_data){{
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_MILENAGE,
aud3g = (struct osmo_sub_auth_data2){{
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_MILENAGE,
.u.umts.k_len = 16,
.u.umts.opc_len = 16,
.u.umts.sqn = 31,
}};
}};
osmo_hexparse("{Ki}",
aud3g.u.umts.k, sizeof(aud3g.u.umts.k));
osmo_hexparse("{OPc}",
aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc));
osmo_hexparse("{Ki}",
aud3g.u.umts.k, sizeof(aud3g.u.umts.k));
osmo_hexparse("{OPc}",
aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc));
osmo_hexparse("{RAND}",
fake_rand, sizeof(fake_rand));
osmo_hexparse("{RAND}",
fake_rand, sizeof(fake_rand));
vec = (struct osmo_auth_vector){{ {{0}} }};
vec = (struct osmo_auth_vector){{ {{0}} }};
vec.res_len = 8;
VERBOSE_ASSERT(aud3g.u.umts.sqn, == 31, "%"PRIu64);
rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
VERBOSE_ASSERT(rc, == 1, "%d");
rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
VERBOSE_ASSERT(rc, == 1, "%d");
VERBOSE_ASSERT(aud3g.u.umts.sqn, == 32, "%"PRIu64);
VEC_IS(&vec,
" rand: {RAND}\n"
" ck: {MIL3G-CK}\n"
" ik: {MIL3G-IK}\n"
" res: {MIL3G-RES}0000000000000000\n"
" kc: {Kc}\n"
" sres: {SRES#1}\n"
);
VEC_IS(&vec,
" rand: {RAND}\n"
" ck: {MIL3G-CK}\n"
" ik: {MIL3G-IK}\n"
" res: {MIL3G-RES}0000000000000000\n"
" kc: {Kc}\n"
" sres: {SRES#1}\n"
);
comment_end();
}}

View File

@@ -55,7 +55,7 @@ char *vec_str(const struct osmo_auth_vector *vec)
if (pos >= end) \
return buf; \
pos += snprintf(pos, sizeof(buf) - (pos - buf), \
" " #what ": %s\n", \
" " #what ": %s\n", \
osmo_hexdump_nospc((void*)&vec->what, sizeof(vec->what)))
append(rand);
@@ -71,7 +71,7 @@ char *vec_str(const struct osmo_auth_vector *vec)
#define VEC_IS(vec, expect) do { \
char *_is = vec_str(vec); \
if (strcmp(_is, expect)) { \
if (strcmp(_is, expect)) { \
fprintf(stderr, "MISMATCH! expected ==\n%s\n", \
expect); \
char *a = _is; \
@@ -100,15 +100,16 @@ int rand_get(uint8_t *rand, unsigned int len)
FUNCTIONS
int main()
int main(int argc, char **argv)
{
printf("3GPP TS 55.205 Test Sets\n");
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_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");

View File

@@ -1,7 +1,10 @@
AM_CFLAGS = \
AM_CPPFLAGS = \
$(all_includes) \
-I$(top_srcdir)/include \
-I$(top_builddir)/include \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
$(LIBOSMOCORE_CFLAGS) \

View File

@@ -122,16 +122,16 @@ static void _fill_invalid(void *dest, size_t size)
/* 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,
struct osmo_sub_auth_data2 *aud2g,
struct osmo_sub_auth_data2 *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;
static struct osmo_sub_auth_data g_aud2g;
static struct osmo_sub_auth_data g_aud3g;
static struct osmo_sub_auth_data2 g_aud2g;
static struct osmo_sub_auth_data2 g_aud3g;
static int g_rc;
static int64_t g_id;
@@ -180,18 +180,21 @@ void dump_subscr(struct hlr_subscriber *subscr)
#undef Pb
}
void dump_aud(const char *label, struct osmo_sub_auth_data *aud)
void dump_aud(const char *label, struct osmo_sub_auth_data2 *aud)
{
if (aud->type == OSMO_AUTH_TYPE_NONE) {
fprintf(stderr, "%s: none\n", label);
return;
}
fprintf(stderr, "%s: struct osmo_sub_auth_data {\n", label);
fprintf(stderr, "%s: struct osmo_sub_auth_data2 {\n", label);
#define Pf(name, fmt) \
Pfo(name, fmt, aud)
#define Phex(name) \
Pfv(name, "'%s'", osmo_hexdump_nospc(aud->name, sizeof(aud->name)))
#define Phexl(name, len) \
Pfv(name, "'%s'", osmo_hexdump_nospc(aud->name, aud->len))
Pfv(type, "%s", osmo_sub_auth_type_name(aud->type));
Pfv(algo, "%s", osmo_auth_alg_name(aud->algo));
@@ -200,9 +203,9 @@ void dump_aud(const char *label, struct osmo_sub_auth_data *aud)
Phex(u.gsm.ki);
break;
case OSMO_AUTH_TYPE_UMTS:
Phex(u.umts.opc);
Phexl(u.umts.opc, u.umts.opc_len);
Pf(u.umts.opc_is_op, "%u");
Phex(u.umts.k);
Phexl(u.umts.k, u.umts.k_len);
Phex(u.umts.amf);
if (aud->u.umts.sqn) {
Pf(u.umts.sqn, "%"PRIu64);
@@ -219,6 +222,7 @@ void dump_aud(const char *label, struct osmo_sub_auth_data *aud)
#undef Pf
#undef Phex
#undef Phexl
}
void db_raw_sql(struct db_context *dbc, const char *sql)
@@ -246,7 +250,7 @@ static int db_subscr_lu_str(struct db_context *dbc, int64_t subscr_id,
return db_subscr_lu(dbc, subscr_id, &vlr_nr, is_ps, NULL);
}
static void test_subscr_create_update_sel_delete()
static void test_subscr_create_update_sel_delete(void)
{
int64_t id0, id1, id2, id_short;
comment_start();
@@ -262,13 +266,13 @@ static void test_subscr_create_update_sel_delete()
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), 0);
ASSERT_SEL(imsi, imsi2, 0);
id2 = g_subscr.id;
ASSERT_RC(db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_SEL(imsi, imsi0, 0);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_SEL(imsi, imsi1, 0);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_SEL(imsi, imsi2, 0);
ASSERT_RC(db_subscr_create(dbc, "123456789 000003", DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EINVAL);
@@ -541,7 +545,7 @@ static const struct sub_auth_data_str *mk_aud_3g(enum osmo_auth_algo algo,
return &aud;
}
static void test_subscr_aud()
static void test_subscr_aud(void)
{
int64_t id;
@@ -586,7 +590,7 @@ static void test_subscr_aud()
ASSERT_SEL_AUD(imsi0, 0, id);
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
mk_aud_2g(OSMO_AUTH_ALG_XOR, "CededEffacedAceFacedBadFadedBeef")),
mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "CededEffacedAceFacedBadFadedBeef")),
0);
ASSERT_SEL_AUD(imsi0, 0, id);
@@ -604,7 +608,7 @@ static void test_subscr_aud()
-ENOENT);
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
mk_aud_2g(OSMO_AUTH_ALG_XOR, "CededEffacedAceFacedBadFadedBeef")),
mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "CededEffacedAceFacedBadFadedBeef")),
0);
ASSERT_SEL_AUD(imsi0, 0, id);
@@ -707,12 +711,12 @@ static void test_subscr_aud()
ASSERT_SEL_AUD(imsi0, 0, id);
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
mk_aud_2g(OSMO_AUTH_ALG_XOR, "f000000000000f00000000000f000000f00000000")),
mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "f000000000000f00000000000f000000f00000000")),
-EINVAL);
ASSERT_SEL_AUD(imsi0, 0, id);
ASSERT_RC(db_subscr_update_aud_by_id(dbc, id,
mk_aud_2g(OSMO_AUTH_ALG_XOR, "f00")),
mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "f00")),
-EINVAL);
ASSERT_SEL_AUD(imsi0, 0, id);
@@ -783,7 +787,7 @@ static void test_subscr_aud()
/* Make each key too short in this test. Note that we can't set them longer than the allowed size without changing the
* table structure. */
static void test_subscr_aud_invalid_len()
static void test_subscr_aud_invalid_len(void)
{
int64_t id;
@@ -845,7 +849,7 @@ static void test_subscr_aud_invalid_len()
comment_end();
}
static void test_subscr_sqn()
static void test_subscr_sqn(void)
{
int64_t id;
@@ -918,6 +922,50 @@ static void test_subscr_sqn()
comment_end();
}
static void test_ind(void)
{
comment_start();
#define ASSERT_IND(VLR, IND) do { \
unsigned int ind; \
struct osmo_cni_peer_id vlr; \
OSMO_ASSERT(!osmo_cni_peer_id_set_str(&vlr, OSMO_CNI_PEER_ID_IPA_NAME, VLR)); \
ASSERT_RC(db_ind(dbc, &vlr, &ind), 0); \
fprintf(stderr, "%s ind = %u\n\n", osmo_quote_str((char*)vlr.ipa_name.val, vlr.ipa_name.len), ind); \
if (ind != (IND)) \
fprintf(stderr, " ERROR: expected " #IND "\n"); \
} while (0)
#define IND_DEL(VLR) do { \
struct osmo_cni_peer_id vlr; \
OSMO_ASSERT(!osmo_cni_peer_id_set_str(&vlr, OSMO_CNI_PEER_ID_IPA_NAME, VLR)); \
ASSERT_RC(db_ind_del(dbc, &vlr), 0); \
fprintf(stderr, "%s ind deleted\n\n", osmo_quote_str((char*)vlr.ipa_name.val, vlr.ipa_name.len)); \
} while (0)
ASSERT_IND("msc-23", 1);
ASSERT_IND("sgsn-11", 2);
ASSERT_IND("msc-42", 3);
ASSERT_IND("sgsn-22", 4);
ASSERT_IND("msc-0x17", 5);
ASSERT_IND("sgsn-0xaa", 6);
ASSERT_IND("msc-42", 3);
ASSERT_IND("sgsn-22", 4);
ASSERT_IND("msc-0x17", 5);
ASSERT_IND("sgsn-0xaa", 6);
ASSERT_IND("sgsn-0xbb", 7);
ASSERT_IND("msc-0x2a", 8);
ASSERT_IND("msc-42", 3);
ASSERT_IND("sgsn-22", 4);
ASSERT_IND("msc-23", 1);
ASSERT_IND("sgsn-11", 2);
IND_DEL("msc-0x17"); /* dropped IND == 5 */
ASSERT_IND("msc-0x2a", 8); /* known CS remains where it is */
ASSERT_IND("any-unknown", 9); /* new VLR takes a new IND from the end */
comment_end();
}
static struct {
bool verbose;
} cmdline_opts = {
@@ -980,9 +1028,13 @@ int main(int argc, char **argv)
handle_options(argc, argv);
osmo_init_logging2(ctx, &hlr_log_info);
log_set_print_filename(osmo_stderr_target, cmdline_opts.verbose);
log_set_print_filename2(osmo_stderr_target,
cmdline_opts.verbose ?
LOG_FILENAME_BASENAME :
LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");
@@ -998,6 +1050,7 @@ int main(int argc, char **argv)
test_subscr_aud();
test_subscr_aud_invalid_len();
test_subscr_sqn();
test_ind();
printf("Done\n");
db_close(dbc);

View File

@@ -27,7 +27,7 @@ struct hlr_subscriber {
.imsi = '123456789000002',
}
db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000000': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
@@ -36,10 +36,10 @@ struct hlr_subscriber {
.imsi = '123456789000000',
}
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
@@ -48,10 +48,10 @@ struct hlr_subscriber {
.imsi = '123456789000001',
}
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0
@@ -824,7 +824,7 @@ db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_COMP128v1, "01234567
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 3G Auth Data
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v1,
.u.gsm.ki = '0123456789abcdef0123456789abcdef',
@@ -841,7 +841,7 @@ db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_COMP128v1, "01234567
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 3G Auth Data
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v1,
.u.gsm.ki = '0123456789abcdef0123456789abcdef',
@@ -853,7 +853,7 @@ db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_COMP128v2, "BeadedBe
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 3G Auth Data
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v2,
.u.gsm.ki = 'beadedbeeaced1ebbeddefacedfacade',
@@ -865,21 +865,21 @@ db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_COMP128v3, "DeafBedd
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 3G Auth Data
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'deafbeddedbabeacceededfadeddecaf',
}
3G: none
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR, "CededEffacedAceFacedBadFadedBeef")) --> 0
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "CededEffacedAceFacedBadFadedBeef")) --> 0
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 3G Auth Data
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = XOR,
.algo = XOR-2G,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: none
@@ -900,14 +900,14 @@ 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
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "CededEffacedAceFacedBadFadedBeef")) --> 0
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 3G Auth Data
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = XOR,
.algo = XOR-2G,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: none
@@ -932,7 +932,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -954,7 +954,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -970,7 +970,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'deaf0ff1ced0d0dabbedd1ced1cef00d',
@@ -985,7 +985,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1001,7 +1001,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'cededeffacedacefacedbadfadedbeef',
@@ -1033,7 +1033,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'cededeffacedacefacedbadfadedbeef',
@@ -1069,12 +1069,12 @@ db_subscr_update_aud_by_id(dbc, id, mk_aud_3g(OSMO_AUTH_ALG_MILENAGE, "BeefedCaf
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1097,12 +1097,12 @@ DAUC Cannot update auth tokens: Unknown auth algo: 99999
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1112,17 +1112,17 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
.u.umts.ind_bitlen = 5,
}
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR, "f000000000000f00000000000f000000f00000000")) --> -EINVAL
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "f000000000000f00000000000f000000f00000000")) --> -EINVAL
DAUC Cannot update auth tokens: Invalid KI: 'f000000000000f00000000000f000000f00000000'
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1132,17 +1132,17 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
.u.umts.ind_bitlen = 5,
}
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR, "f00")) --> -EINVAL
db_subscr_update_aud_by_id(dbc, id, mk_aud_2g(OSMO_AUTH_ALG_XOR_2G, "f00")) --> -EINVAL
DAUC Cannot update auth tokens: Invalid KI: 'f00'
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1157,12 +1157,12 @@ DAUC Cannot update auth tokens: auth algo not suited for 2G: MILENAGE
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1177,12 +1177,12 @@ DAUC Cannot update auth tokens: Invalid OP/OPC: '0f000000000000f00000000000f0000
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1197,12 +1197,12 @@ DAUC Cannot update auth tokens: Invalid K: '000000000000f00000000000f000000'
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1217,12 +1217,12 @@ DAUC Cannot update auth tokens: Invalid ind_bitlen: 29
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1237,12 +1237,12 @@ DAUC Cannot update auth tokens: Invalid OP/OPC: 'X000000000000f00000000000f00000
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1257,12 +1257,12 @@ DAUC Cannot update auth tokens: Invalid K: 'f000000000000 f00000000000 f000000'
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
2G: struct osmo_sub_auth_data {
2G: struct osmo_sub_auth_data2 {
.type = GSM,
.algo = COMP128v3,
.u.gsm.ki = 'cededeffacedacefacedbadfadedbeef',
}
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1338,7 +1338,7 @@ sqlite3_prepare_v2(dbc->db, sql, -1, &stmt, NULL) --> SQLITE_OK
sqlite3_step(stmt) --> SQLITE_DONE
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -ENOKEY
DAUC IMSI='123456789000000': Error reading Ki, expected length 16 but has length 15
DAUC IMSI='123456789000000': Error reading Ki, expected min length 16 but has length 15
DAUC IMSI='123456789000000': No 3G Auth Data
@@ -1359,7 +1359,7 @@ sqlite3_step(stmt) --> SQLITE_DONE
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -5
DAUC IMSI='123456789000000': No 2G Auth Data
DAUC IMSI='123456789000000': Error reading K, expected length 16 but has length 15
DAUC IMSI='123456789000000': Error reading K, expected min length 16 but has length 15
@@ -1374,7 +1374,7 @@ sqlite3_step(stmt) --> SQLITE_DONE
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -5
DAUC IMSI='123456789000000': No 2G Auth Data
DAUC IMSI='123456789000000': Error reading OP, expected length 16 but has length 15
DAUC IMSI='123456789000000': Error reading OP, expected min length 16 but has length 15
@@ -1389,7 +1389,7 @@ sqlite3_step(stmt) --> SQLITE_DONE
db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> -5
DAUC IMSI='123456789000000': No 2G Auth Data
DAUC IMSI='123456789000000': Error reading OPC, expected length 16 but has length 15
DAUC IMSI='123456789000000': Error reading OPC, expected min length 16 but has length 15
@@ -1458,7 +1458,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1477,7 +1477,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1495,7 +1495,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1513,7 +1513,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1534,7 +1534,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1550,7 +1550,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1568,7 +1568,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1586,7 +1586,7 @@ db_get_auth_data(dbc, imsi0, &g_aud2g, &g_aud3g, &g_id) --> 0
DAUC IMSI='123456789000000': No 2G Auth Data
2G: none
3G: struct osmo_sub_auth_data {
3G: struct osmo_sub_auth_data2 {
.type = UMTS,
.algo = MILENAGE,
.u.umts.opc = 'beefedcafefaceacedaddeddecadefee',
@@ -1613,3 +1613,83 @@ db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> -ENOENT
===== test_subscr_sqn: SUCCESS
===== test_ind
db_ind(dbc, &vlr, &ind) --> 0
"msc-23\0" ind = 1
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-11\0" ind = 2
db_ind(dbc, &vlr, &ind) --> 0
"msc-42\0" ind = 3
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-22\0" ind = 4
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x17\0" ind = 5
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-0xaa\0" ind = 6
db_ind(dbc, &vlr, &ind) --> 0
"msc-42\0" ind = 3
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-22\0" ind = 4
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x17\0" ind = 5
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-0xaa\0" ind = 6
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-0xbb\0" ind = 7
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x2a\0" ind = 8
db_ind(dbc, &vlr, &ind) --> 0
"msc-42\0" ind = 3
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-22\0" ind = 4
db_ind(dbc, &vlr, &ind) --> 0
"msc-23\0" ind = 1
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-11\0" ind = 2
db_ind_del(dbc, &vlr) --> 0
"msc-0x17\0" ind deleted
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x2a\0" ind = 8
db_ind(dbc, &vlr, &ind) --> 0
"any-unknown\0" ind = 9
===== test_ind: SUCCESS

View File

@@ -43,5 +43,5 @@ OsmoHLR# subscriber imsi 5555555 create
MSISDN: none
OsmoHLR# subscriber imsi 5555555 update msisdn 55555555555555
% Updated subscriber IMSI='5555555' to MSISDN='55555555555555'
OsmoHLR# subscriber imsi 5555555 update aud2g xor ki 55555555555555555555555555555555
OsmoHLR# subscriber imsi 5555555 update aud2g xor-2g ki 55555555555555555555555555555555
OsmoHLR# subscriber imsi 5555555 update aud3g milenage k 55555555555555555555555555555555 opc 55555555555555555555555555555555

View File

@@ -12,7 +12,7 @@ Table auc_2g contents:
algo_id_2g|ki|subscriber_id
1|BeefedCafeFaceAcedAddedDecadeFee|1
2|33333333333333333333333333333333|4
4|55555555555555555555555555555555|6
6|55555555555555555555555555555555|6
Table: auc_3g
name|type|notnull|dflt_value|pk
@@ -85,6 +85,8 @@ DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 2
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 3
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 4
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 5
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 6
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 7
DMAIN Cmdline option --db-check: Database was opened successfully, quitting.
Resulting db:
@@ -99,15 +101,15 @@ Table auc_2g contents:
algo_id_2g|ki|subscriber_id
1|BeefedCafeFaceAcedAddedDecadeFee|1
2|33333333333333333333333333333333|4
4|55555555555555555555555555555555|6
6|55555555555555555555555555555555|6
Table: auc_3g
name|type|notnull|dflt_value|pk
algo_id_3g|INTEGER|1||0
ind_bitlen|INTEGER|1|5|0
k|VARCHAR(32)|1||0
op|VARCHAR(32)|0||0
opc|VARCHAR(32)|0||0
k|VARCHAR(64)|1||0
op|VARCHAR(64)|0||0
opc|VARCHAR(64)|0||0
sqn|INTEGER|1|0|0
subscriber_id|INTEGER|0||1
@@ -117,6 +119,13 @@ algo_id_3g|ind_bitlen|k|op|opc|sqn|subscriber_id
5|5|44444444444444444444444444444444|44444444444444444444444444444444||0|5
5|5|55555555555555555555555555555555||55555555555555555555555555555555|0|6
Table: ind
name|type|notnull|dflt_value|pk
ind|INTEGER|0||1
vlr|TEXT|1||0
Table ind contents:
Table: subscriber
name|type|notnull|dflt_value|pk
ggsn_number|VARCHAR(15)|0||0
@@ -171,5 +180,5 @@ osmo-hlr --database $db --db-check --config-file $srcdir/osmo-hlr.cfg
rc = 0
DMAIN hlr starting
DDB using database: <PATH>test.db
DDB Database <PATH>test.db' has HLR DB schema version 5
DDB Database <PATH>test.db' has HLR DB schema version 7
DMAIN Cmdline option --db-check: Database was opened successfully, quitting.

View File

@@ -61,7 +61,7 @@ CREATE TABLE auc_2g (
);
INSERT INTO auc_2g VALUES(1,1,'BeefedCafeFaceAcedAddedDecadeFee');
INSERT INTO auc_2g VALUES(4,2,'33333333333333333333333333333333');
INSERT INTO auc_2g VALUES(6,4,'55555555555555555555555555555555');
INSERT INTO auc_2g VALUES(6,6,'55555555555555555555555555555555');
CREATE TABLE auc_3g (
subscriber_id INTEGER PRIMARY KEY, -- subscriber.id
algo_id_3g INTEGER NOT NULL, -- enum osmo_auth_algo value

View File

@@ -1,9 +1,9 @@
AM_CPPFLAGS = \
$(all_includes) \
-I$(top_srcdir)/include \
$(NULL)
AM_CFLAGS = \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(NULL)
@@ -17,7 +17,7 @@ EXTRA_DIST = \
gsup_test.err \
$(NULL)
noinst_PROGRAMS = \
check_PROGRAMS = \
gsup_test \
$(NULL)

View File

@@ -101,7 +101,7 @@ int main(int argc, char **argv)
{
ctx = talloc_named_const(NULL, 0, "gsup_test");
osmo_init_logging2(ctx, &info);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);

View File

@@ -1,44 +0,0 @@
AM_CPPFLAGS = \
$(all_includes) \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOABIS_CFLAGS) \
$(NULL)
AM_LDFLAGS = \
-no-install \
$(NULL)
EXTRA_DIST = \
gsup_server_test.ok \
gsup_server_test.err \
$(NULL)
noinst_PROGRAMS = \
gsup_server_test \
$(NULL)
gsup_server_test_SOURCES = \
gsup_server_test.c \
$(NULL)
gsup_server_test_LDADD = \
$(top_srcdir)/src/gsup_server.c \
$(top_srcdir)/src/gsup_router.c \
$(top_srcdir)/src/gsup_send.c \
$(top_srcdir)/src/gsupclient/cni_peer_id.c \
$(top_srcdir)/src/gsupclient/gsup_req.c \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(NULL)
.PHONY: update_exp
update_exp:
$(builddir)/gsup_server_test >"$(srcdir)/gsup_server_test.ok" 2>"$(srcdir)/gsup_server_test.err"

View File

@@ -1,145 +0,0 @@
/* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU 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 <stdio.h>
#include <osmocom/core/utils.h>
#include <osmocom/hlr/gsup_server.h>
#define comment_start() printf("\n===== %s\n", __func__)
#define comment_end() printf("===== %s: SUCCESS\n\n", __func__)
#define btw(fmt, args...) printf("\n" fmt "\n", ## args)
#define VERBOSE_ASSERT(val, expect_op, fmt) \
do { \
printf(#val " == " fmt "\n", (val)); \
OSMO_ASSERT((val) expect_op); \
} while (0)
void osmo_gsup_server_add_conn(struct llist_head *clients,
struct osmo_gsup_conn *conn);
static void test_add_conn(void)
{
struct llist_head _list;
struct llist_head *clients = &_list;
struct osmo_gsup_conn conn_inst[23] = {};
struct osmo_gsup_conn *conn;
unsigned int i;
comment_start();
INIT_LLIST_HEAD(clients);
btw("Add 10 items");
for (i = 0; i < 10; i++) {
osmo_gsup_server_add_conn(clients, &conn_inst[i]);
printf("conn_inst[%u].auc_3g_ind == %u\n", i, conn_inst[i].auc_3g_ind);
OSMO_ASSERT(clients->next == &conn_inst[0].list);
}
btw("Expecting a list of 0..9");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
OSMO_ASSERT(conn == &conn_inst[i]);
i++;
}
btw("Punch two holes in the sequence in arbitrary order,"
" a larger one from 2..4 and a single one at 7.");
llist_del(&conn_inst[4].list);
llist_del(&conn_inst[2].list);
llist_del(&conn_inst[3].list);
llist_del(&conn_inst[7].list);
btw("Expecting a list of 0,1, 5,6, 8,9");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
i++;
}
btw("Add conns, expecting them to take the open slots");
osmo_gsup_server_add_conn(clients, &conn_inst[12]);
VERBOSE_ASSERT(conn_inst[12].auc_3g_ind, == 2, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[13]);
VERBOSE_ASSERT(conn_inst[13].auc_3g_ind, == 3, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[14]);
VERBOSE_ASSERT(conn_inst[14].auc_3g_ind, == 4, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[17]);
VERBOSE_ASSERT(conn_inst[17].auc_3g_ind, == 7, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[18]);
VERBOSE_ASSERT(conn_inst[18].auc_3g_ind, == 10, "%u");
btw("Expecting a list of 0..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
i++;
}
btw("Does it also work for the first item?");
llist_del(&conn_inst[0].list);
btw("Expecting a list of 1..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i + 1);
i++;
}
btw("Add another conn, should take auc_3g_ind == 0");
osmo_gsup_server_add_conn(clients, &conn_inst[20]);
VERBOSE_ASSERT(conn_inst[20].auc_3g_ind, == 0, "%u");
btw("Expecting a list of 0..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
i++;
}
btw("If a client reconnects, it will (likely) get the same auc_3g_ind");
VERBOSE_ASSERT(conn_inst[5].auc_3g_ind, == 5, "%u");
llist_del(&conn_inst[5].list);
conn_inst[5].auc_3g_ind = 423;
osmo_gsup_server_add_conn(clients, &conn_inst[5]);
VERBOSE_ASSERT(conn_inst[5].auc_3g_ind, == 5, "%u");
comment_end();
}
int main(int argc, char **argv)
{
printf("test_gsup_server.c\n");
test_add_conn();
printf("Done\n");
return 0;
}

View File

@@ -1,94 +0,0 @@
test_gsup_server.c
===== test_add_conn
Add 10 items
conn_inst[0].auc_3g_ind == 0
conn_inst[1].auc_3g_ind == 1
conn_inst[2].auc_3g_ind == 2
conn_inst[3].auc_3g_ind == 3
conn_inst[4].auc_3g_ind == 4
conn_inst[5].auc_3g_ind == 5
conn_inst[6].auc_3g_ind == 6
conn_inst[7].auc_3g_ind == 7
conn_inst[8].auc_3g_ind == 8
conn_inst[9].auc_3g_ind == 9
Expecting a list of 0..9
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
Punch two holes in the sequence in arbitrary order, a larger one from 2..4 and a single one at 7.
Expecting a list of 0,1, 5,6, 8,9
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 5
conn[3].auc_3g_ind == 6
conn[4].auc_3g_ind == 8
conn[5].auc_3g_ind == 9
Add conns, expecting them to take the open slots
conn_inst[12].auc_3g_ind == 2
conn_inst[13].auc_3g_ind == 3
conn_inst[14].auc_3g_ind == 4
conn_inst[17].auc_3g_ind == 7
conn_inst[18].auc_3g_ind == 10
Expecting a list of 0..10
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
conn[10].auc_3g_ind == 10
Does it also work for the first item?
Expecting a list of 1..10
conn[0].auc_3g_ind == 1
conn[1].auc_3g_ind == 2
conn[2].auc_3g_ind == 3
conn[3].auc_3g_ind == 4
conn[4].auc_3g_ind == 5
conn[5].auc_3g_ind == 6
conn[6].auc_3g_ind == 7
conn[7].auc_3g_ind == 8
conn[8].auc_3g_ind == 9
conn[9].auc_3g_ind == 10
Add another conn, should take auc_3g_ind == 0
conn_inst[20].auc_3g_ind == 0
Expecting a list of 0..10
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
conn[10].auc_3g_ind == 10
If a client reconnects, it will (likely) get the same auc_3g_ind
conn_inst[5].auc_3g_ind == 5
conn_inst[5].auc_3g_ind == 5
===== test_add_conn: SUCCESS
Done

View File

@@ -1,11 +1,11 @@
AM_CPPFLAGS = \
$(all_includes) \
-I$(top_srcdir)/include \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOABIS_CFLAGS) \

View File

@@ -32,148 +32,6 @@ struct qname_enc_dec_test {
size_t qname_max_len; /* default: strlen(qname) + 1 */
};
static const struct qname_enc_dec_test qname_enc_dec_test_data[] = {
{
/* OK: typical mslookup domain */
.domain = "hlr.1234567.imsi",
.qname = "\x03" "hlr" "\x07" "1234567" "\x04" "imsi",
},
{
/* Wrong format: double dot */
.domain = "hlr..imsi",
.qname = NULL,
},
{
/* Wrong format: double dot */
.domain = "hlr",
.qname = "\x03hlr\0\x03imsi",
},
{
/* Wrong format: dot at end */
.domain = "hlr.",
.qname = NULL,
},
{
/* Wrong format: dot at start */
.domain = ".hlr",
.qname = NULL,
},
{
/* Wrong format: empty */
.domain = "",
.qname = NULL,
},
{
/* OK: maximum length */
.domain =
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"12345"
,
.qname =
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\x05" "12345"
},
{
/* Error: too long domain */
.domain =
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"12345toolong"
,
.qname = NULL,
},
{
/* Error: too long qname */
.domain = NULL,
.qname =
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
},
{
/* Error: wrong token length in qname */
.domain = NULL,
.qname = "\x03" "hlr" "\x07" "1234567" "\x05" "imsi",
},
{
/* Error: wrong token length in qname */
.domain = NULL,
.qname = "\x02" "hlr" "\x07" "1234567" "\x04" "imsi",
},
{
/* Wrong format: token length at end of qname */
.domain = NULL,
.qname = "\x03hlr\x03",
},
{
/* Error: overflow in label length */
.domain = NULL,
.qname = "\x03" "hlr" "\x07" "1234567" "\x04" "imsi",
.qname_max_len = 17,
},
};
void test_enc_dec_rfc_qname(void *ctx)
{
char quote_buf[300];
int i;
fprintf(stderr, "-- %s --\n", __func__);
for (i = 0; i < ARRAY_SIZE(qname_enc_dec_test_data); i++) {
const struct qname_enc_dec_test *t = &qname_enc_dec_test_data[i];
char *res;
if (t->domain) {
fprintf(stderr, "domain: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->domain, -1));
fprintf(stderr, "exp: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->qname, -1));
res = osmo_mdns_rfc_qname_encode(ctx, t->domain);
fprintf(stderr, "res: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), res, -1));
if (t->qname == res || (t->qname && res && strcmp(t->qname, res) == 0))
fprintf(stderr, "=> OK\n");
else
fprintf(stderr, "=> ERROR\n");
if (res)
talloc_free(res);
fprintf(stderr, "\n");
}
if (t->qname) {
size_t qname_max_len = t->qname_max_len;
if (qname_max_len)
fprintf(stderr, "qname_max_len: %lu\n", qname_max_len);
else
qname_max_len = strlen(t->qname) + 1;
fprintf(stderr, "qname: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->qname, -1));
fprintf(stderr, "exp: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->domain, -1));
res = osmo_mdns_rfc_qname_decode(ctx, t->qname, qname_max_len);
fprintf(stderr, "res: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), res, -1));
if (t->domain == res || (t->domain && res && strcmp(t->domain, res) == 0))
fprintf(stderr, "=> OK\n");
else
fprintf(stderr, "=> ERROR\n");
if (res)
talloc_free(res);
fprintf(stderr, "\n");
}
}
}
#define PRINT_HDR(hdr, name) \
fprintf(stderr, "header %s:\n" \
".id = %i\n" \
@@ -216,7 +74,7 @@ static const struct osmo_mdns_rfc_header header_enc_dec_test_data[] = {
},
};
void test_enc_dec_rfc_header()
void test_enc_dec_rfc_header(void)
{
int i;
@@ -241,7 +99,7 @@ void test_enc_dec_rfc_header()
}
}
void test_enc_dec_rfc_header_einval()
void test_enc_dec_rfc_header_einval(void)
{
struct osmo_mdns_rfc_header out = {0};
struct msgb *msg = msgb_alloc(4096, "dns_test");
@@ -289,7 +147,7 @@ void test_enc_dec_rfc_question(void *ctx)
struct msgb *msg = msgb_alloc(4096, "dns_test");
PRINT_QST(&in, "in");
assert(osmo_mdns_rfc_question_encode(ctx, msg, &in) == 0);
assert(osmo_mdns_rfc_question_encode(msg, &in) == 0);
fprintf(stderr, "encoded: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
out = osmo_mdns_rfc_question_decode(ctx, msgb_data(msg), msgb_length(msg));
assert(out);
@@ -353,7 +211,7 @@ void test_enc_dec_rfc_record(void *ctx)
size_t record_len;
PRINT_REC(&in, "in");
assert(osmo_mdns_rfc_record_encode(ctx, msg, &in) == 0);
assert(osmo_mdns_rfc_record_encode(msg, &in) == 0);
fprintf(stderr, "encoded: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
out = osmo_mdns_rfc_record_decode(ctx, msgb_data(msg), msgb_length(msg), &record_len);
fprintf(stderr, "record_len: %lu\n", record_len);
@@ -578,18 +436,17 @@ static void test_result_from_answer(void *ctx)
}
}
int main()
int main(int argc, char **argv)
{
void *ctx = talloc_named_const(NULL, 0, "main");
osmo_init_logging2(ctx, NULL);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_level(osmo_stderr_target, 1);
log_set_print_category(osmo_stderr_target, 1);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
test_enc_dec_rfc_qname(ctx);
test_enc_dec_rfc_header();
test_enc_dec_rfc_header_einval();
test_enc_dec_rfc_question(ctx);

View File

@@ -1,85 +1,3 @@
-- test_enc_dec_rfc_qname --
domain: "hlr.1234567.imsi"
exp: "\3hlr\a1234567\4imsi"
res: "\3hlr\a1234567\4imsi"
=> OK
qname: "\3hlr\a1234567\4imsi"
exp: "hlr.1234567.imsi"
res: "hlr.1234567.imsi"
=> OK
domain: "hlr..imsi"
exp: NULL
res: NULL
=> OK
domain: "hlr"
exp: "\3hlr"
res: "\3hlr"
=> OK
qname: "\3hlr"
exp: "hlr"
res: "hlr"
=> OK
domain: "hlr."
exp: NULL
res: NULL
=> OK
domain: ".hlr"
exp: NULL
res: NULL
=> OK
domain: ""
exp: NULL
res: NULL
=> OK
domain: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345"
exp: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\512345"
res: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\512345"
=> OK
qname: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\512345"
exp: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345"
res: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345"
=> OK
domain: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345toolong"
exp: NULL
res: NULL
=> OK
qname: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\
exp: NULL
res: NULL
=> OK
qname: "\3hlr\a1234567\5imsi"
exp: NULL
res: NULL
=> OK
qname: "\2hlr\a1234567\4imsi"
exp: NULL
res: NULL
=> OK
qname: "\3hlr\3"
exp: NULL
res: NULL
=> OK
qname_max_len: 17
qname: "\3hlr\a1234567\4imsi"
exp: NULL
res: NULL
=> OK
-- test_enc_dec_rfc_header --
header in:
.id = 1337

View File

@@ -80,14 +80,14 @@ static int server_recv(struct osmo_fd *osmo_fd, unsigned int what)
return n;
}
static void server_init()
static void server_init(void)
{
fprintf(stderr, "%s\n", __func__);
server_mc = osmo_mdns_sock_init(ctx, TEST_IP, TEST_PORT, server_recv, NULL, 0);
OSMO_ASSERT(server_mc);
}
static void server_stop()
static void server_stop(void)
{
fprintf(stderr, "%s\n", __func__);
OSMO_ASSERT(server_mc);
@@ -98,7 +98,7 @@ static void server_stop()
struct osmo_mslookup_client* client;
struct osmo_mslookup_client_method* client_method;
static void client_init()
static void client_init(void)
{
fprintf(stderr, "%s\n", __func__);
client = osmo_mslookup_client_new(ctx);
@@ -117,7 +117,7 @@ static void client_recv(struct osmo_mslookup_client *client, uint32_t request_ha
osmo_mslookup_client_request_cancel(client, request_handle);
}
static void client_query()
static void client_query(void)
{
struct osmo_mslookup_id id = {.type = OSMO_MSLOOKUP_ID_IMSI,
.imsi = "123456789012345"};
@@ -134,7 +134,7 @@ static void client_query()
osmo_mslookup_client_request(client, &query, &handling);
}
static void client_stop()
static void client_stop(void)
{
fprintf(stderr, "%s\n", __func__);
osmo_mslookup_client_free(client);
@@ -154,7 +154,7 @@ const struct timeval fake_time_start_time = { 0, 0 };
osmo_timers_update(); \
} while (0)
static void fake_time_start()
static void fake_time_start(void)
{
struct timespec *clock_override;
@@ -167,7 +167,7 @@ static void fake_time_start()
osmo_clock_override_enable(CLOCK_MONOTONIC, true);
fake_time_passes(0, 0);
}
static void test_server_client()
static void test_server_client(void)
{
fprintf(stderr, "-- %s --\n", __func__);
server_init();
@@ -190,7 +190,7 @@ static void test_server_client()
client_stop();
}
bool is_multicast_enabled()
bool is_multicast_enabled(void)
{
bool ret = true;
struct addrinfo *ai;
@@ -222,7 +222,7 @@ bool is_multicast_enabled()
/*
* Run all tests
*/
int main()
int main(int argc, char **argv)
{
if (!is_multicast_enabled()) {
fprintf(stderr, "ERROR: multicast is disabled! (OS#4361)");
@@ -233,7 +233,7 @@ int main()
ctx = talloc_named_const(NULL, 0, "main");
osmo_init_logging2(ctx, NULL);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_level(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);

View File

@@ -147,7 +147,7 @@ const struct timeval fake_time_start_time = { 0, 0 };
osmo_timers_update(); \
} while (0)
static void fake_time_start()
static void fake_time_start(void)
{
struct timespec *clock_override;
@@ -169,12 +169,12 @@ static void result_cb_once(struct osmo_mslookup_client *client,
LOGP(DMSLOOKUP, LOGL_DEBUG, "result_cb(): %s\n", osmo_mslookup_result_name_c(ctx, query, result));
}
int main()
int main(int argc, char **argv)
{
ctx = talloc_named_const(NULL, 0, "main");
osmo_init_logging2(ctx, NULL);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_level(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);

Some files were not shown because too many files have changed in this diff Show More