Commit Graph

6871 Commits

Author SHA1 Message Date
Neels Hofmeyr 8d4faf10cd cosmetic: lchan activ: no need to clear mr again
In lchan state UNUSED, on activating an lchan, we zero out the lchan->mr_ms_lv
and mr_bts_lv. However, in UNUSED's onenter function, we already called
lchan_reset(), clearing out the lchan completely.

Drop two lines of unnecessary code.

Change-Id: I8b38f222f1c8c822e8e5e776850dbc60e30e8b8d
2018-08-29 13:58:42 +02:00
Neels Hofmeyr 6ba4058d56 fix dependency bug: include mgcp_client/, not mgcp/
In osmo_bsc_sigtran.c, instead of osmocom/mgcp/mgcp_common.h, include the same
file from mgcp_client/. (mgcp_common.h is identically installed both by
libosmo-mgcp and libosmo-mgcp-client, in their respective include dir.)

Trying to include from mgcp/ breaks the debian package builds, since only
libosmo-mgcp-client is installed as per osmo-bsc dependencies. The error was
introduced by:

commit d8f46c0074
"MGCP: add 'X-Osmo-IGN: C' for SCCPlite by default"
change id I257ad574d8060fef19afce9798bd8a5a7f8c99fe

Change-Id: I917b0c08ed91172ecb68c946aecb02c5109fcced
2018-08-29 13:31:57 +02:00
Neels Hofmeyr e706a15e33 log: tweaks and more context in osmo_bsc_sigtran_send()
Change-Id: I3d51f17b0f6ceb0e5237b4d6d5252c701fc2fe6b
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 128600c561 inter-BSC HO: send failure msg directly
If inter-BSC HO failed, the conn is by definition not in an active state, and
hence it makes no sense to verify the gscon FSM state before sending. Directly
call osmo_bsc_sigtran_send().

Change-Id: Ic49c94462041800674fa961c4d19c0c045bfe0c0
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 721c762e3b log: 'sending BSSMAP HO Request ACK'
Change-Id: Ie472c32861d9c9ca9ebec0221837030ffd83c73a
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 1752ab3285 log: lchan_rtp_fsm: add missing '\n'
Change-Id: Ifa46295ef23cf3728bc946fe27b34f0607a24c9e
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 193c1e3ab0 lchan_fsm: safer 'concluded' flag
The flag lchan->activate.concluded prevents entering the
lchan_on_fully_established()/lchan_on_activation_failure() more than once. So
far it was checked by callers, instead place in the functions themselves.

There is a potential functional change here, since during lchan_fail(), the
concluded flag was set only after entering lchan_on_activation_failure(). Now
it is already set at the start and prevents multiple re-entry beyond doubt.

This patch is not a result of an actual observed faulty behavior, just from
reading the code and seeing the slight loophole.

Change-Id: I0c906438b05442d66255203eb816453b7193a6d8
2018-08-29 02:02:10 +02:00
Neels Hofmeyr e23e1aeec2 cosmetic: lchan_fsm failure: log about state transitions
Early on during failure, log which state transition is intended after failure
handling.

If such state is already reached after failure handling, do not log "state
transition not permitted", but rather skip the state change and log "Already in
state X".

Change-Id: I81f53b38637823e62860cb773b7573bb5c21fdb0
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 3ea8baeab0 lchan_fsm: lchan_fail_to(): store target state early
lchan_fail_to() is a macro to preserve useful source file:line information in
logging. But a side effect is that its target state argument might evaluate
differently at the end of the macro, if, say, the fi->state has changed.

I hit such an instance on timeout of WAIT_RLL_RTP_ESTABLISH:
lchan_fsm_timer_cb() calls macro lchan_fail(), which calls
lchan_fail_to(lchan_fsm_on_error[fi->state]). Unlike for normal function
invocation, this argument changes as fi->state changes. Since releasing the
lchan_rtp_fsm already transitions the lchan fi into WAIT_RF_RELEASE_ACK, the
final state change of lchan_fail_to() suddenly evaluates to the broken state
instead of the intended WAIT_RF_RELEASE_ACK.

Early in lchan_fail_to(), store the argument's value as of macro invocation.

Change-Id: Id9bf4580a112ee5629f553a8bcb6b5b03b1c5f53
2018-08-29 02:02:10 +02:00
Neels Hofmeyr d8b41fc677 inter-BSC HO incoming: drop old/wrong RTP port code
Drop nonsensical legacy code.

The Circuit Identifier Code in A/SCCPlite does *not* indicate the RTP port to
use. Rather, it indicates the MGW endpoint name to use when configuring the
BSC's side of the MGW endpoint, and only the MGW will ever know the RTP port.

Change-Id: I471bd5e5cc2a083dd37290aeaae5c334ca5f7eed
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 4c6d3ea513 inter-BSC HO incoming: continue despite missing Classmark
3GPP mandates either Classmark Information 1 or 2 in BSSMAP Handover Request,
but an SCCPlite MSC currently tested does not pass either of them. Make this
missing IE a non-fatal error, continuing anyway should work out.

See 3GPP TS 48.008, 3.2.1.8 HANDOVER REQUEST, where it says "Classmark
Information 1 or Classmark Information 2" with note 6: "One of these two
elements is sent."

Change-Id: I34d64b028210b4df8652fee1a8830ec4a4e3ac11
2018-08-29 02:02:10 +02:00
Neels Hofmeyr 4122c15ea9 neighbor_ident_vty.c: fix CI format, should be 16bit
In the 'lac-ci' and 'cgi' neighbor identity VTY parameters, fix the CI part to
<0-65535>.

Use 65535 as CI in the neighbor_ident.vty test to verify the range.

Change-Id: Ie93bfe176b9d2d9445966e4ab0b928b9aa62a77f
2018-08-29 02:00:33 +02:00
Neels Hofmeyr a7b88414fb cosmetic: neighbor_ident_vty.c: add and use common string defs
The "bts", "lac" and "lac-ci" VTY parameters and documentation are used more
than once in this file. Define once and re-use.

Prepares cosmetically for a fix of the CI format in upcoming
Ie93bfe176b9d2d9445966e4ab0b928b9aa62a77f.

Change-Id: I88a377c6d77c5f18877343f84f7a26f851a427ff
2018-08-27 00:48:26 +02:00
Neels Hofmeyr d8f46c0074 MGCP: add 'X-Osmo-IGN: C' for SCCPlite by default
Use libosmo-mgcp-client's new X-Osmo-IGN header to indicate that CallIDs are
allowed to mismatch.

Add VTY commands 'msc' / 'mgw x-osmo-ign call-id' and 'no mgw x-osmo-ign' to
switch this behavior explicitly.

For SCCPlite MSCs, unless a specific config was issued, always send
'X-Osmo-IGN: C' by default, to ignore CallID mismatches.

Depends: Id7ae275ffde8ea9389270cfe3db087ee8db00b51 (osmo-mgw)
Change-Id: I257ad574d8060fef19afce9798bd8a5a7f8c99fe
2018-08-25 17:07:20 +02:00
Pau Espin 24f2f55132 abis_nm_ipaccess_rsl_connect: Log bts and trx nr
Change-Id: I0c895a44527d5396d3dabb273e000acd86aece1c
2018-08-23 17:20:09 +02:00
Pau Espin 9862bcb5cd Fix heap-use-after-free due to OML link destruction
ipaccess_drop_oml was being called inside an osmo_fd cb context, were
-EBADF must be returned if the structure holding the osmo_fd is freed.
In the middle of the path (see OS#3495 for path tree) it goes through a
signal dispatch, so it's impossible to make sure we return some value to
the osmo_fd cb. As a result, it is required to defer dropping the OML
Link from current code path and do it through a timer.

Fixes following ASan report:
20180822124927913  <0004> abis_nm.c:787 OC=RADIO-CARRIER(02) INST=(00,00,ff): CHANGE ADMINISTRATIVE STATE NACK CAUSE=Message cannot be performed
20180822124927913  <0004> osmo_bsc_main.c:186 Got CHANGE ADMINISTRATIVE STATE NACK going to drop the OML links.
20180822124927913  <0015> bts_ipaccess_nanobts.c:406 (bts=0) Dropping OML link.
...
=================================================================
==17607==ERROR: AddressSanitizer: heap-use-after-free on address 0x62e000060a68 at pc 0x7f5ea8e27086 bp 0x7ffde92b6d80 sp 0x7ffde92b6d78
READ of size 8 at 0x62e000060a68 thread T0
    #0 0x7f5ea8e27085 in handle_ts1_write input/ipaccess.c:371
    #1 0x7f5ea8e27085 in ipaccess_fd_cb input/ipaccess.c:391
    #2 0x7f5ea9147ca8 in osmo_fd_disp_fds libosmocore/src/select.c:217
    #3 0x7f5ea9147ca8 in osmo_select_main libosmocore/src/select.c:257
    #4 0x555813ab79d6 in main osmo-bsc/osmo_bsc_main.c:922
    #5 0x7f5ea76d02e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #6 0x555813ab84e9 in _start (/bin/osmo-bsc+0x34d4e9)

Fixes: OS#3495
Change-Id: I7c794c763481c28e8c35dc9b11d27969e16feb3c
2018-08-23 16:47:30 +02:00
Neels Hofmeyr 5f0a63d678 fix lchan_rtp_fsm: missing event handling
Release and Rollback events are allowed but unhandled in states
WAIT_MGW_CONFIGURED and ROLLBACK, and hence would result in an assertion. Add
handling in these states.

Change-Id: Iab233c592384902098644eee27bb8445fde3aa6f
2018-08-22 19:56:35 +00:00
Pau Espin dcbcbad374 abis_nm: Fix trailing whitespacing
Change-Id: Ia434b349e85019d2224a6f9a699058dccc6072dc
2018-08-22 12:25:44 +02:00
Pau Espin 889e0169a7 abis_nm: Fix heap-use-after-free in abis_nm_set_channel_attr
LOGPFOH uses the msgb through "foh", so we have to free msgb after
calling it, not before.

Fixes following ASAN report:
20180822120155990 DNM <0004> abis_nm.c:1889 OC=CHANNEL(03) INST=(00,01,06): Set Chan Attr (bts=0,trx=1,ts=6)
=================================================================
==16465==ERROR: AddressSanitizer: heap-use-after-free on address 0x61a00002b3f0 at pc 0x7f587f44c0db bp 0x7ffc59e31df0 sp 0x7ffc59e31de8
READ of size 1 at 0x61a00002b3f0 thread T0
    #0 0x7f587f44c0da in abis_nm_dump_foh libosmocore/src/gsm/abis_nm.c:937
    #1 0x561e09e1532c in abis_nm_set_channel_attr osmo-bsc/src/osmo-bsc/abis_nm.c:1892
    #2 0x561e09efd269 in nm_statechg_event osmo-bsc/src/osmo-bsc/bts_ipaccess_nanobts.c:168
    #3 0x561e09efd269 in bts_ipa_nm_sig_cb osmo-bsc/src/osmo-bsc/bts_ipaccess_nanobts.c:335
    #4 0x7f587efb3d16 in osmo_signal_dispatch libosmocore/src/signal.c:120
    #5 0x561e09e18e31 in abis_nm_rx_statechg_rep osmo-bsc/src/osmo-bsc/abis_nm.c:255
    #6 0x561e09e18e31 in abis_nm_rcvmsg_report osmo-bsc/src/osmo-bsc/abis_nm.c:380
    #7 0x561e09e18e31 in abis_nm_rcvmsg_fom osmo-bsc/src/osmo-bsc/abis_nm.c:778
    #8 0x561e09e1dc19 in abis_nm_rcvmsg osmo-bsc/src/osmo-bsc/abis_nm.c:926
    #9 0x7f587ec90cc2 in handle_ts1_read input/ipaccess.c:274
    #10 0x7f587ec90cc2 in ipaccess_fd_cb input/ipaccess.c:389
    #11 0x7f587efb1ca8 in osmo_fd_disp_fds libosmocore/src/select.c:217
    #12 0x7f587efb1ca8 in osmo_select_main libosmocore/src/select.c:257
    #13 0x561e09e049d6 in main osmo-bsc/src/osmo-bsc/osmo_bsc_main.c:922
    #14 0x7f587d53a2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #15 0x561e09e054e9 in _start (/bin/osmo-bsc+0x34d4e9)

Fixes: OS#3494
Change-Id: I030117abfdcee387516a4dea7e1e6a9bae8055f6
2018-08-22 12:25:44 +02:00
Neels Hofmeyr c649c3fe8e use __FILE__, not __BASE_FILE__
The intention was to use the file's basename, but __BASE_FILE__ means "the root
file that is being parsed and contains #include statements".

If we had a function using __BASE_FILE__ and that was defined in an #included
file, __BASE_FILE__ would indicate the first file where the #include is, and
not the file where the function is defined. __BASE_FILE__ works for us because
we don't ever include function definitions that log something, so __BASE_FILE__
always coincides with __FILE__ for our logging; but still __BASE_FILE__ is
semantically the wrong constant.

Related: OS#2740
Change-Id: Ic6d9dafc96c9d467ae53be2cd41adcf26a4e5125
2018-08-20 12:40:43 +02:00
Pau Espin 4db98554fd bsc: Use libosmocore API to track osmo_signal structs
libosmocore recently had the new API introduced for this purpose.

Depends: libosmocore Change-Id Id58ca18eb826b8f4183a7cf0dbb2b38cba702a09
Change-Id: Id07260635327617f8da5050af1e906891a89c530
2018-08-17 07:06:08 +00:00
Philipp Maier 0c8771e34f doc: update mgw settings in example config file
The example config file lacks a default port setting for the local
mgcp client port. Lets update that.

Change-Id: I6b1c5097d98ec2ab97d51f99b1105db3de85c75f
Related: OS#2874
2018-08-13 10:10:17 +00:00
Philipp Maier 48338570e1 lcls: do not LCLS call legs with different codecs
It is theoretically possible to LCLS two legs that use different
codecs. However, this requires transcoding capabilities on the
local MGW. If the local MGW lacks transcoding features such a
local circuit should be avoided. Enabeling LCLS under such
coditions should be optional (VTY)

- Add check to avoid LCLS on different codec/rate
- Add VTY-Option to optionally override the check
  (MGW is able to transcode)

Change-Id: I157549129a40c64364dc126f67195759e5f1d60f
Related: OS#1602
2018-08-08 13:02:58 +02:00
Philipp Maier 628a05e738 GSCON: call api of a_reset.c with msc object directly
The API of a_reset.c is currently called with a pointer to struct
reset_ctx. This puts the responsibility of checking the presence of
msc->a.reset_fsm to the caller. It would be much more effective if the
caller would check if msc->a.reset_fsm before dereferencing it.

This also fixes at least one segfault that ocurrs when gscon_timer_cb()
is called but no sccp connection is present yet. Therefore the pointer
to bsc_msc_data would not be populated. This is now detected by
a_reset.c itsself.

- minor code cleanups
- call a_reset.c functions with msc (struct bsc_msc_data)

Change-Id: I0802aaadf0af4e58e41c98999e8c6823838adb61
Related: OS#3447
2018-08-07 15:11:41 +00:00
Philipp Maier bf4e29a7df GSCON: avoid sending connection oriented data when not connected
When no connection is present and had never existed, then
conn->sccp.msc is unpopulated. However, there may be situations where
osmo_bsc_sigtran_send() is executed while no connection is present.

At the moment we assert on conn->sccp.msc, which would cause osmo-bsc
to exit. In order to avoid this, better check conn->sccp.msc and drop
the sccp message when the check is negative.

- Remove assertion, add check.

Change-Id: I4eaa983702224e5995a388ea9890ee04212eb569
Related: OS#3446
2018-08-07 12:09:01 +02:00
Philipp Maier c1a0f7a1f5 sigtran: fix memleak in osmo_bsc_sigtran_send()
The function osmo_bsc_sigtran_send() checks if the MSC is ready by
calling a_reset_conn_ready(). If it is not ready it returns with
-EINVAL. The msg message buffer is not freed, so we leak memory in those
edge cases.

- Make sure msg is freed when MSC is not ready.
- Add a comment that osmo_bsc_sigtran_send() takes ownership of msg

Change-Id: Ib1ff1d20e960a356bcee276b7c1bf9c93283e7af
2018-08-07 12:06:36 +02:00
Harald Welte 1152362b51 handover_fsm.c: Fix -Werror=format-security errors
When building with -Werror=format-security, such as our OBS builds,
it fails like this:

[  118s] handover_fsm.c: In function 'parse_ho_request':
[  118s] handover_fsm.c:478:4: error: format not a string literal and no format arguments [-Werror=format-security]
[  118s]     gsm0808_cell_id_name(&req->cell_id_serving));
[  118s]     ^~~~~~~~~~~~~~~~~~~~
[  118s] handover_fsm.c:489:4: error: format not a string literal and no format arguments [-Werror=format-security]
[  118s]     gsm0808_cell_id_name(&req->cell_id_target));
[  118s]     ^~~~~~~~~~~~~~~~~~~~
[  120s] cc1: some warnings being treated as errors

Let's make sure we don't call sprintf() and friends without a format
string.  In fact, if we only want to copy a string without extra
formatting, use osmo_strlcpy() or OSMO_STRLCPY_ARRAY().

Change-Id: I56cff3618f012f6b019f4fca7e2768814487137a
2018-08-01 18:35:34 +02:00
Harald Welte 13af4d7ec5 Migrate from osmo_ipa_idtag_parse() to ipa_ccm_id_resp_parse()
In libosmocore Change-ID I1834d90fbcdbfcb05f5b8cfe39bfe9543737ef8f
we have introduced ipa_ccm_id_resp_parse() as a bugfixed replacement
of ipa_ccm_idtag_parse().

The main difference is that the returned "value" parts now have
a correct reported "length", whereas before this commit they all
reported a one-byte too-long "length" for each IE.

Change-Id: I7d5ab323989c13d0cc6ff05547306edb918e423f
2018-08-01 13:43:44 +02:00
Philipp Maier c80cce67af gscon: use BSS-common payload types on BSS side
In cases where a codec has no fixed (IANA) payload type number, a
dynamically coosen payload type number is used. For the route between
BSC and MSC 3GPP as designated certain payload type numbers. However,
beond that, those payload type numbers may not necessarly apply. The
RTP communication between BTS and BSC still might run on a completely
different payload type number.

libosmo-netif contains a header file which payload type numbers
shall be used. Lets use those in order to signal the same payload type
numbers as we actually use in the RTP packets to the MGW.

Change-Id: I507a1b1446c8f140b2950d73cf737797604c1ac3
Related: OS#2728
Related: OS#3384
2018-08-01 11:27:17 +02:00
Philipp Maier a406b167c1 endpoint_fsm: add missing return in mgcp_pick_codec
The function mgcp_pick_codec is responsible to set the codec
information. In cases whee the codec type can not be determined
correctly it sets verb_info->codecs_len = 0, indicating to the caller
that no codocs are set. However, after that it does not return, it sets
an invalid codec anyway.

- Add missing return to keep the no-codec setting in case of error.

Change-Id: I8d1f8553357b6ad328ab1e5d4525fad0dd282a42
2018-08-01 10:56:59 +02:00
Neels Hofmeyr 94d30f2b25 cosmetic: gscon: don't re-enter ST_CLEARING
I often see "ERROR [ST_CLEARING] Entering ST_CLEARING not permitted!", avoid
the bogus error messages by checking entering ST_CLEARING only if not in it
yet. Still don't allow re-entering, to not restart the timeout.

Change-Id: Ia1f171c08dcbc529f907a20eed43bf5ee3a452b3
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 34c881a811 cosmetic: rename osmo_bsc_api.c to gsm_08_08.c
Change-Id: I91922f557072d0fb8cfe213a8a7b50f3bb23dea0
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 81a496340c cosmetic: rename bsc_api.h to gsm_08_08.h
See also I91922f557072d0fb8cfe213a8a7b50f3bb23dea0, which renames
osmo_bsc_api.c to gsm_08_08.c.

Change-Id: I7179eb27183ee213f8fc8d548895b67aa43dc6a2
2018-07-28 12:18:23 +02:00
Neels Hofmeyr b5ce49f872 cosmetic: reduce bsc_api.h
Remove as much as possible from bsc_api.h. Use '#pragma once'. Tweak head
comment.

BSC_API_CONN_POL_{ACCEPT,REJECT}: only user is static complete_layer3(), just
use a bool return value instead.

msc_connected(): only used in osmo_bsc_api.c, make static there.

Instead of including gsm_data.h, declare structs opaquely, include stdint.h.
codec_pref_test.c used this as indirect gsm_data.h include via osmo_bsc.h,
include gsm_data.h there directly.

osmo_bsc.h: instead of including bsc_api.h, declare opaque structs.

gsm_04_08_rr.h: declare opaque structs to replace indirect include of
gsm_data.h.

Change-Id: Ia9c0f9828317236048e40ec9ecf9990592e2190a
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 8757f42c8e cosmetic: dissolve bsc_api.c
gsm0808_page() is just a thin wrapper for rsl_paging_cmd(), the only caller is
page_ms() from paging.c. Directly call rsl_paging_cmd() instead.

Move gsm0808_cipher_mode() to the only caller in osmo_bsc_bssap.c, make static.

Change-Id: Ib7ce026b52d4ba3e53a8b2824e74ea92432c48c5
2018-07-28 12:18:23 +02:00
Neels Hofmeyr a07b667453 vty: 'handover any': pick more random chans, use lchan_select_by_type()
The 'handover any' VTY command is only useful for testing. It is even more
useful if it doesn't always pick the first used lchan but produces more random
handovers.

The algorithm takes a random number as input, iterates over used lchans once,
and if the random number is larger, takes modulo of the nr of used lchans
counted. A second iteration will then produce a match.

Instead of figuring out the lchan type logic in bsc_vty.c, just use
lchan_select_by_type();

Change-Id: I50b70e02d665b967e401db65581e110bc83101e7
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 6d568ed7ff cosmetic: constify gsm_bts_num() net arg
Change-Id: I9a078ffb781ee55c0ca114fa0d752c1b53067419
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 3c5612f82b create separate logging categories for lchan,ts,as FSMs
Change-Id: Ie889b8860a4a63c7c22ef65025f690d64cd7330c
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 2fc79dd220 allocate larger lchans if no SDCCH are available
Related: OS#3332
Change-Id: I2fcf9e9baa7d03974a367763f3f52f59dfc2cc51
2018-07-28 12:18:23 +02:00
Neels Hofmeyr d5df9a1d0d lchan_fsm: add in_release_handler flag
If a release event is being handled, ignore other ricocheting release events
until that release handling has concluded.

For example, if an lchan is regularly released, it signals the lchan RTP FSM to
release, which then calls back to say "RTP is released" on termination -- this
should not trigger other state changes than the initial release intends.

Change-Id: Iec41e006b6ab9d0f618d36925341f9536353e5d8
2018-07-28 12:18:23 +02:00
Neels Hofmeyr ac85b34476 lchan_fsm: split off lchan_rtp_fsm, establish RTP a bit earlier
Change-Id: Id7a4407d9b63be05ce63f5f2768b7d7e3d5c86fb
2018-07-28 12:18:23 +02:00
Neels Hofmeyr dbb38d532b fix BSC_CTR_ASSIGNMENT doc strings
Change-Id: I9de0c16a14edd8bf4f02b7781ccfd211e0a79463
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 73ecfbb822 cosmetic: FSMs: allow ignorable events
In various FSMs, some events may appear later or earlier without need of
action. Do not indicate these as 'ERROR' (event not permitted), but allow and
ignore them.

Debug-log about some of those.

From the old code, we've taken over the habit to change into
WAIT_BEFORE_RF_RELEASE even before SAPI[0] is released. Hence we may still
receive a SAPI[0] REL_IND in WAIT_BEFORE_RF_RELEASE. Don't show this as error
message, just silently accept it.

Change-Id: Ie320c7c6a1436184aaf2ec5a1843e04f4b3414ab
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 18ce10b7b1 timeslot FSM: permit entering broken state from anywhere
Change-Id: I59abcef2ee1d9e307f8eacf1d5ea663e19099a6a
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 52b5298eab timeslot FSM: fix infinite recursion on failure to send PDCH ACT
If PDCH ACT sending fails and we go back to UNUSED, the UNUSED onenter goes
right back to PDCH ACT and we loop. Avoid by going straight to broken state.

Actually, if we can't send messages, the timeslot is obviously broken, so also
enter the broken state if PDCH deactivation fails to be sent out.

Change-Id: Iebaffd0547a9651c5ba435b54dedab99c2cfdd31
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 459113d810 fix: dispatch TS_EV_RSL_DOWN when losing RSL
Noticed by ttcn3-bsc-test: after TC_ms_rel_ind_does_not_cause_bssmap_reset the
test TC_dyn_pdch_ipa_act_deact would fail because RSL was still indicated as
available, and only OML was properly signalled as down.

Before recent commit I4843d03b3237cdcca0ad2041ef6895ff253d8419 to fix nanobts
and use only flags for RSL and OML presence, the timeslot FSM actually checked
RSL link presence and the lacking RSL DOWN event was not noticed.

Change-Id: I66c7fc5fcc676f4960f3d089b8c2ae5bce37ed99
2018-07-28 12:18:23 +02:00
Neels Hofmeyr bcdbfb7406 fix nanobts: timeslot FSM: use flags to remember OML,RSL status
Before this patch, the timeslot FSM receives OML and RSL ready events.
Afterwards, it relies on examining the RSL and OML status to match the received
events. This doesn't work for the ip.access nanobts, which fails to change the
CHANNEL OM's operational status even though it has sent an Opstart ACK.  We
receive OML CHANNEL Opstart ACK, but the mo's state left at OP_STATE=Disabled.
We apparently cannot rely on the gsm_abis_mo state as assumed before this
patch, since changing the state depends on each BTS vendor's OML
implementation.

Also, implementation wise, it is better to not include assumptions on RSL and
OML implementations in the timeslot FSM. Simply receive the OML and RSL ready
events and remember that they arrived in dedicated flags.

Remove the no longer needed oml_is_ts_ready() callback from struct
gsm_bts_model added in:

  commit 91aa68f762
  "dyn TS: init only when both RSL and the Channel OM are established"
  I99f29d2ba079f6f4b77f0af12d9784588d2f56b3

This keeps osmo-bts operational while fixing ip.access nanobts, where the
CHANNEL OM's state prevented the timeslot FSM from entering operation.

Change-Id: I4843d03b3237cdcca0ad2041ef6895ff253d8419
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 31f525e756 large refactoring: use FSMs for lchans; add inter-BSC HO
Add FSMs:

- timeslot_fsm: handle dynamic timeslots and OML+RSL availability.
- lchan_fsm: handle an individual lchan activation, RTP stream and release,
  signal the appropriate calling FSMs on success, failure, release.
- mgw_endpoint_fsm: handle one entire endpoint with several CI.
- assignment_fsm: BSSMAP Assignment Request.
- handover_fsm: all of intra, inter-MO and inter-MT handover.

Above FSMs absorb large parts of the gscon FSM. The gscon FSM was surpassing
the maximum amount events (32), and it is more logical to treat assignment,
handover and MGW procedures in separate FSMs.

- Add logging macros for each FSM type:
  - LOG_TS()
  - LOG_LCHAN()
  - LOG_MGWEP(), LOG_CI()
  - LOG_ASSIGNMENT()
  - LOG_HO()
  These log with the osmo_fsm_inst where present.
  New style decision: logging without a final newline char is awkward,
  especially for gsmtap logging and when other logs interleave LOGPC() calls;
  we have various cases where the final \n goes missing, and also this invokes
  the log category checking N times instead of once.
  So I decided to make these macros *always* append a newline, but only if
  there is no final newline yet. I hope that the compiler optimizes the
  strlen() of the constant format strings away. Thus I can log with or without
  typing "\n" and always get an \n termination anyway.

General:

- replace osmo_timers, state enums and program-wide osmo_signal_dispatch()
  with dedicated FSM timeouts, states and events.

- introduce a common way to handle Tnnn timers: gsm_timers.h/.c: struct T_def.
  These can be used (with some macro magic) to define a state's timeout once,
  and not make mistakes for each osmo_fsm_inst_state_chg().

Details:

bsc_subscr_conn_fsm.c:

- move most states of this FSM to lchan_fsm, assignment_fsm, handover_fsm and
  mgw_endpoint_fsm.

- There is exactly one state for an ongoing Assignment, with all details
  handled in conn->assignment.fi. The state relies on the assignment_fsm's
  timeout.

- There is one state for an ongoing Handover; except for an incoming Handover
  from a remote BSS, the gscon remains in ST_INIT until the new lchan and conn
  are both established.

- move bssmap_add_lcls_status() to osmo_bsc_lcls.c

abis_rsl.c:

- move all dynamic timeslot logic away into timeslot_fsm. Only keep plain send/receive functions in
  abis_rsl.c

- reduce some rsl functions to merely send a message, rename to "_tx_".
  - rsl_ipacc_mdcx(): add '_tx_' in the name; move parts that change the lchan state out into the
    lchan_fsm, the lchan->abis_ip.* are now set there prior to invoking this function.

- move all timers and error/release handling away into various FSMs.

- tweak ipa_smod_s_for_lchan() and ipa_rtp_pt_for_lchan() to not require an
  lchan passed, but just mode,type that they require. Rename to
  ipacc_speech_mode*() and ipacc_payload_type().

- add rsl_forward_layer3_info, used for inter-BSC HO MO, to just send the RR
  message received during BSSMAP Handover Command.

- move various logging to LOG_LCHAN() in order to log with the lchan FSM instance.
  One drawback is that the lchan FSM is limited to one logging category, i.e. this moves some logging
  from DRR to DRSL. It might actually make sense to combine those categories.

- lose LOGP...LOGPC logging cascades: they are bad for gsmtap logging and for performance.

- handle_classmark_chg(): change logging, move cm2 len check out of the cm3 condition (I hope that's
  correct).

- gsm48_send_ho_cmd(): split off gsm48_make_ho_cmd() which doesn't send right away, so that during
  inter-bsc HO we can make an RR Handover Command to send via the MSC to the remote BSS.

assignment_fsm.c:

- the Chan Mode Modify in case of re-using the same lchan is not implemented
  yet, because this was also missing in the previous implementation (OS#3357).

osmo_bsc_api.c:

- simplify bsc_mr_config() and move to lchan_fsm.c, the only caller; rename to
  lchan_mr_config(). (bsc_mr_config() used to copy the values to mr_bts_lv
  twice, once by member assignment and then again with a memcpy.)

- During handover, we used to copy the MR config from the old lchan. Since we
  may handover between FR and HR, rather set the MR Config anew every time, so
  that FR rates are always available on FR lchans, and never on HR lchans.

Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f (libosmocore),
         I1f2918418c38918c5ac70acaa51a47adfca12b5e (libosmocore)
Change-Id: I82e3f918295daa83274a4cf803f046979f284366
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 596c402835 add gsm_timers, for Tnnn definitions usable by FSMs
Change-Id: If212fcd042051b6fa53484254223614c5b93a9c6
2018-07-28 12:18:23 +02:00
Neels Hofmeyr 68455f30a0 cosmetic: move RR functions from bsc_api.c to gsm_04_08_rr.c
Rationale: bsc_api.c used to be a kind of kitchen sink for various
implementations, we want to dissolve it. Also, combining 0808 and 0408 in the
same c file causes "weird" linking dependencies for utility and test programs.

bsc_api.c will be completely dissolved in upcoming
Ib7ce026b52d4ba3e53a8b2824e74ea92432c48c5.

Change-Id: Ie8ee334145bf7bc3a601d395ea7ab9b2009b61c7
2018-07-28 12:18:23 +02:00