rlcmac: Fix Starting Time rfn->fn calculation

The Starting time contains a "frame number, FN modulo 42432", aka RFN.
The translation to absolute FN was missing.

Depends: libosmocore.git Change-Id Ib71e8da976f6cc84c3a4ab17b0a8c2101492e243
Change-Id: I00741289333853a8db472950ee2ac38dc2c74fd3
This commit is contained in:
Pau Espin 2023-08-02 21:09:06 +02:00
parent a4a34acd91
commit fe2a399be6
7 changed files with 141 additions and 7 deletions

View File

@ -7,3 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
libosmocore >1.8.0 gsm_fn2rfn(), gsm_rfn2fn()

View File

@ -429,15 +429,17 @@ int gprs_rlcmac_decode_gprs_acknack_bits(const Ack_Nack_Description_t *desc,
return num_blocks;
}
/* 12.21 Starting Frame Number Description */
/* TS 44.060 12.21 Starting Frame Number Description
* TS 44.018 10.5.2.38 Starting Time */
uint32_t TBF_StartingTime_to_fn(const StartingTime_t *tbf_start_time, uint32_t curr_fn)
{
const struct gsm_time g_time = {
.t1 = tbf_start_time->N32,
.t2 = tbf_start_time->N51,
.t3 = tbf_start_time->N26
};
return gsm_gsmtime2fn(&g_time);
const uint8_t t1p = tbf_start_time->N32;
const uint8_t t3 = tbf_start_time->N51;
const uint8_t t2 = tbf_start_time->N26;
const uint16_t rfn = 51 * OSMO_MOD_FLR((t3 - t2), 26) + t3 + 51 * 26 * t1p;
const uint32_t fn = gsm_rfn2fn(rfn, curr_fn);
LOGRLCMAC(LOGL_DEBUG, "curr_fn=%u + RFN=%u -> FN=%u\n", curr_fn, rfn, fn);
return fn;
}

View File

@ -16,6 +16,7 @@ check_PROGRAMS = \
csn1_ts_44_018_test \
csn1_ts_44_060_test \
rlcmac_prim_test \
rlcmac_types_test \
$(NULL)
EXTRA_DIST = \
@ -25,6 +26,8 @@ EXTRA_DIST = \
csn1_ts_44_060_test.err \
rlcmac_prim_test.ok \
rlcmac_prim_test.err \
rlcmac_types_test.ok \
rlcmac_types_test.err \
$(NULL)
# Common LDADD entries
@ -44,3 +47,6 @@ csn1_ts_44_060_test_LDADD = $(LDADD)
rlcmac_prim_test_SOURCES = rlcmac_prim_test.c
rlcmac_prim_test_LDADD = $(LDADD)
rlcmac_types_test_SOURCES = rlcmac_types_test.c
rlcmac_types_test_LDADD = $(LDADD)

View File

@ -0,0 +1,88 @@
/* rlcmac_types_test.c
*
* (C) 2023 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdint.h>
#include <stdio.h>
#include <osmocom/core/application.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/select.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include <osmocom/gsm/gsm48_rest_octets.h>
#include <osmocom/gprs/rlcmac/rlcmac.h>
#include <osmocom/gprs/rlcmac/csn1_defs.h>
#include <osmocom/gprs/rlcmac/rlcmac_dec.h>
static void *tall_ctx = NULL;
/* SGSN->PCU->BTS --PCH--> MS containing "Paging Request Type 1" asking for PS services.
* RLCMAC will send GMMRR-PAGE.ind to GMM layer, which is in charge of orchestrating the response. */
static void test_tbf_starting_time_to_fn(const uint32_t cur_fn, const uint32_t fn)
{
const uint16_t rfn = gsm_fn2rfn(fn);
StartingTime_t st;
printf("=== %s(cur_fn=%u, fn=%u) start ===\n", __func__, cur_fn, fn);
/* TBF_STARTING_TIME -- same as 3GPP TS 44.018 §10.5.2.38 Starting Time without tag: */
st.N32 = (rfn / (26 * 51)) % 32;
st.N51 = rfn % 51;
st.N26 = rfn % 26;
printf("cur_fn=%u fn=%u rfn=%u [T1'=%u T3=%u T2=%u]\n",
cur_fn, fn, rfn, st.N32, st.N51, st.N26);
uint32_t res_fn = TBF_StartingTime_to_fn(&st, cur_fn);
printf("res_fn=%u\n", res_fn);
OSMO_ASSERT(res_fn == fn);
printf("=== %s(cur_fn=%u, fn=%u) end ===\n", __func__, cur_fn, fn);
}
static const struct log_info_cat test_log_categories[] = { };
static const struct log_info test_log_info = {
.cat = test_log_categories,
.num_cat = ARRAY_SIZE(test_log_categories),
};
int main(int argc, char *argv[])
{
tall_ctx = talloc_named_const(NULL, 1, __FILE__);
osmo_init_logging2(tall_ctx, &test_log_info);
log_parse_category_mask(osmo_stderr_target, "DLGLOBAL,1:");
osmo_fsm_log_addr(false);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_set_print_level(osmo_stderr_target, 1);
log_set_use_color(osmo_stderr_target, 0);
test_tbf_starting_time_to_fn(0, 0);
test_tbf_starting_time_to_fn(0, 4);
test_tbf_starting_time_to_fn(4953, 4961);
test_tbf_starting_time_to_fn(2229729, 2229786);
test_tbf_starting_time_to_fn(2229777, 2229786);
test_tbf_starting_time_to_fn(1320458, 1320462);
talloc_free(tall_ctx);
}

View File

@ -0,0 +1,6 @@
DLGLOBAL DEBUG curr_fn=0 + RFN=0 -> FN=0
DLGLOBAL DEBUG curr_fn=0 + RFN=4 -> FN=4
DLGLOBAL DEBUG curr_fn=4953 + RFN=4961 -> FN=4961
DLGLOBAL DEBUG curr_fn=2229729 + RFN=23322 -> FN=2229786
DLGLOBAL DEBUG curr_fn=2229777 + RFN=23322 -> FN=2229786
DLGLOBAL DEBUG curr_fn=1320458 + RFN=5070 -> FN=1320462

View File

@ -0,0 +1,24 @@
=== test_tbf_starting_time_to_fn(cur_fn=0, fn=0) start ===
cur_fn=0 fn=0 rfn=0 [T1'=0 T3=0 T2=0]
res_fn=0
=== test_tbf_starting_time_to_fn(cur_fn=0, fn=0) end ===
=== test_tbf_starting_time_to_fn(cur_fn=0, fn=4) start ===
cur_fn=0 fn=4 rfn=4 [T1'=0 T3=4 T2=4]
res_fn=4
=== test_tbf_starting_time_to_fn(cur_fn=0, fn=4) end ===
=== test_tbf_starting_time_to_fn(cur_fn=4953, fn=4961) start ===
cur_fn=4953 fn=4961 rfn=4961 [T1'=3 T3=14 T2=21]
res_fn=4961
=== test_tbf_starting_time_to_fn(cur_fn=4953, fn=4961) end ===
=== test_tbf_starting_time_to_fn(cur_fn=2229729, fn=2229786) start ===
cur_fn=2229729 fn=2229786 rfn=23322 [T1'=17 T3=15 T2=0]
res_fn=2229786
=== test_tbf_starting_time_to_fn(cur_fn=2229729, fn=2229786) end ===
=== test_tbf_starting_time_to_fn(cur_fn=2229777, fn=2229786) start ===
cur_fn=2229777 fn=2229786 rfn=23322 [T1'=17 T3=15 T2=0]
res_fn=2229786
=== test_tbf_starting_time_to_fn(cur_fn=2229777, fn=2229786) end ===
=== test_tbf_starting_time_to_fn(cur_fn=1320458, fn=1320462) start ===
cur_fn=1320458 fn=1320462 rfn=5070 [T1'=3 T3=21 T2=0]
res_fn=1320462
=== test_tbf_starting_time_to_fn(cur_fn=1320458, fn=1320462) end ===

View File

@ -64,6 +64,13 @@ cat $abs_srcdir/rlcmac/rlcmac_prim_test.err > experr
AT_CHECK([$abs_top_builddir/tests/rlcmac/rlcmac_prim_test], [0], [expout], [experr])
AT_CLEANUP
AT_SETUP([rlcmac/rlcmac_types])
AT_KEYWORDS([rlcmac rlcmac_types])
cat $abs_srcdir/rlcmac/rlcmac_types_test.ok > expout
cat $abs_srcdir/rlcmac/rlcmac_types_test.err > experr
AT_CHECK([$abs_top_builddir/tests/rlcmac/rlcmac_types_test], [0], [expout], [experr])
AT_CLEANUP
AT_SETUP([sm/sm_prim])
AT_KEYWORDS([sm sm_prim])
cat $abs_srcdir/sm/sm_prim_test.ok > expout