summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorlaranjeiro2010-06-04 07:46:46 +0000
committerlaranjeiro2010-06-04 07:46:46 +0000
commitd2df53358941f4f89d0238871ede17c9f5516838 (patch)
tree5cebfe5a2e6d8c80fafa199f9fea14c6334f5b6c /cesar
parent0eff7f0897bed5bd1f8b4b82848ce660248fa5b0 (diff)
cesar: NEK index to use in whole modem
- bsu: add functions and unit tests (with stubs) - cp/beacon: remove nek_index - cp/cco/action: use bsu function - mac/common: add a define for the number of NEK git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7166 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar')
-rw-r--r--cesar/bsu/bsu.h14
-rw-r--r--cesar/bsu/src/bsu.c18
-rw-r--r--cesar/bsu/stub/Module1
-rw-r--r--cesar/bsu/stub/src/bsu.c23
-rw-r--r--cesar/bsu/test/utest/src/bsut.c25
-rw-r--r--cesar/cp/beacon/inc/beacon.h4
-rw-r--r--cesar/cp/beacon/src/beacon.c10
-rw-r--r--cesar/cp/beacon/test/src/beacon.c9
-rw-r--r--cesar/cp/cco/action/src/cco_action.c6
-rw-r--r--cesar/cp/cco/action/test/Makefile8
-rw-r--r--cesar/cp/cco/action/test/utest/Makefile2
-rw-r--r--cesar/mac/common/defs.h3
12 files changed, 99 insertions, 24 deletions
diff --git a/cesar/bsu/bsu.h b/cesar/bsu/bsu.h
index a9d4068d08..35c0b5fd05 100644
--- a/cesar/bsu/bsu.h
+++ b/cesar/bsu/bsu.h
@@ -139,6 +139,20 @@ bsu_power_on (u8 snid);
void
bsu_activate (bool status);
+/**
+ * Get the current NEK index.
+ * \return the current NEK index.
+ */
+uint
+bsu_nek_index_current (void);
+
+/**
+ * Get the next NEK index.
+ * \return the current NEK index.
+ */
+uint
+bsu_nek_index_next (void);
+
END_DECLS
#endif /* bsu_bsu_h */
diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c
index 83957086a6..94a2a1fa70 100644
--- a/cesar/bsu/src/bsu.c
+++ b/cesar/bsu/src/bsu.c
@@ -757,3 +757,21 @@ bsu_activate (bool status)
bsu_aclf_activate (ctx->aclf, false);
}
}
+
+uint
+bsu_nek_index_current (void)
+{
+ bsu_t *ctx = &bsu_global;
+ dbg_assert (ctx->sta_avln);
+ return ctx->sta_avln->bs.schedules.nek_switch[0];
+}
+
+uint
+bsu_nek_index_next (void)
+{
+ bsu_t *ctx = &bsu_global;
+ dbg_assert (ctx->sta_avln);
+ uint index_max =
+ ctx->sta_avln->bs.schedules.nek_switch[BSU_BEACON_SCHEDULES_MAX-1];
+ return (index_max + 1) % MAC_NEK_INDEX_NB;
+}
diff --git a/cesar/bsu/stub/Module b/cesar/bsu/stub/Module
new file mode 100644
index 0000000000..a77ba31d31
--- /dev/null
+++ b/cesar/bsu/stub/Module
@@ -0,0 +1 @@
+SOURCES:=bsu.c
diff --git a/cesar/bsu/stub/src/bsu.c b/cesar/bsu/stub/src/bsu.c
new file mode 100644
index 0000000000..bf29540b42
--- /dev/null
+++ b/cesar/bsu/stub/src/bsu.c
@@ -0,0 +1,23 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cesar/bsu/stub/src/bsu.c
+ * \brief BSU stubs.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "bsu/bsu.h"
+
+uint
+bsu_nek_index_current (void) __attribute ((weak));
+
+uint
+bsu_nek_index_current (void)
+{
+ return 0;
+}
diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c
index 974c6e89f6..79c6b1be4f 100644
--- a/cesar/bsu/test/utest/src/bsut.c
+++ b/cesar/bsu/test/utest/src/bsut.c
@@ -615,6 +615,30 @@ test_case_bsu_persistent_schedules_update (test_t test)
}
void
+test_case_bsu_nek_index (test_t test)
+{
+ test_case_begin (test, "NEK index");
+ bsu_test_t t;
+ bsu_test_init (&t);
+ test_begin (test, "Current index")
+ {
+ uint index = bsu_nek_index_current ();
+ test_fail_unless (index == 0);
+ index = bsu_nek_index_next ();
+ test_fail_unless (index == 1);
+ /* Change NEK index in schedules. */
+ t.bsu->sta_avln->bs.schedules.nek_switch [0] = 1;
+ index = bsu_nek_index_current ();
+ test_fail_unless (index == 1);
+ /* Next index. */
+ index = bsu_nek_index_next ();
+ test_fail_unless (index == 0);
+ }
+ test_end;
+ bsu_test_uninit (&t);
+}
+
+void
test_suite_bsu (test_t t)
{
test_suite_begin (t, "BSU test");
@@ -625,4 +649,5 @@ test_suite_bsu (test_t t)
test_case_bsu_update (t);
test_case_bsu_timer_event (t);
test_case_bsu_persistent_schedules_update (t);
+ test_case_bsu_nek_index (t);
}
diff --git a/cesar/cp/beacon/inc/beacon.h b/cesar/cp/beacon/inc/beacon.h
index 99d697bb8b..bfd26dbf12 100644
--- a/cesar/cp/beacon/inc/beacon.h
+++ b/cesar/cp/beacon/inc/beacon.h
@@ -138,10 +138,6 @@ struct cp_beacon_t
* shall post an event in the FSM.
*/
hal_timer_instance_t leon_timer;
-
- /** Nek index. */
- uint nek_index;
-
/**
* Discover process use by the CCo. */
cp_beacon_discover_t discover;
diff --git a/cesar/cp/beacon/src/beacon.c b/cesar/cp/beacon/src/beacon.c
index 587f6e2c15..57acc4934d 100644
--- a/cesar/cp/beacon/src/beacon.c
+++ b/cesar/cp/beacon/src/beacon.c
@@ -543,12 +543,7 @@ cp_beacon_countdowns (cp_t *ctx)
if (ctx->beacon.eks.kccd)
{
if (ctx->beacon.eks.kccd <= intervals)
- {
- if (ctx->beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK)
- ctx->beacon.nek_index = !ctx->beacon.nek_index;
-
ctx->beacon.eks.kccd = 0;
- }
else
ctx->beacon.eks.kccd -= intervals;
}
@@ -829,11 +824,10 @@ cp_beacon_change_nek (cp_t *ctx, uint eks, cp_key_t nek, bool now)
dbg_assert (ctx->mac_config);
if (now)
- index = ctx->beacon.nek_index;
+ index = bsu_nek_index_current ();
else
{
- index = !ctx->beacon.nek_index;
-
+ index = bsu_nek_index_next ();
ctx->beacon.eks.kccd = CP_BEACON_COUNTDOWN_EKS;
ctx->beacon.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
ctx->beacon.eks.new_eks = eks;
diff --git a/cesar/cp/beacon/test/src/beacon.c b/cesar/cp/beacon/test/src/beacon.c
index 6d42fbcc13..315769fe63 100644
--- a/cesar/cp/beacon/test/src/beacon.c
+++ b/cesar/cp/beacon/test/src/beacon.c
@@ -245,15 +245,19 @@ test_suite_beacon__beacon_generation (test_t test)
mac_config_t mac_config;
cl_t cl;
sar_t sar;
+ bsu_aclf_t aclf;
/* Configure the context. */
memset (&mac_config, 0, sizeof (mac_config_t));
memset (&cl, 0, sizeof (cl_t));
memset (&sar, 0, sizeof (sar_t));
+ memset (&aclf, 0, sizeof (bsu_aclf_t));
cp.mac_config = &mac_config;
cp.cl = &cl;
cp.sar = &sar;
+ cp.bsu_aclf = &aclf;
+ aclf.beacon_period = BSU_ACLF_BP_50HZ_TCK;
cp_sta_mgr_init (&cp);
cp_beacon_init (&cp);
@@ -1093,7 +1097,6 @@ test_case_beacon_eks_change_cco (test_t test)
test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN);
test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
test_fail_unless (cp.beacon.eks.kccd == CP_BEACON_COUNTDOWN_EKS);
- test_fail_unless (cp.beacon.nek_index == 0);
}
test_end;
@@ -1213,7 +1216,6 @@ test_case_beacon_eks_change_sta (test_t test)
test_fail_unless (cp.beacon.eks.kccd == 0);
test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
- test_fail_unless (cp.beacon.nek_index == 1);
cp_beacon_uninit (&cp);
cp_sta_mgr_uninit (&cp);
@@ -1274,14 +1276,12 @@ test_case_beacon_eks_change_sta (test_t test)
cp.beacon.eks.kccd = 2;
cp.beacon.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
cp.beacon.eks.new_eks = MAC_EKS_MIN + 1;
- cp.beacon.nek_index = 0;
cp_beacon_beacon_not_received (&cp);
test_fail_unless (cp.beacon.eks.kccd == 1);
test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
- test_fail_unless (cp.beacon.nek_index == 0);
cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK;
cp.beacon.last_countdown_date = 0;
@@ -1290,7 +1290,6 @@ test_case_beacon_eks_change_sta (test_t test)
test_fail_unless (cp.beacon.eks.kccd == 0);
test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
- test_fail_unless (cp.beacon.nek_index == 1);
cp_beacon_uninit (&cp);
cp_sta_mgr_uninit (&cp);
diff --git a/cesar/cp/cco/action/src/cco_action.c b/cesar/cp/cco/action/src/cco_action.c
index 3bc454e772..db8f23efc2 100644
--- a/cesar/cp/cco/action/src/cco_action.c
+++ b/cesar/cp/cco/action/src/cco_action.c
@@ -637,11 +637,11 @@ cp_cco_action__cco__cm_get_key_req_pid0 (cp_t *ctx, cp_mme_rx_t * get_key_req)
if (req.key_type == CP_MSG_KEY_NEK)
{
uint i;
-
- cnf.eks = ctx->mac_config->nek[ctx->beacon.nek_index].eks;
+ uint index = bsu_nek_index_current ();
+ cnf.eks = ctx->mac_config->nek[index].eks;
for (i = 0; i < COUNT (ctx->mac_config->nek[0].nek_enc); i++)
cnf.key.key[i] =
- ctx->mac_config->nek[ctx->beacon.nek_index].nek_enc[i];
+ ctx->mac_config->nek[index].nek_enc[i];
}
/* Send the TEI map. */
diff --git a/cesar/cp/cco/action/test/Makefile b/cesar/cp/cco/action/test/Makefile
index ba8d55ed79..fda737aaae 100644
--- a/cesar/cp/cco/action/test/Makefile
+++ b/cesar/cp/cco/action/test/Makefile
@@ -12,20 +12,20 @@ action_SOURCES = action-test.c core_stub.c \
action_MODULES = lib cp/cco/action mac/common cp/sta/mgr \
cp/av/cco/region/stub \
cp/fsm/stub cp/beacon/stub cl/stub\
- cp/secu cp/msg/stub
+ cp/secu cp/msg/stub bsu/stub
garbage_SOURCES = garbage.c core_stub.c \
sar_stub.c pbproc_stub.c sta_action.c
garbage_MODULES = lib cp/cco/action mac/common cp/sta/mgr cp/fsm/stub \
cp/av/cco/region/stub \
- cp/beacon/stub cl/stub cp/secu cp/msg/stub
+ cp/beacon/stub cl/stub cp/secu cp/msg/stub bsu/stub
status_SOURCES = status.c pbproc_stub.c sar_stub.c sta_action.c
status_MODULES = lib cp/cco/action mac/common cp/sta/mgr \
cp/av/cco/region/stub \
cp/fsm/stub cp/beacon/stub cp/sta/core/stub \
cp/msg/stub cl/stub mac/sar/stub cp/secu/stub \
- cp/secu
+ cp/secu bsu/stub
keys_SOURCES = action_gen_nek.c pbproc_stub.c sar_stub.c \
sta_action.c
@@ -33,11 +33,13 @@ keys_MODULES = lib cp/cco/action mac/common cp/sta/mgr \
cp/secu cp/av/cco/region/stub \
cp/fsm/stub cp/beacon/stub cp/sta/core/stub \
cp/msg/stub cl/stub mac/sar/stub cl/stub \
+ bsu/stub
fsm_handover_SOURCES= fsm_handover.c sta_action.c
fsm_handover_MODULES= lib cp/cco/action mac/common cp/sta/mgr \
cp/secu cp/av/cco/region/stub \
cp/fsm/stub cp/beacon/stub cp/sta/core/stub \
cp/msg/stub cl/stub mac/sar/stub \
+ bsu/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp/cco/action/test/utest/Makefile b/cesar/cp/cco/action/test/utest/Makefile
index 60414497f9..32a9048dce 100644
--- a/cesar/cp/cco/action/test/utest/Makefile
+++ b/cesar/cp/cco/action/test/utest/Makefile
@@ -11,6 +11,6 @@ test_cco_action_SOURCES = test_cco_action.c handover.c nek.c \
test_cco_action_MODULES = lib lib/scenario cp/cco/action cp/sta/mgr \
cp/fsm/stub mac/common cl/stub \
cp/sta/core/stub cp/beacon/stub cp/msg/stub \
- cp/av/cco/region/stub
+ cp/av/cco/region/stub bsu/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/mac/common/defs.h b/cesar/mac/common/defs.h
index 712f7ebe76..d606fd7a33 100644
--- a/cesar/mac/common/defs.h
+++ b/cesar/mac/common/defs.h
@@ -115,4 +115,7 @@ enum mac_eks_t
MAC_EKS_CLEAR = 0xf,
};
+/** Number of NEK index handled */
+#define MAC_NEK_INDEX_NB 2
+
#endif /* mac_common_defs_h */