Commit Graph

13 Commits

Author SHA1 Message Date
Neels Hofmeyr 526b4a5f35 ts,lchan_fsm: do not attempt to allocate CBCH subslots
In case a given channel combination contains a CBCH, it replaces sub-slot 2
with a CBCH, i.e. we must not attempt to allocate the same for SDCCH.

On timeslot initialization, immediately place such an lchan FSM into new state
LCHAN_ST_CBCH, so that it never appears unused and never is picked during
lchan_select(). Also set lchan->type = GSM_LCHAN_CBCH.

Verified by configuring CBCH timeslots and watching 'show lchan summary'.

Immediately after RSL and OML are up, these pchan types show lchan 2 in state
CBCH:

  BTS 0, TRX 0, Timeslot 0 CCCH+SDCCH4+CBCH, Lchan 2, Type CBCH, State CBCH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm
  BTS 0, TRX 0, Timeslot 1 SDCCH8+CBCH, Lchan 2, Type CBCH, State CBCH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm

With a 'phys_chan_config ccch+sdcch4+cbch' and three phones simultaneously
requesting USSD, I see:

  BTS 0, TRX 0, Timeslot 0 CCCH+SDCCH4+CBCH, Lchan 0, Type SDCCH, State ESTABLISHED - L1 MS Power: 14 dBm RXL-FULL-dl:  -53 dBm RXL-FULL-ul:  -47 dBm
  BTS 0, TRX 0, Timeslot 0 CCCH+SDCCH4+CBCH, Lchan 1, Type SDCCH, State ESTABLISHED - L1 MS Power: 30 dBm RXL-FULL-dl:  -47 dBm RXL-FULL-ul:  -47 dBm
  BTS 0, TRX 0, Timeslot 0 CCCH+SDCCH4+CBCH, Lchan 2, Type CBCH, State CBCH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm
  BTS 0, TRX 0, Timeslot 0 CCCH+SDCCH4+CBCH, Lchan 3, Type SDCCH, State ESTABLISHED - L1 MS Power: 16 dBm RXL-FULL-dl:  -47 dBm RXL-FULL-ul:  -47 dBm

With 'phys_chan_config SDCCH8+CBCH' and three phones simultaneously attaching,
I see:

  BTS 0, TRX 0, Timeslot 1 SDCCH8+CBCH, Lchan 0, Type SDCCH, State WAIT_RLL_RTP_ESTABLISH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm
  BTS 0, TRX 0, Timeslot 1 SDCCH8+CBCH, Lchan 1, Type SDCCH, State WAIT_RLL_RTP_ESTABLISH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm
  BTS 0, TRX 0, Timeslot 1 SDCCH8+CBCH, Lchan 2, Type CBCH, State CBCH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm
  BTS 0, TRX 0, Timeslot 1 SDCCH8+CBCH, Lchan 3, Type SDCCH, State WAIT_RLL_RTP_ESTABLISH - L1 MS Power: 0 dBm RXL-FULL-dl: -110 dBm RXL-FULL-ul: -110 dBm

i.e. in all cases the CBCH lchan remains occupied and is not allocated as
SDCCH.

Detaching and re-attaching the BTS reliably brings back the CBCH state. Also
verified that changing the osmo-bsc config from telnet vty and dropping oml
followed by the BTS re-attaching brings back the CBCH state.

Change-Id: I2bafc5f696e818e38f8907ad0c8f38494df0623d
2018-09-11 02:08:41 +02:00
Neels Hofmeyr 021971781d lchan_fsm: allow late RTP release events without erroring
Change-Id: Ia463f97402b957bd13a95d18d291d1c1f006f089
2018-09-10 00:51:35 +00:00
Neels Hofmeyr dd6849da18 lchan: pick proper power and ta values
When activating an lchan, the power levels should be maximum and TA zero. Only
if a new lchan is assigned within the same cell does it make sense to take over
the previous power and TA levels.

In LCHAN_EV_ACTIVATE:

- Separate the code that copies previous encryption data. This should happen
  regardless of whether we're staying in the same cell or not.

- For the power,TA levels, take over an old lchan's values only when it is
  assigning a new lchan in the same cell.

Change-Id: I360b003398487fa6f934296ff03643c33ec61a35
2018-08-29 14:14:32 +02:00
Neels Hofmeyr f213fcbd43 cosmetic: lchan activ: drop todo comments
Drop the todo comments about "for_conn->encr". I have intended that as an idea
to store encryption info in the conn instead of the lchan, which might make
sense, but there's no use in these comments.

Change-Id: I47e90062c784dd7919fff3115e2bee3314b30cd5
2018-08-29 14:13:44 +02:00
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 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 3c5612f82b create separate logging categories for lchan,ts,as FSMs
Change-Id: Ie889b8860a4a63c7c22ef65025f690d64cd7330c
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 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 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