dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/30863 )
Change subject: bts: refuse to set invalid frame numbers ......................................................................
bts: refuse to set invalid frame numbers
A valid GSM frame ranges from 0 to 2715647. When using set_current_frame_number() to set the current frame number (source usually is the layer 1 and below) we should not allow invalid frame numbers.
Note: this also fixes FnTest which uses invalid frame numbers for testsing.
Change-Id: Iaae31b370fababba975d419b0d20ac15618c296e Related: OS#5198 --- M src/bts.cpp M tests/fn/FnTest.cpp M tests/fn/FnTest.ok 3 files changed, 21 insertions(+), 14 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/63/30863/1
diff --git a/src/bts.cpp b/src/bts.cpp index cf39aa4..069758b 100644 --- a/src/bts.cpp +++ b/src/bts.cpp @@ -338,6 +338,13 @@
void bts_set_current_frame_number(struct gprs_rlcmac_bts *bts, uint32_t fn) { + /* Refuse to set frame numbers that exceed the valid range */ + if (fn > GSM_TDMA_HYPERFRAME) { + LOGP(DRLCMAC, LOGL_ERROR, + "cannot set frame number (%u) exceeds valid range (0-%u)\n", fn, GSM_TDMA_HYPERFRAME); + return; + } + /* The UL frame numbers lag 3 behind the DL frames and the data * indication is only sent after all 4 frames of the block have been * received. Sometimes there is an idle frame between the end of one diff --git a/tests/fn/FnTest.cpp b/tests/fn/FnTest.cpp index e5ac46d..ae15164 100644 --- a/tests/fn/FnTest.cpp +++ b/tests/fn/FnTest.cpp @@ -92,13 +92,13 @@ fn = calc_fn(bts, RFN_MODULUS - 1); OSMO_ASSERT(fn == 42431);
- set_fn(bts, RFN_MODULUS * 123 + 16); + set_fn(bts, RFN_MODULUS * 12 + 16); fn = calc_fn(bts, RFN_MODULUS - 4); - OSMO_ASSERT(fn == 5219132); + OSMO_ASSERT(fn == 509180);
- set_fn(bts, RFN_MODULUS * 123 + 451); + set_fn(bts, RFN_MODULUS * 12 + 451); fn = calc_fn(bts, RFN_MODULUS - 175); - OSMO_ASSERT(fn == 5218961); + OSMO_ASSERT(fn == 509009);
/* Lets check a special cornercase. We assume that @@ -125,7 +125,7 @@ /* Also check with some corner case * values where Fn and RFn reach its * maximum/minimum valid range */ - set_fn(bts, GSM_MAX_FN); + set_fn(bts, GSM_MAX_FN-1); fn = calc_fn(bts, RFN_MODULUS-1); OSMO_ASSERT(fn == GSM_MAX_FN-1);
@@ -133,9 +133,9 @@ fn = calc_fn(bts, RFN_MODULUS-1); OSMO_ASSERT(fn == GSM_MAX_FN-1);
- set_fn(bts, GSM_MAX_FN); + set_fn(bts, GSM_MAX_FN-1); fn = calc_fn(bts, 0); - OSMO_ASSERT(fn == GSM_MAX_FN); + OSMO_ASSERT(fn == GSM_MAX_FN-RFN_MODULUS*2);
set_fn(bts, 0); fn = calc_fn(bts, 0); diff --git a/tests/fn/FnTest.ok b/tests/fn/FnTest.ok index be6400f..4884ca5 100644 --- a/tests/fn/FnTest.ok +++ b/tests/fn/FnTest.ok @@ -19,11 +19,11 @@ bts: fn=42433 rfn=42431 ==> fn=42431
-bts: fn=5219152 -rfn=42428 ==> fn=5219132 +bts: fn=509200 +rfn=42428 ==> fn=509180
-bts: fn=5219587 -rfn=42257 ==> fn=5218961 +bts: fn=509635 +rfn=42257 ==> fn=509009
bts: fn=0 rfn=42419 ==> fn=2715635 @@ -37,14 +37,14 @@ bts: fn=23 rfn=42390 ==> fn=2715606
-bts: fn=2715648 +bts: fn=2715647 rfn=42431 ==> fn=2715647
bts: fn=0 rfn=42431 ==> fn=2715647
-bts: fn=2715648 -rfn=0 ==> fn=2715648 +bts: fn=2715647 +rfn=0 ==> fn=2630784
bts: fn=0 rfn=0 ==> fn=0