summaryrefslogtreecommitdiff
path: root/cesar/cp/eoc/beacon/test/utest2
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/eoc/beacon/test/utest2')
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/Config8
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/Makefile20
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/inc/scenario_defs.h63
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/override/cp/inc/context.h56
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/override/cp/sta/core/defs.h57
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/override/cyg/kernel/kapi.h37
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/beacon.c1389
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/beacon_scenario.c245
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/bsu_beacon_stub.c69
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/bsu_stub.c61
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/bsu_stub_scenario.c55
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/ca_stub.c65
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/fsm_stub.c58
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/pbproc_stub.c27
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/phy_stub.c29
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/scenario_actions.c25
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/secu_stub.c25
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/sta_mgr_stub.c217
-rw-r--r--cesar/cp/eoc/beacon/test/utest2/src/stubs.c91
19 files changed, 2597 insertions, 0 deletions
diff --git a/cesar/cp/eoc/beacon/test/utest2/Config b/cesar/cp/eoc/beacon/test/utest2/Config
new file mode 100644
index 0000000000..c31de04e0a
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/Config
@@ -0,0 +1,8 @@
+CONFIG_CP_EOC = y
+CONFIG_ATU_FACTOR = 3
+CONFIG_CP_EOC_SCHEDULER = y
+CONFIG_MAC_COMMON_EOC_SCHED = y
+CONFIG_MAC_PBPROC_EOC_FC = y
+CONFIG_STATS = n
+CONFIG_CP_EOC_BEACON_SPC_CENTRAL = y
+CONFIG_CP_FSM_DEF = "cp/eoc/fsm/src/fsm/cp_eoc_cco.fsm"
diff --git a/cesar/cp/eoc/beacon/test/utest2/Makefile b/cesar/cp/eoc/beacon/test/utest2/Makefile
new file mode 100644
index 0000000000..3a2f6e8e73
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/Makefile
@@ -0,0 +1,20 @@
+BASE = ../../../../..
+
+INCLUDES = cp/eoc/beacon/test/utest2/override cp/eoc/beacon/test/utest2
+
+HOST_PROGRAMS = beacon_scenario
+
+beacon_scenario_SOURCES = beacon_scenario.c scenario_actions.c \
+ bsu_stub_scenario.c bsu_beacon_stub.c fsm_stub.c \
+ pbproc_stub.c phy_stub.c secu_stub.c sta_mgr_stub.c
+
+beacon_scenario_MODULES = cp/eoc/beacon cp/cco/region/stub \
+ cp/eoc/cco/bw/stub cp/eoc/cco/action/stub \
+ lib lib/scenario cp/eoc/fsm/stub interface/stub \
+ bsu/stub cp/msg/stub cp/sta/core/stub \
+ hal/timer/stub mac/sar/stub cl/stub \
+ mac/common bsu/stub
+
+beacon_scenario_CONFIG_MODULES = cp/eoc
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/cp/eoc/beacon/test/utest2/inc/scenario_defs.h b/cesar/cp/eoc/beacon/test/utest2/inc/scenario_defs.h
new file mode 100644
index 0000000000..9d4711305e
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/inc/scenario_defs.h
@@ -0,0 +1,63 @@
+#ifndef inc_scenario_defs_h
+#define inc_scenario_defs_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/scenario_defs.h
+ * \brief Scenario definitions.
+ * \ingroup test
+ */
+
+#include "cp/fsm/fsm.h"
+
+/* Scenario globals. */
+#define SCENARIO_DEFS_GLOBALS \
+ cp_t *cp;
+
+#define SCENARIO_DEFS_ACTIONS \
+ nek_request, \
+ to_leave, \
+ get_and_process_beacon
+
+/* Actions without parameter. */
+#define __0(action) \
+typedef scenario_empty_t scenario_action_ ## action ## _t; \
+void \
+scenario_action_ ## action ## _cb ( \
+ scenario_globals_t *globals, scenario_params_t *params);
+
+__0 (nek_request)
+__0 (to_leave)
+__0 (get_and_process_beacon)
+
+#undef __0
+
+/* Scenario events. */
+/* Scenario events. */
+#define SCENARIO_DEFS_EVENTS \
+ cp_fsm_event_beacon_new, \
+ cp_fsm_event_bare_new
+
+/* Any event. */
+#define __p_(param) param;
+
+#define __e(event, param...) \
+typedef struct \
+{ \
+ PREPROC_FOR_EACH (__p_, ## param) \
+} scenario_event_ ## event ## _t;
+
+__e (cp_fsm_event_bare_new, cp_fsm_event_type_t type)
+__e (cp_fsm_event_beacon_new, cp_fsm_event_type_t type,
+ bsu_beacon_t *beacon, cp_net_t *net,
+ cp_sta_t *sta)
+
+#undef __p_
+#undef __e
+
+#endif /* inc_scenario_defs_h */
diff --git a/cesar/cp/eoc/beacon/test/utest2/override/cp/inc/context.h b/cesar/cp/eoc/beacon/test/utest2/override/cp/inc/context.h
new file mode 100644
index 0000000000..14f89bbc41
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/override/cp/inc/context.h
@@ -0,0 +1,56 @@
+#ifndef overide_cp_inc_context_h
+#define overide_cp_inc_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file overide/cp/inc/context.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "cp/cco/region/region.h"
+#include "cp/cco/region/inc/context.h"
+#include "cp/cco/bw/bw.h"
+#include "cp/cco/bw/inc/context.h"
+#include "interface/interface.h"
+#include "cp/sta/mgr/sta_mgr.h"
+#include "cp/sta/mgr/inc/sta_mgr.h"
+
+#include "cp/types.h"
+#include "cp/cco/action/inc/cco_action.h"
+#include "cp/sta/action/inc/context.h"
+#include "cp/eoc/beacon/beacon.h"
+#include "cp/eoc/beacon/inc/beacon.h"
+#include "cl/cl.h"
+#include "mac/common/config.h"
+#include "mac/common/store.h"
+#include "mac/sar/sar.h"
+#include "mac/pbproc/pbproc.h"
+#include "lib/rnd.h"
+#include "lib/trace.h"
+
+
+struct cp_t
+{
+ cp_beacon_t beacon;
+ mac_store_t *mac_store;
+ cp_cco_bw_t bw;
+ cp_cco_region_t region;
+ cp_sta_mgr_t sta_mgr;
+
+ hal_timer_t *hal_timer;
+ interface_t *interface;
+
+ mac_config_t *mac_config;
+ bsu_aclf_t *bsu_aclf;
+ pbproc_t *pbproc;
+ void *bsu;
+};
+
+#endif /* overide_cp_inc_context_h */
diff --git a/cesar/cp/eoc/beacon/test/utest2/override/cp/sta/core/defs.h b/cesar/cp/eoc/beacon/test/utest2/override/cp/sta/core/defs.h
new file mode 100644
index 0000000000..9698b44e93
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/override/cp/sta/core/defs.h
@@ -0,0 +1,57 @@
+#ifndef cp_sta_core_defs_h
+#define cp_sta_core_defs_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/sta/core/defs.h
+ * \brief Sta core defs.
+ * \ingroup cp/sta/core
+ *
+ */
+#include "cp/fsm/forward.h"
+
+/** Forward declaration. */
+typedef struct cp_sta_core_t cp_sta_core_t;
+
+/*
+ * the sta core event flags
+ * these are some flags, so take care to give a value with all bits set to 0 but one.
+ */
+enum cp_sta_core_event_flag_t
+{
+ CP_STA_CORE_EVENT_FLAG_RECV_BEACON = 0x1,
+ CP_STA_CORE_EVENT_FLAG_RECV_MME = 0x2,
+ CP_STA_CORE_EVENT_FLAG_FSM = 0x4,
+ CP_STA_CORE_EVENT_FLAG_GARBAGE = 0x8,
+ CP_STA_CORE_EVENT_FLAG_TERMINATE = 0x10
+};
+typedef enum cp_sta_core_event_flag_t cp_sta_core_event_flag_t;
+
+/** Definition of alarm info structure
+ * (applications should not use it directly but use "alias" defined just below) */
+struct cp_sta_core_timed_event_def_t
+{
+ /* eCos alarm. */
+ uint alarm;
+ /* eCos alarm handle. */
+ uint alarm_handle;
+ /* the sta core event flag to set
+ * (auto or user-specified when creating/launching timer alarm). */
+ cp_sta_core_event_flag_t event_flag;
+ /* FSM event specified when creating/launching timer alarm
+ * (set if the previous flag is CP_STA_CORE_EVENT_FLAG_FSM). */
+ cp_fsm_event_t *fsm_event;
+ /* flag indicating a periodic alarm (if set to true)
+ * or one-shot alarm (if set to false). */
+ bool cyclic_alarm;
+ /* pointer to CP context. */
+ cp_t *cp_ctx;
+};
+typedef struct cp_sta_core_timed_event_def_t cp_sta_core_timed_event_def_t;
+
+#endif /* cp_sta_core_defs_h */
diff --git a/cesar/cp/eoc/beacon/test/utest2/override/cyg/kernel/kapi.h b/cesar/cp/eoc/beacon/test/utest2/override/cyg/kernel/kapi.h
new file mode 100644
index 0000000000..019e5d3a07
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/override/cyg/kernel/kapi.h
@@ -0,0 +1,37 @@
+#ifndef override_cyg_kernel_kapi_h
+#define override_cyg_kernel_kapi_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file override/cyg/kernel/kapi.h
+ * \brief override some kernel api from <cyg/kernel/kapi.h>.
+ * \ingroup cp_msg
+ *
+ *
+ */
+
+struct cyg_resolution_t
+{
+ u32 dividend;
+ u32 divisor;
+} ;
+
+typedef struct cyg_resolution_t cyg_resolution_t;
+
+typedef u64 cyg_tick_count_t;
+
+int
+cyg_real_time_clock (void);
+
+cyg_resolution_t
+cyg_clock_get_resolution (int clock);
+
+cyg_tick_count_t
+cyg_current_time (void);
+
+#endif
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/beacon.c b/cesar/cp/eoc/beacon/test/utest2/src/beacon.c
new file mode 100644
index 0000000000..62146069b0
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/beacon.c
@@ -0,0 +1,1389 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/beacon.c
+ * \brief Unit test for the beacon module.
+ * \ingroup cp_beacon
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/slist.h"
+#include "lib/test.h"
+#include "lib/circular_buffer.h"
+
+#include "mac/common/ntb.h"
+#include "mac/common/store.h"
+
+#include "cp/beacon/beacon.h"
+#include "cp/av/beacon/discover.h"
+
+#include "cp/cp.h"
+#include "cp/inc/context.h"
+
+#include "cl/inc/context.h"
+#include "mac/sar/inc/context.h"
+
+#define TEST_CCO_MAC 0x0013d7001001ull
+
+void
+cp_beacon_receive (cp_t *ctx, bsu_beacon_t *beacon);
+
+void
+cp_beacon_sta_compute_schedules (cp_t *ctx, bsu_beacon_t *beacon_data);
+
+struct test_beacon_t
+{
+ cp_t cp;
+ mac_config_t mac_config;
+ cl_t cl;
+ sar_t sar;
+ bsu_aclf_t aclf;
+ uint ca;
+ bool bsu_updated;
+};
+typedef struct test_beacon_t test_beacon_t;
+
+void
+test_beacon_init (test_beacon_t *ctx)
+{
+ memset (ctx, 0, sizeof (test_beacon_t));
+ lib_rnd_init (&ctx->cp.rnd, 0x1234);
+ ctx->cp.mac_config = &ctx->mac_config;
+ ctx->cp.sar = &ctx->sar;
+ ctx->cp.cl = &ctx->cl;
+ ctx->cp.bsu_aclf = &ctx->aclf;
+ ctx->cp.bsu = (bsu_t *) &ctx->bsu_updated;
+ *((bsu_aclf_frequency_t*) &ctx->aclf.frequency) = BSU_ACLF_FREQ_50HZ;
+ *((bsu_aclf_bp_t*) &ctx->aclf.beacon_period_theo_tck) =
+ BSU_ACLF_BP_50HZ_TCK;
+ ctx->aclf.beacon_period_tck = ctx->aclf.beacon_period_theo_tck;
+ ctx->cp.mac_store = mac_store_init();
+ ctx->cp.ca = (ca_t*) &ctx->ca;
+ cp_sta_mgr_init (&ctx->cp);
+ cp_cco_bw_init (&ctx->cp);
+ cp_cco_region_init (&ctx->cp);
+ cp_beacon_init (&ctx->cp);
+ ctx->cp.beacon.last_countdown_call_date_active = true;
+}
+
+void
+test_beacon_uninit (test_beacon_t *ctx)
+{
+ cp_beacon_uninit (&ctx->cp);
+ cp_cco_bw_uninit (&ctx->cp);
+ cp_cco_region_uninit (&ctx->cp);
+ cp_sta_mgr_uninit (&ctx->cp);
+ mac_store_uninit (ctx->cp.mac_store);
+}
+
+bsu_beacon_t*
+test_new_beacon (void)
+{
+ /** Create a central beacon. */
+ bsu_beacon_t *beacon = blk_alloc ();
+ dbg_assert (beacon);
+ memset (beacon, 0, sizeof (bsu_beacon_t));
+ beacon->vf.nid = 1;
+ beacon->vf.stei = 1;
+ beacon->vf.bt = BSU_BEACON_TYPE_CENTRAL;
+ beacon->vf.hm = MAC_COEXISTENCE_FULL_HYBRID_MODE;
+ beacon->vf.ncnr = false;
+ beacon->vf.npsm = false;
+ beacon->vf.numslots = 0;
+ beacon->vf.slotusage = 0;
+ beacon->vf.slotid = 0;
+ beacon->vf.aclsss = true;
+ beacon->vf.hoip = false;
+ beacon->vf.rtsbf = false;
+ beacon->vf.nm = MAC_NM_CSMA_ONLY;
+ beacon->vf.ccocap = 0;
+ beacon->bmis.change_snid.present = true;
+ beacon->bmis.change_snid.snidccd = 3;
+ beacon->bmis.change_snid.new_snid = 0xC;
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address = TEST_CCO_MAC;
+ beacon->bmis.region.nb = 1;
+ beacon->bmis.region.region[0].end_time_atu = 3907;
+ beacon->bmis.region.region[0].rt = CP_CCO_REGION_TYPE_BEACON;
+ beacon->bmis.nps.ns = 1;
+ beacon->bmis.nps.sais[0].end_time_atu = 3907;
+ beacon->bmis.nps.sais[0].glid = 0x45;
+ beacon->bmis.nps.sais[0].stpf = false;
+ beacon->bmis.nbe = 4;
+ beacon->params.rx_parameters.snid = 0;
+ beacon->params.rx_parameters.access = HPAV_ACCESS_IN_HOME;
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ beacon->params.frequency_error_valid = false;
+ return beacon;
+}
+
+/** Uninitialise
+ * \param test the test object.
+ *
+ * The uninit procedure, shall stop the timers and release all the object
+ * referenced by the beacon module.
+ *
+ * * Stop the HAL timer
+ * * Stop the eCos timer
+ * * Release all beacon received and not processed yet.
+ * * Call the uninit function for the common sub context.
+ *
+ * Environment
+ * This test shall insert some data in the pointers and the context.
+ *
+ * 1. Add at least two beacon in the received list.
+ * 2. Add a central beacon in the central sub context.
+ * 3. Add a discover beacon in the discover sub context.
+ * 4. Add a proxy beacon in the discover sub context.
+ *
+ * Result
+ * At the end the beacon module shall not have any referenced on any object.
+ */
+void
+test_case_beacon_uninit (test_t test)
+{
+ test_case_begin (test, "Beacon uninit");
+ test_begin (test, "remove beacons received")
+ {
+ test_beacon_t ctx;
+ test_beacon_init (&ctx);
+ bsu_beacon_t *b;
+ uint i;
+ for (i = 0; i < 2; i++)
+ {
+ b = blk_alloc ();
+ b->next = NULL;
+ b->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&ctx.cp, b);
+ }
+ test_beacon_uninit (&ctx);
+ test_fail_unless (slist_empty (ctx.cp.beacon.list., bare));
+ }
+ test_end;
+}
+
+void
+test_case_beacon__deactivate (test_t test)
+{
+ test_case_begin (test, "Deactivate");
+ test_begin (test, "Deactivate beacon module")
+ {
+ test_beacon_t ctx;
+ uint nb_beacons = 2;
+ test_beacon_init (&ctx);
+ /* Still configuring the test... */
+ ctx.cp.beacon.leon_timer.status = true;
+ /* Allocate some beacons. */
+ uint i;
+ for (i = 0; i < nb_beacons; i++)
+ {
+ bsu_beacon_t *beacon = blk_alloc ();
+ beacon->next = NULL;
+ slist_push_back (ctx.cp.beacon.list., beacon, bare);
+ }
+ /* test. */
+ cp_beacon_deactivate (&ctx.cp);
+ test_fail_unless (slist_empty (ctx.cp.beacon.list., bare));
+ test_beacon_uninit (&ctx);
+ test_fail_if (blk_check_memory () != true, "Memory leaks");
+ }
+ test_end;
+}
+
+static
+void
+test_beacon_variant_field (test_t test, bsu_beacon_t *beacon, cp_nid_t nid,
+ mac_coexistence_mode_t hm, u8 slot_usage, u8 slot_id, bool hoipflag)
+{
+ test_begin (test, "variant field: Constant values")
+ {
+ test_fail_unless (beacon->vf.ncnr ==
+ CP_BEACON_NON_COORDINATED_NETWORK);
+ test_fail_unless (beacon->vf.npsm == CP_BEACON_NPSM_NOT_ACTIVE);
+ test_fail_unless (beacon->vf.numslots == 1);
+ test_fail_unless (beacon->vf.aclsss == 0);
+ test_fail_unless (beacon->vf.rtsbf == false);
+ test_fail_unless (beacon->vf.nm == MAC_NM_CSMA_ONLY);
+ test_fail_unless (beacon->vf.ccocap == CP_CCO_LEVEL);
+ }
+ test_end;
+
+ test_begin (test, "Variant field: variant fields")
+ {
+ test_fail_unless (beacon->vf.nid == nid);
+ test_fail_unless (beacon->vf.hm == hm);
+ test_fail_unless (beacon->vf.slotusage == slot_usage);
+ test_fail_unless (beacon->vf.slotid == slot_id);
+ test_fail_unless (beacon->vf.hoip == hoipflag);
+ }
+ test_end;
+}
+
+static
+void
+test_beacon_discover_info (test_t test, bsu_beacon_t *beacon, bool updated,
+ bool cco_status, bool pco_status, u8 nb_sta, u8 nb_net, bool authenticated)
+{
+ test_begin (test, "Beacon entries : discover info")
+ {
+ u32 info_data;
+ bitstream_t bitstream;
+
+ bitstream_write_init (&bitstream, &info_data, 4);
+ bitstream_write (&bitstream, (int)updated, 1);
+ bitstream_write (&bitstream, CP_CCO_LEVEL, 2);
+ bitstream_write (&bitstream, CP_PCO_CAP, 1);
+ bitstream_write (&bitstream, CP_BACKUP_CCO_CAP, 1);
+ bitstream_write (&bitstream, cco_status, 1);
+ bitstream_write (&bitstream, pco_status, 1);
+ bitstream_write (&bitstream, false, 1);
+ bitstream_write (&bitstream, nb_sta, 8);
+ bitstream_write (&bitstream, nb_net, 8);
+ bitstream_write (&bitstream, authenticated, 1);
+ bitstream_write (&bitstream, false, 1);
+ bitstream_write (&bitstream, 0, 6);
+ bitstream_finalise (&bitstream);
+
+ /* discover info data are always present */
+ test_fail_unless (beacon->bmis.discover_info.present == true);
+ test_fail_unless (beacon->bmis.discover_info.info_data == info_data);
+ }
+ test_end;
+}
+static
+void
+test_beacon_bentries (test_t test, bsu_beacon_t *beacon,
+ bool disc_flag, cp_tei_t disc_tei,
+ uint hoip_cd, cp_tei_t hoip_tei,
+ uint kc_cd, enum bsu_beacon_eks_kbc_t kbc, u8 eks,
+ mac_coexistence_mode_t new_hm,
+ uint snid_cd, cp_snid_t new_snid)
+{
+ test_begin (test, "Beacon entries")
+ {
+ /* Discover. */
+ test_fail_unless (beacon->bmis.discover.present == disc_flag);
+ if (disc_flag)
+ test_fail_unless (beacon->bmis.discover.tei == disc_tei);
+ /* Handover in progress. */
+ if (beacon->bmis.handover.present)
+ {
+ test_fail_unless (beacon->bmis.handover.hcd == hoip_cd);
+ test_fail_unless (beacon->bmis.handover.tei == hoip_tei);
+ }
+ /* eks. */
+ if (beacon->bmis.eks.present)
+ {
+ test_fail_unless (beacon->bmis.eks.kccd == kc_cd);
+ test_fail_unless (beacon->bmis.eks.kbc == kbc);
+ test_fail_unless (beacon->bmis.eks.new_eks == eks);
+ }
+ /* Change hm. */
+ if (beacon->bmis.change_hm.present)
+ {
+ test_fail_unless (beacon->bmis.change_hm.hmccd ==
+ CP_BEACON_COUNTDOWN_HM);
+ test_fail_unless (beacon->bmis.change_hm.newhm == new_hm);
+ }
+ /* Change snid. */
+ if (beacon->bmis.change_snid.present)
+ {
+ test_fail_unless (beacon->bmis.change_snid.snidccd == snid_cd);
+ test_fail_unless (beacon->bmis.change_snid.new_snid == new_snid);
+ }
+ /* others. */
+ test_fail_unless (beacon->bmis.bpsto.present == true);
+ test_fail_unless (beacon->bmis.mac_address.present == true);
+ test_fail_unless (beacon->bmis.relocation.present == false);
+ test_fail_unless (beacon->bmis.aclsc.present == false);
+ test_fail_unless (beacon->bmis.cns.present == false);
+ }
+ test_end;
+}
+
+void
+test_suite_beacon__beacon_generation (test_t test)
+{
+ test_beacon_t ctx;
+ bsu_beacon_t beacon;
+ test_beacon_init (&ctx);
+
+ /* Data set one */
+ const cp_nid_t nid_1 = 0x001456789ABCDEF0ull;
+ const cp_tei_t tei_1 = 42;
+ const cp_snid_t snid_1 = 0xFE;
+ const u8 slot_id_1 = 1;
+ enum cp_beacon_hoip_e hoip_flag_1 = CP_BEACON_HOIP_FALSE;
+ const bool cco_flag_1 = true;
+ const bool pco_flag_1 = false;
+ const bool authen_1 = true;
+ const mac_coexistence_mode_t hm_1 = MAC_COEXISTENCE_AV_ONLY_MODE;
+ const uint kc_cd = 0xAB;
+ const enum bsu_beacon_eks_kbc_t kbc = BSU_BEACON_EKS_KBC_NEK;
+ const u8 eks = 0x12;
+ const uint hoip_cd = 0xCD;
+ const cp_tei_t hoip_tei = 44;
+ const mac_coexistence_mode_t new_hm = MAC_COEXISTENCE_FULL_HYBRID_MODE;
+ const u8 snid_cd = 0xA;
+ const cp_snid_t new_snid = 0xF;
+
+ cp_net_t *net_1 = cp_sta_mgr_add_avln (&ctx.cp, snid_1, nid_1);
+ cp_sta_own_data_set_tei (&ctx.cp, tei_1);
+ cp_net_set_slot_id_and_usage (&ctx.cp, net_1, slot_id_1, 0);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net_1);
+ cp_av_beacon_handover_hoipflag (&ctx.cp, hoip_flag_1);
+ cp_sta_own_data_set_cco_status (&ctx.cp, cco_flag_1);
+ cp_sta_own_data_set_pco_status (&ctx.cp, pco_flag_1);
+ cp_sta_own_data_set_authenticated_status (&ctx.cp, authen_1);
+ ctx.cp.beacon.discover.discover_interval_bp = 10;
+ ((cp_sta_own_data_t *)&ctx.cp.sta_mgr.sta_own_data)->hybrid_mode = hm_1;
+
+ cp_beacon_change_hm (&ctx.cp, new_hm);
+ ctx.cp.beacon.eks.kccd = kc_cd;
+ ctx.cp.beacon.eks.kbc = kbc;
+ ctx.cp.beacon.eks.new_eks = eks;
+ ctx.cp.beacon.hoip.hoipcd = hoip_cd;
+ ctx.cp.beacon.hoip.cco = hoip_tei;
+ ctx.cp.beacon.snids.snidcd = snid_cd;
+ ctx.cp.beacon.snids.snid = new_snid;
+ ctx.cp.beacon.discover.countdown_bp = 0; // so that the flag is true
+
+ /* Regions. */
+ cp_cco_region_alloc_t *region;
+ uint end_time_atu = 3907;
+
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA;
+ region->end_time_atu = end_time_atu;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ /* Fill the beacon data share memory */
+ cp_beacon_fill (&ctx.cp, &beacon);
+
+ test_suite_begin (test, "Beacon generation");
+ test_case_begin (test, "fill share memory");
+
+ /* Check the variant fields */
+ test_beacon_variant_field (test, &beacon, nid_1, hm_1, (1 << slot_id_1),
+ slot_id_1, hoip_flag_1);
+ /* Check the discover info field */
+ test_beacon_discover_info (test, &beacon, true, cco_flag_1, pco_flag_1,
+ 0, 0, authen_1);
+ /* Check most bentry fields */
+ test_beacon_bentries (test, &beacon,
+ true, tei_1,
+ hoip_cd, hoip_tei,
+ kc_cd, kbc, eks,
+ new_hm,
+ snid_cd, new_snid);
+ /* Check regions bentries */
+ test_begin (test, "Region")
+ {
+ test_fail_unless (beacon.bmis.region.nb == 1);
+ test_fail_unless (beacon.bmis.region.region[0].rt ==
+ CP_BEACON_REGION_TYPE_SHARED_CSMA);
+ test_fail_unless (beacon.bmis.region.region[0].end_time_atu ==
+ end_time_atu);
+ }
+ test_end;
+ /* Check schedule bentries */
+ test_begin (test, "schedule")
+ {
+ test_fail_unless (beacon.bmis.ps.nb == 0);
+ test_fail_unless (beacon.bmis.nps.ns == 0);
+ }
+ test_end;
+
+ /* Change values */
+
+ /* Data set two */
+ const cp_nid_t nid_2 = 0x001567890ABCDEF0ull;
+ const cp_tei_t tei_2 = 43;
+ const cp_snid_t snid_2 = 0xEF;
+ const u8 slot_id_2 = 2;
+ enum cp_beacon_hoip_e hoip_flag_2 = CP_BEACON_HOIP_TRUE;
+ const bool cco_flag_2 = false;
+ const bool pco_flag_2 = true;
+ const bool authen_2 = false;
+ const mac_coexistence_mode_t hm_2 = MAC_COEXISTENCE_NB - 1;
+
+ cp_net_t *net_2 = cp_sta_mgr_add_avln (&ctx.cp, snid_2, nid_2);
+ cp_sta_own_data_set_tei (&ctx.cp, tei_2);
+ cp_net_set_slot_id_and_usage (&ctx.cp, net_2, slot_id_2, 0);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net_2);
+ cp_av_beacon_handover_hoipflag (&ctx.cp, hoip_flag_2);
+ cp_sta_own_data_set_cco_status (&ctx.cp, cco_flag_2);
+ cp_sta_own_data_set_pco_status (&ctx.cp, pco_flag_2);
+ cp_sta_own_data_set_authenticated_status (&ctx.cp, authen_2);
+ ((cp_sta_own_data_t *)&ctx.cp.sta_mgr.sta_own_data)->hybrid_mode = hm_2;
+
+ ctx.cp.beacon.eks.kccd = 0;
+ ctx.cp.beacon.hoip.hoipcd = 0;
+ ctx.cp.beacon.snids.snidcd = 0;
+ ctx.cp.beacon.hm.hmcd = 0;
+
+ /* Regions. */
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_BEACON;
+ region->end_time_atu = end_time_atu - 10;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_STAYOUT;
+ region->end_time_atu = end_time_atu + 10;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ /* Schedules. */
+ uint nb, ns;
+ int i;
+ cp_cco_bw_alloc_t *sched;
+
+ for (i = 1, nb = 0; i < 8; i += 6, nb++)
+ {
+ for (ns=0; ns < 2; ns++)
+ {
+ sched = cp_cco_bw_alloc_init (&ctx.cp);
+ sched->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT;
+ sched->pscd = i;
+ sched->cscd = i;
+ sched->stpf = false;
+ sched->glid = 0x55 + nb;
+ sched->end_time_atu = end_time_atu + nb * 10 + ns * 5;
+ sched->start_time_atu = end_time_atu + nb * 10 + ns * 5 -4;
+ cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, sched);
+ slab_release (sched);
+ }
+ }
+
+ for (ns = 0; ns < BSU_BEACON_BMIS_SCHEDULES_SAI_MAX; ns++)
+ {
+ sched = cp_cco_bw_alloc_init (&ctx.cp);
+ sched->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT;
+ sched->pscd = ns;
+ sched->cscd = ns;
+ sched->stpf = false;
+ sched->glid = 0x45 + ns;
+ sched->start_time_atu = end_time_atu - 10 * (ns + 1) -9;
+ sched->end_time_atu = end_time_atu - 10 * (ns + 1);
+ cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, sched);
+ slab_release (sched);
+ }
+
+ /* Fill the beacon data share memory */
+ cp_beacon_fill (&ctx.cp, &beacon);
+
+ test_suite_begin (test, "Beacon generation 2");
+ test_case_begin (test, "fill share memory 2");
+
+ /* Check the variant fields */
+ test_beacon_variant_field (test, &beacon, nid_2, hm_2,
+ (1 << slot_id_2) + (1 << slot_id_1),
+ slot_id_2, hoip_flag_2);
+ /* Check the discover info field */
+ test_beacon_discover_info (test, &beacon, true, cco_flag_2, pco_flag_2,
+ 0, 1, authen_2);
+ /* Check most bentry fields */
+ test_beacon_bentries (test, &beacon,
+ false, tei_2, 0, 0, 0, 0, 0, 0, 0, 0);
+
+ /* Check regions bentries */
+ test_begin (test, "Region 2")
+ {
+ test_fail_unless (beacon.bmis.region.nb == 3);
+ test_fail_unless (beacon.bmis.region.region[0].rt ==
+ CP_BEACON_REGION_TYPE_BEACON);
+ test_fail_unless (beacon.bmis.region.region[0].end_time_atu ==
+ end_time_atu - 10);
+ test_fail_unless (beacon.bmis.region.region[1].rt ==
+ CP_BEACON_REGION_TYPE_SHARED_CSMA);
+ test_fail_unless (beacon.bmis.region.region[1].end_time_atu ==
+ end_time_atu);
+ test_fail_unless (beacon.bmis.region.region[2].rt ==
+ CP_BEACON_REGION_TYPE_STAYOUT);
+ test_fail_unless (beacon.bmis.region.region[2].end_time_atu ==
+ end_time_atu + 10);
+ }
+ test_end;
+
+ /* Check schedule bentries */
+ test_begin (test, "schedule 2")
+ {
+ for (i = 1, nb = 0; i < 8; i += 6, nb++)
+ {
+ test_fail_unless (beacon.bmis.ps.ps[nb].pscd == i);
+ test_fail_unless (beacon.bmis.ps.ps[nb].cscd == i);
+ test_fail_unless (beacon.bmis.ps.ps[nb].ns == 2);
+
+ for (ns = 0; ns < 2; ns++)
+ {
+ test_fail_unless (beacon.bmis.ps.ps[nb].sais[ns].stpf ==
+ false);
+ test_fail_unless (beacon.bmis.ps.ps[nb].sais[ns].glid ==
+ 0x55 + nb);
+ test_fail_unless (
+ beacon.bmis.ps.ps[nb].sais[ns].start_time_atu ==
+ end_time_atu + nb * 10 + ns * 5 - 4);
+ test_fail_unless (
+ beacon.bmis.ps.ps[nb].sais[ns].end_time_atu ==
+ end_time_atu + nb * 10 + ns * 5);
+ }
+ }
+ test_fail_unless (beacon.bmis.ps.nb == nb);
+
+ for (i = BSU_BEACON_BMIS_SCHEDULES_SAI_MAX - 1, ns = 0; i >= 0;
+ i--, ns++)
+ {
+ test_fail_unless (beacon.bmis.nps.sais[ns].stpf ==
+ false);
+ test_fail_unless (beacon.bmis.nps.sais[ns].glid ==
+ 0x45 + i);
+ test_fail_unless (
+ beacon.bmis.nps.sais[ns].start_time_atu ==
+ end_time_atu - (i + 1) * 10 - 9);
+ test_fail_unless (
+ beacon.bmis.nps.sais[ns].end_time_atu ==
+ end_time_atu - (i + 1) * 10);
+ }
+ test_fail_unless (beacon.bmis.nps.ns == ns);
+ }
+ test_end;
+ test_beacon_uninit (&ctx);
+}
+
+void
+test_case_beacon_snid_change_cco (test_t test)
+{
+ uint snid;
+ cp_net_t *net;
+ test_beacon_t ctx;
+
+ test_case_begin (test, "CCo");
+ test_beacon_init (&ctx);
+
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0xA, 1);
+ cp_sta_own_data_set_snid (&ctx.cp, 0xA);
+ cp_sta_own_data_set_tei (&ctx.cp, 1);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+ cp_sta_own_data_set_cco_status (&ctx.cp, true);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x123456789ABCull);
+
+
+ test_begin (test, "Change SNID")
+ {
+ /* Process the test. */
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 0);
+
+ snid = 1;
+ cp_beacon_change_snid (&ctx.cp, snid);
+
+ test_fail_unless (ctx.cp.beacon.snids.snid == snid);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == CP_BEACON_COUNTDOWN_SNID);
+ }
+ test_end;
+
+ test_begin (test, "Change SNID, check bentry in Central beacon")
+ {
+ cp_cco_region_alloc_t *region;
+ cp_cco_bw_alloc_t *alloc;
+ set_t set_schedules;
+ set_t set_regions;
+ bsu_beacon_t beacon;
+
+ set_init (&set_schedules, cp_cco_bw_alloc_less);
+ set_init (&set_regions, cp_cco_region_alloc_less);
+ cp_cco_region_init (&ctx.cp);
+ cp_cco_bw_init (&ctx.cp);
+
+ /* Regions. */
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA;
+ region->end_time_atu = 3907;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ /* Schedules. */
+ alloc = cp_cco_bw_alloc_init (&ctx.cp);
+ alloc->pscd = 7;
+ alloc->cscd = 7;
+ alloc->stpf = false;
+ alloc->glid = 0x45;
+ alloc->end_time_atu = 3907;
+ alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT;
+ cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc);
+ slab_release (alloc);
+
+ cp_beacon_fill (&ctx.cp, &beacon);
+
+ test_fail_unless (beacon.bmis.change_snid.present == true);
+ test_fail_unless (beacon.bmis.change_snid.snidccd == ctx.cp.beacon.snids.snidcd);
+ test_fail_unless (beacon.bmis.change_snid.new_snid == ctx.cp.beacon.snids.snid);
+
+ cp_cco_bw_alloc_clean (&ctx.cp, &set_schedules);
+ cp_cco_region_alloc_clean (&ctx.cp, &set_regions);
+
+ cp_beacon_sta_compute_schedules (&ctx.cp, &beacon);
+ alloc = cp_cco_bw_alloc_get_first (&ctx.cp, &ctx.cp.bw.alloc_list);
+ test_fail_unless (alloc->persistence ==
+ CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT);
+ alloc = cp_cco_bw_alloc_get_next (&ctx.cp, &ctx.cp.bw.alloc_list, alloc);
+ test_fail_unless (!alloc);
+ cp_cco_region_alloc_clean (&ctx.cp, &set_regions);
+ cp_cco_bw_alloc_clean (&ctx.cp, &set_schedules);
+ cp_cco_bw_uninit (&ctx.cp);
+ cp_cco_region_uninit (&ctx.cp);
+ }
+ test_end;
+
+ /* Uninit all the data. */
+ test_beacon_uninit (&ctx);
+}
+
+
+void
+test_case_beacon_snid_change_sta (test_t test)
+{
+ test_case_begin (test, "Station");
+ u32 last_countdown_call_date = phy_date () - BSU_ACLF_BP_60HZ_TCK - 100;
+ test_begin (test, "Beacon reception")
+ {
+ bsu_beacon_t *beacon;
+ cp_net_t *net;
+ cp_sta_own_data_t *own;
+ test_beacon_t ctx;
+ test_beacon_init (&ctx);
+ /** Init the context. */
+ ctx.cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK;
+ ctx.cp.beacon.last_countdown_call_date_active = true;
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ /* Configure station own data. */
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ own->nid_track = 1;
+ own->tei_track = 1;
+ own->cco_mac_addr_track = TEST_CCO_MAC;
+ /** Check snid default values. */
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 0);
+ test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0);
+ test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0);
+ /** Create a central beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_snid.present = true;
+ beacon->bmis.change_snid.new_snid = 0xC;
+ beacon->bmis.change_snid.snidccd = 3;
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ /** Check snid values are taken. */
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0xC);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 3);
+ test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0);
+ test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0);
+ /** Create the next beacon (countdown decreased). */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_snid.snidccd = 2;
+ /** launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ /** Check countdown. */
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0xC);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 2);
+ test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0);
+ test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0);
+ /** Create the next beacon (countdown decreased). */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_snid.snidccd = 1;
+ /** launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ /** Check countdown. */
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0xC);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 1);
+ test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0);
+ test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0);
+ /* Create the beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_snid.present = false;
+ beacon->bmis.nbe--;
+ beacon->params.rx_parameters.snid = 0xC;
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ /** Check new snid is 0xC. */
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0xC);
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 0);
+ test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0xC);
+ test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0xC);
+
+ dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1));
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+
+ test_begin (test, "Beacon missed")
+ {
+ test_beacon_t ctx;
+ cp_net_t *net;
+ cp_cco_region_alloc_t *region;
+ cp_cco_bw_alloc_t *alloc;
+ test_beacon_init (&ctx);
+ /* Regions. */
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA;
+ region->end_time_atu = 3907;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ /* Schedules. */
+ alloc = cp_cco_bw_alloc_init (&ctx.cp);
+ alloc->stpf = false;
+ alloc->glid = 0x45;
+ alloc->end_time_atu = 3907;
+ alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT;
+ cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc);
+ slab_release (alloc);
+
+ /* Configure station own data. */
+ net = cp_sta_mgr_add_avln (&ctx.cp, 1, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+
+ /* Configure the test. */
+ ctx.cp.beacon.snids.snidcd = 2;
+ ctx.cp.beacon.snids.snid = 0xc;
+
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_beacon_not_received (&ctx.cp);
+
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 1);
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0xc);
+
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_beacon_not_received (&ctx.cp);
+
+ test_fail_unless (ctx.cp.beacon.snids.snidcd == 0);
+ test_fail_unless (ctx.cp.beacon.snids.snid == 0xc);
+ test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0xC);
+ test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0xC);
+
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
+test_suite_beacon_snid_change (test_t test)
+{
+ test_suite_begin (test, "Change SNID");
+
+ test_case_beacon_snid_change_cco (test);
+ test_case_beacon_snid_change_sta (test);
+}
+
+void
+test_case_beacon_hm_change_sta (test_t test)
+{
+ test_case_begin (test, "Station");
+ u32 last_countdown_call_date = phy_date () - BSU_ACLF_BP_60HZ_TCK - 100;
+ test_begin (test, "Beacon reception")
+ {
+ test_beacon_t ctx;
+ bsu_beacon_t *beacon;
+ cp_net_t *net;
+ cp_sta_own_data_t *own;
+ /** Init the context. */
+ test_beacon_init (&ctx);
+ ctx.cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK;
+ /** Configure station own data. */
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ own->nid_track = 1;
+ own->tei_track = 1;
+ own->cco_mac_addr_track = TEST_CCO_MAC;
+ own->hybrid_mode = 0;
+ /** Create a central beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_hm.present = true;
+ beacon->bmis.change_hm.newhm = 1;
+ beacon->bmis.change_hm.hmccd = 3;
+ beacon->bmis.nbe = 4;
+ /** Check default values. */
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0);
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 0);
+ test_fail_unless (own->hybrid_mode == 0);
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ /** Check values are taken. */
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0x1);
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 3);
+ test_fail_unless (own->hybrid_mode == 0);
+ /** Create the new beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_hm.hmccd = 2;
+ /** launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ /** Check values are taken. */
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0x1);
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 2);
+ test_fail_unless (own->hybrid_mode == 0);
+ /** Create the new beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_hm.hmccd = 1;
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0x1);
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 1);
+ test_fail_unless (own->hybrid_mode == 0);
+ /* Create the beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.change_hm.present = false;
+ beacon->bmis.nbe = 3;
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0x1);
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 0);
+ test_fail_unless (own->hybrid_mode == 0x1);
+ dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1));
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+
+ test_begin (test, "Beacon missed")
+ {
+ test_beacon_t ctx;
+ cp_net_t *net;
+ cp_cco_region_alloc_t *region;
+ cp_cco_bw_alloc_t *alloc;
+ cp_sta_own_data_t *own;
+ test_beacon_init (&ctx);
+ /* Regions. */
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA;
+ region->end_time_atu = 3907;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ /* Schedules. */
+ alloc = cp_cco_bw_alloc_init (&ctx.cp);
+ alloc->stpf = false;
+ alloc->glid = 0x45;
+ alloc->end_time_atu = 3907;
+ alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT;
+ cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc);
+ slab_release (alloc);
+
+ /* Configure station own data. */
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+
+ /* Configure the test. */
+ ctx.cp.beacon.hm.hmcd = 2;
+ ctx.cp.beacon.hm.hm = 0x1;
+
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_beacon_not_received (&ctx.cp);
+
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 1);
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0x1);
+
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_beacon_not_received (&ctx.cp);
+
+ test_fail_unless (ctx.cp.beacon.hm.hmcd == 0);
+ test_fail_unless (ctx.cp.beacon.hm.hm == 0x1);
+ test_fail_unless (own->hybrid_mode == 0x1);
+
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
+test_suite_beacon_hm_change (test_t test)
+{
+ test_suite_begin (test, "Hybrid mode change");
+
+ test_case_beacon_hm_change_sta (test);
+}
+
+void
+test_case_beacon_eks_change_cco (test_t test)
+{
+ cp_key_t nek;
+ cp_net_t *net;
+ test_beacon_t ctx;
+ test_case_begin (test, "CCo");
+
+ /** Configure the context. */
+ test_beacon_init (&ctx);
+
+ /** Configure our station. */
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0xA, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 1);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+ cp_sta_own_data_set_cco_status (&ctx.cp, true);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x123456789ABCull);
+
+ test_begin (test, "Change EKS")
+ {
+ uint i;
+ /** Check default values. */
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 0);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == 0);
+
+ /** Change nek. */
+ for (i = 0; i < COUNT (nek.key); i++)
+ nek.key[i] = i;
+ cp_beacon_change_nek (&ctx.cp, MAC_EKS_MIN, nek, false /* not now*/);
+
+ /** Check new values. */
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
+ test_fail_unless (ctx.cp.beacon.eks.kccd == CP_BEACON_COUNTDOWN_EKS);
+ }
+ test_end;
+
+ /* Uninit all the data. */
+ test_beacon_uninit (&ctx);
+}
+
+void
+test_case_beacon_eks_change_sta (test_t test)
+{
+ test_case_begin (test, "Station");
+ u32 last_countdown_call_date = phy_date () - BSU_ACLF_BP_60HZ_TCK - 100;
+ test_begin (test, "Beacon reception")
+ {
+ bsu_beacon_t *beacon;
+ cp_net_t *net;
+ cp_sta_own_data_t *own;
+ test_beacon_t ctx;
+ /** Init the context. */
+ test_beacon_init (&ctx);
+ /** Configure station own data. */
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ own->nid_track = 1;
+ own->tei_track = 1;
+ own->cco_mac_addr_track = TEST_CCO_MAC;
+ /** Create a central beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.eks.present = true;
+ beacon->bmis.eks.kccd = 2;
+ beacon->bmis.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
+ beacon->bmis.eks.new_eks = MAC_EKS_MIN + 1;
+ mac_eks_t ref_eks_current = MAC_EKS_MIN + 2;
+ mac_eks_t ref_eks_next = MAC_EKS_MIN + 3;
+ ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks =
+ ref_eks_current;
+ ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks = ref_eks_next;
+ /** Check default values. */
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 0);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN);
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 2);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
+ test_fail_unless (
+ ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks ==
+ ref_eks_current);
+ test_fail_unless (ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks ==
+ ref_eks_next);
+ /* Create the beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.eks.kccd = 1;
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 1);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
+ test_fail_unless (
+ ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks ==
+ ref_eks_current);
+ test_fail_unless (ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks ==
+ ref_eks_next);
+ /* Create the beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.eks.present = false;
+ beacon->bmis.nbe--;
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 0);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NB);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
+ test_fail_unless (
+ ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks ==
+ ref_eks_current);
+ test_fail_unless (ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks ==
+ MAC_EKS_CLEAR);
+ dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1));
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+
+ test_begin (test, "Beacon missed")
+ {
+ cp_net_t *net;
+ cp_cco_region_alloc_t *region;
+ cp_cco_bw_alloc_t *alloc;
+ test_beacon_t ctx;
+ test_beacon_init (&ctx);
+ /* Regions. */
+ region = cp_cco_region_alloc_init (&ctx.cp);
+ region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA;
+ region->end_time_atu = 3907;
+ cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region);
+ slab_release (region);
+
+ /* Schedules. */
+ alloc = cp_cco_bw_alloc_init (&ctx.cp);
+ alloc->stpf = false;
+ alloc->glid = 0x45;
+ alloc->end_time_atu = 3907;
+ alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT;
+ cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc);
+ slab_release (alloc);
+
+ /* Configure station own data. */
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+
+ /* Configure the test. */
+ ctx.cp.beacon.eks.kccd = 2;
+ ctx.cp.beacon.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
+ ctx.cp.beacon.eks.new_eks = MAC_EKS_MIN + 1;
+
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_beacon_not_received (&ctx.cp);
+
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 1);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
+
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_beacon_not_received (&ctx.cp);
+
+ test_fail_unless (ctx.cp.beacon.eks.kccd == 0);
+ test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NB);
+ test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1);
+
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
+test_suite_beacon_eks_change (test_t test)
+{
+ test_suite_begin (test, "Encryption key change");
+
+ test_case_beacon_eks_change_cco (test);
+ test_case_beacon_eks_change_sta (test);
+}
+
+void
+test_suite_beacon_mac_address_bentry (test_t test)
+{
+ test_suite_begin (test, "Central beacon");
+ test_case_begin (test, "Mac address bentry missing");
+ test_begin (test, "Beacon reception")
+ {
+ bsu_beacon_t *beacon;
+ cp_net_t *net;
+ cp_sta_own_data_t *own;
+ test_beacon_t ctx;
+ /** Init the context. */
+ test_beacon_init (&ctx);
+ ctx.cp.beacon.last_countdown_call_date_active = false;
+ /** Configure station own data. */
+ own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1);
+ cp_sta_own_data_set_tei (&ctx.cp, 2);
+ cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull);
+ cp_sta_mgr_set_our_avln (&ctx.cp, net);
+ own->nid_track = 1;
+ own->tei_track = 1;
+ own->cco_mac_addr_track = MAC_ZERO;
+ /** Create a central beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.mac_address.present = false;
+ /* launch the test. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ cp_sta_t *cco = cp_net_get_cco (&ctx.cp, net);
+ test_fail_unless (cco);
+ test_fail_unless (cp_sta_get_mac_address (cco) == MAC_BROADCAST);
+ test_fail_unless (cp_sta_get_cco_status (cco) == true);
+ slab_release (cco);
+ /* Mac address in the central beacon is present, but our track on the
+ * mac address is still MAC_ZERO. */
+ beacon = test_new_beacon ();
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS (0x01, 0x23, 0x45, 0x67, 0x8a, 0xbc);
+ cp_beacon_receive (&ctx.cp, beacon);
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ cco = cp_net_get_cco (&ctx.cp, net);
+ test_fail_unless (cco);
+ /* The beacon is not processed. */
+ test_fail_unless (cp_sta_get_mac_address (cco)
+ != beacon->bmis.mac_address.mac_address);
+ test_fail_unless (cp_sta_get_cco_status (cco) == true);
+ slab_release (cco);
+ /* MAC address tracked is different from our CCo. */
+ beacon = test_new_beacon ();
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS (0x00, 0x13, 0xd7, 0x00, 0x00, 0x01);
+ cp_beacon_receive (&ctx.cp, beacon);
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ cco = cp_net_get_cco (&ctx.cp, net);
+ test_fail_unless (cco);
+ test_fail_unless (cp_sta_get_mac_address (cco)
+ != beacon->bmis.mac_address.mac_address);
+ test_fail_unless (cp_sta_get_cco_status (cco) == true);
+ slab_release (cco);
+ /* Set the track mac address. */
+ own->cco_mac_addr_track =
+ MAC_ADDRESS (0x00, 0x13, 0xd7, 0x00, 0x00, 0x01);
+ /* This beacon should be processed as our CCo's central beacon. */
+ beacon = test_new_beacon ();
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS (0x00, 0x13, 0xd7, 0x00, 0x00, 0x01);
+ cp_beacon_receive (&ctx.cp, beacon);
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ cco = cp_net_get_cco (&ctx.cp, net);
+ test_fail_unless (cco);
+ test_fail_unless (cp_sta_get_mac_address (cco)
+ == beacon->bmis.mac_address.mac_address);
+ test_fail_unless (cp_sta_get_cco_status (cco) == true);
+ slab_release (cco);
+ /* This one should no be processed as our CCo's central beacon. It
+ * comes from another one. */
+ beacon = test_new_beacon ();
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS (0x01, 0x23, 0x45, 0x67, 0x8a, 0xbc);
+ cp_beacon_receive (&ctx.cp, beacon);
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ cco = cp_net_get_cco (&ctx.cp, net);
+ test_fail_unless (cco);
+ test_fail_unless (cp_sta_get_mac_address (cco) ==
+ MAC_ADDRESS (0x00, 0x13, 0xd7, 0x00, 0x00, 0x01));
+ test_fail_unless (cp_sta_get_cco_status (cco) == true);
+ slab_release (cco);
+ dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1));
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
+test_suite_beacon_no_net (test_t t)
+{
+ test_suite_begin (t, "No net for beacon processing");
+ test_case_begin (t, "Beacon process");
+ u32 last_countdown_call_date = phy_date () - BSU_ACLF_BP_60HZ_TCK - 100;
+ test_begin (t, "let's go")
+ {
+ test_beacon_t ctx;
+ test_beacon_init (&ctx);
+ bsu_beacon_t *beacon = blk_alloc ();
+ cp_beacon_fill (&ctx.cp, beacon);
+ uint i;
+ for (i = 0; i < HPAV_AVLNS_NB_MAX; i++)
+ cp_sta_mgr_add_avln (&ctx.cp, i + 1, i);
+ test_fail_unless (!cp_sta_mgr_add_avln (&ctx.cp, 15, 30));
+ beacon->params.rx_parameters.snid = 0xf;
+ beacon->vf.nid = 0x1234;
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (!cp_sta_mgr_get_avln (&ctx.cp, 15, 30));
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
+test_suite_beacon_spoc_update (test_t test)
+{
+ test_beacon_t ctx;
+ u32 last_countdown_call_date = phy_date () - BSU_ACLF_BP_60HZ_TCK - 100;
+ test_beacon_init (&ctx);
+ test_suite_begin (test, "SPOC update");
+ test_case_begin (test, "Frequency error invalid and valid");
+ test_begin (test, "SPOC only updated if F.E. is valid")
+ {
+ cp_sta_own_data_t *own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ ctx.cp.beacon.spoc_update_interval_ms = 1;
+ bsu_beacon_t *beacon = test_new_beacon ();
+ cp_sta_mgr_add_avln (&ctx.cp, beacon->params.rx_parameters.snid,
+ beacon->vf.nid);
+ ctx.cp.beacon.spoc_update_date = phy_date () - 1;
+ cp_sta_own_data_set_nid (&ctx.cp, beacon->vf.nid);
+ own->nid_track = beacon->vf.nid;
+ own->tei_track = beacon->vf.stei;
+ own->cco_mac_addr_track = TEST_CCO_MAC;
+ beacon->params.rx_parameters.snid =
+ cp_sta_own_data_get_snid (&ctx.cp);
+ /* Process a received beacon with a frequency error invalid. */
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (!ctx.cp.beacon.spoc_updated);
+ /* This received beacon has a valid frequency error, SPOC should be
+ * updated. */
+ beacon = test_new_beacon ();
+ beacon->params.frequency_error_valid = true;
+ beacon->params.rx_parameters.snid =
+ cp_sta_own_data_get_snid (&ctx.cp);
+ ctx.cp.beacon.spoc_update_date = phy_date () - 1;
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.spoc_updated);
+ /* This received beacon has a invalid frequency error. SPOC updated
+ * flag stay at true. */
+ beacon = test_new_beacon ();
+ beacon->params.frequency_error_valid = false;
+ ctx.cp.beacon.spoc_update_date = phy_date () - 1;
+ cp_beacon_receive (&ctx.cp, beacon);
+ ctx.cp.beacon.last_countdown_call_date = last_countdown_call_date;
+ cp_beacon_get_and_process_beacon (&ctx.cp);
+ test_fail_unless (ctx.cp.beacon.spoc_updated);
+ }
+ test_end;
+ test_beacon_uninit (&ctx);
+}
+
+void
+test_suite_beacon_hoip_ended (test_t t)
+{
+ test_suite_begin (t, "Handover ended, avoid to send the last beacon");
+ test_case_begin (t, "Handover in progress");
+ test_beacon_t ctx;
+ test_beacon_init (&ctx);
+ test_begin (t, "Handover not ended")
+ {
+ ctx.bsu_updated = false;
+ ctx.cp.beacon.hoip.hoipcd = 2;
+ cp_beacon_cco_update_beacon_data (&ctx.cp);
+ test_fail_unless (ctx.bsu_updated);
+ }
+ test_end;
+ test_begin (t, "Handover Ended")
+ {
+ ctx.bsu_updated = false;
+ ctx.cp.beacon.hoip.hoipcd = 1;
+ cp_beacon_cco_update_beacon_data (&ctx.cp);
+ test_fail_unless (!ctx.bsu_updated);
+ }
+ test_end;
+ test_beacon_uninit (&ctx);
+}
+
+
+void
+test_suite_beacon_update_tracking (test_t t)
+{
+ test_suite_begin (t, "Update tracking");
+ test_case_begin (t, "Update tracking");
+ test_begin (t, "update tracking")
+ {
+ test_beacon_t ctx;
+ test_beacon_init (&ctx);
+ u8 tei = MAC_TEI_STA_MAX;
+ mac_t mac = MAC_ADDRESS (0x00, 0x13, 0xd7, 0x78, 0x79, 0x80);
+ cp_net_t *net = cp_sta_mgr_add_avln (&ctx.cp, 1, 1);
+ cp_sta_t *sta = cp_sta_mgr_sta_add (&ctx.cp, net, tei, mac);
+ cp_sta_own_data_t *own = cp_sta_mgr_get_sta_own_data (&ctx.cp);
+ test_fail_unless (own->tei_track != tei);
+ test_fail_unless (own->cco_mac_addr_track != mac);
+ cp_beacon_update_tracking (&ctx.cp, sta);
+ test_fail_unless (own->tei_track == tei);
+ test_fail_unless (own->cco_mac_addr_track == mac);
+ slab_release (sta);
+ test_beacon_uninit (&ctx);
+ }
+ test_end;
+}
+
+int
+main (void)
+{
+ test_t test;
+ test_init (test, 0, NULL);
+
+ test_case_beacon_uninit (test);
+ test_case_beacon__deactivate (test);
+ test_suite_beacon__beacon_generation (test);
+ test_suite_beacon_snid_change (test);
+ test_suite_beacon_hm_change (test);
+ test_suite_beacon_eks_change (test);
+ test_suite_beacon_mac_address_bentry (test);
+ test_suite_beacon_no_net (test);
+ test_suite_beacon_spoc_update (test);
+ test_suite_beacon_hoip_ended (test);
+ test_suite_beacon_update_tracking (test);
+
+ test_case_begin (test, "Memory allocation");
+ test_begin (test, "memory leaks")
+ {
+ test_fail_if (blk_check_memory () != true, "Memory leaks");
+ }
+ test_end;
+
+ test_result (test);
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/beacon_scenario.c b/cesar/cp/eoc/beacon/test/utest2/src/beacon_scenario.c
new file mode 100644
index 0000000000..d6b668e8b9
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/beacon_scenario.c
@@ -0,0 +1,245 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/beacon_scenario.c
+ * \brief Unit test for the beacon module.
+ * \ingroup cp_beacon
+ *
+ * « long description »
+ */
+
+#include "common/std.h"
+#include "lib/slist.h"
+#include "lib/scenario/scenario.h"
+#include "lib/test.h"
+#include "cp/inc/context.h"
+#include "config.h"
+
+bsu_beacon_t beacon_data;
+extern bool cco_status;
+extern cp_net_t our_avln;
+
+void
+cp_beacon_receive (void *ul, bsu_beacon_t *beacon);
+
+void
+beacon_same_nid_test_case (test_t test)
+{
+ cp_t cp;
+ bsu_beacon_t *beacon;
+ scenario_globals_t globals = { .cp = &cp, };
+
+ /** Init the context. */
+ memset (&cp, 0, sizeof (cp_t));
+ mac_config_t mac_config;
+ memset (&mac_config, 0, sizeof (mac_config_t));
+ cp.mac_config = &mac_config;
+ cp_sta_mgr_init (&cp);
+ /* This device is cco */
+ cco_status = true;
+
+ test_case_begin (test, "get_and_process_beacon");
+
+ beacon = (bsu_beacon_t *) blk_alloc ();
+ memset (beacon, 0, sizeof (bsu_beacon_t));
+ beacon->vf.stei = 1;
+ beacon->vf.nid = 1;
+ beacon->params.rx_parameters.snid = 2;
+ /* the beacon is sent by an other cco than our */
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS(0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC);
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&cp, beacon);
+
+ test_begin (test, "cco receives beacon with same nid")
+ {
+ scenario_entry_t entries[] =
+ {
+ SCENARIO_ACTION (get_and_process_beacon),
+ SCENARIO_EVENT (cp_fsm_event_beacon_new,
+ .type = CP_FSM_EVENT_TYPE_BEACON_WITH_SAME_NID,
+ beacon, &our_avln, NULL),
+ SCENARIO_END
+ };
+ scenario_run (test, entries, &globals);
+ }
+ test_end;
+
+ beacon = (bsu_beacon_t *) blk_alloc ();
+ beacon->vf.stei = 4;
+ beacon->vf.nid = 1;
+ beacon->params.rx_parameters.snid = 1;
+ /* the beacon is sent by an other cco than our */
+ beacon->bmis.mac_address.present = true;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS(0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC);
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&cp, beacon);
+ cco_status = false;
+
+ test_begin (test, "sta receives beacon")
+ {
+ scenario_entry_t entries[] =
+ {
+ SCENARIO_ACTION (get_and_process_beacon),
+ SCENARIO_END
+ };
+ scenario_run (test, entries, &globals);
+ }
+ test_end;
+}
+
+void
+beacon_nek_request_test_case_eoc (test_t test)
+{
+ cp_t cp;
+ bsu_beacon_t *beacon;
+ scenario_globals_t globals = { .cp = &cp, };
+
+ /** Init the context. */
+ memset (&cp, 0, sizeof (cp_t));
+ mac_config_t mac_config;
+ memset (&mac_config, 0, sizeof (mac_config_t));
+ cp.mac_config = &mac_config;
+ bsu_aclf_t aclf;
+ memset (&aclf, 0, sizeof (bsu_aclf_t));
+ cp.bsu_aclf = &aclf;
+ *((bsu_aclf_bp_t*) &cp.bsu_aclf->beacon_period_theo_tck) =
+ BSU_ACLF_BP_50HZ_TCK;
+ cp_sta_mgr_init (&cp);
+
+ mac_eks_t ref_eks_current = MAC_EKS_MIN + 2;
+ mac_eks_t ref_eks_next = MAC_EKS_MIN + 3;
+
+ mac_config.nek_mgr.store[0].eks = ref_eks_current;
+ mac_config.nek_mgr.store[1].eks = ref_eks_next;
+ mac_config.nek_mgr.next_nek = &mac_config.nek_mgr.store[1];
+
+ test_case_begin (test, "get_and_process_beacon");
+
+ /** Test with eks from the beacon different than the local next eks
+ * we check a to_leave event is sent. */
+ beacon = (bsu_beacon_t *) blk_alloc ();
+ beacon->bmis.eks.present = true;
+ beacon->bmis.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
+ beacon->bmis.eks.new_eks = ref_eks_next + 1;
+ beacon->vf.stei = 1;
+ beacon->vf.nid = 1;
+ beacon->params.rx_parameters.snid = 1;
+ beacon->bmis.mac_address.present = false;
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&cp, beacon);
+
+ test_begin (test, "different eks")
+ {
+ scenario_entry_t entries[] =
+ {
+ SCENARIO_ACTION (get_and_process_beacon),
+ SCENARIO_EVENT (cp_fsm_event_bare_new,
+ .type = CP_FSM_EVENT_TYPE_to_leave),
+ SCENARIO_END
+ };
+ scenario_run (test, entries, &globals);
+ }
+ test_end;
+
+ /** Test with matching eks
+ * we check that no event is sent. */
+ beacon = (bsu_beacon_t *) blk_alloc ();
+ beacon->bmis.eks.present = true;
+ beacon->bmis.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
+ beacon->bmis.eks.new_eks = ref_eks_next;
+ beacon->vf.stei = 1;
+ beacon->vf.nid = 1;
+ beacon->params.rx_parameters.snid = 1;
+ beacon->bmis.mac_address.present = false;
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&cp, beacon);
+
+ test_begin (test, "same eks")
+ {
+ scenario_entry_t entries[] =
+ {
+ SCENARIO_ACTION (get_and_process_beacon),
+ SCENARIO_END
+ };
+ scenario_run (test, entries, &globals);
+ }
+ test_end;
+
+ /** Test with everything ok, but the local next eks is invalid
+ * we check that a to_leave event is sent. */
+ mac_config.nek_mgr.next_nek = NULL;
+
+ beacon = (bsu_beacon_t *) blk_alloc ();
+ beacon->bmis.eks.present = true;
+ beacon->bmis.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
+ beacon->bmis.eks.kccd = 1;
+ beacon->bmis.eks.new_eks = ref_eks_next;
+ beacon->vf.stei = 1;
+ beacon->vf.nid = 1;
+ beacon->params.rx_parameters.snid = 1;
+ beacon->bmis.mac_address.present = false;
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&cp, beacon);
+ test_begin (test, "next eks is invalid")
+ {
+ scenario_entry_t entries[] =
+ {
+ SCENARIO_ACTION (get_and_process_beacon),
+ SCENARIO_EVENT (cp_fsm_event_bare_new,
+ .type = CP_FSM_EVENT_TYPE_to_leave),
+ SCENARIO_END
+ };
+ scenario_run (test, entries, &globals);
+ }
+ test_end;
+ /** Test the countdown elapsed and no nek was received. */
+ beacon = (bsu_beacon_t *) blk_alloc ();
+ beacon->vf.stei = 1;
+ beacon->vf.nid = 1;
+ beacon->bmis.eks.present = false;
+ beacon->params.rx_parameters.snid = 1;
+ beacon->bmis.mac_address.present = false;
+
+ beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
+ cp_beacon_receive (&cp, beacon);
+ test_begin (test, "next eks is invalid")
+ {
+ scenario_entry_t entries[] =
+ {
+ SCENARIO_ACTION (get_and_process_beacon),
+ SCENARIO_EVENT (cp_fsm_event_bare_new,
+ .type =CP_FSM_EVENT_TYPE_to_leave),
+ SCENARIO_END
+ };
+ scenario_run (test, entries, &globals);
+ }
+ test_end;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t t;
+ test_init (t, argc, argv);
+
+ beacon_same_nid_test_case (t);
+ /* Use appropriate test. */
+ beacon_nek_request_test_case_eoc (t);
+ test_result (t);
+ return test_nb_failed (t) == 0 ? 0 : 1;
+}
+
+mac_t
+cp_sta_get_mac_address (cp_sta_t *ctx)
+{
+ dbg_assert (ctx);
+ return MAC_ADDRESS (0x00, 0x13, 0xd7, 0x11, 0x12, 0x13);
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/bsu_beacon_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/bsu_beacon_stub.c
new file mode 100644
index 0000000000..20123664fd
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/bsu_beacon_stub.c
@@ -0,0 +1,69 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/beacon/stub/src/beacon.c
+ * \brief BSU bsu_beacon STUB functions.
+ * \ingroup bsu
+ *
+ * Functions to read and write bsu_beacons.
+ */
+#include "common/std.h"
+#include "common/defs/homeplugAV.h"
+#include "lib/bitstream.h"
+#include "bsu/beacon/beacon.h"
+#include "cp/defs.h"
+
+
+pb_beacon_t pbbeacon;
+extern bsu_beacon_t beacon_data;
+
+pb_beacon_t*
+bsu_beacon_write (bsu_beacon_t *beacon, bsu_beacon_type_t type,
+ mac_config_t *mac_config, pbproc_tx_beacon_params_t *params)
+{
+ return &pbbeacon;
+}
+
+
+/**
+ * Read the beacon entry header and length.
+ * \param stream the bitstream context.
+ * \param header the pointer to store the header.
+ * \param length the pointer to store the length.
+ * \return true on success, false otherwise.
+ */
+bool
+bsu_beacon_read_bmi_header (bitstream_t *bitstream, uint *header,
+ uint *length)
+{
+ *header = bitstream_read (bitstream, 8);
+ *length = bitstream_read (bitstream, 8);
+ if (BSU_BEACON_ENTRY_IS_BENTRY (*header))
+ return true;
+ return false;
+}
+
+bool
+bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon)
+{
+ beacon->vf.nid = 1;
+ beacon->vf.stei = 1;
+ beacon->vf.bt = BSU_BEACON_TYPE_CENTRAL;
+ beacon->bmis.mac_address.mac_address =
+ MAC_ADDRESS(0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC);
+ beacon->bmis.eks.present = beacon_data.bmis.eks.present;
+ beacon->bmis.eks.kbc = beacon_data.bmis.eks.kbc;
+ beacon->bmis.eks.new_eks = beacon_data.bmis.eks.new_eks;
+
+ return true;
+}
+
+void
+bsu_beacon_countdown (bsu_beacon_t *beacon)
+{
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/bsu_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/bsu_stub.c
new file mode 100644
index 0000000000..1b2fd6fc3f
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/bsu_stub.c
@@ -0,0 +1,61 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bsu_stub.c
+ */
+#include "common/std.h"
+#include "bsu/beacon/beacon.h"
+#include "bsu/aclf/aclf.h"
+#include "bsu/bsu.h"
+
+void
+bsu_aclf_beacon_period_start_date (bsu_aclf_t *ctx, u32 *bpsd, uint nb)
+{
+ uint i;
+
+ bpsd[0] = BSU_ACLF_BP_50HZ_TCK;
+
+ for (i = 1; i < nb; i++)
+ bpsd[i] = bpsd[i - 1] + BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_start_date_next (bsu_aclf_t *ctx)
+{
+ return BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_tck (bsu_aclf_t *ctx)
+{
+ return BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_atu (bsu_aclf_t *ctx)
+{
+ return MAC_TCK_TO_ATU (ctx->beacon_period_tck);
+}
+
+
+void
+bsu_update (bsu_t *ctx, bsu_beacon_t *beacon, bsu_update_sta_type_t sta)
+{
+ bool *updated = (bool*) ctx;
+ *updated = true;
+}
+
+void
+bsu_update_discover_info (bsu_t *ctx, bsu_beacon_bmi_discover_info_t *discover)
+{
+}
+
+void
+bsu_update_nid_snid (bsu_t *ctx, u64 nid, u8 snid)
+{
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/bsu_stub_scenario.c b/cesar/cp/eoc/beacon/test/utest2/src/bsu_stub_scenario.c
new file mode 100644
index 0000000000..05689be7a6
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/bsu_stub_scenario.c
@@ -0,0 +1,55 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bsu_stub.c
+ */
+#include "common/std.h"
+#include "bsu/beacon/beacon.h"
+#include "bsu/aclf/aclf.h"
+#include "bsu/bsu.h"
+
+void
+bsu_aclf_beacon_period_start_date (bsu_aclf_t *ctx, u32 *bpsd, uint nb)
+{
+ uint i;
+
+ bpsd[0] = BSU_ACLF_BP_50HZ_TCK;
+
+ for (i = 1; i < nb; i++)
+ bpsd[i] = bpsd[i - 1] + BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_start_date_next (bsu_aclf_t *ctx)
+{
+ return BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_tck (bsu_aclf_t *ctx)
+{
+ return BSU_ACLF_BP_60HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_atu (bsu_aclf_t *ctx)
+{
+ return MAC_TCK_TO_ATU (BSU_ACLF_BP_60HZ_TCK);
+}
+
+void
+bsu_update_discover_info (
+ bsu_t *ctx, bsu_beacon_bmi_discover_info_t *discover)
+{
+}
+
+void
+bsu_update_nid_snid (bsu_t *ctx, u64 nid, u8 snid)
+{
+}
+
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/ca_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/ca_stub.c
new file mode 100644
index 0000000000..aef5b49ce7
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/ca_stub.c
@@ -0,0 +1,65 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/beacon/test/central_beacon/src/ca_stub.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "mac/ca/ca.h"
+
+static ca_schedule_t _casched[8];
+
+ca_schedule_t *
+ca_alloc_get_schedule (ca_t *ctx, uint index)
+{
+ if (index < 8)
+ {
+ return &_casched[index];
+ }
+
+ return NULL;
+}
+
+void
+ca_alloc_update_beacon_periods (ca_t *ctx,
+ ca_beacon_period_t *beacon_periods,
+ uint beacon_periods_nb) __attribute__ ((weak));
+
+void
+ca_alloc_update_beacon_periods (ca_t *ctx,
+ ca_beacon_period_t *beacon_periods,
+ uint beacon_periods_nb)
+{
+}
+
+
+void
+ca_mfs_remove (ca_t *ctx, mfs_tx_t *mfs)
+{
+}
+
+void
+ca_mfs_add (ca_t *ctx, mfs_tx_t *mfs)
+{
+ dbg_assert (ctx);
+ dbg_assert (mfs);
+}
+
+
+void
+ca_mfs_update_common (ca_t *ctx, mfs_tx_t *mfs, bool locked)
+{
+}
+
+void
+ca_mfs_hold_common (ca_t *ctx, mfs_tx_t *mfs, bool locked)
+{
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/fsm_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/fsm_stub.c
new file mode 100644
index 0000000000..78ed2c857c
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/fsm_stub.c
@@ -0,0 +1,58 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/fsm_stub.c
+ * \brief FSM stub.
+ * \ingroup test
+ */
+#include "common/std.h"
+#include "cp/fsm/fsm.h"
+
+#include "lib/scenario/scenario.h"
+
+cp_fsm_event_t *
+cp_fsm_event_bare_new (cp_t *ctx, cp_fsm_event_type_t type)
+{
+ dbg_assert (ctx);
+ switch (type)
+ {
+ case CP_FSM_EVENT_TYPE_cco__snid_conflict:
+ case CP_FSM_EVENT_TYPE_net_list_empty:
+ case CP_FSM_EVENT_TYPE_sta_status_changed:
+ /* Ignore. */
+ return INVALID_PTR;
+ default:
+ ;
+ }
+ scenario_event (cp_fsm_event_bare_new, param);
+ test_fail_unless (type == param->type);
+ return INVALID_PTR;
+}
+
+cp_fsm_event_t *
+cp_fsm_event_beacon_new (
+ cp_t *ctx, cp_fsm_event_type_t type, bsu_beacon_t *beacon,
+ cp_net_t *net, cp_sta_t *sta)
+{
+ dbg_assert (ctx);
+ switch (type)
+ {
+ case CP_FSM_EVENT_TYPE_BEACON:
+ /* Ignore. */
+ return INVALID_PTR;
+ default:
+ ;
+ }
+ scenario_event (cp_fsm_event_beacon_new, param);
+ test_fail_unless (type == param->type);
+ test_fail_unless (beacon == param->beacon);
+ test_fail_unless (net == param->net);
+ test_fail_unless (sta == param->sta);
+ return INVALID_PTR;
+}
+
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/pbproc_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/pbproc_stub.c
new file mode 100644
index 0000000000..645e0a85db
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/pbproc_stub.c
@@ -0,0 +1,27 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2013 Mstar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/pbproc_stub.c
+ * \brief pbproc stub
+ * \ingroup cp_eoc_beacon_test_utest2
+ *
+ */
+
+#include "common/std.h"
+#include "hal/phy/spoc/spoc.h"
+#include "mac/pbproc/pbproc.h"
+
+void
+pbproc_spoc_update (pbproc_t *pbproc, bool sync, s32 rho_q30)
+{
+}
+
+void
+pbproc_spoc_reset (pbproc_t *pbproc)
+{
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/phy_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/phy_stub.c
new file mode 100644
index 0000000000..97baa8d937
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/phy_stub.c
@@ -0,0 +1,29 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/phy_stub.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "hal/phy/phy.h"
+#include "bsu/aclf/aclf.h"
+
+u32
+phy_clock_get_zero_cross_captured_date (phy_t *phy)
+{
+ return 0;
+}
+
+u32
+phy_date ()
+{
+ return BSU_ACLF_BP_60HZ_TCK+1;
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/scenario_actions.c b/cesar/cp/eoc/beacon/test/utest2/src/scenario_actions.c
new file mode 100644
index 0000000000..1e71f46112
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/scenario_actions.c
@@ -0,0 +1,25 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/scenario_actions.c
+ * \brief Scenario actions.
+ * \ingroup test
+ */
+#include "common/std.h"
+#include "cp/beacon/beacon.h"
+#include "lib/scenario/scenario.h"
+
+#define __0(ACTION) \
+void \
+scenario_action_ ## ACTION ## _cb (scenario_globals_t *globals, \
+ scenario_params_t *params) \
+{ \
+ cp_beacon_ ## ACTION (globals->cp); \
+}
+
+__0 (get_and_process_beacon)
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/secu_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/secu_stub.c
new file mode 100644
index 0000000000..89f0605a3e
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/secu_stub.c
@@ -0,0 +1,25 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/secu_stub.c
+ * \brief cp/secu stub.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "cp/secu/secu.h"
+
+void
+cp_secu_pbb_dec_gen (cp_key_t enc, cp_key_t *dec)
+{
+ dec->key[0] = 0xdeaddead;
+ dec->key[1] = 0xdeaddead;
+ dec->key[2] = 0xdeaddead;
+ dec->key[3] = 0xdeaddead;
+}
+
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/sta_mgr_stub.c b/cesar/cp/eoc/beacon/test/utest2/src/sta_mgr_stub.c
new file mode 100644
index 0000000000..6554aa77af
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/sta_mgr_stub.c
@@ -0,0 +1,217 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/beacon/test/src/sta_mgr_stub.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "cp/sta/mgr/sta_own_data.h"
+#include "cp/sta/mgr/net.h"
+#include "cp/sta/mgr/inc/net.h"
+#include "cp/sta/mgr/inc/sta.h"
+#include "cp/sta/mgr/inc/sta_mgr.h"
+#include "cp/sta/mgr/sta_mgr.h"
+#include "cp/inc/context.h"
+
+cp_sta_own_data_t own_data;
+cp_net_t our_avln;
+bool cco_status;
+
+
+void
+cp_sta_mgr_init (cp_t *ctx)
+{
+ dbg_assert (ctx);
+
+ own_data.nid_track = 1;
+ own_data.tei_track = 1;
+ own_data.cco_mac_addr_track = MAC_ZERO;
+ cco_status = false;
+
+ memset (&ctx->sta_mgr, 0, sizeof (cp_sta_mgr_t));
+
+
+ // Initialise the slab cache.
+ slab_cache_init (&ctx->sta_mgr.sta_slab_cache,
+ "Station cache",
+ sizeof (cp_sta_private_t),
+ (slab_object_destructor_t) NULL);
+}
+
+
+cp_sta_own_data_t *
+cp_sta_mgr_get_sta_own_data (cp_t *ctx)
+{
+ return &own_data;
+}
+
+bool
+cp_sta_own_data_get_cco_status (cp_t *ctx)
+{
+ return cco_status;
+}
+
+bool
+cp_sta_own_data_get_pco_status (cp_t *ctx)
+{
+ return false;
+}
+
+u8
+cp_sta_mgr_get_num_discovered_stas (cp_t *ctx)
+{
+ return 0;
+}
+
+u8
+cp_sta_mgr_get_num_discovered_net (cp_t *ctx)
+{
+ return 0;
+}
+
+bool
+cp_sta_own_data_get_authenticated_status (cp_t *ctx)
+{
+ return true;
+}
+
+cp_tei_t
+cp_sta_own_data_get_tei (cp_t *ctx)
+{
+ return 2;
+}
+
+cp_net_t *
+cp_sta_mgr_get_our_avln (cp_t *ctx)
+{
+ return &our_avln;
+}
+
+cp_nid_t
+cp_sta_own_data_get_nid (cp_t *ctx)
+{
+ return 1;
+}
+
+u8
+cp_sta_mgr_get_slot_usage (cp_t *ctx)
+{
+ return 1;
+}
+
+u8
+cp_net_get_slot_id (cp_t *ctx, cp_net_t *net)
+{
+ return 0;
+}
+
+mac_network_mode_t
+cp_net_get_nm (cp_t *ctx, cp_net_t *net)
+{
+ return MAC_NM_UNCOORDINATED;
+}
+
+cp_sta_t *
+cp_sta_mgr_sta_add (cp_t *ctx, cp_net_t *net, cp_tei_t tei, mac_t mac_address)
+{
+ cp_sta_private_t *sta;
+
+ sta = (cp_sta_private_t *) slab_alloc (&ctx->sta_mgr.sta_slab_cache);
+ memset (sta, 0, sizeof (cp_sta_private_t));
+
+ // Add a reference on the station.
+ slab_addref (sta);
+
+ return &sta->public_data;
+}
+
+void
+cp_net_set_cco (cp_t *ctx, cp_net_t *net, cp_tei_t tei){}
+
+void
+cp_net_set_pco (cp_t *ctx, cp_net_t *net, cp_tei_t tei){}
+
+void
+cp_sta_set_authenticated_ (
+ cp_t *ctx, cp_sta_t *sta, bool auth __FL){}
+
+void
+cp_sta_own_data_set_snid (cp_t *ctx, cp_snid_t snid){}
+
+cp_sta_t *
+cp_sta_mgr_sta_get_assoc (cp_t *ctx, cp_net_t *net, cp_tei_t tei)
+{
+ return NULL;
+}
+
+cp_net_t *
+cp_sta_mgr_add_avln (cp_t *ctx, cp_snid_t snid, cp_nid_t nid)
+{
+ return &our_avln;
+}
+
+void
+cp_net_set_access (cp_t *ctx, cp_net_t *net, hpav_access_t access){}
+
+void
+cp_net_set_slot_id_and_usage (cp_t *ctx, cp_net_t *net,
+ u8 slot_id, u8 slot_usage){}
+
+cp_snid_t
+cp_sta_own_data_get_snid (cp_t *ctx)
+{
+ return 1;
+}
+
+u8
+cp_net_get_num_stas (cp_t *ctx, cp_net_t *net)
+{
+ dbg_assert (net);
+ return net->num_stas;
+}
+
+cp_sta_t *
+cp_net_sta_get_first (cp_t *ctx, cp_net_t *net, cp_net_sta_status_t assoc)
+{
+ return NULL;
+}
+
+cp_tei_t
+cp_sta_get_tei (cp_sta_t *ctx)
+{
+ return 0;
+}
+
+cp_sta_t *
+cp_net_sta_get_next (cp_t *ctx, cp_net_t *net, cp_sta_t *prev_sta)
+{
+ return NULL;
+}
+
+mac_t
+cp_sta_own_data_get_mac_address (cp_t *ctx)
+{
+ return MAC_ADDRESS(0x12, 0x34, 0x56, 0x78, 0x9A, 0xBD);
+}
+
+cp_sta_t *
+cp_sta_mgr_sta_get_from_mac (cp_t *ctx, mac_t mac_addr)
+{
+ return NULL;
+}
+
+cp_snid_t
+cp_net_get_snid (cp_t *ctx, cp_net_t *net)
+{
+ dbg_assert (net);
+
+ return net->snid;
+}
diff --git a/cesar/cp/eoc/beacon/test/utest2/src/stubs.c b/cesar/cp/eoc/beacon/test/utest2/src/stubs.c
new file mode 100644
index 0000000000..4a4aa3c161
--- /dev/null
+++ b/cesar/cp/eoc/beacon/test/utest2/src/stubs.c
@@ -0,0 +1,91 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/av/beacon/test/utest/src/stubs.c
+ * \brief Stubs functions.
+ * \ingroup cp_av_beacon
+ */
+#include "common/std.h"
+#include "cp/secu/secu.h"
+#include "bsu/beacon/beacon.h"
+#include "bsu/aclf/aclf.h"
+#include "bsu/bsu.h"
+#include "hal/phy/spoc/spoc.h"
+#include "mac/pbproc/pbproc.h"
+#include "mac/ca/ca.h"
+
+static ca_schedule_t _casched[8];
+
+ca_schedule_t *
+ca_alloc_get_schedule (ca_t *ctx, uint index)
+{
+ if (index < 8)
+ {
+ return &_casched[index];
+ }
+
+ return NULL;
+}
+
+void
+cp_secu_pbb_dec_gen (cp_key_t enc, cp_key_t *dec)
+{
+ dec->key[0] = 0xdeaddead;
+ dec->key[1] = 0xdeaddead;
+ dec->key[2] = 0xdeaddead;
+ dec->key[3] = 0xdeaddead;
+}
+
+void
+bsu_aclf_beacon_period_start_date (bsu_aclf_t *ctx, u32 *bpsd, uint nb)
+{
+ uint i;
+
+ bpsd[0] = BSU_ACLF_BP_50HZ_TCK;
+
+ for (i = 1; i < nb; i++)
+ bpsd[i] = bpsd[i - 1] + BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_start_date_next (bsu_aclf_t *ctx)
+{
+ return BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_tck (bsu_aclf_t *ctx)
+{
+ return BSU_ACLF_BP_50HZ_TCK;
+}
+
+u32
+bsu_aclf_beacon_period_atu (bsu_aclf_t *ctx)
+{
+ return MAC_TCK_TO_ATU (ctx->beacon_period_tck);
+}
+
+
+void
+bsu_update (bsu_t *ctx, bsu_beacon_t *beacon, bsu_update_sta_type_t sta)
+{
+ bool *updated = (bool*) ctx;
+ *updated = true;
+}
+
+u32
+phy_clock_get_zero_cross_captured_date (phy_t *phy)
+{
+ return 0;
+}
+
+u32
+phy_date ()
+{
+ return BSU_ACLF_BP_60HZ_TCK+1;
+}