aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2019-11-14 15:37:16 +0100
committerfixeria <axilirator@gmail.com>2019-11-20 13:35:02 +0000
commit5c5ad3cb4afb131ce32cdc857899540c51aab604 (patch)
treef541e63f67984dc5d2fc1c04408e8fc6bcb7dea9
parentae5e1d7110f1c87a0c4458cba47149b18f4ed2b6 (diff)
scheduler_trx.c: avoid division by zero when calculating BER
There is theoretical risk that when calculating the BER that a division by zero occurrs. Lets add a check to avoid n_errors / n_bits_total when n_bits_total is zero. Change-Id: I1c0731b9a60be4b8c0c84b85b4403168120ceacd Fixes: CID#205696
-rw-r--r--src/osmo-bts-trx/loops.c10
-rw-r--r--src/osmo-bts-trx/loops.h3
-rw-r--r--src/osmo-bts-trx/scheduler_trx.c4
3 files changed, 13 insertions, 4 deletions
diff --git a/src/osmo-bts-trx/loops.c b/src/osmo-bts-trx/loops.c
index e73d842c..47e9cf30 100644
--- a/src/osmo-bts-trx/loops.c
+++ b/src/osmo-bts-trx/loops.c
@@ -268,11 +268,19 @@ void trx_loop_sacch_clock(struct l1sched_trx *l1t, uint8_t chan_nr,
}
void trx_loop_amr_input(struct l1sched_trx *l1t, uint8_t chan_nr,
- struct l1sched_chan_state *chan_state, float ber)
+ struct l1sched_chan_state *chan_state,
+ int n_errors, int n_bits_total)
{
struct gsm_bts_trx *trx = l1t->trx;
struct gsm_lchan *lchan = &trx->ts[L1SAP_CHAN2TS(chan_nr)]
.lchan[l1sap_chan2ss(chan_nr)];
+ float ber;
+
+ /* calculate BER (Bit Error Ratio) */
+ if (n_bits_total == 0)
+ ber = 1.0; /* 100% BER */
+ else
+ ber = (float) n_errors / (float) n_bits_total;
/* check if loop is enabled */
if (!chan_state->amr_loop)
diff --git a/src/osmo-bts-trx/loops.h b/src/osmo-bts-trx/loops.h
index 78699031..978cb7ec 100644
--- a/src/osmo-bts-trx/loops.h
+++ b/src/osmo-bts-trx/loops.h
@@ -22,7 +22,8 @@ void trx_loop_sacch_clock(struct l1sched_trx *l1t, uint8_t chan_nr,
struct l1sched_chan_state *chan_state);
void trx_loop_amr_input(struct l1sched_trx *l1t, uint8_t chan_nr,
- struct l1sched_chan_state *chan_state, float ber);
+ struct l1sched_chan_state *chan_state,
+ int n_errors, int n_bits_total);
void trx_loop_amr_set(struct l1sched_chan_state *chan_state, int loop);
diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c
index 9945b2ce..b54c35b5 100644
--- a/src/osmo-bts-trx/scheduler_trx.c
+++ b/src/osmo-bts-trx/scheduler_trx.c
@@ -1215,7 +1215,7 @@ int rx_tchf_fn(struct l1sched_trx *l1t, enum trx_chan_type chan,
if (rc)
trx_loop_amr_input(l1t,
trx_chan_desc[chan].chan_nr | bi->tn, chan_state,
- (float)n_errors/(float)n_bits_total);
+ n_errors, n_bits_total);
amr = 2; /* we store tch_data + 2 header bytes */
/* only good speech frames get rtp header */
if (rc != GSM_MACBLOCK_LEN && rc >= 4) {
@@ -1427,7 +1427,7 @@ int rx_tchh_fn(struct l1sched_trx *l1t, enum trx_chan_type chan,
if (rc)
trx_loop_amr_input(l1t,
trx_chan_desc[chan].chan_nr | bi->tn, chan_state,
- (float)n_errors/(float)n_bits_total);
+ n_errors, n_bits_total);
amr = 2; /* we store tch_data + 2 two */
/* only good speech frames get rtp header */
if (rc != GSM_MACBLOCK_LEN && rc >= 4) {