summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2013-06-23 10:53:09 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2013-07-29 12:45:00 +0200
commit77d13e901b9e5d962709828c0c5e7ee68655d3cb (patch)
treee6df210c8fcec6957e1c079b00649e5e045cc425
parent01cee5dd20b801dd52cafc03ccbe60265db93e84 (diff)
Fix: meas_rep.c will only use valid DL measurement reports
When averaging measurements, only the valid reports are used. If there is no valid report in the averaging window at all, an error is returned.
-rw-r--r--openbsc/src/libbsc/meas_rep.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/openbsc/src/libbsc/meas_rep.c b/openbsc/src/libbsc/meas_rep.c
index 2a8d5ac5e..ee9ff6515 100644
--- a/openbsc/src/libbsc/meas_rep.c
+++ b/openbsc/src/libbsc/meas_rep.c
@@ -28,12 +28,20 @@ static int get_field(const struct gsm_meas_rep *rep,
{
switch (field) {
case MEAS_REP_DL_RXLEV_FULL:
+ if (!(rep->flags & MEAS_REP_F_DL_VALID))
+ return -EINVAL;
return rep->dl.full.rx_lev;
case MEAS_REP_DL_RXLEV_SUB:
+ if (!(rep->flags & MEAS_REP_F_DL_VALID))
+ return -EINVAL;
return rep->dl.sub.rx_lev;
case MEAS_REP_DL_RXQUAL_FULL:
+ if (!(rep->flags & MEAS_REP_F_DL_VALID))
+ return -EINVAL;
return rep->dl.full.rx_qual;
case MEAS_REP_DL_RXQUAL_SUB:
+ if (!(rep->flags & MEAS_REP_F_DL_VALID))
+ return -EINVAL;
return rep->dl.sub.rx_qual;
case MEAS_REP_UL_RXLEV_FULL:
return rep->ul.full.rx_lev;
@@ -72,7 +80,7 @@ int get_meas_rep_avg(const struct gsm_lchan *lchan,
enum meas_rep_field field, unsigned int num)
{
unsigned int i, idx;
- int avg = 0;
+ int avg = 0, valid_num = 0;
if (num < 1)
return -EINVAL;
@@ -85,11 +93,18 @@ int get_meas_rep_avg(const struct gsm_lchan *lchan,
for (i = 0; i < num; i++) {
int j = (idx+i) % ARRAY_SIZE(lchan->meas_rep);
+ int val = get_field(&lchan->meas_rep[j], field);
- avg += get_field(&lchan->meas_rep[j], field);
+ if (val >= 0) {
+ avg += val;
+ valid_num++;
+ }
}
- return avg / num;
+ if (valid_num == 0)
+ return -EINVAL;
+
+ return avg / valid_num;
}
/* Check if N out of M last values for FIELD are >= bd */
@@ -107,7 +122,7 @@ int meas_rep_n_out_of_m_be(const struct gsm_lchan *lchan,
int j = (idx + i) % ARRAY_SIZE(lchan->meas_rep);
int val = get_field(&lchan->meas_rep[j], field);
- if (val >= be)
+ if (val >= be) /* implies that val < 0 will not count */
count++;
if (count >= n)