Commit Graph

1183 Commits

Author SHA1 Message Date
Pau Espin f8af776fba sms_queue: Print dest msisdn instead of unknown subscriber
If subscriber is NULL, vlr_subscr_msisdn_or_name() returns string
"unknown", which is less informative than printing destination msisdn
expected for the queued sms.
This happens for instance if an sms was queued with Store&Forward and
destination subscriber is not currently registered

Change-Id: I4b8b54c9c41b17d4e1fa7ece63aa91a98036ef11
2019-04-09 19:45:03 +07:00
Philipp Maier 4826465708 vlr_sgs: start lu expiration timer on sgs eps detach
When the subscriber is detached from SGs services (but not from 2g
services). Then the subscriber essentially becomes a regular 2g
subscriber, which means thet the lu expiration timer needs to be
started.

Change-Id: If95c63706dc1c5a537f7cd1b6481252427cbf234
Related: OS#3614
2019-04-07 18:57:39 +00:00
Philipp Maier 0803d88d9a vlr_sgs: fix SGs IMSI detech from non EPS services
When the subscriber is detached from non EPS services while the
SGs-association is not SGs-NULL, it needs to be removed from the VLR
database.

Change-Id: I575cf6036ad39468f590b2d57a06cd3512a4c31c
Related: OS#3614
2019-04-07 18:57:31 +00:00
Vadim Yanitskiy 96262a7ca6 libmsc/sms_queue.c: fix memleak in smsq_take_next_sms()
A memleak has been noticed after executing some of TTCN-3 test
cases. For example, the following ones:

  - MSC_Tests.TC_lu_and_mo_sms,
  - MSC_Tests.TC_lu_and_mt_sms.

The key point is that MSC_Tests.TC_lu_and_mo_sms basically sends
a MO SMS to a non-attached subscriber with MSISDN 12345, so this
message is getting stored in the SMSC's database.

As soon as the SMSC's queue is triggered, sms_submit_pending() would
retrieve pending messages from the database by calling function
smsq_take_next_sms() in loop and attempt to deliver them.

This function in it's turn checks whether the subscriber is attached
or not. If not, the allocated 'gsm_sms' structure would not be
free()ed! Therefore, every time smsq_take_next_sms() is called,
one 'gsm_sms' structure for an unattached subscriber is leaked.

Furthermore, there is a unit test called 'sms_queue_test', that
actually does cover smsq_take_next_sms() and was designed to
catch some potential memory leaks, but...

In order to avoid emulating the low-level SQLite API, the unit
test by design overwrites some functions of libmsc, including
db_sms_get_next_unsent_rr_msisdn(), that is being called by
smsq_take_next_sms().

The problem is that the original function in libmsc does
allocate a 'gsm_sms' structure on heap (using talloc), while
the overwriting function did this statically, returning a
pointer to stack. This critical difference made it impossible
to spot the memleak in smsq_take_next_sms() during the
unit test execution.

Let's refactor 'sms_queue_test' to use dynamic memory allocation,
and finally fix the evil memleak in smsq_take_next_sms().

Change-Id: Iad5e4d84d8d410ea43d5907e9ddf6e5fdb55bc7a
Closes: OS#3860
2019-04-01 12:02:57 +00:00
Keith Whyte 18f1138a6d Write configuration correctly from vty (alert notifications)
The default is [yes] alert-notifications, therefore write
"no alert-notifications" in the case that this has
been set, in order to preserve configuration after
write is called from vty.

Change-Id: I079aea96ee83fbf04f782dcab344d41a4ef04657
2019-03-29 22:48:38 +00:00
Vadim Yanitskiy 81635d3400 libmsc: fix: properly initialize the SGs server
It was observed that the SGs server is started before
the actual VTY configuration is parsed. For example:

  sgs
   local-port 9999
   local-ip 127.0.0.1
   vlr-name vlr.example.net

produces the following debug output:

  <0011> sgs_server.c:185 SGs socket bound to r=NULL<->l=0.0.0.0:29118
  DLSS7 NOTICE <001e> osmo_ss7.c:1284 0: ASP Restart for server not implemented yet!
  DSGS NOTICE <0011> sgs_server.c:185 SGs socket bound to r=NULL<->l=0.0.0.0:9999
  DSGS NOTICE <0011> sgs_server.c:185 SGs socket bound to r=NULL<->l=127.0.0.1:9999
  DMNCC DEBUG <0004> msc_main.c:604 Using internal MNCC handler.

The first startup is triggered by sgs_iface_init(), before reading
the VTY configuration, so the logging style is different. The next
two calls to sgs_server_open() are triggered during reading of the
VTY configuration by cfg_sgs_local_port() and cfg_sgs_local_ip().

Let's avoid starting the SGs server three times, and do it once,
after the VTY configuration is parsed. Also, keep the possibility
to change the binding parameters at run-time.

Change-Id: Ie0c31205ac48be7e50d0380a89833771b2708da4
2019-03-28 17:10:11 +07:00
Vadim Yanitskiy 1d802e2635 libmsc/sgs_vty.c: don't print SGs socket error twice
Because sgs_server_open() already does this.

Change-Id: Ifea308645c7829691dbcf53e4f59841090119006
2019-03-28 10:09:11 +00:00
Vadim Yanitskiy 4eaefc2222 libmsc/sgs_iface.c: register sgs_vlr_reset_fsm on DSO load
Change-Id: I80cd2e5645d6e391080376250c0853a3f3f821ef
2019-03-28 10:09:11 +00:00
Vadim Yanitskiy 118a0b890e libmsc/sgs_iface.c: fix copy-paste error
Change-Id: I57b773659302ad4c92b6e670c6156e90a50189ba
2019-03-28 10:09:11 +00:00
Neels Hofmeyr 83e311fa3e vlr_subscr_name(): use OSMO_STRBUF
We now have a nicer way to compose strings in a buffer than this.
(Cosmetic preparation for inter-MSC handover patch.)

Change-Id: I7813068032475deb3850af05f7ba5a6f652e7fa2
2019-03-24 16:49:07 +00:00
Philipp Maier 8fa2dbe5b1 msc_vty: add missing header file
The symbol GSM0808_SPEECH_FULL_BM is used in msc_vty.c, but gsm_08_08.h,
where the symbol is declared is not included.

Change-Id: I31a8894031aa2321d7dbf2586d076bc303247278
2019-03-19 18:52:56 +01:00
Sylvain Munaut da9f37ed20 libvlr: Allow 2G auth tuples to be re-used without going through AUTH
If the key_seq we get in the first messages matches the last_tuple, then
both we and the MS already know the key to use and we don't need the
AUTH REQUEST/RESPONSE cycle.

Security wise ... not so good, and so IMHO the 'auth required' option
in the MSC should always be set. But this allows to turn on ciphering on
a channel without doing any MM transaction, and so the MS doesn't turn
on the T3240 timer which allows to have a ciphered silent-call channel
that won't timeout.

Change-Id: Ief840a2ae7a0ffd2bf0bf726f209a79e3f787646
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2019-03-19 15:24:01 +00:00
Harald Welte 31f4c1f927 a_iface: OSMO_ASSERT() if we ever want to send BSSAP with invalid length
Let's add a safeguard against sending BSSAP messages with invalid length
values.  This should never happen, and we'd rather see osmo-msc assert
during the development cycle than ever releasing a version which sends
invalid messages out on the wire.

Change-Id: I94327a0d276c65b528a8c7e33dde61ed53582284
Related: OS#3805
2019-03-19 13:39:14 +00:00
Philipp Maier 9286114f6f silent_call: use osmo_strlcpy() instead of strncpy()
If gsm_silent_call_start() is called with an over long string in
traffic_dst_ip, then the target string might be left unterminated. Lets
use osmo_strlcpy() so that we can be sure the result in scd->traffic_ip
is always terminated.

Fixes: CID#196068
Change-Id: Ic81842175e412ae7d97d023b612412f33411d60c
2019-03-15 09:51:15 +01:00
Sylvain Munaut 935583069d libmsc: Allow different channel types to be requested as silent calls
Change-Id: I82645708dd27864cf33ea9cc993ead0983415602
2019-03-14 12:39:31 +00:00
Neels Hofmeyr f90496f577 vty: add cmd subscriber ID sms delete-all
In ttcn3-msc-tests, so far we leave an intentionally failed MT SMS in the SMS
queue, which may cause it to re-appear in subsequent tests.

Allow removing all SMS for a given subscriber from the SMS database for good.

(I dimly remember a user report where the SMS queue spams failed SMS attempts,
and the only way to get rid of SMS for a given subscriber is to tamper with the
sms.db file directly. This should no longer be necessary with this command.)

Related: I7dce12942a65eaaf97f78ca69401c7f93faacb9e (osmo-ttcn3-hacks)
Change-Id: I637cbd7adc075a192f49752b38779391472ff06d
2019-03-08 04:51:18 +01:00
Neels Hofmeyr 34a36da3ef SMS queue: properly log failed attempts number
Change-Id: I16f2d29855eb715eccbdc5def225f43c110fab8e
2019-03-07 04:17:53 +01:00
Neels Hofmeyr 864d32c043 gsm_04_11_gsup.c: drop unused conn lookup
An earlier code state used the conn to lookup the transaction, but this is now
done by vsub. Hence the conn lookup is not used and not needed.

conn is no longer used since 36c44b2100,
change-Id I093f36d63e671e50e54fc6236e97a777cc6da77b,
"transaction: change arguments of trans_find_by_sm_rp_mr()"

Change-Id: Ia878d70138c883cb1a1d983516aff83efa6488ce
2019-03-07 04:17:47 +01:00
Neels Hofmeyr 8e2c6a31c1 use only accepted ran_conns for new transactions
In connection_for_subscriber(), do not return a ran_conn that is not yet
authenticated nor one that is already in release.

Using a ran_conn that is not yet authenticated may cause an auth/ciph
violation.

Using a ran_conn that is already in release may cause a use-after-free, see
OS#3842 for a description.

To be paranoid, upon releasing a conn, go through the transaction freeing
motions again by calling trans_conn_closed(), just in case some odd code path
added another transaction while the conn was already in release.

Related: OS#3842
Change-Id: Id957032e0ae1ff8ba055a75c3523447d3d06cbc3
2019-03-07 03:58:29 +01:00
Keith Whyte a3a8821167 Don't deliver alert notifications to ESME not yet bound.
We create a new ESME in smsc->esme_list on establishment
of a TCP connection, yet we do not know the system id 
or anything else, until the ESME identifies and authenticates.

So do not send alert notifications until
we know the bind status (and system_id)

Change-Id: Iec92d4c145ca050c2e212139572eeaae581b99df
2019-02-28 14:18:29 +00:00
Vadim Yanitskiy 477cbc6d93 libmsc/msc_vty.c: drop dead comparison against null
Since vsub->sgs.mme_name is allocated statically, comparing it
to null doesn't make sense - it's always != NULL.

Change-Id: Ib2933a20471ebff9dfe1d9fdddf39d177504c951
Fixes: CID#178166 Array compared against 0 (NO_EFFECT)
2019-02-28 00:14:21 +07:00
Vadim Yanitskiy 4d75877e61 libmsc/sgs_vty.c: always write server address and VLR name
Comparing an array to null is not useful, because the expression
will always evaluate as true. Let's just always write SGs server
address and VLR name, no mater whether default values are used
or not, same as we do for the HLR address and port.

Change-Id: If045e42fca0315b0777eb86c44bf934ce58b340b
Fixes: CID#190871 Array compared against 0 (NO_EFFECT)
2019-02-28 00:14:15 +07:00
Vadim Yanitskiy e9ef7c6b9a libmsc/sgs_iface.c: fix SGS_STATE_NS11 counter reference
The SGS_STATE_TS11 is not for counters, it's for timers!

Change-Id: Ifbb1a37e644ae8bf8e7959f6f6cd6403ac1f2f1b
Fixes: CID#190872 Out-of-bounds read (OVERRUN)
2019-02-26 23:16:45 +00:00
Vadim Yanitskiy 1396e1ca35 libmsc/ran_conn.c: add missing 'break' to OSMO_RAT_EUTRAN_SGS
Change-Id: I18dfd08ea0857f2751164a295dd9de20a2024ac3
Fixes: CID#190874
2019-02-26 23:16:10 +00:00
Vadim Yanitskiy 64623e1848 libmsc/gsm_09_11.c: implement guard timer for NCSS sessions
It may happen that either the MS or an EUSE would become
unresponsive during a call independent SS session, e.g.
due to a bug, or a dropped message. In such cases, the
corresponding transaction would remain unfreed forever.

This change introduces a guard timer, that prevents keeping
'stalled' NCSS sessions forever. As soon as it expires, both
sides (i.e. MS and EUSE) are getting notified, and the
transaction is being released.

By default, the timer expires after 30 seconds. As soon as
either the MS, or an EUSE initiates any activity,
the watchdog timer is rescheduled.

The timeout value can be configured from the VTY:

  msc
   ...
   ! Use 0 to disable this timer
   ncss guard-timeout 30

Please note that changing the timeout value at run-time
doesn't affect the existing NCSS sessions, excepting the
case when the timer is disabled at run-time.

This change makes TC_lu_and_ss_session_timeout pass.

Change-Id: Icf4d87c45e90324764073e8230e0fb9cb96dd9cb
Related Change-Id: (TTCN) I3e1791773d56617172ae27a46889a1ae4d400e2f
Related: OS#3655
2019-02-20 03:22:38 +07:00
Harald Welte 390d140b56 a_iface: Fix hexdumping of N-DATA.req
For some reason the existing code was using msgb_hexdump_l2() while the
L2 header is not used by the BSSAP transmit code.  Let's fix this.

Change-Id: I52a1eb3a867ece63fcfa4c2a720d035ebfb90a7b
2019-02-18 13:52:09 +01:00
Harald Welte fd96d45049 a_iface: use 'const' qualifier for ran_conn whenever possible
Change-Id: I8a15c9baae2071569e2ecc4635ddaf5a0001f959
2019-02-18 13:52:09 +01:00
Harald Welte 977b5486b1 a_iface: Centralize/wrap BSSAP / N-DATA transmission
We don't want multiple callers to osmo_sccp_tx_data_msg() each having
to hex-dump a log message about the to-be-transmitted message, with
half of the caller sitest missing that printing.  Let's centralize
all calls of osmo_sccp_tx_data_msg() in a wrapper function which
takes care of the related OSMO_ASSERT() and the related printing.

Change-Id: I6159ea72cc8e0650eda6c49544acd65e9c15e817
2019-02-18 13:52:05 +01:00
Vadim Yanitskiy baeeb90907 transaction: fix description of trans_assign_trans_id()
Change-Id: I80238d89e95b6fd791961c48de80aac69ff5b0e9
2019-02-15 02:19:30 +07:00
Max d8daaae91e transaction: clarify magic 0xff transaction ID
Change-Id: I2d3a6334f49989bedbb1430d26ffad8b61dfd873
2019-02-15 02:19:30 +07:00
Max 30fb97aa43 transaction: drop meaningless ti_flag of trans_assign_trans_id()
According to GSM 04.07, the TI flag takes one bit and can be
either of the following:

  '0'B - transaction is allocated by sender of a message,
  '1'B - transaction is allocated by receiver of a message.

Since we store transaction ID in gsm_trans structure, we also store
TI flag (as a part of transaction ID), which in this context means:

  '0'B - transaction is allocated by us (OsmoMSC),
  '1'B - transaction is allocated by some MS.

In 100% cases, trans_assign_trans_id() is used to assign transaction IDs
to transactions allocated by us (i.e. OsmoMSC) for MT connections. And
there is no need to use it for MO transactions, because they basically
already do contain a valid transaction ID assigned by the MS.

Change-Id: Ie11999900b1789652ee078d34636dcda1e137eb0
2019-02-15 02:19:24 +07:00
Vadim Yanitskiy 114bad8c48 libmsc/osmo_msc.c: move connection ref-counting code to 'ran_conn.c'
The connection ref-counting implementation is specific to RAN
connections, and is not applicable for anything else. Moreover,
the API of this code is declared in 'ran_conn.h', so let's
move the code to a more logical place.

Change-Id: I593675d9bf56eaef12afdaf596ee1337b9a44259
2019-02-14 09:26:47 +00:00
Vadim Yanitskiy 3acfe68b8b libmsc/gsm_04_80.c: add msc_send_ussd_release_complete_cause()
According to GSM 04.80, section 2.5.1, Release complete message
may have an optional Cause IE. Let's add a new function, that
allows to specify cause location and value.

This function will be used by the upcoming changes.

Change-Id: I3b9e8e4f473d113d5b9e9e5d33f7914202077203
Depends Change-Id: (libosmocore) Ie3ac85fcef90a5e532334ba3482804d5305c88d7
2019-02-13 12:50:14 +00:00
Vadim Yanitskiy f20c6b7bd5 libmsc/gsm_04_80.c: use gsm0480_create_release_complete()
The previous implementation of msc_send_ussd_release_complete() was
based on gsm0480_create_ussd_release_complete(), that doesn't
allow to specify GSM 04.07 transaction identifier.

The ability to specify particular transaction identifier
is required for handling multiple SS/USSD transactions.

Change-Id: Id2975c3383f18e83124ba38927c03980d67ddadb
Depends Change-Id: (libosmocore) Ie3ac85fcef90a5e532334ba3482804d5305c88d7
2019-02-13 12:50:14 +00:00
Philipp Maier 896950ab82 a_iface: Include CSFB Indication into BSSMAP CLEAR COMMAND
When a call ends that has been established in an CSFB context, we should
add a CSFB Indication IE to the BSSMAP CLEAR COMMAND to instruct the BSC
to add further CSFB related IEs into the RR RELEASE.

- Check if an SGs association exists and add CSFB Indication IE

Change-Id: I6cfa4b3becdd0138d74e2e1eddd83a0b1568c1de
Related: OS#3778
2019-02-07 10:01:46 +01:00
Harald Welte 0df904dea9 Add SGs Interface
Add an SGs interface (3GPP TS 29.118) to osmo-msc in order to support
SMS tunneling and Circuit Switched Fallback (CSFB)

Change-Id: I73359925fc1ca72b33a1466e6ac41307f2f0b11d
Related: OS#3615
2019-02-04 13:36:26 +01:00
Vadim Yanitskiy c7de62cc53 libmsc/gsm_04_11.c: introduce and use gsm411_assign_sm_rp_mr()
Initially, it was assumed that if there is no active RAN connection,
we can just start counting from 0x00, as there are no other SMS
related transactions, and transaction itself is allocated using
talloc_zero(). Until now it was looking good, but...

As soon as we establish RAN connection with subscriber, we already
have a transaction with SM-RP-MR 0x00, but conn->next_rp_ref also
remains 0x00 - it isn't being increased!

It means that we can face a SM-RP-MR conflict (or collision) if
another MT SMS would arrive to the MSC (from SMSC over GSUP)
when this transaction is still active, i.e. the first SMS is
still being sent, because conn->next_rp_ref++ would
return 0x00 again.

Moreover, there might be already a MO SMS transaction, and using
the conn->next_rp_ref counter wouldn't prevent us from having
duplicate SM-RP-MR value.

Let's get rid of this per-connection counter, and introduce a
function instead, that would iterate over existing transactions
and look for an unused SM-RP-MR value.

This change makes the following test cases pass:

  - TC_gsup_mt_sms_rp_mr,
  - TC_gsup_mo_mt_sms_rp_mr.

Discovered by: Neels Hofmeyr
Related Change-Id: (TTCN) I3a52d44f4abde9b6b471b9108c1cee905884c9bc
Related Change-Id: (TTCN) I17cbbaa64d9bce770f985588e93cd3eecd732120
Change-Id: Ife6d954c46b7d8348a4221ab677d0355eb3ee7ac
2019-02-01 18:55:54 +00:00
Vadim Yanitskiy cfd058dbf1 libmsc/gsm_04_11.c: also assign SM-RP-MR to MO transactions
Previously, SM-RP Message Reference was assigned to MT transactions
only, but not to MO transactions. As a result, this could lead to
having a few transactions with duplicate SM-RP-MR value, because
in case of MO SMS, trans->sms.sm_rp_mr would remain 0x00.

Let's parse SM-RP-MR from MO SMS messages in gsm0411_rcv_sms(),
and assign it to the new transaction after allocation.

Change-Id: I4d07354175444f9764fb0dd6ea188a64494d79fe
2019-02-01 18:55:54 +00:00
Vadim Yanitskiy 36c44b2100 transaction: change arguments of trans_find_by_sm_rp_mr()
The need to pass a pointer to RAN connection in order to find
a transaction limits possible use cases of trans_find_by_sm_rp_mr(),
e.g. when we need to find a transaction, but RAN connection is not
established yet.

Moreover, the pointer to RAN connection was only used to obtain
pointers to gsm_network and vlr_subscr, so we can just
pass them directly.

Change-Id: I093f36d63e671e50e54fc6236e97a777cc6da77b
2019-02-01 18:55:54 +00:00
Vadim Yanitskiy ce9e1f664e libmsc/ran_conn.c: cosmetic: use tabs instead of N * 8 spaces
Change-Id: I09515aea9da8e2b5836c5c6409f094fae05633d4
2019-01-26 11:36:14 +07:00
Vadim Yanitskiy e4574f09d0 transaction.c: cosmetic: use 'default' branch in trans_free()
Change-Id: Ia28ba52b0ea4771843a2a1faa346f7357604b8aa
2019-01-26 11:36:08 +07:00
Max 3614fd6d11 Various logging fixes
Log transaction allocation errors as such. While at it, use proper
subsystem to log missing VLR subscriber.

Change-Id: I617be8793b9416ccd49022c72f7d93df7f4fb4d9
2019-01-24 19:08:07 +00:00
Max 80d8ffda8c Handle LCLS-NOTIFICATION message from BSS
Change-Id: Ibf5f9cad1f70aee56d5bca8fe09a24ca417e7a63
Related: OS#2487
2019-01-24 17:37:08 +00:00
Neels Hofmeyr a92025e8fd fix build: apply msgb_wrap_with_TL() rename
After libosmocore commit
If1e851ac605c8d2fde3da565b0bd674ea6350c2e
b27e6feb699712345373e87a48187dc622e4fa92
the osmo-msc master build is broken.

Apply the msgb_wrap_with_TL() rename to msgb_push_tl() to unbreak the build.

Change-Id: I1d4675e0c907b2f92f2ec79b02356391a6d72aa8
2019-01-22 01:58:55 +01:00
Max 45df98bd85 vty: make 'sh connect/transact' readable again
After recent changes to vlr_subscr_name() result became variable-length
which messes up old vty code. Fix this by moving it to the very end and
adjusting headers as necessary. While at it, make sure we don't print
headers if we have nothing else to show.

Change-Id: Id06b4277ff790d95457d0cc2f94ef6bf5366bb21
2019-01-17 19:27:05 +01:00
Keith Whyte 72520f8d4f Cosmetic: Fix spelling in smpp vty
Change-Id: Id3fa3f26c333bf445590fd75ad7a08be68fed3e2
2019-01-17 14:04:07 +00:00
Keith Whyte c6d219cd83 Make alert notifications vty configurable per ESME
Adds (no) alert-notifications as a per-esme vty command,
in order to allow some ESMEs to be excluded from alerts.

The default is still to send alert notifications to all esme,
so no changes are required to the config file to maintain
identical operation after this patch.

Change-Id: I57f4d268ca6fe6a233f2caaffce62e4aade01274
2019-01-17 14:03:27 +00:00
Max 0e8dfadc7a SMS: remove code duplication in transaction init
Move code which allocates transaction for SMS and initializes
corresponding FSM into separate function (shared by MT and MO code
paths) to avoid code duplication and simplify further modifications.

Change-Id: I3563e11bebb58e656592df2ff7db96f41deaf735
2019-01-17 12:17:52 +00:00
Max 4813152691 Enable SMS-related log in VLR tests
The likely reason why it was disabled is due to
paging_cb_mmsms_est_req() logging pointers which results in unstable log
output. Fixing this allows us to track SMS-related regressions properly.

Change-Id: I44ae817d9edb73d182ff33ff5a2fd942e224e344
2019-01-16 12:56:30 +00:00
Oliver Smith 7d05309e3a VLR: send CHECK-IMEI to EIR/HLR
When check-imei-req is enabled in the VTY config, do not accept IMEIs
sent by the ME directly anymore. Send the IMEI to the EIR/HLR and wait
for its ACK or NACK.

OsmoHLR also accepts all IMEIs at this point, but this allows to
optionally store the IMEI in the HLR DB.

Depends: Ib240474b0c3c603ba840cf26babb38a44dfc9364 (osmo-hlr)
Related: OS#3733
Change-Id: Ife868ed71c36cdd02638072abebf61fc949080a7
2019-01-16 10:42:56 +00:00
Max c065ca3171 Fix trans_has_conn() doxygen description
Change-Id: Ica5e498e03d0a157a661e428dfd68739f572d073
2019-01-14 15:30:26 +01:00
Philipp Maier ec5901c8f2 gsm_04_08: Fix nullpointer deref
The pointers conn, conn->vsub and conn->vsub->last_tuple are checked,
but before the check those pointers are already dereferenced during
assignment. This defeats the purpose of the check. Lets dereference
those pointers after the check.

Fixes: CID#190404
Change-Id: Ice4992606f3799eac13154ec0b9f53e46d2e178e
2019-01-12 10:26:00 +00:00
gsmevent admin 9b9e76fe01 gsm_04_08_cc.c: drop non-sensible error message
Change-Id: Icbf099e418281eb908e7916503f178ab7ea26ffe
2019-01-12 09:51:22 +00:00
Neels Hofmeyr 5769d36b44 err log: fully log MS supported A5 algos on mismatch
Change-Id: Icb18e0f0bb420de066e7eb8fc683f192ba2a7368
2019-01-12 09:51:22 +00:00
Neels Hofmeyr a725970d85 tweak fsm_msc_mgcp FSM and FI name
Instead of

  MGW(MGW_99)

use a name of

  msc-mgcp(MSISDN:2331_GERAN_A:00000017_trans99)

1. The FSM is communication towards an MGW, not the MGW itself. When reading
combined logging (gsmtap_log), it is confusing to read 'MGW' in a log coming
from the MSC. The API is also called msc_mgcp_*.

2. Calling the FSM instance 'MGW_' again doesn't make sense.

3. Indicate 'trans' before the trans_id (trans_id was already shown, but not
indicated what it was).

4. Also indicate the actual subscriber's identification.

5. Also indicate the RAN connection and conn_id.

This comes up while trying to understand a call coming in on an already
established call: parsing the log with a human brain is near torture without
this info, taking extremely long to get grips on.

Change-Id: Ie5fc1ffb7eba0209fee4666a075655cd24d27473
2019-01-12 09:51:22 +00:00
Neels Hofmeyr b62289aa27 mm_rx_id_resp(): use osmo_mi_name()
Change-Id: I6bb053def223ed698351ad9f52c1e36293df5d59
2019-01-12 09:51:22 +00:00
Neels Hofmeyr 361e571815 refactor log ctx for vlr_subscr and ran_conn
ran_conn_get_conn_id(): instead of a talloc allocated string, return a static
buffer in ran_conn_get_conn_id(). So far this function had no callers.

Refactor ran_conn_update_id() API: during early L3-Complete, when no subscriber
is associated yet, update the FSM Id by the MI type seen in the L3 Complete
message: ran_conn_update_id_from_mi(). Later on set the vsub and re-update.

Call vlr.ops->subscr_update when the TMSI is updated, so that log context
includes the TMSI from then on.

Enrich context for vlr_subscr_name and ran_conn fi name.

Include all available information in vlr_subscr_name(); instead of either IMSI
or MSISDN or TMSI, print all of them when present. Instead of a short log,
rather have more valuable context.

A context info would now look like:

  Process_Access_Request_VLR(IMSI-901700000014706:MSISDN-2023:TMSI-0x08BDE4EC:GERAN-A-3:PAGING_RESP)

It does get quite long, but ensures easy correlation of any BSSAP / IuCS
messages with log output, especially if multiple subscribers are busy at the
same time.

Print TMSI and TMSInew in uppercase hexadecimal, which is the typical
representation in the telecom world.

When showing the RAN conn id
  GERAN_A-00000017
becomes
  GERAN-A-23
- We usually write the conn_id in decimal.
- Leading zeros are clutter and might suggest hexadecimal format.
- 'GERAN-A' and 'UTRAN-Iu' are the strings defined by osmo_rat_type_name().

Depends: I7798c3ef983c2e333b2b9cbffef6f366f370bd81 (libosmocore)
Depends: Ica25919758ef6cba8348da199b0ae7e0ba628798 (libosmocore)
Change-Id: I66a68ce2eb8957a35855a3743d91a86299900834
2019-01-12 09:51:22 +00:00
Neels Hofmeyr 7ce21dc589 rx CM Service Req: reject double use sooner
When a CM Service Req is being rejected, we should do so before changing the
state of the current conn.

Concerning multiple CM Service Requests: in fact we should store multiple
requests, but first fix the status quo of rejecting multiple requests.

Change-Id: I39209ee6662694aa054a2fc0d21eae76fb33e2f1
2019-01-12 09:51:22 +00:00
Neels Hofmeyr 46c06e28c1 add LOG_RAN_CONN() to use the conn->fi->id for context
For each conn, set a default logging category, to distinguish categories for
BSSMAP and RANAP based conns.

LOG_RAN_CONN(): log with the conn's default category,

LOG_RAN_CONN_CAT(): log with a manually set category (mostly for keeping
previous DMM logging on the same category).

In some places, replace LOGP() using manual context with LOG_RAN_CONN(), and
remove the manual context info, now provided by the conn->fi->id.

This is loosely related to inter-BSC and inter-MSC handover: to speed up
refactoring, I want to avoid the need for manual logging context and just use
this LOG_RAN_CONN().

Change-Id: I0a7809840428b1e028df6eb683bc5ffcc8df474a
2019-01-12 09:51:22 +00:00
Neels Hofmeyr 55d22d9e5e use osmo_lu_type_name() from libosmocore
Change-Id: Ib562bb5fb272c0c3ae0849f32b28faa2c26f9bb7
2019-01-12 09:51:22 +00:00
Vadim Yanitskiy 82cc8a5cfa libmsc/gsm_04_11.c: accept MT SMS messages over GSUP
Change-Id: I57357982ca0e51f6722c24a4aa1d0fb3e6caef88
Depends-on: (core) Ibe325c64ae2d6c626b232533bb4cbc65fc2b5d71
Depends-on: (OsmoHLR) I0589ff27933e9bca2bcf93b8259004935778db8f
Related Change-Id: (TTCN) I63a25c8366cce0852df6b628365151661a22a25f
Related: OS#3587
2019-01-11 21:42:43 +00:00
Max 4a5cfa559a Use explicit protocol discriminator for NC SS/USSD session
In gsm0911_rcv_nc_ss() we sometimes use pdisc parsed from msgb and
sometimes constant. This function is only called when protocol
discriminator is GSM48_PDISC_NC_SS so there's no point in parsing it
again from msgb.

Let's make it consistent and always use constant.

Change-Id: Iae40bf9906fe676ff817c709120015fca4c9e042
2019-01-10 17:41:05 +01:00
Oliver Smith 5598aaef23 VLR: vlr_subscr_{,msisdn_or_}name: const vsub arg
Make the vsub argument of both vlr_subscr_msisdn_or_name()
and vlr_subscr_name() a const.

The LOGVSUBP() macro uses vlr_subscr_name() and will not generate a
warning anymore when used with a const vsub.

Change-Id: If609269191f4df6186d823a2eee14012846328e2
2019-01-09 14:34:34 +00:00
Oliver Smith 361fa46444 vlr_core.h: remove duplicate declarations
Remove vlr_subscr_name() and vlr_subscr_alloc() declarations from
vlr_core.h, as they are already defined in osmocom/msc/vlr.h and vlr.h
gets included on top of vlr_core.h.

Change-Id: I5c029be490577b513395dc3f2c2698f365157e73
2019-01-09 14:34:14 +00:00
Oliver Smith 0fec28a506 msc_vty.c: make check-imei-rqd configurable
Related: OS#3189
Change-Id: Iee516b9cd7877b21207ce9a6d954109f19558163
2019-01-09 14:33:35 +00:00
Oliver Smith d6e24fd155 Cosmetic: msc_vty: remove redundant "0 =", "1 ="
Remove "0 =", "1 =" in-front of the boolean descriptions of
auth-tuple-reuse-on-error. The online VTY doc and the pdf manual
prepend the value automatically.

Change-Id: Ifd14c2fb3f58701eaf66570d729a660233fb83ed
2019-01-09 14:32:34 +00:00
Neels Hofmeyr 2c268697e9 use mgcp-client configured endpoint domain name
Rationale: reading pcaps becomes so much easier when each of osmo-bsc and
osmo-msc address their MGW with differing domain names. Otherwise, both will
have a '0@mgw' endpoint and it gets really confusing.

After this, with according configuration, there can be a '0@bsc' and a '0@msc'
endpoint.

osmo-mgw-for-msc.cfg:
 mgcp
  domain msc

osmo-msc.cfg:
 msc
  mgw endpoint-domain msc

Depends: Ia662016f29dd8727d9c4626d726729641e21e1f8 (osmo-mgw)
Change-Id: I87ac11847d1a6d165ee9a2b5d8a4978e7ac73433
2019-01-05 04:37:56 +01:00
Neels Hofmeyr 7814a83298 use osmo_rat_type from libosmocore
Replace locally defined enum ran_type with libosmocore's new enum
osmo_rat_type, and value_string ran_type_names with osmo_rat_type_names.

The string representations change, which has cosmetic effects on the test suite
expectations.

Depends: I659687aef7a4d67ca372a39fef31dee07aed7631 (libosmocore)
Change-Id: I2c78c265dc99df581e1b00e563d6912c7ffdb36b
2019-01-04 17:26:14 +00:00
Neels Hofmeyr 3a3ed9b704 vty cfg: move 'ipa-name' from 'msc' to 'hlr' section
during code review, I completely overlooked this:

We've added the 'ipa-name', which identifies the MSC on the GSUP link to the
HLR, under the 'msc' section, while all other GSUP/HLR related config is under
the 'hlr' section.

Before we roll that out in a release, move it over to 'hlr'.

Related: OS#3355
Change-Id: I1a572865aa90c5fa43c6f57282a6e2b06776e425
2019-01-04 16:32:21 +00:00
Neels Hofmeyr 868f505d86 vlr: auth_fsm: make sure vsub->auth_fsm = NULL when it terminates
Probably fixes this segfault:

    at ../../../../src/osmo-msc/src/libvlr/vlr_lu_fsm.c:957
    file=file@entry=0x5611d8f10c28 "../../../../src/osmo-msc/src/libvlr/vlr_lu_fsm.c", line=line@entry=1467)
    at ../../../src/libosmocore/src/fsm.c:580
    parent_event_failure=parent_event_failure@entry=6, parent_event_data=parent_event_data@entry=0x0, vlr=0x5611d98862b0,
    msc_conn_ref=msc_conn_ref@entry=0x5611d9aa8150, type=VLR_LU_TYPE_REGULAR, tmsi=4294967295, imsi=0x7ffd756c1cf0 "262423403004874",
    old_lai=0x7ffd756c1ce0, new_lai=0x7ffd756c1ce8, authentication_required=true, ciphering_required=true, is_r99=false, is_utran=false,
    assign_tmsi=true) at ../../../../src/osmo-msc/src/libvlr/vlr_lu_fsm.c:1467
    at ../../../../src/osmo-msc/src/libmsc/gsm_04_08.c:443

The segfault is indirectly caused by 1fbf45c291,
'enrich context for vlr_subscr_name and ran_conn fi name', which sets auth_fsm
context, on a non-NULL auth_fsm that has been deallocated.

Change-Id: I3c528eed295be2ee673ea295804372f388a0dccd
2019-01-04 16:24:59 +00:00
Neels Hofmeyr f383d411e6 abort assignment on Assignment Failure
If Assignment fails in the BSC, trigger an EV_TEARDOWN_ERROR in the mgcp_ctx
FSM instance, so that the call gets torn down immediately. Before this, the
non-call would idle around without anything happening.

Related: OS#3236
Depends: I11b182a03f5ecb6df7cd8f260757d3626c8e945d (libosmocore)
Change-Id: I358cfbaf0f44f25148e8b9bafcb9257b1952b35a
2019-01-04 16:24:59 +00:00
Neels Hofmeyr fcf49d3f4e fix: incoming call during ongoing call
If a call is already busy and another call is coming in, do not try to
immediately assign an lchan (before this patch, it fails because there already
is an mgcp_ctx for the conn). Leave the second CC transaction waiting.

When a call is hung up, as soon as the old mgcp_ctx is discarded, look for
other CC transactions that are waiting. If there is one, trigger assignment, so
a new mgcp_ctx is set up for the new call.

This fixes the following scenario:

- from A, call B.
- from C, call B; B rings during ongoing call.
- in B, pick up the call, choose to drop the old call.

After this patch, and with osmo-bsc patch with change-id
  I0c00ec2c120e5008281755adcd4944a3ce4d8355
we are now able to talk to the new caller.

I currently haven't tested yet what happens if there is *three* peers trying to
talk to the same number, running out of lab phones (not really, just not
bothering now). Possibly we should be taking over the particular call indicated
by the CC TI; instead, the current patch version takes on whichever waiting
call it finds first. This is fine if *one* additional call comes in on an
ongoing call, and this is already a huge improvement to what we had before.

Related: OS#3735
Change-Id: I0ba216b737909e92080a722db26e3577726c63cb
2019-01-04 16:24:59 +00:00
Neels Hofmeyr a35712d576 move trans->assignment_done to cc.assignment_started
The flag is set to true when an assignment has been started, and it is only
relevant for a CC transaction. So fix naming and place in cc struct.

Cosmetic preparation for I1f8746e7babfcd3028a4d2c0ba260c608c686c76 and
I0ba216b737909e92080a722db26e3577726c63cb/

Change-Id: I8dacf46141ba0b664e85b0867ade330c97d8495f
2019-01-04 16:24:59 +00:00
Neels Hofmeyr b16259f9ad remove code dup: add msc_mgcp_try_call_assignment()
Various places in the code check a flag whether assignment was started and
launch it. To fix incoming-call-during-ongoing-call, I will tweak that logic.
To be able to do that only in one place, remove code dup.

Cosmetic preparation for I1f8746e7babfcd3028a4d2c0ba260c608c686c76 and
I0ba216b737909e92080a722db26e3577726c63cb/

Depends: I11b182a03f5ecb6df7cd8f260757d3626c8e945d (libosmocore: LOGPFSMSL)
Change-Id: I11c0b7dc3f1a747028629b48e522bb3b864884ba
2019-01-04 16:24:59 +00:00
Max 7916ca1c2d Constify transaction helpers parameters
Change-Id: If002a1ff6ba4218cc16592946798340fcb1852ae
2019-01-04 09:38:07 +00:00
Neels Hofmeyr 1035d90c17 fix vlr ops.subscr_assoc re-association
In rare cases, a conn is already associated with a subscriber. So far, we
abort()ed on that, bringing the entire osmo-msc down. Rather log an error and
keep the service running.

In vlr.ops.subscr_assoc, add success/failure return value, and abort the
LU/PARQ on error.

I haven't figured out in detail yet why/how a subscriber would re-launch a
LU/PARQ on a conn that is already associated, so far it is merely clear that we
do not want to crash the MSC if that happens. A log is in OS#3742.

Related: OS#3742, OS#3743
Change-Id: Ic0d54644bc735700220b1ef3a4384c217d57d20f
2019-01-04 01:46:46 +00:00
Neels Hofmeyr 3350bf9f78 release RTP stream only for matching CC transaction
Do not break the currently ongoing call when rejecting a second incoming
caller.

There may be multiple (up to seven) simultaneous CC transactions, and there is
one mgcp_ctx for the currently active RTP stream.

Release the MGCP context only when the active CC transaction is releasing.
Before this patch, any CC transaction release would destroy the single MGCP
context, possibly breaking the currently ongoing call (another CC trans).

This also fixes a possible use-after-free if there were pending MGCP message
responses for the MGCP context; they are canceled properly for a released
transaction, but since one transaction would free the other transaction's MGCP
state, the clean up did not take place and possibly caused an mgcp client
response handling to access a freed mgcp_ctx.

Related: OS#3735
Change-Id: I1f8746e7babfcd3028a4d2c0ba260c608c686c76
2019-01-03 00:34:53 +00:00
Neels Hofmeyr c43b966d32 cosmetics in msc_mgcp_call_release()
Use local variables instead of writing trans->conn-> all the time.

Cosmetic preparation for I1f8746e7babfcd3028a4d2c0ba260c608c686c76 and
I0ba216b737909e92080a722db26e3577726c63cb/

Change-Id: I99717b3b72a9d7cbc95455ea25b2018ec1755308
2019-01-03 00:34:53 +00:00
Vadim Yanitskiy 76ef72dda8 libmsc/gsm_04_11.c: forward MO SMS messages over GSUP
Change-Id: I7d651fde3d608d02f275a74043dc42262aabb1b8
Depends-on: (core) Ic37f3b2114b8095cfce22977e67133b9103942e3
Depends-on: (core) Ibe325c64ae2d6c626b232533bb4cbc65fc2b5d71
Depends-on: (OsmoHLR) I0589ff27933e9bca2bcf93b8259004935778db8f
Related Change-Id: (TTCN) I7abc95b8e416f7308d54e11be11c08586d18e6c5
Related Change-Id: (TTCN) Id14bbd8bd51558cdacefea0fe042769cd69ed5c8
Related: OS#3587
2018-12-30 11:48:22 +01:00
Vadim Yanitskiy f40e46fdf4 libmsc/VTY: introduce kill-switch for routing SMS over GSUP
As a rudiment of OsmoNiTB, OsmoMSC is still involved in SMS
processing, storage (in SQLite DB), and routing (via SMPP).
In real networks this is done by the external entity called
SMSC (SMS Centre), while the MSC is doing re-encapsulation
of GSM 04.11 SM-TL (Transport Layer) payload (i.e. TPDU)
between SM-RL (Relay Layer) and MAP.

Since OsmoMSC itself is not a 'Network in The Box' anymore, it
makes sense to replicate the 'traditional' behaviour of MSC.
The problem is that this behaviour cannot co-exist with the
current implementation, so the key idea is to rip out the
local SMS storage and routing from OsmoMSC, and (re)implement
it in a separate process (OsmoSMSC?).

As a temporary solution, this change introduces a 'kill-switch'
VTY option that enables routing of SMS messages over GSUP
towards ESME (through VLR and HLR), but breaks the local
storage and routing. This is why it's disabled by default.

As soon as we move the SMS processing and storage away from
OsmoMSC, this behaviour would be enabled by default, and
the VTY option would be hidden and deprecated. At the moment,
this option basically does nothing, and will take an effect
in the follow-up changes.

Change-Id: Ie57685ed2ce1e4c978e775b68fdffe58de44882b
Related: OS#3587
2018-12-30 11:48:22 +01:00
Max 3332ac4430 MNCC: use log wrapper for call processing
Add log/debug wrappers to conveniently print local and remote call
references.

Change-Id: I5c44d7bb28f1ff895dd4f839d75840495503c916
2018-12-23 09:51:53 +00:00
Stefan Sperling b361ea7037 use vty->type instead of local variable
We can check if we're parsing the config file by checking
whether vty->type equals VTY_FILE. This avoids the use of
an extra local variable to track the parsing state.

Change-Id: I85161575e025f7c389832427a434bd8e2d6ecc75
Fixes: 1051c42088
Related: OS#3355
2018-12-21 12:38:47 +00:00
Neels Hofmeyr 4e0bd4b598 mgcp log tweak: say RAN, not BTS, like surrounding logging
Change-Id: Ibb40155189a7f05ba2da4fcf9cf03fda5ffc3683
2018-12-19 17:17:06 +00:00
Neels Hofmeyr 5d66970cd7 fix msc_mgcp_fsm_evt_names: two missing events
Change-Id: I66ebaf0a55de1a46bccbc86652ffa9b73c951ebf
2018-12-19 17:17:06 +00:00
Philipp Maier 6d71ccf484 msc_vty: also show IMEI and IMEISV
When the VLR subscriber information is shown on the VTY it shows IMSI
and TMSI, but not IMEI and IMEISV. Since in some cases this information
might be helpful, lets display it as well.

Change-Id: Iedd75dbb9850388ec1fedb984ed0b8bf4c62e780
2018-12-19 12:27:17 +00:00
Max 7d41d870de Remove redundancy in LAC processing
Always use LAC which is part of Cell Global ID otherwise we might end up
in a situation where separately stored LAC differs.

Both are described in 3GPP TS 23.008 $2.4 as temporary subscriber data
to be stored in VLR. Both are defined in 3GPP TS 23.003. The LAC is part
of LAI which is part of CGI so there should be no case when those values
differ for a given subscriber.

Change-Id: I993ebc3e14f25e83124b6d3f8461a4b18f971f8e
2018-12-19 11:48:33 +01:00
Philipp Maier 2a0ac3b162 msc_vty: display current RAN type
When a subscriber is displayed the RAN type is not included in the
overview. Meanwhile the MSC supports multiple different ran types it
becomes important to see in which RAN the subscriber is currently
active.

Change-Id: I000cafd5e41b9951d51b6bd6672ee68a224b8212
Related: OS#3615
2018-12-19 10:17:59 +01:00
Philipp Maier 89561bc4e7 msc_vty: display subscriber flags
When a VLR subscriber is displayed on the VTY we get a lot of meta
information, but there are also some flags to handle the internal
subscriber status e.g. conf_by_radio_contact_ind. Lets display those
flags as well as this information can be very helpful when debugging
problems in the VLR

Change-Id: I59a9145a4daad50d68de3fd5c3291f027256917f
2018-12-19 10:17:59 +01:00
Neels Hofmeyr 14c6f3ee95 vty: show subscriber: put() before printing the use count
Do not show the VTY command's own use count during 'show subscriber <ID>'.

When using 'show subscriber msisdn 2023', I was surprised to see a use count of
2 and suspected a use count leak. With 'show subscriber cache' however, the use
count is 1.

So I realized it is the vty command's own use count that makes it two, besides
the lu_complete=true one.

Change-Id: Id02b57b7ed299b010b9f8b9e809548eb1e6aa699
2018-12-18 18:01:26 +00:00
Max c4e4fa762c Use proper type for tch_rtp_connect() parameter
Change-Id: I6e2efcd2e25d6ec2ff35a4b8cfcda02abe97fa59
2018-12-18 17:46:15 +01:00
Max 964da93c69 CC: log more details about unhandled message/state
Change-Id: I8e0febd04f7338aed7222dcfcd9bfddc7b8fda59
2018-12-17 17:45:41 +00:00
Max 020ec7ac0c cosmetic: drop unused variable
Change-Id: Iff358eb2328cdd052e66b572aeec1b767174949b
2018-12-17 17:36:25 +01:00
Neels Hofmeyr 5c8b144ebd comment: vlr: put the 'balancing' comment closer to the put()
Change-Id: Ic42768b22d63d182455c8d860961c44159973d0c
2018-12-17 14:39:16 +00:00
Neels Hofmeyr d50f8988f7 vlr_lu_fsm: drop unused out_state INIT -> WAIT_IMEI
There is no state transition from INIT to WAIT_IMEI, only to WAIT_SUB_PRES.

If there were code to skip WAIT_SUB_PRES, the allowed state transitions would
have to be the same as for WAIT_SUB_PRES, i.e. also WAIT_IMEI_TMSI and
WAIT_TMSI_CNF. For now just opt for the status quo.

Change-Id: I18ef9e8c96b52401d98f49dc410f13681231b533
2018-12-17 14:39:16 +00:00
Neels Hofmeyr 5f1ac6dce6 tweak comment to indicate sub_pres_vlr fsm as dead code
sub_pres_vlr_fsm_start() only ever has an effect if ms_not_reachable_flag ==
true. But there simply is no code that sets this flag. So
sub_pres_vlr_fsm_start() is currently dead code.

Also, examining the FSM, if it should ever be set to true, this would halt the
LU/CM Service/Paging response, since the FSM would merely change its state
without dispatching asynchronous messages. No chance of finishing.

Short of dropping the code entirely, first just mark it. The point being that
this models some FSM definition from 3GPP specs, and we have a couple other
"if (0)" branches in the VLR...

Change-Id: I198d442e9ed288f37c7d4e5ec87b82dc53114e99
2018-12-17 14:39:16 +00:00
Neels Hofmeyr 88063dd368 log: by default start with all categories on LOGL_NOTICE
They were on DEBUG during early development stages, and it's high time that I
drop those back to NOTICE.

Change-Id: I3b46e9107a7a1d81a44d2a2eb855c10960a1ab6b
2018-12-17 13:50:49 +00:00
Max b099a7f8ad cosmetic: drop duplicated #include
Change-Id: I216425ba5994a49981d51bce6cfa7c3fa5fe9e40
2018-12-17 10:49:50 +01:00
Stefan Sperling 1051c42088 require 'ipa-name' option to be set via config file
The 'ipa-name' option can now only be set via the configuration file
because changing the IPA name at run-time conflicts with active
GSUP connections and routes configured in the HLR. The osmo-msc
program must be restarted if its IPA name needs to change.

Change-Id: I6cff91793e646e0396e8f1bc87d0f52709e5f12a
Related: OS#3355
2018-12-13 10:16:49 +01:00
Neels Hofmeyr 85cb2538f4 Revert "move ASS-COMPL MGCP handling out of a_iface_bssap.c"
Two reasons:

- the caller of msc_mgcp_ass_complete() from Iu, iucs_rx_rab_assign(), failed
  to be adjusted, breaking IuCS, as an --enable-iu --enable-werror build shows.
  Unfortunately our gerrit verification doesn't --enable-werror for osmo-msc.

- the condition of requiring ST_MDCX_RAN is faulty, breaking GSM CS.

This reverts commit 212c0c9bda.

Change-Id: I8348675c2f7c8856ea1682d05ee54160d4cfeb96
2018-12-11 19:52:30 +01:00
Stefan Sperling 36dedeeb12 provide software version information to gsup peer
Provide software version information to the GSUP peer. The version now
shows up in logs like this: Software_Version='osmo-msc-1.2.0.120-1263b'

Change-Id: I2eba32569349facdbb1fda201067c62cc804ccf4
Depends: I317d6c59f77e92fbb2b875a83dc0ec2fa5cb6006
Related: OS#3355
2018-12-11 13:08:00 +00:00
Stefan Sperling afa030d6f9 make gsup ipa name configurable in osmo-msc.cfg
Add a 'ipa-name' VTY command which overrides the default IPA name
used by the MSC. This is a prerequisite for inter-MSC handover.

Related: OS#3355
Change-Id: I317d6c59f77e92fbb2b875a83dc0ec2fa5cb6006
2018-12-11 13:08:00 +00:00
Neels Hofmeyr aa14bac370 LU: do not always invoke sub_pres_vlr_fsm_start()
sub_pres_vlr_fsm_start() starts the FSM, invokes the START event, and then this
FSM invariably always directly terminates when vsub->ms_not_reachable_flag ==
false.

So if it is false, there is not much use in instantiating a whole FSM instance
that just terminates again, we might as well directly issue the
parent-term-event and save some logging space.

The same condition is already in place in the vlr_proc_acc_fsm.c in
_proc_arq_vlr_node2_post_vlr() for CM Service Request and Paging Response. Now
also skip this for LU.

Change-Id: Id2303a795dfd381f76e94ff8ff2f495926ca8ba0
2018-12-11 11:37:27 +00:00
Stefan Sperling ad797ce2bb detach cancelled subscribers from VLR
When a subscriber is cancelled, fake an IMSI detach to
ensure that the subscriber gets removed from the VLR.

I am not entirely sure if this change is correct but
it does make TTCN3 test MSC_Tests.TC_gsup_cancel pass.

Change-Id: I5918106e4a94ba2e6c61bcd7b90d3bf0565513cc
Related: OS#2886
2018-12-11 09:16:15 +00:00
Neels Hofmeyr 325f106b34 drop gsm48 RR ciph mode compl from permitted initial messages
It is a message that is initially permitted, but it is in fact not handled in
the L3 code but already before, upon receiving
BSS_MAP_MSG_CIPHER_MODE_COMPLETE.

Change-Id: I0079f07271ca76bd457d0e700f3a736eb9066b47
2018-12-10 14:21:03 +01:00
Neels Hofmeyr 212c0c9bda move ASS-COMPL MGCP handling out of a_iface_bssap.c
BSSMAP Assignment Complete: sort MGCP handling upon Assignment Complete to the
proper locations. a_iface_bssap.c is not the right place to invoke the MGCP
related procedures.

- in a_iface_bssap.c only decode the IEs.
- call ran_conn_assign_compl() and pass decoded values.
- drop msc_assign_compl(), it was dead code; instead:
- add ran_conn_assign_compl()
- pass on all MGCP related info to msc_mgcp_ass_complete()
- move all MGCP ctx related handling from a_iface_bssap.c to msc_mgcp.c.

I'm dropping some comments to save some time, because if I adjust them IMHO
they would still anyway restate the obvious.

ran_conn_assign_compl() is now quite a thin shim, but it makes sense to have
it:

- This is the place that should tear down the ran_conn in case assignment
  failed, left for a future patch.

- In the light of upcoming inter-MSC handover, ran_conn_assign_compl() will be
  the place where the Assignment Complete message might be relayed to a remote
  MSC.

Change-Id: I8137215c443239bddf3e69b5715839a365b73b6c
2018-12-10 14:20:59 +01:00
Neels Hofmeyr 4e0dd536b4 ASS-COMPL: do not fire Sec Mode Compl event
BSSMAP Assignment Complete:
Do not invoke ran_conn_rx_sec_mode_compl(), that's just weird.

Instead this should call msc_assign_compl(), which is currently dead code and
does nothing ... and there are some more strings attached, being resolved in a
subsequent patch.

Change-Id: I448fdb783364628005437b3d866d1a076a9767d7
2018-12-07 15:04:33 +01:00
Neels Hofmeyr 80447ebe6c add VTY commands: mncc internal / external (== -M)
So far the only way to use external MNCC is to pass the -M cmdline arg:

  osmo-msc -M /path/to/socket

However, the osmo-msc.service file for systemd is installed by 'make install',
and hence it is quite impractical to depend on such a config item to be
required in the service file:

- It defies any scheme an operator may have in place to compose the
  osmo-msc.cfg file -- this option doesn't go in the .cfg file but needs
  separate action to add to the installed service file.

- After a make install or package upgrades / re-installations, this option will
  be plain overwritten silently, or lead to the need for resolving file
  conflicts.

The initial spark for this came from configuring the 35c3 GSM from cfg
templates.

Change-Id: I2ec59d5eba407f83295528b51b93678d446b9cee
2018-12-05 19:35:11 +00:00
Neels Hofmeyr 05c5680ba1 vty: mncc cfg: separate the 'mncc' from 'mncc-guard-timeout'
I want to add 'mncc internal' and 'mncc external' commands, and IMHO makes most
sense to have a common 'mncc' keyword to start MNCC config commands with. To
put it in terms of VTY online help:

  OsmoMSC(config-msc)# mncc ?
    internal       Use internal MNCC handler
    external       Use internal MNCC handler
    guard-timeout  Set global guard timeout

So far only the 'guard-timeout' exists, I want to add 'internal' and 'external'
in a subsequent commit.

Keep the old command 'mncc-guard-timeout' as deprecated alias. That means it
still works from old config files, but online documentation will omit it.

On 'write', write back the new format instead.

Rationale: see I2ec59d5eba407f83295528b51b93678d446b9cee

Change-Id: I52d69af48e1ddc87b3fb54bf66a01b1b8cbf5abe
2018-12-05 19:35:11 +00:00
Neels Hofmeyr fb153cbf8c msc_main: mncc: move mncc socket decision to after read_cfg
First step towards allowing to configure the MNCC socket path by config file.

Rationale: see I2ec59d5eba407f83295528b51b93678d446b9cee

Change-Id: Ifc87c1cacaa809d04fc23e8ccd761bee4509c805
2018-12-05 19:35:11 +00:00
Neels Hofmeyr a2ed9b50c6 cosmetic: msc_main.c: default args definition style
Explicitly name each arg with its default value, omit zero values, end last
item in comma.

Change-Id: I0e0f1e2c8722768b6c61fd6544911b20fe1af212
2018-12-05 19:35:11 +00:00
Philipp Maier 425bb8ea83 gsm_subscriber: make function msc_paging_request() static
The function msc_paging_request() is only called from within
gsm_subscriber.c but never from outside. Lets make it static.

Change-Id: I2efc8eac01a4dd8733118067eecf566c13062106
2018-12-05 16:19:34 +00:00
Neels Hofmeyr 7b61ffe69b GSM_EXTENSION_LENGTH -> VLR_MSISDN_LENGTH
gsm_subscriber.h contains some legacy cruft, part of which is that the VLR's
max MSISDN length should rather be defined in vlr.h. Same for GSM_NAME_LENGTH
-> VLR_NAME_LENGTH.

Adjust some sms_queue stuff that anyway includes vlr.h already.

Drop gsm_subscriber.h from vlr.h.

Add other (more concise) includes that thus become necessary, since the include
chain vlr.h->gsm_subscriber.h->gsm_data.h is no longer in place.

Change-Id: Iab5c507ec04fc2884187cf946f6ae2240e4a31f8
2018-11-30 22:46:15 +01:00
Neels Hofmeyr 8b6e536007 move gsm_auth_tuple to vlr.h as vlr_auth_tuple
Along goes GSM_KEYSEQ_INVAL as VLR_*.

It's where it logically belongs, and is almost the only reason why vlr.h
includes gsm_data.h. The remaining reason, GSM_EXTENSION_LENGTH, will be moved
by upcoming patch.

Change-Id: I122feae7ee3cbc59e941daef35a954bce29fec76
2018-11-30 22:46:15 +01:00
Neels Hofmeyr df6d2e3838 cosmetic: drop some unused opaque struct defs
Change-Id: I4d461dd39d0abdc4f2327445671459340ca1c946
2018-11-30 22:46:15 +01:00
Neels Hofmeyr 7992122bac combine several small .h in msc_common.h
For hysterical raisins, there are some header files that contain few
declarations, and where the name doesn't reflect the content. Combine them to
new msc_common.h:

- common.h
- common_cs.h
- osmo_msc.h

Change-Id: I9e3a587342f8d398fb27354a2f2475f8797cdb28
2018-11-30 22:46:15 +01:00
Neels Hofmeyr a8945ce37c move ran_conn declarations to new ran_conn.h
With the dawn of inter-BSC,MSC handover, adopting the MSC-A,-I,-T roles from
3GPP TS 49.008, the RAN connection shall soon be a neatly separated corner of
osmo-msc, so gravitate ran_conn decarations to files of matching name.

Also, the current chaos of API defined in files with mismatching/meaningless
names drives me crazy.

Change-Id: Ice31e6c43e46678538c65261f150c67e1d0845e5
2018-11-30 22:46:15 +01:00
Neels Hofmeyr 69d4395342 move subscr_conn.c to ran_conn.c
subscr_conn.c exclusively defines ran_conn related things. Rename the file.

Change-Id: I6aa6b335842116c717a554c981083a914724ee21
2018-11-30 22:46:15 +01:00
Neels Hofmeyr 3c20a5ee74 rename some RAN conn related stuff to ran_conn_*
Following previous rename of gsm_subscriber_connection:

Some functions and #defines are still called like "msc_conn" or just "msc_",
while they are clearly about a RAN conn.

To avoid confusion with the future separate concepts of MSC roles and a RAN
connection, rename all those to match the common "ran_conn" prefix.

Change-Id: Ia17a0a35f11911e00e19cafb5d7828d729a69640
2018-11-30 22:46:13 +01:00
Neels Hofmeyr c036b79918 rename gsm_subscriber_connection to ran_conn
In preparation for inter-BSC and inter-MSC handover, we need to separate the
subscriber management logic from the actual RAN connections. What better time
to finally rename gsm_subscriber_connection.

* Name choice:

In 2G, this is a connection to the BSS, but even though 3GPP TS commonly talk
of "BSS-A" and "BSS-B" when explaining handover, it's not good to call it
"bss_conn": in 3G a BSS is called RNS, IIUC.

The overall term for 2G (GERAN) and 3G (UTRAN) is RAN: Radio Access Network.

* Rationale:

A subscriber in the MSC so far has only one RAN connection, but e.g. for
inter-BSC handover, a second one needs to be created to handover to. Most of
the items in the former gsm_subscriber_connection are actually related to the
RAN, with only a few MM and RTP related items. So, as a first step, just rename
it to ran_conn, to cosmetically prepare for moving the not strictly RAN related
items away later.

Also:

- Rename some functions from msc_subscr_conn_* to ran_conn_*
- Rename "Subscr_Conn" FSM instance name to "RAN_conn"
- Rename SUBSCR_CONN_* to RAN_CONN_*

Change-Id: Ic595f7a558d3553c067f77dc67543ab59659707a
2018-11-30 22:45:42 +01:00
Neels Hofmeyr d03e728915 drop msc_compl_l3() return value
msc_compl_l3() always returns MSC_CONN_ACCEPT, because the conn FSM handles (or
should handle) all reject cases. The accept/reject return value is a legacy
from libbsc internally passing a conn over to libmsc, in osmo-nitb.

Drop enum msc_compl_l3_rc.
Change msc_compl_l3_rc() to return void.
Change all callers to always act like for acceptance, as they always did anyway.
Drop some local variables now no longer needed.
Adjust the comment to msc_compl_l3().
Drop a bunch of #if-0'd code from msc_compl_l3().

Change-Id: I759d15f4e820d5fc16397ed7210ce92308e52a09
2018-11-30 22:44:23 +01:00
Neels Hofmeyr f41658d52e rename gsm_encr to geran_encr, it is only applicable on GERAN
On UTRAN, Security Mode is used instead of Ciphering Command, which does not
feature an A5 algorithm id.

Change-Id: Idc7ca9da1aa13ae16f5db2cb1024676cbc770820
2018-11-30 22:44:23 +01:00
Neels Hofmeyr b0779bbcab populate gsm_subscriber_connection->encr during Ciph
The gsm_subscriber_connection->encr is never used. Use it.

When sending the Ciphering Mode Command, populate the encryption key.
When receivint the Ciphering Mode Complete, populate the chosen alg_id.

Out of paranoia, store the enc key only if the size is large enough.

Hence the vty_dump_one_conn() now reports the actually chosen A5 algorithm ID
used.

For 3G connections, though, this will still remain 0 in the VTY, since there is
no explicit A5 algorithm negotiated on UTRAN. (Security Mode Command and
Security Mode Complete instead of the GERAN Ciphering.)

(Note, 'struct gsm_encr encr' will be renamed to 'struct geran_encr geran_encr'
in Idc7ca9da1aa13ae16f5db2cb1024676cbc770820)

Change-Id: Ice2c470c360612249f97301944c6fdf9443c7dce
2018-11-30 22:44:23 +01:00
Neels Hofmeyr dbaab50da3 adjust copyright in subscr_conn.c
Change-Id: Ia89e2d343a850234557e365457705a11d26fd925
2018-11-30 22:44:23 +01:00
Neels Hofmeyr 7486a94f56 cosmetic: subscr_conn_fsm_auth_ciph() should be static
Only used in subscr_conn.c.

Change-Id: Iaa2c63d2b06f59d34e0465c40a98741f56ec526a
2018-11-30 22:44:23 +01:00
Neels Hofmeyr e777b5f575 drop unused SUBSCR_CONN_E_INVALID
The idea to catch uninitialized vars was completely moot. We pass events by
constants anyway.

Change-Id: I6f3c964ee04fec9a96f385199fb3141ac8d672d4
2018-11-30 22:44:23 +01:00
Vadim Yanitskiy 14e32a41d8 libmsc/gsm_04_11.c: fix: always use SAPI 3 for MT SMS
In I4a07ece80d8dd40b23da6bb1ffc9d3d745b54092 I've introduced a
regression. According to GSM TS 04.11, section 2.3, SAPI 3 shall
be used for both MO/MT SMS transmissions. Due to a mistake,
caused by misunderstanding of the meaning of trans->dlci, SAPI 3
was not assigned to SM transactions if there is already an active
RAN connection with subscriber. Let's fix this.

Let's also drop this misleading comment:

  /* FIXME: specify SACCH in case we already have active TCH */

because it's a task of the BSC/BTS to decide which lchan to use.

Change-Id: I08d0801a89d377441e95fb8e3dd27c8d587f89e9
Related: OS#3716
2018-11-30 19:43:28 +00:00
Neels Hofmeyr f9773b0b97 drop unused gsm_network->handover.active
gsm_network contains an int handover.active which is always zero. Drop it.

There is real handover code coming up soon, one part of this is to avoid
confusion.

The internal MNCC code queried it to decide whether to MNCC_BRIDGE or proxy RTP
(MNCC_FRAME_RECV). Since RTP is being handled by osmo-mgw since forever, drop
that entire condition from mncc_builtin.

Change-Id: Ie16e718266882588b38297121364ca0b7fdfe948
2018-11-30 04:56:59 +01:00
Neels Hofmeyr 344ee30bd4 drop unused gsm_subscr_conn->mncc_rtp_bridge
Change-Id: I322dc18cfe2cc573744261df837e719b5cf224ba
2018-11-30 04:49:12 +01:00
Vadim Yanitskiy 24e025e3e2 libmsc/gsm_04_11.c: refactor MT SMS message handling
According to GSM TS 04.11, the SMC (Short Message Control) state
machine is a part of CM-sublayer of L3, that is responsible for
connection management (establisment and releasing), and SM-RP
(Relay Protocol) message delivery.

For some reason, the connection establisment request from SMC
(GSM411_MMSMS_EST_REQ) was not handled properly - it was
always assumed that connection is already established.

This is why the code initiating a MT (Mobile Terminated) SMS
transfer had to establish a radio connection with subscriber
manually.

Let's benefit from having the SMC state machine, and offload
connection establishment to it. This change makes the local
implementation closer to GSM TS 04.11, and facilitates the
further integration of GSUP transport.

NOTE: the expected unit test output is changed, because now we
always allocate a transaction first, and then establish a
connection, not vice versa.

Change-Id: I4a07ece80d8dd40b23da6bb1ffc9d3d745b54092
2018-11-29 02:54:54 +07:00
Ivan Kluchnikov 9bd4fd601a libmsc/transaction: introduce trans_find_by_sm_rp_mr()
According to GSM TS 04.11, section 8.2.3, the RP Message Reference
is a mandatory field for all messages on the SM-RL (SM Relay Layer),
that is used to link an RP-ACK or RP-ERROR message to the associated
(preceding) RP-DATA or RP-SMMA message transfer attempt.

This change extends the transaction state structure with SM-RP-MR,
and introduces a new function for matching transactions within a
given connection by this reference.

Change-Id: Ice47c37ecef4416e65ecee8931d946c915316791
2018-11-29 02:54:54 +07:00
Vadim Yanitskiy 87c7ea3c5a libmsc/gsm_09_11.c: drop redundant assertion of stored msgb
It's already asserted at the beginning of handle_paging_event().

Change-Id: Ia558e11c6bde7bff130e4b76a4402ecc8068f1ed
2018-11-28 17:01:29 +00:00
Vadim Yanitskiy 380b2195cf libmsc/transaction.c: cosmetic: fix typo
Change-Id: I6d72b856e40ba81ee2f1e60693055705b5993b09
2018-11-27 15:14:31 +07:00
Vadim Yanitskiy 535f110d09 libmsc/gsm_04_11.c: refactor RP-DATA header validation
It's much better to have both RP-DATA header parsing and validation
code in a single function. There is no need to pass all the header
fields (DA, OA, UI) to gsm411_rx_rp_ud() because they are not
used there.

Change-Id: Iaf295949148e2a613c5403d1f7a926fcd6849c15
2018-11-25 21:48:29 +07:00
Vadim Yanitskiy 0c8998f066 libmsc/gsm_04_11.c: don't pass msgb to gsm411_rx_rp_{ack|error}
Passing a message buffer containing the whole encoded message, and
a pointer to the RP header (struct gsm411_rp_hdr) is redundant.

Change-Id: I0eb5c7c485ab7d109966431bd875fa74e00936d7
2018-11-25 21:48:29 +07:00
Philipp Maier 54729d6e5e osmo_msc: remove unused parameter from msc_dtap()
The parameter link_id in the function msc_dtap() is unused. Lets remove
it.

Change-Id: I7ba67b0cb514c91bc87a7b396ed3962b7a68e7da
2018-11-23 10:04:29 +00:00
Vadim Yanitskiy c350c093c4 msc/gsm_04_11.h: use forward-declaration for _gsm411_sms_trans_free()
Change-Id: I87f96abd2b2d446751d8f95c9164c5eb6a58e66c
2018-11-21 20:52:36 +07:00
Vadim Yanitskiy 0cd761c604 libmsc/db.c: cosmetic: mark missing breaks in switch as intended
Change-Id: I3f4f34ecd0c5bb2d1a675ad5c4669fcffb87f292
Closes: Coverity CID#148209
2018-11-21 19:48:16 +07:00
Max 58099f699f Use libosmocore to function to parse cipher mode reject cause
This allow us to handle both regular and extended cause transparently.

Change-Id: I7742ac41dd0642a5a40ce79d23250f8d9e6ae556
Related: OS#3187
2018-11-20 17:27:40 +00:00
Max f1329c533d Use BSSAP-specific TLV parser from libosmocore
Change-Id: Iae1a3ffcebf1b0b95e61cd5dffe7ef734796fcfc
2018-11-20 15:24:54 +00:00
Pau Espin 3710623e36 msc: vty: Fix integer printf formatting
| ../../../git/src/libmsc/msc_vty.c:1202:44: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t {aka long long unsigned int}' [-Wformat=]
|   vty_out(vty, "Location Update         : %lu attach, %lu normal, %lu periodic%s",
|                                             ^

Change-Id: Iae1c0b20a519ce71a21f72cea3c63694ef10adb4
2018-11-19 11:11:17 +01:00
Max 48a595e8ba Fix build with latest libosmocore
Remove locally defined function which conflicts with the one in
libosmocore.

Change-Id: I464c16034b76e4599ac42857f60442c3fd000c75
2018-11-19 09:48:22 +00:00
Keith Whyte bea25f1302 libmsc: Don't send SMS STATUS REPORT locally if the ESME accepted it.
When using smpp-first, after the ESME accepts our STATUS REPORT,
we were sending it locally into gsm340_rx_sms_submit() anyway.
In the case of the ESME mirroring the report back to us, this
would result in two copies of the status report in the SMS
database, which were also both then delivered to the MS.
This causes no visible error to the user but is a waste of radio
resources.

With this patch, we check if it is the sms_report that has had 
receiver set in sms_route_mt_sms() and not the original SMS we
are reporting on, which of course already has receiver set.

Change-Id: I3529b89535800eaa1127721d613fa7bbcb8b23be
2018-11-19 09:32:20 +00:00
Philipp Maier 6038ad4cf9 vlr: drop unused is_ps parameter in vlr_subscr_req_lu()
the function vlr_subscr_req_lu() has a parameter is_ps, which is set
to vsub->vlr->cfg.is_ps by the only caller in vlr_lu_fsm.c. Inside the
function one can see that vsub->vlr->cfg.is_ps is used directly to
decide between PS or CS LU, we could also use is_ps there. Presumably
the parameter is_ps had been abandonned in an early development stage
and was not removed, so lets drop the parameter.

Change-Id: Id239721773b90099d122b232dae1ba457be9d255
2018-11-16 18:11:50 +00:00
Max c51609aa5c vty: add command to show all known BSC
Change-Id: I247fdce00f43072b0a2a0122b80bd40cdd9e0128
2018-11-13 15:59:39 +00:00
Philipp Maier 5b6ccce1c6 cosmetic: remove forgotten debug printf
the control interface command subscriber-list-active-v1 contains a stray
debug printf, lets remove it.

Change-Id: I085cf7b4a45708ccb883f70f71f4fbcfda58d332
2018-11-08 11:10:15 +01:00
Max 366390d81a Add counters for BSSMAP cipher mode messages
Count COMPLETE and REJECT messages. Besides general troubleshooting
that's also useful for TTCN-3 tests to check that OsmoMSC processed
those messages as expected.

Change-Id: I5822b2b38b64f1a691b26c926a8e2bece21dc624
Related: OS#3187
2018-11-02 22:06:09 +00:00
Max 662e2ba73e Properly parse cause in cipher mode reject
Use appropriate TLV routines to get and log the value of rejection
cause.

Change-Id: I26b3eb0deff6dbd217b23d284bbc6e6a9eebc8e6
Fixes: OS#3187
2018-11-02 22:06:09 +00:00
Neels Hofmeyr dd2aeba02c lu_fsm: result cb: use proper cause type (warning/coverity)
enum gsm48_gmm_cause is the wrong enum to pass to lu_fsm_failure(). Use enum
gsm48_reject_value instead.

Change-Id: If661f72056decb28c0ee82ad2449630a24d4f31c
2018-10-30 19:51:15 +01:00
Philipp Maier 9ca7b31cbf gsm_04_08_cc: Add global guard timer for MNCC
The external MNCC handler may hang indefinitely in cases where the remote
end of the MNCC ceases to work properly. Add a global guard timer to
make sure the call reaches ACTIVE state.

Change-Id: I7375d1e17cd746aac4eadfe1e587e82cf1630d3d
Related: OS#3599
2018-10-24 10:27:39 +02:00
Harald Welte f6400737f9 gsm0407_is_duplicate(): Handle error ret of gsm0407_pdisc_ctr_bin()
Change-Id: If9525694bcbc5c6c0e622e899dd634dc11ed61c4
Fixes: Coverity CID#182702
2018-10-21 12:56:20 +02:00
Philipp Maier 782ccec526 msc_mgcp: move mncc struct initalization to where its actually needed
The function _handle_error() initalizes a struct gsm_mncc variable
on startup. The initalization accesses mgcp_ctx->trans->callref. All
this is done before the assertion on mgcp_ctx. Later in the code one
finds an if which tests on mgcp_ctx->free_ctx. This is the only part of
the code that accesses the mncc struct variable. We should move the
initalization there as well.

- Move initalization of struct gsm_mncc mncc into the if body
  that uses it.

Change-Id: I86983eabd999c4275dcc0e4a169ef2aa1e33c747
Related: OS#3635
2018-10-08 17:18:37 +02:00
Neels Hofmeyr d0756b152b GSUP client: send CN domain IE on LU request
Give the HLR a chance to send us updated subscriber data by indicating the CN
domain to be Circuit Switched, only during a LU Request GSUP message.

Adjust msc_vlr_tests to expect the added GSUP CN domain IE to indicate CS, i.e.
append '280102'.

Related: OS#3601
Change-Id: I0c2d33fbfdb4728e480679120d06b7f3a2ccfd76
2018-09-30 23:55:25 +02:00
Stefan Sperling 722f2b4161 fix a use-after-free in msc_mgcp.c:_handle_error()
Move code which needs to test the mgcp_ctx->free_ctx flag upwards
such that it runs before we're calling functions which will
potentially free mgcp_ctx. The code being moved up takes effect
only in case mgcp_ctx won't be freed, so there should be no
functional difference.

Change-Id: I5df17c19e2a68c019f7eaf582b14585caa54b32a
Related: OS#2885
2018-09-28 14:26:35 +02:00
Philipp Maier e2497f70bb mncc: fix byte ordering of IP-Address in mncc
At the moment osmo-msc populates the member ip in struct gsm_mncc_rtp
with the wrong byte ordering. This causes LCR or
osmo-sip-connector to receive the IP address in the wrong order, which
eventually leads into a reversed IP address in the SDP part of the SIP
messages.

Change-Id: I86148179b549b511528e4c65213eb6c204cc609e
Related: OS#3431
2018-09-28 10:40:40 +02:00
Neels Hofmeyr 86ed06c048 vty: add SCCP related vty commands
Depends: I214ea51fc6bfa2a9a4dd7c34b43add0c77ffe22e (libosmo-sccp)
Change-Id: I245b153785f615b998bb5279cb8d93787d57b4b7
2018-09-27 03:35:02 +02:00
Neels Hofmeyr 68cf957bfd fix Classmark Update without VLR subscriber
This recent patch moves Classmark storage to the VLR subscriber, and introduced
a segfault when a Classmark Update is received during IMSI detach:

commit 986fe7ed18
change-id I27081bf6e9e017923b2d02607f7ea06beddad82a
Mon Sep 17 01:12:13 2018 +0200
"store classmark in vlr_subscr, not conn"

It assumed that we would never accept any Classmark Update messages unless we
also have a valid subscriber for it. Well, that is proven wrong by the
ttcn3-msc-test TC_imsi_detach_by_imsi(), which brings osmo-msc to its knees.

Fix: in case of no valid vlr_subscr being present, store Classmark in the conn
temporarily, and copy any received Classmark to VLR subscriber as soon as it
gets associated with the conn (if at all).

Change-Id: Ib2a2ae6bf86e8f29fc6751a8b5cdb7187cd70290
2018-09-18 16:13:58 +02:00
Neels Hofmeyr 3117b701c8 A5/n Ciph: request Classmark Update if missing
When the VLR requests a Ciphering Mode with vlr_ops.set_ciph_mode(), and if we
need a ciph algo flag from a Classmark information that is not yet known
(usually CM 2 during LU), send a BSSMAP Classmark Request to get it.

To manage the intermission of the Classmark Request, add
- msc_classmark_request_then_cipher_mode_cmd(),
- state SUBSCR_CONN_S_WAIT_CLASSMARK_UPDATE,
- event SUBSCR_CONN_E_CLASSMARK_UPDATE.

From state AUTH_CIPH, switch to state WAIT_CLASSMARK_UPDATE. Once the BSSMAP
Classmark Response, is received, switch back to SUBSCR_CONN_S_AUTH_CIPH and
re-initiate Ciphering Mode.

To be able to re-enter the Ciphering Mode algo decision, factor it out into
msc_geran_set_cipher_mode().

Rationale:

In the following commit, essentially we stopped supporting A5/3 ciphering:

commit 71330720b6
"MSC: Intersect configured A5 algorithms with MS-supported ones"
Change-Id: Id124923ee52a357cb7d3e04d33f585214774f3a3

A5/3 was no longer supported because from that commit on, we strictly checked
the MS-supported ciphers, but we did not have Classmark 2 available during
Location Updating.

This patch changes that: when Classmark 2 is missing, actively request it by a
BSSMAP Classmark Request; continue Ciphering only after the Response. Always
request missing Classmark, even if a lesser cipher were configured available.

If the Classmark Update response fails to come in, cause an attach failure.
Instead, we could attempt to use a lesser cipher that is also enabled. That is
left as a future feature, should that become relevant. I think it's unlikely.

Technically, we could now end up requesting a Classmark Updating both during LU
(vlr_lu_fsm) and CM Service/Paging Response (proc_arq_fsm), but in practice the
only time we lack a Classmark is: during Location Updating with A5/3 enabled.
A5/1 support is indicated in CM1 which is always available, and A5/3 support is
indicated in CM2, which is always available during CM Service Request as well
as Paging Response. So this patch has practical relevance only for Location
Updating. For networks that permit only A5/3, this patch fixes Location
Updating. For networks that support A5/3 and A5/1, so far we always used A5/1
during LU, and after this patch we request CM2 and likely use A5/3 instead.

In msc_vlr_test_gsm_ciph, verify that requesting Classmark 2 for A5/3 works
during LU. Also verify that the lack of a Classmark Response results in attach
failure.

In msc_vlr_test_gsm_ciph, a hacky unit test fakes a situation where a CM2 is
missing during proc_arq_fsm and proves that that code path works, even though
the practical relevance is currently zero. It would only become interesting if
ciphering algorithms A5/4 and higher became relevant, because support of those
would be indicated in Classmark 3, which would always require a Classmark
Request.

Related: OS#3043
Depends: I4a2e1d3923e33912579c4180aa1ff8e8f5abb7e7 (libosmocore)
Change-Id: I73c7cb6a86624695bd9c0f59abb72e2fdc655131
2018-09-17 02:08:07 +02:00
Neels Hofmeyr 986fe7ed18 store classmark in vlr_subscr, not conn
Store all Classmark information in the VLR.

So, we now always know the Classmark 1 (mandatory IE for LU). This is visible
in the msc_vlr_tests -- they no longer indicate "assuming A5/1 is supported"
because classmark 1 is missing, because we now know the Classmark 1.

Rationale:

During Location Updating, we receive Classmark 1; during CM Service Request and
Paging Response, we receive Classmark 2. So far we stored these only for the
duration of the conn, so as soon as a LU is complete, we would forget CM1.

In other words, for anything else than a LU Request, we had no Classmark 1
available at all.

During Ciphering Mode Command, we rely on Classmark 1 to determine whether A5/1
is supported. That is moot if we don't even have a Classmark 1 for any CM
Service Request or Paging Response initiated connections.

The only reason that A5/1 worked is that we assume A5/1 to work if Classmark 1
is missing. To add to the confusion, if a phone indicated that it did *not*
support A5/1 in the Classmark 1, according to spec we're supposed to not
service it at all. A code comment however says that we instead want to heed the
flag -- which so far was only present in a Location Updating initiated
connection. Now we can make this decision without assuming things.

This got my attention while hacking on sending a BSSMAP Classmark Request from
the MSC if it finds missing Classmark information, and was surprised to see it
it lacking CM1 to decide about A5/1.

Change-Id: I27081bf6e9e017923b2d02607f7ea06beddad82a
2018-09-17 01:12:13 +02:00
Neels Hofmeyr 36115c9d9a cosmetic: mute "COMPLETE_LAYER_3 not permitted"
For networks without Authentication, the conn is already accepted when
SUBSCR_CONN_E_COMPLETE_LAYER_3 is emitted. Mute that misleading error message.
All is actually fine.

Adjust expected test logs.

Change-Id: I2d19d0a7cf3226ee1456f75a68e007ba98232402
2018-08-23 15:52:43 +02:00
Pau Espin 060a6c4d97 msc: Set talloc ctx for osmo_signal structures
Otherwise they end up in the NULL ctx.

Depends: libosmocore Change-Id Id58ca18eb826b8f4183a7cf0dbb2b38cba702a09

Change-Id: I5d5b456eb85fbdb0ca2140c56ebf3d207b4a0bba
2018-08-17 07:06:37 +00:00
Vadim Yanitskiy 381370b82a osmo-msc: track the use of talloc NULL memory contexts
Tracking NULL memory contexts allows one to detect memory chunks,
allocated outside the application's root context, which in most
cases are results of some mistake.

In b874486e8e the repotring of
NULL-context state was introduced, but without asking talloc
to track the use of NULL memory contexts it doesn't make sense.

Change-Id: I4b5e3946ee21c7d0ed6c66b1059dbce5ad312f88
2018-08-14 19:17:43 +07:00
Vadim Yanitskiy d8d4d8caae osmo-msc: free the VTY talloc context on exit
This is a follow up change before enabling the track of NULL talloc
contexts. Since there is no other way to deinitialize libosmovty,
let's free its root context on exit. Otherwise one would see
lots of memory chunks on exit...

Change-Id: I278f85f023210de6b4626d4493d10d20996f606a
2018-08-14 19:13:15 +07:00
Pau Espin b874486e8e osmo-msc: Improve shutdown due to signal and print talloc report on exit
Same as we do in osmo-hlr.

Change-Id: If6ea9171fd79f03251342f75987690b0d9dc3814
2018-08-13 16:30:28 +02:00
Keith Whyte f02d17f75a libmsc/mncc_sock.c: Add lchan_type_offset in queue_hello()
lchan_type was removed from gsm_mncc and the hello message
on initial import from legacy OpenBSC in 
Change-Id: Id3705236350d5f69e447046b0a764bbabc3d493c

This patch follows on from Change-Id: Ia02373a36df7605507ee3de49173a9fd6547b726
which reintroduced lchan_type to the gsm_mncc struct.

This patch restores the lchan_type_offset to the hello protocol message

Without this patch, LCR will issue an error and disconnect from the MNCC socket.

Change-Id: I65312082fa5dc0721170f923840e992ef9481a63
Closes: OS#3461
2018-08-10 14:31:30 +00:00
Philipp Maier 8ad3dacebb mgcp: use codec information returned with ASSIGNMENT COMPL.
When the assignment completes a choosen codec is returned. At the
moment we do not use this information.

- add struct members for codec info (both, RAN and CN)
- parse codec info in BSSMAP ASSIGNMENT COMPLETE
- use codec info on mgcp

Since the MNCC API is not complete yet, we currently only use the
codec info only on the internal MNCC yet.

Change-Id: I9d5b1cd016d9a058b22a367d0e5e9f2ef447931a
Related: OS#2728
2018-08-07 16:51:30 +00:00
Vadim Yanitskiy 6cc377d359 RRLP: print log when sending a position request
Change-Id: Ia2446e05f63ac219f630ab9db1ea9bf305f0a4b9
2018-08-05 22:42:04 +07:00
Vadim Yanitskiy 1b8913090e RRLP: migrate and share mode definitions from msc_vty.c
Change-Id: I9560e6eab0ad1b5d57ca732741fc0b6f61f1a4a2
2018-08-05 11:33:20 +00:00
Vadim Yanitskiy 1f9b0865ec RRLP: fix: actually init the RRLP signal handlers
Change-Id: I3618b4af48839d6d4b747be4eef2f57fa8f870c9
Closes: OS#3129
2018-08-05 11:33:20 +00:00
Vadim Yanitskiy d01b594092 RRLP: properly name the init function
We don't actually deal with DSO loading here...

Change-Id: I24d0c9ad52f07f08176ad129878b48a591a3af6c
2018-08-05 11:33:20 +00:00
Harald Welte 1ea6baf1ec Remove local libgsupclient; Use libosmo-gsup-client from osmo-hlr
osmo-hlr has recently (as of Change-Id
Iad227bb477d64da30dd6bfbbe1bd0c0a55be9474) a working shared library
implementation of libosmo-gsup-client.

We can remove the local implementation in osmo-msc and use the
system-installed shared library instead.

Change-Id: I6f542945403cf2e3ddac419186b09ec0e2d43b69
2018-08-05 11:20:21 +02:00
Vadim Yanitskiy 0622ef5308 libmsc/gsm_09_11.c: clean up the local GSM 04.80 API
Since we don't process SS/USSD requests in OsmoMSC anymore, there
are some useless GSM 04.80 functions remained from the past.

In particular, this change does the following:

  - removes both gsm0480_send_{ussd_response|return_error}
    functions because they are not used anymore;

  - changes symbol prefix from 'gsm0480_' to 'msc_', in order to
    avoid possible conflicts with the libosmogsm's GSM 04.80 API;

  - cleans up useless includes;

Change-Id: I2990d8627bce0ce6afb1dcf6b11bb194292380d3
2018-08-05 07:15:01 +00:00
Vadim Yanitskiy 096be50c82 libmsc/rrlp.c: add missing include
Change-Id: Id33c9e5c04d61d08110ae80209f73ed14a5ef59c
2018-08-04 01:17:44 +07:00
Harald Welte a44b970592 migrate to oap_client in libosmogsm
libosmogsm in libosmocore.git from Change-Id
Ie36729996abd30b84d1c30a09f62ebc6a9794950 onwards contains oap_client.c,
so we don't need our local copy here in this repo anymore.

Change-Id: Ib6496c35d0ce6eb531e97129dc45a9f68e503b34
Requires: libosmocore.git Change-Id Ie36729996abd30b84d1c30a09f62ebc6a9794950
2018-07-31 17:21:24 +00:00
Vadim Yanitskiy ad64e2a8c7 libmsc/gsm_09_11.c: introduce counter for active sessions
Change-Id: Ia17e7c747fffb5267d3ca5bc4193c1be4a57ef3a
2018-07-30 21:28:01 +02:00
Vadim Yanitskiy 8e25cc5298 libmsc/gsm_09_11.c: introduce rate counters for NC_SS sessions
This change introduces some new rate counters for call-independent
SS/USSD connections. As OsmoMSC doesn't handle the messages itself,
and only responsible for dispatching messages between both
A and GSUP interfaces, the following is taken into account:

  - MS-initiated and network-initiated requests to establish
    a NC SS/USSD session (transaction) - "nc_ss:m{o|t}_requests";

  - successfully established MS-initiated and network-initiated
    SS/USSD sessions (transactions) - "nc_ss:m{o|t}_established".

Change-Id: I23c9475abc9951d82f3342fdc5aaa367836f7741
2018-07-30 21:28:01 +02:00
Vadim Yanitskiy fcc24ed553 libmsc/gsm_09_11.c: properly handle MS-initiated release
According to GSM TS 02.90, section 4.3, release of the connection
used for SS/USSD is normally the responsibility of the network.
But the user may also initiate connection release, e.g. by
pressing the 'red button'.

TTCN-3 test case: I7936ed5072ed2ae02f039dc90a1fece1e7f70a70
Change-Id: I76fc277bf9db614a97824b1541cd5bb75aa3e29d
2018-07-30 21:28:01 +02:00
Vadim Yanitskiy f2f83b07f3 libmsc/gsm_09_11.c: implement network-initiated sessions
This change introduces a possibility to establish network-initiated
SS/USSD transactions with a subscriber in either IDLE, or DEDICATED
state. In the first case, a new transaction is established using
Paging procedure. If a subscriber already has an active connection,
a separate new transaction is established.

TTCN-3 test case: I073893c6e11be27e9e36f98f11c1491d0c173985
Change-Id: Ief14f8914ef013bd6efd7be842f81fbf053f02e2
2018-07-30 21:28:01 +02:00
Vadim Yanitskiy 8a6ef55ec5 libmsc/gsm_09_11.c: forward SS/USSD messages to HLR over GSUP
In order to be able to support external SS/USSD gateway, we should
not terminate the GSM 04.80 messages at OsmoMSC. Instead, we need
to follow the GSM TS 09.11 specification, and forward all messages
unhandled by OsmoMSC to OsmoHLR over GSUP protocol.

This change implements forwarding of MO SS/USSD messages. The
forwarding assumes transcoding between GSM 04.80 messages and
GSUP messages. The payload of Facility IE is carried 'as is'.

As a side-effect, this will disable the osmo-msc internal handler
implementing the "*#100#" for obtaining the subscribers own phone
number.  In order to re-gain this functionality, you will need a
modern osmo-hlr (Change-Id I1d09fab810a6bb9ab02904de72dbc9e8a414f9f9)
and the following line in your osmo-hlr.cfg:
 hlr
  ussd route prefix *#100# internal own-msisdn

TTCN-3 test case: I01de73aced6057328a121577a5a83bc2615fb2d4
Change-Id: Ide5f7e350b537db80cd8326fc59c8bf2e01cb68c
2018-07-30 15:35:14 +00:00
Vadim Yanitskiy 8a0e2588e2 libvlr/vlr.c: forward unhandled GSUP messages towards MSC
Some internal sub-systems, such as SS/USSD or SMS implementation,
may also need to use GSUP connection with HLR. Previously, it was
only available within the libvlr code, and nowhere else.

Let's introduce the generic GSUP message router, which will
receive messages unhandled by VLR itself, and route them to
a handler depending on the message type.

Change-Id: Ib8146ce5788c8f249dcaa39d61bd0388574bf892
2018-07-29 16:22:06 +02:00
Neels Hofmeyr a4efe3f435 cosmetic: typos in log and comment
Change-Id: I2416d9a45e88f4317aa8e6644f5581a6f4f119c8
2018-07-26 20:31:55 +02:00
Neels Hofmeyr c18c2bf9fc Iu MGCP: no need to loopback on the cn side
Change-Id: I501a7846c76dd703beb3991362b1ccbd62dfd155
2018-07-26 20:31:55 +02:00
Neels Hofmeyr fa391ee86c vlr_access_req_fsm.c: use osmo_strlcpy and avoid compiler error
gcc 8.1.0:
../../../../src/osmo-msc/src/libvlr/vlr_access_req_fsm.c:679:3: error: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 31 [-Werror=stringop-truncation]
   strncpy(par->imsi, mi_string, sizeof(par->imsi)-1);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Mobile Identity is a union of various kinds, but the IMSI is at most 15
digits, so truncation is "intended". I hope other layers validate the correct
length of an IMSI MI.

Change-Id: I0a17a188fc91e42e252ae4bf1d6cd0bf0e5eb077
2018-07-26 20:31:55 +02:00
Harald Welte 27989d41dc libmsc: move L3 call-control to separate C file (gsm_04_08_cc.c)
The CC sub-layer is fairly self-contained, so let's move it to
a separate C source file.  The old gsm_04_08.c file now only
contains the 04.07 / DTAP core and MM sub-layer handling.

I did this initially as an experiment to see how self-contained
our CC implementation really is.  Given this rather straight-forward
patch builds fine, CC really is self-contained (yay!).

Change-Id: Idb8dd7a8d9d8b4a28c492f12da3cc3305b695cca
2018-07-25 18:53:57 +00:00
Stefan Sperling 9fbb6008e0 VLR: reject overlong IMSIs in ID RESP messages
Overlong IMSIs in ID RESP messages were accepted and used in
truncated form.

Log an error when truncation occurs, and prevent truncated IMSIs
from being installed for a subscriber via ID RESP messages.
Other code paths leading to vlr_subscr_set_imsi() with truncated
IMSIs will only a leave a trail of log entries for now, because
vlr_subscr_set_imsi() is currently unable to return an error code.

Change-Id: I785c994f41a646d8d83d3d82f5a9ae6b572eb641
Related: OS#2864
2018-06-25 19:21:57 +00:00
Pau Espin a232eeb2e4 msc_main: Fix typo in description of version param
Change-Id: I553a2695aec19517b3c67f5eb5d495180e24d7e8
2018-06-15 14:58:59 +02:00
Vadim Yanitskiy 5df4e4ddde libmsc/gsm_04_80.c: make the API abstract from ss_request struct
There is no need to pass a pointer to a ss_request struct when
calling the gsm0480_send_ussd_* functions, because they only
use both transaction ID and InvokeID from there, which may
be passed directly.

This change allows one to use this API without parsing the
whole GSM 04.80 message, or when parsing is failed. Moreover,
if InvokeID is not available, one can pass any incorrect,
(e.g. negative) value, so the universal NULL tag will be used.
Finally, setting a TI flag is also up to the caller.

Change-Id: I13d5abbfdcf8238ebaf0566c420f09cd9255b648
2018-06-12 23:31:34 +07:00
Vadim Yanitskiy 9aec25e464 libmsc/gsm_09_11.c: properly indicate transaction errors
Previously it was intended that we are always parsing the
whole GSM 04.80 message, including the Invoke ID. But
there is no need to do that, since we are going to
forward the Facility IE payload to HLR in near future.

Moreover, there was a mistake (my bad) - transaction is
being established before parsing of the message, so the
req structure remains uninitialized until that.

Let's just send RELEASE COMPLETE message without any Cause or
Facility IEs. We could indicate a problem using the first one,
but according to GSM TS 04.80, the Cause IE only makes sense
when "its functional handling is specified in the service
description or GSM TS 09.11".

Change-Id: Iecba2dccada9bbcdeb3a9dfd868719aeedc07022
2018-06-12 23:07:36 +07:00
Vadim Yanitskiy f5b9e6cdf6 libmsc/gsm_04_08.c: expose gsm48_tx_simple()
This function could be also used by other parts of code, e.g.
by gsm_04_11.c or by gsm_09_11.c, during initialization of
a new transaction. No need to hide it.

Change-Id: I9a9d17fca4901163dae10d76455aa4cf54497156
2018-06-12 23:07:26 +07:00
Vadim Yanitskiy 5b860faf4e Use proper naming for GSM TS 09.11 implementation
During a long time, we had both file and symbol names, actually
related to Supplementary Services, with the 'ussd' abbreviation.
This is not absolutely wrong, but isn't correct at the same time.

USSD is a kind of Supplementary Services, this is only a part
of them. There are also 'structured' Supplementary Services,
which can be call related or call independent.

The "Signalling interworking for supplementary services" is
defined by GSM TS 09.11, and this is exactly what MSC should
implement. Let's use the specification number for naming, as
we do e.g. in the GSM 04.11 (SMS) implementation.

Change-Id: Ic1eaceddb58132318e4e941be542da34b8ebefe1
2018-06-12 06:14:36 +07:00
Vadim Yanitskiy 10c6419798 libmsc/ussd.c: use connection ref-counting and transactions
A subscriber may have a few active transactions at the same time.
For example, one can receive SMS messages during a call, or during
an active SS/USSD session.

We already have connection ref-counting and transactions for CC
and SMS, so let's also use both for SS/USSD.

Change-Id: I21c6777cb88f1f4f80f75dcd39734e952bd4e8b0
2018-06-10 22:28:40 +07:00
Vadim Yanitskiy 846efcba95 libmsc: properly name the MSC_CONN_USE token for SS
Previously the MSC_CONN_USE token for Supplementary Services was
called 'MSC_CONN_USE_TRANS_USSD'. Non-call related Supplementary
Services is not only about USSD, so let's rename it.

Change-Id: I5b3517c87a32fa64dea6b0c912f2b76c5c25a112
2018-06-10 22:22:49 +07:00
Vadim Yanitskiy 635f98cf31 libmsc/ussd.c: FIX: properly indicate errors
There are error and problem codes defined by GSM TS 04.80:

  - Error codes are used when a message is structured correctly,
    but something is wrong in context of the current operation.
    Usually they are carried by 'Return Error' component.

  - Problem codes are used when something is wrong with the
    message structure, or with carried values. They are
    carried by 'Reject' component.

    There are three groups of them (see table 3.13):

      - General Problem Codes (table 3.14),
      - Invoke Problem Codes (table 3.15),
      - Return Result Problem Codes (table 3.16),
      - Return Error Problem Codes (table 3.17).

    The first group is general purpose, and can be sent in
    response to any kind of message, excluding 'Reject' itself.
    Other ones are bound to specific component types, such as
    'Invoke', 'Return Result' and 'Return Error'.

For some reason, a 'Reject' component with the general problem
code 'GSM_0480_GEN_PROB_CODE_UNRECOGNISED' was always used in
OsmoMSC. Even when the message structure is correct.

Let's properly indicate errors in the following way:

  - 'Reject' with GSM_0480_GEN_PROB_CODE_UNRECOGNISED
    when the gsm0480_decode_ss_request() fails to decode
    a message. It can only return 0 or 1, so it's hard to
    guess which exact part of message caused the error.

  - 'Return Error' with GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION
    when the operation code is not related to USSD.

  - 'Return Error' with GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE
    when the requested USSD code is unhandled (not supported).

There is a TTCN-3 testcase for this:

https://gerrit.osmocom.org/9470/

Change-Id: I800e7ec98dc9d0bca2d45a8b8255d60253d63e14
2018-06-08 17:13:44 +07:00
Philipp Maier 5046db98b1 mgcp: hack to keep IuUP working
Since change If9a81d057f73150e483286472e73c45e7a453a6d removes the
RTP loopback at the beginning. This also means that the Hack we
do to run the IuUP negotiation via looping back the first few
RTP packets will not work anymore. However, we should keep that
hack as long as we do not have IuUP support in the MGW.

- Start RTP connection in loopback mode for IuUP

Change-Id: I4c7d90de4dc87e8baf7cf4a0c69d0e9e8c92e27b
2018-05-29 12:02:38 +02:00
Philipp Maier 65d8d0d9b5 mgcp: do not start connections in loopback mode
When the MSC creates the connections for the BSS side and for the
PBX

Change-Id: If9a81d057f73150e483286472e73c45e7a453a6d
2018-05-29 10:03:41 +02:00
Stefan Sperling defc3c8caf implement periodic Location Update expiry in the VLR
Remove subscribers which fail to send periodic Location Updates from the
list of subscribers known to the VLR. This complements the IMSI detach
procedure: periodic LU expiry triggers an implicit IMSI detach.

Expired subscribers are purged from a periodic timer which iterates
over all subscribers once per minute.

Subscribers with an active connection do not expire. This is controlled
by the subscriber conn FSM which sets a subscriber's the LU expiry timeout
value to GSM_SUBSCRIBER_NO_EXPIRATION while a connection is active.

Add support for fake time with osmo_clock_gettime() to msc_vlr tests.

This functionality existed in OpenBSC but was lost during the nitb split.
This code took some inspiration from the OpenBSC implementation.

Related: OS#1976
Change-Id: Iebdee8b12d22acfcfb265ee41e71cfc8d9eb3ba9
2018-05-23 14:55:00 +02:00
Stefan Sperling 2d95ab67d1 remove redundant unconditional PKG_CHECK_MODULES for libsmpp
The configure script should only check for libsmpp with --enable-smpp.

Also, disable the build of smpp_mirror with --disable-smpp.

Change-Id: Ic4a8a5c970c04a6257ee4c8e3977e98c4ddfda13
Fixes: a55dda703f
Related: If7e1af11cdac8587bb4d66fb4eacee4b79945359
Related: OS#3232
2018-05-18 14:09:33 +02:00
Philipp Maier f913e5f575 a_reset: cleanup + remove dead code
a_reset.c/h was originally developed to be used in both, bsc and
msc without changes. Unfortunately no suitable library has been
found for a_reset.c/h so the file ended up as duplicated code in
both split brances. Eventually we decided to specialize the
generalized code again, which means some of the functions needed
only by osmo-bsc are removed.

- Remove dead code
- Fix timer identification number (T16)
- use fi->priv to hold context info
- Minor cosmetic fixes

Change-Id: I8e489eb494d358d130e51cb2167929edeaa12e92
Depends: libosmocore I36d221c973d3890721ef1d376fb9be82c4311378
Related: OS#3103
2018-05-17 20:14:01 +00:00
Philipp Maier 6f4752e00c vlr_access_req_fsm: use correct cause codes
The FSM that controls the VLR ACCESS uses cause code 9
(GSM48_REJECT_MS_IDENTITY_NOT_DERVIVABLE) to signal that the
identity of the MS is currently not known in VLR (MSC-Reboot)
However, this cause code is from the GMM domain and is interpreted
as GSM48_REJECT_SRV_OPT_TMP_OUT_OF_ORDER by the MS, which cauese
the MS not to make a new LOCATION UPDATE on CM SERVICE REQUEST

- use GSM48_REJECT_IMSI_UNKNOWN_IN_VLR and
  GSM48_REJECT_IMSI_UNKNOWN_IN_VLR instead of
  GSM48_REJECT_IMSI_UNKNOWN_IN_VLR

Change-Id: Ic058c93387f9be9af4940f8961839c02b93ee370
Closes: OS#3266
2018-05-16 10:34:16 +02:00
Pau Espin 86f212666a setup_trig_pag_evt: Fix heap-use-after-free
Catched by osmo-gsm-tester running test voice:octphy.

Fixes following AddressSanitizer report:
==18864==ERROR: AddressSanitizer: heap-use-after-free on address 0x61a000016f18 at pc 0x55f1b29eee5c bp 0x7ffdaa2ac000 sp 0x7ffdaa2abff8
WRITE of size 8 at 0x61a000016f18 thread T0
    #0 0x55f1b29eee5b in setup_trig_pag_evt osmo-msc/src/libmsc/gsm_04_08.c:1490
    #1 0x55f1b2a086c1 in subscr_paging_dispatch osmo-msc/src/libmsc/gsm_subscriber.c:101
    #2 0x7fb88e07c1c9 in osmo_timers_update libosmocore/src/timer.c:257
    #3 0x7fb88e07f1b1 in osmo_select_main libosmocore/src/select.c:253
    #4 0x55f1b29b600b in main osmo-msc/msc_main.c:694
    #5 0x7fb88bebe2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #6 0x55f1b29b69f9 in _start (osmo-msc/bin/osmo-msc+0xf09f9)

Related: OS#3198

Change-Id: Ie7fdca4d48e247c77a53e81aec2b6bacd8fef678
2018-04-24 14:02:03 +02:00
Pau Espin 3f8cec8f66 setup_trig_pag_evt: Always log correct paging failure case
Change-Id: I5c7a49b42b6ced1a5e0afb3485eaf94ef55bbf23
2018-04-24 13:52:00 +02:00
Pau Espin 25adebea4c setup_trig_pag_evt: Remove uneeded default case in switch statement
Take the chance to  pass a var of type enum instead, so the compiler
warns us if a new enum value is added. For instance, if we remove
GSM_PAGING_EXPIRED from the switch statement:

src/libmsc/gsm_04_08.c:1463:2: warning: enumeration value ‘GSM_PAGING_EXPIRED’ not handled in switch [-Wswitch]
  switch (paging_event) {
  ^~~~~~

Change-Id: I65d871704b9636c594dc982200fbe7f7ce6784f5
2018-04-24 11:47:00 +02:00
Pau Espin 4cf452fbd8 Remove unused GSM_PAGING_OOM
Change-Id: Ie5883953f48d11ec498f47c30ab4201bb956368c
2018-04-24 11:35:37 +02:00
Pau Espin 7e300d8741 smpp_smsc_conf: Fix heap-use-after-free
Fixes following error catched by enabling address sanitizer:
==20792==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000122610 at pc 0x7f9c9c3fe063 bp 0x7ffd2e68f600 sp 0x7ffd2e68edb0
READ of size 11 at 0x60b000122610 thread T0
    #0 0x7f9c9c3fe062  (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x3c062)
    #1 0x7f9c9beb8ee4 in talloc_strdup (/usr/lib/x86_64-linux-gnu/libtalloc.so.2+0x6ee4)
    #2 0x56096a7cf75b in smpp_smsc_conf src/libmsc/smpp_smsc.c:983
    #3 0x56096a7cf9df in smpp_smsc_start src/libmsc/smpp_smsc.c:1015
    #4 0x56096a7d4935 in smpp_openbsc_start src/libmsc/smpp_openbsc.c:785
    #5 0x56096a755ad0 in main src/osmo-msc/msc_main.c:598
    #6 0x7f9c9927b2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #7 0x56096a756979 in _start (/home/jenkins/workspace/osmo-gsm-tester_run-prod/trial-805/inst/osmo-msc/bin/osmo-msc+0xf0979)

Related: OS#3181

Change-Id: Iaf0d251c8d2912266a087ada4d20905146e08592
2018-04-17 16:10:35 +02:00
Neels Hofmeyr 21adb2bcd1 cosmetic: use enum ranap_nsap_addr_enc instead of int
The only reason to use int instead of the enum was the lack of header
iu_client.h when not building with Iu support. Rather use the configure result
properly, include the header when Iu support is built and use the proper enum.

Omit the entire iu sub-struct when building without Iu.

Add LIBOSMORANAP_CFLAGS to libvlr, in order to find the iu_client.h header (now
also included from gsm_data.h).

Rationale: Instead of using a questionable typecast from int* to enum*, we can
now use the enum member directly without needing to silence compiler warnings.

Change-Id: Ic9f8bf53f4b605c166e84cd7edd90c10fe7d7a1f
2018-04-16 01:50:46 +02:00
Harald Welte 37a3ae8585 sms_queue: fix use-after-free on 'pending'
This bug is super obvious: We cannot first call
sms_pending_free(pending) and then in the next line still dereference
the pending->sms_id member.

This bug was introduced in January with Change-Id: I3749855fe25d9d4e37ec96b0c2bffbc692b66a78
and apparently nobody has tested any MT-SMS with asan enabled since?

Change-Id: Ibf17f270cdeb8153036eda3de274dd163bbff7e6
Closes: OS#3152
2018-04-14 20:57:42 +02:00
Harald Welte ce96928e12 smpp: Unset esme->acl on socket close
We set acl->esme during _process_bind(), but we don't clear it
in case the TCP connection for the ESME is dead.  This leads to
a stale acl->esme pointer, which we will attempt to dereference
the next time a SMS is delivered to a route pointing to this acl,
where it will be a heap use-after-free.

This was discovered using AddressSanitizer and MSC_Tests.ttcn

Closes: OS#3168
Change-Id: I1f140d7f9c7d89f200ddbcd81a8df66de69fb3e4
2018-04-14 15:07:36 +02:00
Neels Hofmeyr 99a8d235f3 msc conn ref counts: log human readable list of conn owners
Change-Id: I2a09efafbdbdde0399238f7d79feea8612605201
2018-04-12 19:40:01 +00:00
Neels Hofmeyr 158095960b refactor VLR FSM result handling
Instead of keeping separate enums for FSM results and translating between those
and the actual 04.08 reject causes that will ultimately reach the MS, just pass
enum gsm48_reject_value cause codes around everywhere.

Collapse some VLR *_timeout() and *_cancel() api to just *_cancel() with a
gsm48 cause arg.

(Hopefully) improve a few reject causes, but otherwise just aim for more
transparent decisions on which cause value is used, for future fixes of
returned causes.

Depends: I6661f139e68a498fb1bef10c266c2f064b72774a (libosmocore)
Change-Id: I27bf8d68737ff1f8dc6d11fb1eac3d391aab0cb1
2018-04-12 19:40:00 +00:00
Vadim Yanitskiy 048eb30684 libmsc/ussd: don't overwrite rc if decoding failed
Change-Id: I344e4b3a9aad617686a7ddbdeae5780fd8b07e58
2018-04-12 09:27:44 +00:00
Neels Hofmeyr fe4ba7c057 cosmetic: embed compl_l3_type in FSM id
In the subscr_conn_fsm instance's ID, include the Complete Layer 3 type, so
that we can see on the first glance whether a state transition belongs to MO or
MT.

The huge patch is due to the cosmetic change affecting nearly every single log
line in the msc_vlr_tests, by nature of changing the FSM's ID.

Related: OS#3122
Change-Id: I2a7e27e0f16df1872dcda64cb928c3b8528ea3f7
2018-04-11 21:39:44 +00:00
Neels Hofmeyr 2a5cd93d8f fix BSC Clear Request
On receiving a Clear Request, don't send a Clear Command "out of band", let the
FSM do the release handling by invoking msc_subscr_conn_mo_close().

Fixes: ttcn3 MSC_Tests.TC_lu_clear_request
Change-Id: I168b889ac7989641cc679b781dcffb87ff13a710
2018-04-11 21:39:44 +00:00
Neels Hofmeyr 4068ab278b properly receive BSSMAP Clear Complete and Iu Release Complete
When sending a BSSMAP Clear or Iu Release, do not immediately discard the conn,
but wait until a BSSMAP Clear Complete / Iu Release Complete has been received.

Hence we will no longer show in the log that an incoming Release/Clear Complete
belongs to an unknown subscriber, but will still be around to properly log the
release.

Related: OS#3122
Change-Id: Ie4c6aaba3866d6e5b98004e8870a215e8cf8ffc1
2018-04-11 21:39:44 +00:00
Neels Hofmeyr e3d3dc6ea2 refactor subscr_conn and subscr_conn_fsm de-/alloc
Refactor:

1. Glue the gsm_subscriber_connection alloc to the subscr_conn_fsm.
2. Add separate AUTH_CIPH state to the FSM.
3. Use conn->use_count to trigger conn release.
4. Add separate RELEASING state to the FSM.
5. Add rate counters for each of the three Complete Layer 3 types.

Details:

1. Glue the gsm_subscriber_connection alloc to the subscr_conn_fsm.

Historically, a gsm_subscriber_connection was allocated in libbsc land, and
only upon Complete Layer 3 did libmsc add the fsm instance. After splitting
openbsc.git into a separate osmo-msc, this is no longer necessary, hence:

Closely tie gsm_subscriber_connection allocation to the subscr_conn_fsm
instance: talloc the conn as a child of the FSM instance, and discard the conn
as soon as the FSM terminates.

2. Add separate AUTH_CIPH state to the FSM.

Decoding the Complete Layer 3 message is distinctly separate from waiting for
the VLR FSMs to conclude. Use the NEW state as "we don't know if this is a
valid message yet", and the AUTH_CIPH state as "evaluating, don't release".

A profound effect of this: should we for any odd reason fail to leave the FSM's
NEW state, the conn will be released right at the end of msc_compl_l3(),
without needing to trigger release in each code path.

3. Use conn->use_count to trigger conn release.

Before, the FSM itself would hold a use count on the conn, and hence we would
need to ask it whether it is ready to release the conn yet by dispatching
events, to achieve a use_count decrement.

Instead, unite the FSM instance and conn, and do not hold a use count by the
FSM. Hence, trigger an FSM "UNUSED" event only when the use_count reaches zero.
As long as use counts are done correctly, the FSM will terminate correctly.

These exceptions:

- The new AUTH_CIPH state explicitly ignores UNUSED events, since we expect the
  use count to reach zero while evaluating Authentication and Ciphering. (I
  experimented with holding a use count by AUTH_CIPH onenter() and releasing by
  onleave(), but the use count and thus the conn are released before the next
  state can initiate transactions that would increment the use count again.
  Same thing for the VLR FSMs holding a use count, they should be done before
  we advance to the next state. The easiest is to simply expect zero use count
  during the AUTH_CIPH state.)

- A CM Service Request means that even though the MSC would be through with all
  it wants to do, we shall still wait for a request to follow from the MS.
  Hence the FSM holds a use count on itself while a CM Service is pending.

- While waiting for a Release/Clear Complete, the FSM holds a use count on
  itself.

4. Add separate RELEASING state to the FSM.

If we decide to release for other reasons than a use count reaching zero, we
still need to be able to wait for the msc_dtap() use count on the conn to
release.

(An upcoming patch will further use the RELEASING state to properly wait for
Clear Complete / Release Complete messages.)

5. Add rate counters for each of the three Complete Layer 3 types.

Besides LU, also count CM Service Request and Paging Response
acceptance/rejections. Without these counters, only very few of the auth+ciph
outcomes actually show in the counters.

Related: OS#3122
Change-Id: I55feb379e176a96a831e105b86202b17a0ffe889
2018-04-11 21:39:44 +00:00
Neels Hofmeyr dc2514b220 CC: intentionally release T308 on BSSMAP Clear Request from BSC
So far we hit a running T308 during CC release when caused by a BSSMAP Clear
Request, and we loudly log that as error.

However, now I understand that T308 is a direct cause of the dispatch of a REL
IND towards MNCC, which is used to indicate teardown to MNCC. So during
_gsm48_cc_trans_free(), we first clear all timers, then invoke
mncc_release_ind() which starts another timer (useful for graceful CC Release,
but in this code path the intention is immediate release). Simply immediately
cancel the timer again and release the conn.

A separate question is whether a BSSMAP Clear Request should be less aggressive
in releasing the connections; i.e. instead of calling trans_free() all around,
to rather ask each transaction to "please stop soon", somehow.

Related: OS#3062
Change-Id: I231fdb574a086a206321148474cbdc7ca9cf39f0
2018-04-11 21:39:44 +00:00
Philipp Maier 79beccd93a msc_mgcp: do not send wildcarded DLCX messages
If an error on the MGW side occurs, the MSC may send out
a DLCX command that contains a wildcarded endpoint name.
Wildcarded DLCX commands are legal in principle but not
in the context of an error on a single endpoint. Apart
from that osmo-mgw is (not yet) capable to handle
wildcarded DLCX command.

The problem is caused by a wrong error handling. When the
first (RAN) CRCX fails the error handling logic tries to
perform a DLCX, but since we did not receive a specific
endpoint name yet, the buffer containing the endpoint name
is still initalized with the wildcarded enpoint name, but
the error handler and the code that generates the DLCX is
not aware of that.

- Perform a check in the error handler function that
  checks if a DLCX can be made (a specific endpoint
  name is set

- Correct the flags in the code that handles the first
  CRCX so that no DLCX is requested in the case of error

Related OS#2882

Change-Id: I64c2a82016d854ad446fd49a5d76a28324e8bd4b
2018-04-11 17:36:45 +02:00
Philipp Maier d997fa176d msc_mgcp.c: log endpoint name instead of pointer
The logtext currently logs the pointer (address) of the string
variable that holds the endpoint name, rather then the endpoint
name itself.

- Use %s instead of %p in format string

Change-Id: I01b3d07aeedd72be60361249a5bf80fbb68b7bb8
2018-04-11 15:25:35 +02:00
Neels Hofmeyr f840e6fe98 trans_free: drop bad assertion
I assumed that trans_free() would always be called before freeing the FSM. But
the actual conn free dance that tries to make sure a release is triggered from
all directions actually may run into a situation where conn->fi is NULL.

The situation is described in OS#3125.

For now simply drop the assert.

The subscr conn and FSM dealloc will soon be glued firmly together; but I want
to add a test against OS#3062 before that, and that would also hit above assertion.

Related: OS#3125 OS#3062
Change-Id: I5c30e0f9545fb76615776ff6cc16b56aeb5b043a
2018-04-10 02:15:02 +02:00
Vadim Yanitskiy f95d5be0ae libmsc/ussd.c: cosmetic: correct log level and message
Change-Id: If6c270fae54ce79c2708c99d7762ce6ff71f43d9
2018-04-09 18:57:33 +00:00
Vadim Yanitskiy 12d221f8cc libmsc/gsm_04_80.c: drop unused 'in_msg' argument
It isn't used, so no need to pass it.

Change-Id: I4248ebf8626d3f7f0bf273fd20cc4f64e979938b
2018-04-09 18:57:33 +00:00
Harald Welte 39b5548808 Permit any Sender MSISDN when sending SMS from VTY
In the old days, OsmoNITB couldn't process any SMS that wasn't between
two subscribers on the same NITB.

We've long re-worked the internals in order to process SMS with
arbitrary sender MSISDN (e.g. from SMPP). However, the VTY command
"subscriber ... sms" was never updated, it seems.

Change-Id: I62b17e0a67989484415f0df2c8cb4ff1f94dbf2b
Closes: OS#3151
2018-04-09 19:19:33 +02:00
Harald Welte 0e2fa5dcb5 DTAP: Ensure proper DLCI is used in MSC-originated DTAP
The DLCI field of the DTAP header indicates the SAPI as well as the
data link (main DCCH or SACCH).  We must make sure to use the correct
DLCI when sending DTAP to the BSC.

We achieve this by
* storing the DLCI in the msgb->cb while parsing the DTAP header
* storing the received DLCI (from msgb->cb) in the transaction for
  mobile-originated transactions
* using the trans->dlci to sent msgb->cb when transmitting L3
* filling the DTAP DLCI value from msgb->cb when transmitting DTAP

For MSC-originated transactions, we choose a DLCI value corresponding
to the service (SAPI=0 for CC, SAPI=3 for SMS) and store that in
trans->dlci.

Closes: OS#3150
Change-Id: If511b20f52575054cab1346d99a8cb68d827fdbf
2018-04-09 16:41:10 +02:00
Neels Hofmeyr 93c7463fce unify allocation of gsm_subscriber_connection
The current msc_subscr_con_allocate() was in fact only used by msc_vlr_tests,
while both a_iface_bssap.c and iucs.c did their own duplicate code of
allocating the gsm_subscriber_connection struct. Unify.

Drop the old msc_subscr_con_allocate(), instead add msc_subscr_conn_alloc().
The new function also takes via_ran and lac arguments directly.

The conn allocation will soon be closely tied to the subscr_conn_fsm instance
allocation, so place the new function definition alongside the other
subscr_conn_fsm API, and match its naming ("conn").

Related: OS#3122
Change-Id: Ia57b42a149a43f9c370b1310e2e1f512183993ea
2018-04-05 01:10:32 +02:00
Neels Hofmeyr 16c42b5fba subscr_conn: store complete_layer3_type in conn, not FSM event arg
Instead of jumping through hoops to pass the Complete Layer 3 operation that
created this conn via FSM event dispatch parameters, put it right in the
gsm_subscriber_connection struct, where it always belonged.

Move definition of the enum complete_layer3_type to gsm_data.h, where
gsm_subscriber_connection is defined.

Introduce msc_subscr_conn_update_id() to set the complete_layer3_type of the
conn as soon as a Complete Layer 3 message is received.

In msc_subscr_conn_update_id(), already include an mi_string argument to
prepare for an upcoming patch where the FSM will be allocated much earlier when
the Mobile Identity is not known yet, and we'll also update the fi->id here.

The odd logging change in the msc_vlr_tests output uncovers a wrong use of the
osmo_fsm_inst_dispatch() data argument for SUBSCR_CONN_E_CN_CLOSE events: if a
child FSM signals unsuccessful result, instead of the failure cause, it passed
the complete_layer3_type, as requested upon FSM allocation, which was then
misinterpreted as a failure cause. Now a child FSM failure will pass NULL
instead, while other SUBSCR_CONN_E_CN_CLOSE events may still pass a valid cause
value.

Related: OS#3122
Change-Id: Iae30dd57a8861c4eaaf56999f872d4e635ba97fb
2018-04-03 02:13:16 +02:00
Neels Hofmeyr 1ba0df26dc cosmetic: rename subscr_conn_from to complete_layer3_type
'subscr_conn_from' could mean anything: from what, RAN type? BSS identifier? MM
action? Clearly name it as the Complete Layer 3 kind it represents.

Related: OS#3122
Change-Id: I6263a80e6db01c2ca48df6c58b05e2fd19347057
2018-04-03 02:13:09 +02:00
Neels Hofmeyr 4d3a66b3f8 cosmetic: rename gsm_subscriber_connection->conn_fsm to ->fi
Match osmo-bsc's naming of the subscriber connection's FSM instance; 'conn->fi'
makes more sense anyway than 'conn->conn_fsm'.

BTW, an upcoming commit will do away with the legacy from libbsc/libmsc duality
and firmly glue the conn allocation to the fi.

Related: OS#3122
Change-Id: If442f2ba78d9722b1065ec30c9a13f372b6a8caa
2018-04-03 02:13:04 +02:00
Neels Hofmeyr ae73d2b16f cosmetic: rx_bssmap: read message type once into local var
Instead of referencing msg->l3h[0] all the time, use local variable msg_type.

Related: OS#3122
Change-Id: If70c9fa00edd462d3470bded6eb2c6521e4d9234
2018-04-03 02:12:09 +02:00
Neels Hofmeyr 80d1101153 drop some dead definitions (gsm_data.h, gsup_client.c)
Change-Id: Icad01d0ad8fa68293160bc56543b9c3dcafc50bb
2018-04-02 23:59:50 +02:00
Neels Hofmeyr 08b3828995 use osmo_init_logging2() with proper talloc ctx
Since the logging allocations now also show up in the root context report, some
tests need adjusted talloc checks.

In msc_vlr_tests, also output the number of talloc blocks before tests are
started to show that the number didn't change after the tests.

Change-Id: Iae07ae60230c7bab28e52b5df97fa3844778158e
2018-03-30 23:20:03 +02:00
Neels Hofmeyr 053e27528c gsup_test_client: gsupc_read_cb: fix uninitialized value 'io'
Change-Id: Idb3ca50009e25c8e10bcbd15e430caf6de18a040
2018-03-26 19:09:07 +02:00
Neels Hofmeyr a6ac98b6aa remove empty libcommon-cs
Change-Id: If6afda250986b12781ae579323985615621ed75c
2018-03-22 17:11:30 +01:00
Neels Hofmeyr 79e580b6ff dissolve libcommon-cs: move gsm48_* code to libmsc, drop sms_next_rp_msg_ref()
Move gsm48_* functions from common_cs.c to libmsc/gsm_04_08.c.

Drop sms_next_rp_msg_ref(), it is just a bunch of bloat around "next_rp_ref++".
Apply the "++" instead, in gsm_04_11.c.

libcommon-cs is now empty, to be removed in subsequent commit.

Change-Id: Ibc410803ce8e273b626124ab9fc934f04df3ae50
2018-03-22 17:10:49 +01:00
Neels Hofmeyr 55014d0509 dissolve libcommon-cs: move gsm_network_init() to libmsc
Move to libmsc/osmo_msc.c (for lack of a better place and reluctance to create
an own file just for gsm_network_init()).

Change-Id: I2279eee4db6f6687726bfd55841b3748d4930f15
2018-03-22 17:07:59 +01:00
Neels Hofmeyr 67fa909494 dissolve libcommon-cs: mv a_reset.c to libmsc
Change-Id: I2936dadf1ec91b39796b6012d5e6c5db39e0bd34
2018-03-22 17:07:36 +01:00
Neels Hofmeyr 8ea65b3270 rename libcommon to libgsupclient
All that is left in libcommon now are the GSUP and OAP client implementations.
These are duplicated in osmo-sgsn.git and make sense to remain somewhat
separate from libmsc. So now they get their own little lib.

Change-Id: Ic71aa119c233b6a0ae169a5b2a53819903d2be82
2018-03-22 17:07:13 +01:00
Neels Hofmeyr 9d74425e27 dissolve libcommon: drop gsm_data.c, move code to libmsc
classmark_is_r99() is only used in gsm_04_08.c, move there as static.
rrlp_mode_* is only used in msc_vty.c, move there as static.
Move ran_type_names[] to msc_ifaces.c.

Change-Id: I5381c72af6841829fbc65940fd7d6f4d5cf583df
2018-03-22 17:06:51 +01:00
Neels Hofmeyr 7a2f58ea63 dissolve libcommon: drop gsm_subscriber_base.c, move vlr_subscr_* to vlr.c
Change-Id: Ia69890da68b8afa8a2a4e8ab58ec5c4a4ba9d06a
2018-03-22 17:06:28 +01:00
Neels Hofmeyr c01e90933f dissolve libcommon: move talloc ctx into msc_main.c, drop talloc_ctx.c
Drop tall_bsc_ctx; in mncc_sock_init(), talloc the mncc_sock_state from
gsm_network.

In tests or utils, move from using an extern tall_bsc_ctx to a local root
context pointer.

Change-Id: I92c252be1d1e7634f1653de47d37c99d77d9501c
2018-03-22 17:06:05 +01:00
Neels Hofmeyr 6a8b9c70fc dissolve libcommon: drop debug.c
Apply more concise logging categories in each main scope. The bulk goes to
msc_main.c, obviously, while tests and utils get a slimmed down bunch of
logging categories.

Change-Id: I969a0662ba273f3721b6820d02151b7a5b8014b8
2018-03-22 17:05:42 +01:00
Neels Hofmeyr 34fd0c69a3 dissolve libcommon: drop unused bsc_version.c
Change-Id: I23f31b1dc265d153598ee9006cae3adaf3cebd2f
2018-03-22 17:04:59 +01:00
Neels Hofmeyr 84a1f7aa80 cosmetic: msc_vty.c: use static gsmnet instead of gsmnet_from_vty()
Now that all VTY definitions are in the same file, we no longer need
gsmnet_from_vty(). Just have one static struct gsm_network *gsmnet populated by
msc_vty_init() and use it in all VTY functions.

Change-Id: I5cb3712a4f4245feb62d42f1b041fe94de5fac1b
2018-03-22 16:52:58 +01:00
Neels Hofmeyr 7c075a2f74 dissolve libcommon,libcommon-cs: clean up vty definitions
From openbsc.git, we still have osmo-msc's VTY definitions spread across
various places. Combine:

- Move the go_parent_cb() and is_config_node() to msc_main.c, drop
  common_vty.c.
- Move all of vty_interface_layer3.c into msc_vty.c.
- Move all of common_cs_vty.c into msc_vty.c.
- Move bsc_vty_init_extra() into msc_vty_init().
- Drop some unused definitions

No functional nor cosmetic changes have been made in the moved code, plain
copy-paste moving (even though the unidiff might look like edits in some
places). I might have adjusted some blank lines though.

Change-Id: Ia818c00ab613a19a34080b160d763b55c19f76b1
2018-03-22 16:52:27 +01:00
Neels Hofmeyr d6a769b51c trans_free: tear down conn when last transaction is done
In trans_free(), call subscr_conn_release_when_unused(), so that we are sure to
clean up after the last transaction is done.

This fixes an error where a conn lingered after a CC failure, because that code
path forgot to trigger cleanup.

Rationale: so far we were triggering the release check after each DTAP dispatch
(compl_l3 and "normal" DTAP), which is sufficient for properly closed
transactions. We also need a check for when a timeout clears an erratic trans.

Adjust test expectation of test_call_mo_to_unknown_timeout to show that the
error is now fixed.

msc_vlr_test_reject_concurrency now sees an additional release checking event
when the SMS transaction is done, which is expected and does not affect the
test otherwise.

Related: OS#2779
Change-Id: I46ff2e9b09b67e4e0d79cccf8c04936f17281fcb
2018-03-22 04:35:28 +00:00
Neels Hofmeyr 3cffc2055d cosmetic: gsm_04_08.c: drop unused struct gsm_lai
Change-Id: I3236841b1701dc902754d4a388c7806b0685a91e
2018-03-21 18:07:20 +00:00
Philipp Maier a2f633184b cosmetic: remove unused variable
Change-Id: Ic19d0401557d506d104b82f88b4dcf72055d62e1
2018-03-21 16:23:58 +01:00
Harald Welte 8a991edd36 a_iface: If L3/DTAP returns error in COMPL L3, close SCCP connection
It's pretty amazing that we print error messages anrd return error
codes, but nobody ever looks at the error code and/or closes the
connection.  Let's change that.

Change-Id: Iec693d8012a7816d1ded8206c2d979ac0546fb6e
2018-03-18 23:00:27 +01:00
Harald Welte 4de011561f a_iface_bssap: Treat inbound RESET as implicit RESET ACK
If both sides are sending RESET at the same time, they are not aware
of each other.  This leads to synchronization problems in wich
the remote side is transmitting e.g. a COMPL L3 INFO after receiving
a RESET ACK, but before even receiving or processing the RESET in
the inverse direction.  So let's treat receiving a RESET as an implicit
RESET ACK to any RESET we may have sent.

Change-Id: I0ae34fbb3735592bb7cffa5aaf421b14a8acc90e
2018-03-18 21:47:15 +00:00
Harald Welte 5060f563c6 BSSAP: Return error code if COMPL L3 with no or too short L3 payload
Change-Id: Ie3bf1351ed11a9eb261737c2da0361e632e7b6e5
2018-03-18 21:55:37 +01:00
Pau Espin 9fac985972 msc_mgcp.c: Fix several wrong ptr printf fmt
Fixes several of these type of warnings:
include/osmocom/core/fsm.h:123:38: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 9 has type ‘char *’ [-Wformat=]
   LOGP((fi)->fsm->log_subsys, level, "%s{%s}: " fmt, \
                                      ^
src/libmsc/msc_mgcp.c:277:71: note: format string is defined here
    "CRCX/RAN: creating connection for the RAN side on MGW endpoint:0x%x...\n", mgcp_ctx->rtp_endpoint);
                                                                      ~^

Change-Id: I17b7bed8fc39612286ba66f250b6b26da01d38c0
2018-03-17 01:54:34 +01:00
Philipp Maier 04d6ddb299 msc_mgcp: to not access higher layers after release
The higher layers (gsm_04_08.c) are informed errors occur. But it
is not checked if the call was already released. If an error occurs
after the call control stack calls msc_mgcp_call_release() then
the higher layers might already have cleaned up and the code
accesses memory that is already freed (trans)

- fix use after free by guarding the call to mncc_tx_to_cc()

Change-Id: I78f1b6a9149488a4ad3f120c1e190a83c07d4b89
Related OS#2881
Related OS#2882
2018-03-16 18:51:27 +00:00
Neels Hofmeyr e9e2f5cde6 cosmetic: rename conn_fsm "bump" event to "release_when_unused"
The naming of "bump" was short and made sense to me at the time of writing, but
it is keeping pretty much everyone else at a distance, no-one intuitively gets
what it is supposed to mean.

Clarify by renaming to "release_when_unused".

Adjust test expectations.

Change-Id: I4dcc55f536f63b13a3da29fff1df5fe16751f83a
2018-03-15 14:24:57 +00:00