diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2021-06-07 01:49:04 +0200 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2021-06-07 01:49:16 +0200 |
commit | 177799fe7eb00154e0a6b415b409e57e2b8ddb4e (patch) | |
tree | d8cd97802020f6af9beae286966cfb7fedda84e9 | |
parent | 68671291f319f089d82b3b66b893c521c75b3811 (diff) |
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
-rw-r--r-- | src/common/l1sap.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/l1sap.c b/src/common/l1sap.c index b17bf011..cd2af57a 100644 --- a/src/common/l1sap.c +++ b/src/common/l1sap.c @@ -592,17 +592,17 @@ static int l1sap_info_time_ind(struct gsm_bts *bts, 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); } |