aboutsummaryrefslogtreecommitdiffstats
path: root/src/sdr
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2011-10-16 17:07:38 +0200
committerSylvain Munaut <tnt@246tNt.com>2011-10-16 17:07:38 +0200
commit02b2575adc2bcbab135d9e9b924d0136dc31dcff (patch)
treeeba0a6ece21830e87ae97a4d4b02658eaf5baaa8 /src/sdr
parentb6fc11d17c4624d875b9c5b87799910f66a9c7a5 (diff)
sdr/fcch: Add safety to FCCH multi rough detection for period discovery
We try to find the periodicity, but in some case, for some signals this can fail and we need to ensure Lp is valid and within bounds since it's used as offset. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/sdr')
-rw-r--r--src/sdr/fcch.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/sdr/fcch.c b/src/sdr/fcch.c
index 9f49f47..5ce6553 100644
--- a/src/sdr/fcch.c
+++ b/src/sdr/fcch.c
@@ -285,7 +285,7 @@ gmr1_fcch_rough_multi(struct osmo_cxvec *search_win_in, int sps, float freq_shif
struct osmo_cxvec *corr = NULL;
float *corr_pwr = NULL;
float pwr_max, pwrs[2], peaks[2], avg, stddev, th, peaks_pwr[N];
- int Lw, Lp, i, pwr_max_idx, a, peaks_cnt;
+ int Lw, Lp, nLp, i, pwr_max_idx, a, peaks_cnt;
int rv;
/* Safety : need 650 ms of signal */
@@ -314,7 +314,9 @@ gmr1_fcch_rough_multi(struct osmo_cxvec *search_win_in, int sps, float freq_shif
goto err;
}
- Lw = (330 * GMR1_SYM_RATE) / 1000; /* Len window */
+ Lw = (320 * GMR1_SYM_RATE) / 1000; /* Len window */
+ Lw += GMR1_FCCH_SYMS;
+
Lp = (320 * GMR1_SYM_RATE) / 1000; /* Len period */
pwr_max_idx = 0;
@@ -354,7 +356,15 @@ gmr1_fcch_rough_multi(struct osmo_cxvec *search_win_in, int sps, float freq_shif
peaks[0] /= pwrs[0];
peaks[1] /= pwrs[1];
- Lp = (int)round(peaks[1] - peaks[0]);
+ nLp = (int)round(peaks[1] - peaks[0]);
+
+ /* Safety */
+ if (abs(nLp - Lp) > 10) {
+ rv = -EINVAL;
+ goto err;
+ }
+
+ Lp = nLp;
/* 'Mix' the two cycles to improve signal. Compute avg at the same time */
avg = 0.0f;