HO: Count the actual meas.rep. get_meas_rep_avg fails if not reached
get_meas_rep_avg will return -EINVAL, if the required number of
measurements are not reached. There will be no handover possible until the
given number of measurements are available.
Change-Id: Ibc4410b4e162cdb6c070128d2c63946bb79d6d65
diff --git a/include/osmocom/bsc/gsm_data_shared.h b/include/osmocom/bsc/gsm_data_shared.h
index fd566d2..fed3494 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -268,6 +268,7 @@
/* cache of last measurement reports on this lchan */
struct gsm_meas_rep meas_rep[6];
int meas_rep_idx;
+ int meas_rep_count;
/* GSM Random Access data */
struct gsm48_req_ref *rqd_ref;
diff --git a/src/libbsc/abis_rsl.c b/src/libbsc/abis_rsl.c
index 64e5c92..457cc95 100644
--- a/src/libbsc/abis_rsl.c
+++ b/src/libbsc/abis_rsl.c
@@ -1470,8 +1470,11 @@
if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) ||
!TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) ||
- !TLVP_PRESENT(&tp, RSL_IE_BS_POWER))
+ !TLVP_PRESENT(&tp, RSL_IE_BS_POWER)) {
+ LOGP(DRSL, LOGL_ERROR, "%s Measurement Report lacks mandatory IEs\n",
+ gsm_lchan_name(mr->lchan));
return -EIO;
+ }
/* Mandatory Parts */
mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR);
@@ -1517,6 +1520,10 @@
return rc;
}
+ mr->lchan->meas_rep_count++;
+ LOGP(DRSL, LOGL_DEBUG, "%s: meas_rep_cnt++=%d\n",
+ gsm_lchan_name(mr->lchan), mr->lchan->meas_rep_count);
+
print_meas_rep(msg->lchan, mr);
send_lchan_signal(S_LCHAN_MEAS_REP, msg->lchan, mr);
diff --git a/src/libbsc/chan_alloc.c b/src/libbsc/chan_alloc.c
index 07248fb..1caa13d 100644
--- a/src/libbsc/chan_alloc.c
+++ b/src/libbsc/chan_alloc.c
@@ -347,6 +347,10 @@
gsm_ts_and_pchan_name(lchan->ts),
lchan->nr, gsm_lchant_name(lchan->type));
+ /* reset measurement report counter and index */
+ lchan->meas_rep_count = 0;
+ lchan->meas_rep_idx = 0;
+
/* clear sapis */
memset(lchan->sapis, 0, ARRAY_SIZE(lchan->sapis));
diff --git a/src/libbsc/meas_rep.c b/src/libbsc/meas_rep.c
index cb8379e..fbd1515 100644
--- a/src/libbsc/meas_rep.c
+++ b/src/libbsc/meas_rep.c
@@ -19,6 +19,7 @@
*
*/
+#include <errno.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/meas_rep.h>
@@ -75,7 +76,10 @@
int avg = 0;
if (num < 1)
- return 0;
+ return -EINVAL;
+
+ if (num > lchan->meas_rep_count)
+ return -EINVAL;
idx = calc_initial_idx(ARRAY_SIZE(lchan->meas_rep),
lchan->meas_rep_idx, num);