Change in osmo-bts[master]: l1sap: fix TDMA frame number wrap in l1sap_info_time_ind()

fixeria gerrit-no-reply at
Mon Jun 7 11:33:48 UTC 2021

fixeria has submitted this change. ( )

Change subject: l1sap: fix TDMA frame number wrap in l1sap_info_time_ind()

l1sap: fix TDMA frame number wrap in l1sap_info_time_ind()

Using the normal arithmetic for TDMA frame numbers may result
in getting wrong values.  Consider the following situation:

  'info_time_ind->fn' is 0 (beginning of period)
   'bts->gsm_time.fn' is 2715647 (end of period)

With these input values the following expression:

  info_time_ind->fn - bts->gsm_time.fn

will be equal to:

  0 - 2715647 or -2715647

In this case osmo-bts does not log an error, because:

  if (-2715647 > 0) // is false

As a consequence, we do not increment number of RACH slots that
have passed by since the last time indication:

  for (i = 0; i < -2715647; i++) // is false

This is why we introduced GSM_TDMA_FN_{SUB,SUM,DIFF,INC} API.

Change-Id: I6168dd75daea50bbe2e19338e637185ac9ac87ef
M src/common/l1sap.c
1 file changed, 4 insertions(+), 4 deletions(-)

  Jenkins Builder: Verified
  dexter: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve

diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index b17bf01..cd2af57 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -592,17 +592,17 @@
 			       struct osmo_phsap_prim *l1sap,
 			       struct info_time_ind_param *info_time_ind)
-	int frames_expired;
-	int i;
+	unsigned int frames_expired;
+	unsigned int i;
 	DEBUGPFN(DL1P, info_time_ind->fn, "Rx MPH_INFO time ind\n");
 	/* Calculate and check frame difference */
-	frames_expired = info_time_ind->fn - bts->gsm_time.fn;
+	frames_expired = GSM_TDMA_FN_SUB(info_time_ind->fn, bts->gsm_time.fn);
 	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"=%d > 1!\n",
+			     "Invalid condition detected: Frame difference is %"PRIu32"-%"PRIu32"=%u > 1!\n",
 			     info_time_ind->fn, bts->gsm_time.fn, frames_expired);

To view, visit
To unsubscribe, or for help writing mail filters, visit

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I6168dd75daea50bbe2e19338e637185ac9ac87ef
Gerrit-Change-Number: 24594
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at>
Gerrit-Reviewer: fixeria <vyanitskiy at>
Gerrit-Reviewer: laforge <laforge at>
Gerrit-Reviewer: neels <nhofmeyr at>
Gerrit-Reviewer: pespin <pespin at>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gerrit-log mailing list