summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNélio Laranjeiro2012-03-28 18:44:01 +0200
committerNélio Laranjeiro2012-07-18 17:36:38 +0200
commit862efc028d75cd3322854ff7f9a51b9b5361942f (patch)
treed7efe3b28550edc60ac9946d5431d2519f42f9c1
parenta4b159734dd5fe2ffc14f0ccde27f42c04758f21 (diff)
cesar/bsu: fix deactivate/activate, closes #3060
-rw-r--r--cesar/bsu/src/bsu.c166
-rw-r--r--cesar/bsu/test/utest/src/bsut.c1
-rw-r--r--cesar/test_general/station/scenario/av/py/sc12_change_nmk.py18
3 files changed, 111 insertions, 74 deletions
diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c
index 3f78462c59..7656a57970 100644
--- a/cesar/bsu/src/bsu.c
+++ b/cesar/bsu/src/bsu.c
@@ -743,6 +743,99 @@ bsu_beacon_send_prepare (bsu_t *ctx, bsu_beacon_type_t type,
}
/**
+ * Handle the timer as STA.
+ * \param ctx the module context.
+ */
+static void
+bsu_timer_event_process__sta (bsu_t *ctx)
+{
+ /* Have we at least received a beacon before using it ?
+ * This can happen after a deactivate followed by an activate event in
+ * which the timer is not stopped. */
+ if (ctx->sta_avln->sync.init)
+ {
+ u32 bpsd0;
+ bsu_aclf_beacon_period_start_date (ctx->aclf, &bpsd0, 1);
+ if (ctx->track_new)
+ {
+ u32 bpsd[BSU_BEACON_SCHEDULES_NB];
+ uint bp = bsu_aclf_beacon_period_tck (ctx->aclf);
+ /* Reset STA clock correction. */
+ bsu_ntb_clock_configure (
+ &ctx->sta_avln->sync, ctx->mac_config, ctx->phy);
+ /* Compute the new BPSD with the data of the new AVLN. */
+ bsu_aclf_compute_beacon_period_start_date (
+ ctx->aclf,
+ ctx->sta_avln->sync.bts
+ - ctx->sta_avln->sync.ntb_offset_tck,
+ ctx->sta_avln->bto,
+ ctx->sta_avln->beacon.bmis.bpsto.present ?
+ ctx->sta_avln->beacon.bmis.bpsto.bpsto : 0);
+ bsu_aclf_beacon_period_start_date (
+ ctx->aclf, bpsd, COUNT (bpsd));
+ /* Decrease countdown, the first schedule will not be
+ * programmed. */
+ bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
+ /* The current beacon period ends after the next beacon period
+ * in the new AVLN starts. */
+ if (less_mod2p32 (bpsd[1], bpsd0 + bp))
+ {
+ bsu_aclf_bpsd_avoid_overlap (ctx->aclf);
+ bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
+ ctx->sta_avln->beacon.beacon_period_start_date = bpsd[2];
+ }
+ else
+ ctx->sta_avln->beacon.beacon_period_start_date = bpsd[1];
+ ctx->track_new = false;
+ }
+ else if (less_mod2p32 (
+ ctx->sta_avln->beacon.beacon_period_start_date, bpsd0))
+ {
+ bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
+ ctx->sta_avln->beacon.beacon_period_start_date = bpsd0;
+ }
+ }
+}
+
+/**
+ * Handle the timer as CCo.
+ * \param ctx the module context.
+ */
+static void
+bsu_timer_event_process__cco (bsu_t *ctx)
+{
+ u32 bpsd0;
+ bsu_aclf_beacon_period_start_date (ctx->aclf, &bpsd0, 1);
+ /* Are update data late ?. */
+ if (less_mod2p32 (
+ ctx->sta_avln->beacon.beacon_period_start_date, bpsd0))
+ /* Create and send the beacon. */
+ bsu_beacon_countdown (&ctx->sta_avln->beacon);
+ if (ctx->track_new)
+ {
+ /* Reset STA clock correction. */
+ bsu_ntb_clock_configure (
+ &ctx->sta_avln->sync, ctx->mac_config, ctx->phy);
+ ctx->track_new = false;
+ }
+ /* Inform PBProc we send a central beacon. */
+ pbproc_beacon_detected (
+ ctx->pbproc,
+ bsu_aclf_beacon_period_start_date_next (ctx->aclf)
+ + bsu_aclf_beacon_period_tck (ctx->aclf));
+ bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_CENTRAL,
+ &ctx->sta_avln->beacon);
+ if (ctx->sta_avln->beacon.bmis.discover.present
+ && ctx->sta_avln->beacon.bmis.discover.tei
+ == ctx->mac_config->tei)
+ {
+ bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_DISCOVER,
+ &ctx->sta_avln->beacon);
+ ctx->sta_avln->beacon.bmis.discover.present = false;
+ }
+}
+
+/**
* BSU timer expires.
* \param ud the module context.
*
@@ -756,82 +849,13 @@ bsu_timer_event_process (void *ud)
if (ctx->activate)
{
dbg_assert (ctx);
- u32 bpsd0;
- bsu_aclf_beacon_period_start_date (ctx->aclf, &bpsd0, 1);
dbg_assert (
less_mod2p32 (phy_date (),
bsu_aclf_beacon_period_start_date_next(ctx->aclf)));
if (ctx->is_sta == BSU_UPDATE_STA_TYPE_STA)
- {
- if (ctx->track_new)
- {
- u32 bpsd[BSU_BEACON_SCHEDULES_NB];
- uint bp = bsu_aclf_beacon_period_tck (ctx->aclf);
- /* Reset STA clock correction. */
- bsu_ntb_clock_configure (
- &ctx->sta_avln->sync, ctx->mac_config, ctx->phy);
- /* Compute the new BPSD with the data of the new AVLN. */
- bsu_aclf_compute_beacon_period_start_date (
- ctx->aclf,
- ctx->sta_avln->sync.bts
- - ctx->sta_avln->sync.ntb_offset_tck,
- ctx->sta_avln->bto,
- ctx->sta_avln->beacon.bmis.bpsto.present ?
- ctx->sta_avln->beacon.bmis.bpsto.bpsto : 0);
- bsu_aclf_beacon_period_start_date (
- ctx->aclf, bpsd, COUNT (bpsd));
- /* Decrease countdown, the first schedule will not be
- * programmed. */
- bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
- /* The current beacon period ends after the next beacon period
- * in the new AVLN starts. */
- if (less_mod2p32 (bpsd[1], bpsd0 + bp))
- {
- bsu_aclf_bpsd_avoid_overlap (ctx->aclf);
- bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
- ctx->sta_avln->beacon.beacon_period_start_date = bpsd[2];
- }
- else
- ctx->sta_avln->beacon.beacon_period_start_date = bpsd[1];
- ctx->track_new = false;
- }
- else if (less_mod2p32 (
- ctx->sta_avln->beacon.beacon_period_start_date, bpsd0))
- {
- bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
- ctx->sta_avln->beacon.beacon_period_start_date = bpsd0;
- }
- }
+ bsu_timer_event_process__sta (ctx);
else
- {
- /* Are update data late ?. */
- if (less_mod2p32 (
- ctx->sta_avln->beacon.beacon_period_start_date, bpsd0))
- /* Create and send the beacon. */
- bsu_beacon_countdown (&ctx->sta_avln->beacon);
- if (ctx->track_new)
- {
- /* Reset STA clock correction. */
- bsu_ntb_clock_configure (
- &ctx->sta_avln->sync, ctx->mac_config, ctx->phy);
- ctx->track_new = false;
- }
- /* Inform PBProc we send a central beacon. */
- pbproc_beacon_detected (
- ctx->pbproc,
- bsu_aclf_beacon_period_start_date_next (ctx->aclf)
- + bsu_aclf_beacon_period_tck (ctx->aclf));
- bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_CENTRAL,
- &ctx->sta_avln->beacon);
- if (ctx->sta_avln->beacon.bmis.discover.present
- && ctx->sta_avln->beacon.bmis.discover.tei
- == ctx->mac_config->tei)
- {
- bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_DISCOVER,
- &ctx->sta_avln->beacon);
- ctx->sta_avln->beacon.bmis.discover.present = false;
- }
- }
+ bsu_timer_event_process__cco (ctx);
bsu_ca_schedules (ctx, ctx->sta_avln, 2);
bsu_avln_countdown_beacon_entries_apply_changes (ctx, ctx->sta_avln);
bsu_avln_countdown_beacon_entries (ctx, ctx->sta_avln);
diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c
index ad4fd34c8f..fc05b69615 100644
--- a/cesar/bsu/test/utest/src/bsut.c
+++ b/cesar/bsu/test/utest/src/bsut.c
@@ -527,6 +527,7 @@ test_case_bsu_timer_event (test_t test)
bsu_activate (t.bsu, true);
t.bsu->aclf->pwl_sync.trig_present = false;
t.phy->phy_date = 0;
+ t.bsu->sta_avln->sync.init = true;
bsu_beacon_t beacon;
bsu_test_create_beacon (&t, &beacon);
bsu_update (t.bsu, &beacon, BSU_UPDATE_STA_TYPE_STA);
diff --git a/cesar/test_general/station/scenario/av/py/sc12_change_nmk.py b/cesar/test_general/station/scenario/av/py/sc12_change_nmk.py
index 67a54b0a14..fe351b6522 100644
--- a/cesar/test_general/station/scenario/av/py/sc12_change_nmk.py
+++ b/cesar/test_general/station/scenario/av/py/sc12_change_nmk.py
@@ -204,14 +204,26 @@ class TestNMK (unittest.TestCase):
# If we send data from station to the CCo it must be received.
# Do not change the way.
avln = self.csi.avln_get (0)
+ self.csi.transmission_result_reset ()
packets = [
csiPacket (payload_size = 200, avln = avln,
- sta_src = avln2sta, sta_dest = avln2sta),
+ sta_src = avln2sta, mac_addr_dest = MAC_BCAST),
+ csiPacket (payload_size = 200, avln = avln,
+ sta_src = avln2cco, mac_addr_dest = MAC_BCAST),
+ csiPacket (payload_size = 200, avln = avln,
+ sta_src = avln2sta, mac_addr_dest = MAC_BCAST),
+ csiPacket (payload_size = 200, avln = avln,
+ sta_src = avln2cco, mac_addr_dest = MAC_BCAST),
+ ]
+ self.csi.process_data_send_traffic (packets)
+ self.csi.process_wait_sec (2)
+ packets = [
+ csiPacket (payload_size = 200, avln = avln,
+ sta_src = avln2sta, sta_dest = avln2cco),
csiPacket (payload_size = 200, avln = avln,
sta_src = avln2cco, sta_dest = avln2sta),
]
- result = send_check_datas (self.csi, avln, packets)
- self.failUnless (result)
+ self.failUnless (send_check_datas (self.csi, avln, packets))
def t3StaStep3 (self):
"""step3: Change the NMK on the USTA. At the end we should have a