fixeria has uploaded this change for review.

View Change

common: track whether gsm_time has been initialized

l1sap_info_time_ind() used 'bts->gsm_time.fn != 0' as a proxy for
"we have a previous frame number to diff against". This is unreliable:
Fn=0 is a _valid_ frame number, recurring on every hyperframe wrap.
If gsm_time.fn happened to be 0 and the next time indication jumped
forward by more than one frame, the real gap was silently swallowed.

It also gave no clean way to suppress the bogus "Invalid condition
detected: Frame difference is ..." message that appears when the PHY
(re)starts its TDMA frame number (e.g. from 0) on bring-up.

Introduce an explicit 'bts->gsm_time_valid' flag instead:

* l1sap_info_time_ind() treats the first indication of an epoch as
having no gap (frames_expired = 0): no warning, no RACH-slot
accounting;
* the flag is cleared in st_op_disabled_notinstalled_on_enter(), so
each BTS bring-up starts a fresh clock epoch regardless of which
FN the PHY reports first.

Change-Id: I7022b0ad084a0c224f7e8c04aca0648915b1a1c6
AI-Assisted: yes (Claude)
Related: OS#7020
---
M include/osmo-bts/bts.h
M src/common/l1sap.c
M src/common/nm_bts_fsm.c
3 files changed, 17 insertions(+), 6 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/54/42854/1
diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index f2287b0..9691a03 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -337,6 +337,11 @@
uint8_t tc4_ctr;
} si;
struct gsm_time gsm_time;
+ /* false until the first PH-TIME.ind of the current clock epoch initializes
+ * gsm_time; reset in st_op_disabled_notinstalled_on_enter(). Used to tell a
+ * fresh clock start (PHY (re)started its TDMA FN, possibly from 0) apart from
+ * a real frame-number gap in l1sap_info_time_ind(). */
+ bool gsm_time_valid;
/* frame number statistics (FN in PH-RTS.ind vs. PH-DATA.ind */
struct {
int32_t min; /* minimum observed */
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index e150398..78938f8 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -621,13 +621,16 @@

DEBUGPFN(DL1P, info_time_ind->fn, "Rx MPH_INFO time ind\n");

- /* Calculate and check frame difference */
- frames_expired = GSM_TDMA_FN_SUB(info_time_ind->fn, bts->gsm_time.fn);
+ /* Calculate and check frame difference. On the first indication of a clock
+ * epoch (e.g. the PHY just (re)started its TDMA FN) there is no previous FN to
+ * diff against, so report no gap and account for no expired RACH slots. */
+ frames_expired = bts->gsm_time_valid ?
+ GSM_TDMA_FN_SUB(info_time_ind->fn, bts->gsm_time.fn) : 0;
+ bts->gsm_time_valid = true;
if (frames_expired > 1) {
- if (bts->gsm_time.fn)
- LOGPFN(DL1P, LOGL_ERROR, info_time_ind->fn,
- "Invalid condition detected: Frame difference is %"PRIu32"-%"PRIu32"=%u > 1!\n",
- info_time_ind->fn, bts->gsm_time.fn, frames_expired);
+ LOGPFN(DL1P, LOGL_ERROR, info_time_ind->fn,
+ "Invalid condition detected: Frame difference is %"PRIu32"-%"PRIu32"=%u > 1!\n",
+ info_time_ind->fn, bts->gsm_time.fn, frames_expired);
}

/* Update our data structures with the current GSM time */
diff --git a/src/common/nm_bts_fsm.c b/src/common/nm_bts_fsm.c
index 36aad73..5c4a534 100644
--- a/src/common/nm_bts_fsm.c
+++ b/src/common/nm_bts_fsm.c
@@ -63,6 +63,9 @@
bts->si_valid = 0;
bts->bsic_configured = false;
bts->bsic = 0xff; /* invalid value */
+ /* The PHY will (re)start its TDMA frame number on the next bring-up;
+ * treat the first PH-TIME.ind as the start of a fresh clock epoch. */
+ bts->gsm_time_valid = false;
TALLOC_FREE(bts->mo.nm_attr);
bts_cbch_reset(bts);
bts_asci_notification_reset(bts);

To view, visit change 42854. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I7022b0ad084a0c224f7e8c04aca0648915b1a1c6
Gerrit-Change-Number: 42854
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>