dexter has uploaded this change for review.

View Change

bts: use GSM_TDMA_FN_ macros and uint32_t in bts_rfn_to_fn

The function bts_rfn_to_fn() uses int32_t for its internal variables and
the input parameter rfn while the callers and everything outside uses
uint32_t to store frame numbers. Lets convert this to uint32_t and use
GSM_TDMA_FN_ macros wherever possible.

Change-Id: Iedd493bb30dd1c342dec031883060c545432e740
Related: OS#5198
---
M src/bts.cpp
M src/bts.h
2 files changed, 12 insertions(+), 14 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/64/30864/1
diff --git a/src/bts.cpp b/src/bts.cpp
index 069758b..f2fb10e 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -33,6 +33,7 @@
#include <gprs_ms_storage.h>
#include <sba.h>
#include <bts_pch_timer.h>
+#include <osmocom/gsm/gsm0502.h>

extern "C" {
#include <osmocom/core/talloc.h>
@@ -720,15 +721,14 @@
}

/* Determine the full frame number from a relative frame number */
-uint32_t bts_rfn_to_fn(const struct gprs_rlcmac_bts *bts, int32_t rfn)
+uint32_t bts_rfn_to_fn(const struct gprs_rlcmac_bts *bts, uint32_t rfn)
{
- int32_t m_cur_rfn;
- int32_t fn;
- int32_t fn_rounded;
+ uint32_t m_cur_rfn;
+ uint32_t fn_rounded;

- /* double-check that relative FN is not negative and fits into int32_t */
+ /* make sure RFN does not exceed the maximum possible value of a valid
+ * GSM frame number. */
OSMO_ASSERT(rfn < GSM_MAX_FN);
- OSMO_ASSERT(rfn >= 0);

/* Note: If a BTS is sending in a rach request it will be fully aware
* of the frame number. If the PCU is used in a BSC-co-located setup.
@@ -748,13 +748,13 @@

/* Compute a "rounded" version of the internal frame number, which
* exactly fits in the RFN_MODULUS raster */
- fn_rounded = bts->cur_fn - m_cur_rfn;
+ fn_rounded = GSM_TDMA_FN_SUB(bts->cur_fn, m_cur_rfn);

/* If the delta between the internal and the external relative frame
* number exceeds a certain limit, we need to assume that the incoming
* rach request belongs to a the previous rfn period. To correct this,
* we roll back the rounded frame number by one RFN_MODULUS */
- if (abs(rfn - m_cur_rfn) > RFN_THRESHOLD) {
+ if (GSM_TDMA_FN_DIFF(rfn, m_cur_rfn) > RFN_THRESHOLD) {
LOGP(DRLCMAC, LOGL_DEBUG,
"Race condition between rfn (%u) and m_cur_fn (%u) detected: rfn belongs to the previous modulus %u cycle, wrapping...\n",
rfn, bts->cur_fn, RFN_MODULUS);
@@ -762,17 +762,15 @@
LOGP(DRLCMAC, LOGL_DEBUG,
"Cornercase detected: wrapping crosses %u border\n",
GSM_MAX_FN);
- fn_rounded = GSM_MAX_FN - (RFN_MODULUS - fn_rounded);
+ fn_rounded = GSM_TDMA_FN_SUB(GSM_MAX_FN, (GSM_TDMA_FN_SUB(RFN_MODULUS, fn_rounded)));
}
else
- fn_rounded -= RFN_MODULUS;
+ fn_rounded = GSM_TDMA_FN_SUB(fn_rounded, RFN_MODULUS);
}

/* The real frame number is the sum of the rounded frame number and the
* relative framenumber computed via RACH */
- fn = fn_rounded + rfn;
-
- return fn;
+ return GSM_TDMA_FN_SUM(fn_rounded, rfn);
}

/* 3GPP TS 44.060:
diff --git a/src/bts.h b/src/bts.h
index 085b448..61c5e43 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -296,7 +296,7 @@
struct GprsMs *bts_alloc_ms(struct gprs_rlcmac_bts *bts, uint8_t ms_class, uint8_t egprs_ms_class);
int bts_add_paging(struct gprs_rlcmac_bts *bts, const struct paging_req_cs *req, struct GprsMs *ms);

-uint32_t bts_rfn_to_fn(const struct gprs_rlcmac_bts *bts, int32_t rfn);
+uint32_t bts_rfn_to_fn(const struct gprs_rlcmac_bts *bts, uint32_t rfn);

struct gprs_rlcmac_dl_tbf *bts_dl_tbf_by_tfi(struct gprs_rlcmac_bts *bts, uint8_t tfi, uint8_t trx, uint8_t ts);
struct gprs_rlcmac_ul_tbf *bts_ul_tbf_by_tfi(struct gprs_rlcmac_bts *bts, uint8_t tfi, uint8_t trx, uint8_t ts);

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

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: Iedd493bb30dd1c342dec031883060c545432e740
Gerrit-Change-Number: 30864
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier@sysmocom.de>
Gerrit-MessageType: newchange