summaryrefslogtreecommitdiff
path: root/cesar/bsu/ntb
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-10-20 18:18:51 +0200
committerNélio Laranjeiro2010-10-21 09:46:11 +0200
commit35b732c2a5689d49f4cfbd79772cdf15cab160ab (patch)
treee0dd1112afd74de91a26753107c9fb6d26f59a77 /cesar/bsu/ntb
parent30933a58451307dca2774d107e6cab819a210670 (diff)
cesar/bsu/ntb: add a frequency error security test, closes #1968
Diffstat (limited to 'cesar/bsu/ntb')
-rw-r--r--cesar/bsu/ntb/src/ntb.c12
-rw-r--r--cesar/bsu/ntb/test/utest/src/ntb.c4
-rw-r--r--cesar/bsu/ntb/test/utest/src/ntb_compute.c50
3 files changed, 66 insertions, 0 deletions
diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c
index a294eec023..d12cf77c59 100644
--- a/cesar/bsu/ntb/src/ntb.c
+++ b/cesar/bsu/ntb/src/ntb.c
@@ -15,6 +15,10 @@
#include "bsu/ntb/ntb.h"
#include <string.h>
+/** Define a security level for frequency error.
+ * If frequency error is greater then re-initialise freq error. */
+#define BSU_FREQ_ERR_SECURITY 50.0e-6
+
#define BSU_NTB_WEIGHT 0.25
#define BSU_NTB_WF BSU_NTB_WEIGHT
#define BSU_NTB_WO BSU_NTB_WEIGHT
@@ -101,6 +105,14 @@ bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts,
dbg_assert (phy);
freq_error = ctx->fe;
bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr);
+ /** Frequency error is too high reset data. */
+ if (ABS (ctx->fe) > BSU_FREQ_ERR_SECURITY)
+ {
+ freq_error = 0;
+ ctx->fe = 0;
+ ctx->init = false;
+ ctx->second_shoot = false;
+ }
ctx->ntb_offset_tck= bsu_ntb_offset (ctx, phy, freq_error, beacon_bts,
beacon_sta_ltmr, beacon_sys_ltmr);
ctx->preamble_sysdate = beacon_sys_ltmr;
diff --git a/cesar/bsu/ntb/test/utest/src/ntb.c b/cesar/bsu/ntb/test/utest/src/ntb.c
index af151acc6b..aa54f25999 100644
--- a/cesar/bsu/ntb/test/utest/src/ntb.c
+++ b/cesar/bsu/ntb/test/utest/src/ntb.c
@@ -18,12 +18,16 @@
void
test_suite_ntb_compute (test_t test);
+void
+test_suite_freq_error (test_t test);
+
int
main (int argc, char **argv)
{
test_t test;
test_init (test, argc, argv);
test_suite_ntb_compute (test);
+ test_suite_freq_error (test);
test_result (test);
return test_nb_failed (test) == 0 ? 0 : 1;
}
diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c
index 702f70e2f3..77a82caff0 100644
--- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c
+++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c
@@ -100,6 +100,56 @@ test_suite_ntb_compute (test_t test)
}
}
+void
+test_case_freq_error (test_t test)
+{
+ test_case_begin (test, "Authorized values");
+ test_begin (test, "Positive and negative")
+ {
+ bsu_ntb_sync_t sync;
+ bsu_ntb_init (&sync);
+ /* Configure with real data. */
+ sync.init = true;
+ sync.second_shoot = true;
+ sync.fe = -1.074e-05;
+ sync.bts = 0x8a1ad69;
+ sync.preamble_sysdate = 0x6f04181;
+ sync.preamble_stadate = 0x6f04181;
+ /* Compute new Frequency error. */
+ bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, 0x21e04ad,
+ 0x1ddf30d3, 0x1ddf30d3);
+ test_fail_unless (sync.fe == 0);
+ test_fail_unless (sync.init == true);
+ test_fail_unless (sync.second_shoot == false);
+ test_fail_unless (
+ sync.ntb_offset_tck == sync.bts - sync.preamble_stadate);
+ /* Negative one. */
+ bsu_ntb_init (&sync);
+ sync.init = true;
+ sync.second_shoot = true;
+ sync.fe = -2.04;
+ sync.bts = 0x8a1ad69;
+ sync.preamble_sysdate = 0x6f04181;
+ sync.preamble_stadate = 0x6f04181;
+ /* Compute new Frequency error. */
+ bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, sync.bts + 1,
+ sync.preamble_sysdate + 1, 0x1ddf30d3);
+ test_fail_unless (sync.fe == 0);
+ test_fail_unless (sync.init == true);
+ test_fail_unless (sync.second_shoot == false);
+ test_fail_unless (
+ sync.ntb_offset_tck == sync.bts - sync.preamble_stadate);
+ }
+ test_end;
+}
+
+void
+test_suite_freq_error (test_t test)
+{
+ test_suite_begin (test, "Check Frequency error authorized values");
+ test_case_freq_error (test);
+}
+
/** STUBS functions. */
u32
phy_sysdate (void) __attribute__ ((weak));