summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-12-03 17:21:47 +0100
committerNélio Laranjeiro2011-01-11 15:39:47 +0100
commitbeb25f77a358fbdf4a6060483df7799779da328a (patch)
tree05f25b068c706844857b623695c3559fd59929ac
parent21a62f1168746cda1b5eb68d76593938dc371db1 (diff)
cesar/bsu: restore discover beacon procedure
-rw-r--r--cesar/bsu/inc/bsu.h4
-rw-r--r--cesar/bsu/inc/interface.h6
-rw-r--r--cesar/bsu/src/bsu.c50
-rw-r--r--cesar/bsu/src/interface.c24
-rw-r--r--cesar/bsu/test/utest/src/bsut.c54
-rw-r--r--cesar/bsu/test/utest/src/schedules.c16
6 files changed, 92 insertions, 62 deletions
diff --git a/cesar/bsu/inc/bsu.h b/cesar/bsu/inc/bsu.h
index cf9960efec..26606bad57 100644
--- a/cesar/bsu/inc/bsu.h
+++ b/cesar/bsu/inc/bsu.h
@@ -21,9 +21,9 @@ BEGIN_DECLS
* \param ctx the bsu context.
* \param beacon the beacon received.
* \param params the phy rx params.
- * \return the avln structure if the beacon is correct i.e. CRC ok.
+ * \return the beacon structure if the beacon is correct i.e. CRC ok.
*/
-bsu_avln_t*
+bsu_beacon_t*
bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
pbproc_rx_beacon_params_t *params);
diff --git a/cesar/bsu/inc/interface.h b/cesar/bsu/inc/interface.h
index 9d49f19d94..3f7966ffc6 100644
--- a/cesar/bsu/inc/interface.h
+++ b/cesar/bsu/inc/interface.h
@@ -20,12 +20,10 @@ BEGIN_DECLS
* \param ctx the module context.
* \param beacon the beacon structure to fill.
* \param direction the reception or transmission.
- * \param avln structure to get the beacon.
*/
void
-bsu_beacon_send_upper_layer (
- bsu_t *ctx, bsu_beacon_direction_t direction,
- bsu_beacon_t *beacon, bsu_avln_t *avln);
+bsu_beacon_send_upper_layer (bsu_t *ctx, bsu_beacon_t *beacon,
+ bsu_beacon_direction_t direction);
/**
* Send a beacon over the medium.
diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c
index d5e6ba8c80..8ed741773b 100644
--- a/cesar/bsu/src/bsu.c
+++ b/cesar/bsu/src/bsu.c
@@ -570,16 +570,26 @@ bsu_beacon_send_prepare (bsu_t *ctx, bsu_beacon_type_t type,
{
pb_beacon_t *beacon;
pbproc_tx_beacon_params_t params;
+ /* Make a copy of the beacon for upper layers. */
+ bsu_beacon_t *ulbeacon = blk_alloc ();
+ memcpy (ulbeacon, bsu_beacon, sizeof (bsu_beacon_t));
+ ulbeacon->vf.stei = ctx->mac_config->tei;
bsu_aclf_bto (ctx->aclf, (s16*) params.bto, COUNT (params.bto));
- bsu_beacon->bmis.discover_info = ctx->discover_info;
- beacon = bsu_beacon_write (bsu_beacon, type, ctx->mac_config, &params);
/* Reset the updated flag in the discover info beacon entry. */
if (type == BSU_BEACON_TYPE_DISCOVER)
+ {
+ ulbeacon->bmis.mac_address_present.present = true;
+ ulbeacon->bmis.mac_address_present.mac_address =
+ ctx->mac_config->sta_mac_address;
+ ulbeacon->bmis.discover_info = ctx->discover_info;
+ ulbeacon->bmis.discover_info.present = true;
bitstream_direct_write (&ctx->discover_info.info_data, 0, 0, 1);
+ }
+ beacon = bsu_beacon_write (ulbeacon, type, ctx->mac_config, &params);
/* Send the beacon. */
bsu_beacon_send (ctx, type, beacon, &params);
bsu_beacon_send_upper_layer (
- ctx, BSU_BEACON_DIRECTION_TO_PLC, bsu_beacon, ctx->sta_avln);
+ ctx, ulbeacon, BSU_BEACON_DIRECTION_TO_PLC);
}
/**
@@ -764,8 +774,7 @@ bsu_beacon_process__avln_tracked (bsu_t *ctx, bsu_beacon_t *beacon,
pbproc_beacon_detected (
ctx->pbproc, params->preamble_date
+ bsu_aclf_beacon_period_tck (ctx->aclf));
- ctx->sta_avln->beacon = *beacon;
- ctx->sta_avln->beacon.params.rx_parameters = *params;
+ memcpy (&ctx->sta_avln->beacon, beacon, sizeof (bsu_beacon_t));
/* NTB synchronisation. */
bsu_ntb_clk_sync (&ctx->sta_avln->sync, ctx->phy,
params->bts, params->preamble_sysdate,
@@ -825,8 +834,7 @@ bsu_beacon_process__avln_not_tracked (bsu_t *ctx, bsu_beacon_t *beacon,
{
for (i = 0; i < HPAV_BEACON_BTO_NB; i++)
avln->bto[i] = params->bto[i];
- avln->beacon = *beacon;
- avln->beacon.params.rx_parameters = *params;
+ memcpy (&avln->beacon, beacon, sizeof (bsu_beacon_t));
/* NTB synchronisation. */
bsu_ntb_clk_sync (&avln->sync, ctx->phy,
params->bts, params->preamble_sysdate,
@@ -842,41 +850,47 @@ bsu_beacon_process__avln_not_tracked (bsu_t *ctx, bsu_beacon_t *beacon,
return avln;
}
-bsu_avln_t*
+bsu_beacon_t*
bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
pbproc_rx_beacon_params_t *params)
{
bsu_avln_t *avln = NULL;
- bsu_beacon_t bsu_beacon;
+ bsu_beacon_t *bsu_beacon = blk_alloc ();
dbg_assert (ctx);
dbg_assert (beacon);
dbg_assert (params);
/* Check the CRC. */
- if (bsu_beacon_read (beacon, &bsu_beacon))
+ if (bsu_beacon_read (beacon, bsu_beacon))
{
- ctx->beacon_nb_recv[bsu_beacon.vf.bt]++;
- bsu_ca_schedules_nm_csma_only (ctx, &bsu_beacon);
- if (bsu_beacon.vf.bt == BSU_BEACON_TYPE_CENTRAL)
+ memcpy (&bsu_beacon->params.rx_parameters, params,
+ sizeof (pbproc_rx_beacon_params_t));
+ ctx->beacon_nb_recv[bsu_beacon->vf.bt]++;
+ bsu_ca_schedules_nm_csma_only (ctx, bsu_beacon);
+ if (bsu_beacon->vf.bt == BSU_BEACON_TYPE_CENTRAL)
{
/* It the beacon from our AVLN ? */
if (ctx->is_sta == BSU_UPDATE_STA_TYPE_STA
- && ctx->nid_track == bsu_beacon.vf.nid
+ && ctx->nid_track == bsu_beacon->vf.nid
&& ctx->snid_track == params->snid
- && ctx->tei_track == bsu_beacon.vf.stei)
+ && ctx->tei_track == bsu_beacon->vf.stei)
avln = bsu_beacon_process__avln_tracked (
- ctx, &bsu_beacon, params);
+ ctx, bsu_beacon, params);
/* Other AVLN. */
else
avln = bsu_beacon_process__avln_not_tracked (
- ctx, &bsu_beacon, params);
+ ctx, bsu_beacon, params);
+ bsu_beacon->params.frequency_error =
+ FIXED (avln->sync.fe, BSU_NTB_FIXED_POINT);
+ bsu_beacon->params.ntb_offset_tck = avln->sync.ntb_offset_tck;
}
}
else
{
BSU_TRACE (BEACON_ERROR, phy_date ());
+ blk_release (bsu_beacon);
return NULL;
}
- return avln;
+ return bsu_beacon;
}
/**
diff --git a/cesar/bsu/src/interface.c b/cesar/bsu/src/interface.c
index 99c3ce4678..d4f0c82c5b 100644
--- a/cesar/bsu/src/interface.c
+++ b/cesar/bsu/src/interface.c
@@ -21,17 +21,11 @@
#include "bsu/inc/context.h"
void
-bsu_beacon_send_upper_layer (
- bsu_t *ctx, bsu_beacon_direction_t direction,
- bsu_beacon_t *beacon, bsu_avln_t *avln)
+bsu_beacon_send_upper_layer (bsu_t *ctx, bsu_beacon_t *beacon,
+ bsu_beacon_direction_t direction)
{
- bsu_beacon_t *bsu_beacon = blk_alloc ();
- *bsu_beacon = avln->beacon;
- bsu_beacon->params.direction = direction;
- bsu_beacon->params.frequency_error =
- FIXED (avln->sync.fe, BSU_NTB_FIXED_POINT);
- bsu_beacon->params.ntb_offset_tck = avln->sync.ntb_offset_tck;
- (*ctx->ul_cb) (ctx->ul_data, bsu_beacon);
+ beacon->params.direction = direction;
+ (*ctx->ul_cb) (ctx->ul_data, beacon);
}
/**
@@ -112,11 +106,9 @@ bsu_beacon_recv (bsu_t *ctx, pb_beacon_t *beacon,
arch_load_cache (&beacon->first_data_word, 1);
arch_load_cache ((u32*) beacon->data, BLK_SIZE / 4);
/* Process the beacon received from the SAR. */
- bsu_avln_t *avln = bsu_beacon_process (ctx, beacon, params);
- if (avln)
- {
- bsu_beacon_send_upper_layer (
- ctx, BSU_BEACON_DIRECTION_FROM_PLC, &avln->beacon, avln);
- }
+ bsu_beacon_t *bsu_beacon = bsu_beacon_process (ctx, beacon, params);
+ if (bsu_beacon)
+ bsu_beacon_send_upper_layer (ctx, bsu_beacon,
+ BSU_BEACON_DIRECTION_FROM_PLC);
blk_release_desc ((blk_t*) beacon);
}
diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c
index 57bcd23009..495fc7a78e 100644
--- a/cesar/bsu/test/utest/src/bsut.c
+++ b/cesar/bsu/test/utest/src/bsut.c
@@ -45,6 +45,7 @@ test_case_bsu_process (test_t test)
bsu_beacon_t beacon_neighbour;
pb_beacon_t *bneighbour;
bsu_beacon_t beacon;
+ bsu_beacon_t *bprocessed;
pb_beacon_t *b;
pbproc_tx_beacon_params_t bpneighbour_tx;
pbproc_tx_beacon_params_t bp_tx;
@@ -60,9 +61,10 @@ test_case_bsu_process (test_t test)
&t.mac_config,
&bpneighbour_tx);
bneighbour->phy_pb.pb_rx.pb_measurement.crc_error = true;
- bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx);
+ bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx);
blk_release_desc ((blk_t*) bneighbour);
/* Central beacon processed ? */
+ test_fail_unless (!bprocessed);
test_fail_unless (t.bsu->avlns[0].snid == 0);
test_fail_unless (t.bsu->avlns[0].beacon.vf.nid == 0);
test_fail_unless (t.bsu->beacon_nb_sent [BSU_BEACON_TYPE_CENTRAL]
@@ -74,18 +76,21 @@ test_case_bsu_process (test_t test)
&t.mac_config,
&bpneighbour_tx);
bneighbour->phy_pb.pb_rx.pb_measurement.crc_error = false;
- bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx);
+ bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx);
/* Central beacon processed ? */
+ test_fail_unless (bprocessed);
test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid);
test_fail_unless (t.bsu->avlns[0].beacon.vf.nid
== beacon_neighbour.vf.nid);
test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL]
== 1);
+ blk_release (bprocessed);
/* NTB called ? */
test_fail_unless (t.bsu->avlns[0].sync.init == true);
/* Second shoot... */
- bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx);
+ bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx);
/* Central beacon processed ? */
+ test_fail_unless (bprocessed);
test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid);
test_fail_unless (t.bsu->avlns[0].beacon.vf.nid
== beacon_neighbour.vf.nid);
@@ -94,6 +99,7 @@ test_case_bsu_process (test_t test)
blk_release_desc ((blk_t*) bneighbour);
test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL]
== 2);
+ blk_release (bprocessed);
/* Our AVLN. */
t.mac_config.tei = 1;
bsu_track_avln (beacon_neighbour.vf.nid, 0x4, t.mac_config.tei);
@@ -102,8 +108,9 @@ test_case_bsu_process (test_t test)
b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL,
&t.mac_config, &bp_tx);
b->phy_pb.pb_rx.pb_measurement.crc_error = true;
- bsu_beacon_process (t.bsu, b, &bp_rx);
+ bprocessed = bsu_beacon_process (t.bsu, b, &bp_rx);
/* Central beacon processed ? */
+ test_fail_unless (!bprocessed);
test_fail_unless (t.bsu->sta_avln->snid == t.bsu->snid_track);
test_fail_unless (t.bsu->sta_avln->beacon.vf.nid == t.bsu->nid_track);
test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL]
@@ -117,8 +124,9 @@ test_case_bsu_process (test_t test)
b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL,
&t.mac_config, &bp_tx);
b->phy_pb.pb_rx.pb_measurement.crc_error = false;
- bsu_beacon_process (t.bsu, b, &bp_rx);
+ bprocessed = bsu_beacon_process (t.bsu, b, &bp_rx);
/* Central beacon processed ? */
+ test_fail_unless (bprocessed);
test_fail_unless (t.bsu->sta_avln->snid == bp_rx.snid);
test_fail_unless (t.bsu->sta_avln->beacon.vf.nid == beacon.vf.nid);
test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL]
@@ -126,6 +134,7 @@ test_case_bsu_process (test_t test)
/* NTB called ? */
test_fail_unless (t.bsu->sta_avln->sync.init == true);
blk_release_desc ((blk_t*) b);
+ blk_release (bprocessed);
}
test_end;
test_begin (test, "Central beacon received with discover request")
@@ -141,7 +150,8 @@ test_case_bsu_process (test_t test)
&btx);
t.bsu->sta_avln->beacon.beacon_period_start_date =
phy_date () - BSU_ACLF_BP_50HZ_TCK - 1000;
- bsu_beacon_process (t.bsu, b, &brx);
+ bsu_beacon_t *bbeacon = bsu_beacon_process (t.bsu, b, &brx);
+ blk_release (bbeacon);
/* Change MAC config TEI for the test. */
bsu_track_avln (beacon.vf.nid, brx.snid, t.mac_config.tei);
t.mac_config.tei = beacon.bmis.discover.tei;
@@ -183,17 +193,21 @@ test_case_bsu_process (test_t test)
&t.mac_config, &btx);
t.bsu->sta_avln->beacon.beacon_period_start_date =
phy_date () - BSU_ACLF_BP_50HZ_TCK - 1000;
- bsu_beacon_process (t.bsu, b, &brx);
+ bsu_beacon_t *bprocessed = bsu_beacon_process (t.bsu, b, &brx);
bsu_avln_t *avln = bsu_avln_get (t.bsu, beacon.vf.nid, brx.snid);
+ test_fail_unless (bprocessed);
test_fail_unless (avln == NULL);
blk_release_desc ((blk_t*) b);
+ blk_release (bprocessed);
b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL,
&t.mac_config, &btx);
- bsu_beacon_process (t.bsu, b, &brx);
+ bprocessed = bsu_beacon_process (t.bsu, b, &brx);
+ test_fail_unless (bprocessed);
avln = bsu_avln_get (t.bsu, beacon.vf.nid, brx.snid);
test_fail_unless (avln != NULL);
test_fail_unless (avln != t.bsu->sta_avln);
blk_release_desc ((blk_t*) b);
+ blk_release (bprocessed);
bsu_track_avln (beacon.vf.nid, brx.snid, 1);
test_fail_unless (avln == t.bsu->sta_avln);
bsu_avln_remove (beacon.vf.nid, brx.snid);
@@ -211,11 +225,11 @@ test_case_bsu_process (test_t test)
bp_rx.snid = 0x4;
bp_rx.bts = 0;
/* Neighbour AVLN. */
- bsu_avln_t *avln = bsu_beacon_process (t.bsu, beacon, &bp_rx);
+ bsu_beacon_t *bbeacon = bsu_beacon_process (t.bsu, beacon, &bp_rx);
+ test_fail_unless (bbeacon == NULL);
+ bsu_avln_t *avln = bsu_avln_get (t.bsu, 0x3, 0x4);
test_fail_unless (avln == NULL);
- avln = bsu_avln_get (t.bsu, 0x3, 0x4);
- test_fail_unless (avln == NULL);
- blk_release_desc ((blk_t*) beacon);
+ blk_release_desc (&beacon->blk);
/* Our AVLN. */
beacon = (pb_beacon_t*) blk_alloc_desc ();
memset (beacon->data, 0, BLK_SIZE);
@@ -227,9 +241,9 @@ test_case_bsu_process (test_t test)
t.bsu->snid_track = bp_rx.snid;
t.bsu->tei_track = 0;
t.bsu->is_sta = BSU_UPDATE_STA_TYPE_STA;
- avln = bsu_beacon_process (t.bsu, beacon, &bp_rx);
- test_fail_unless (avln == NULL);
- blk_release_desc ((blk_t*) beacon);
+ bbeacon = bsu_beacon_process (t.bsu, beacon, &bp_rx);
+ test_fail_unless (bbeacon == NULL);
+ blk_release_desc (&beacon->blk);
}
test_end;
bsu_test_uninit (&t);
@@ -253,21 +267,23 @@ test_case_bsu_process_sta_is_cco (test_t test)
brx.snid = 0x2;
b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL, &t.mac_config,
&btx);
- bsu_avln_t *avln = bsu_beacon_process (t.bsu, b, &brx);
+ bsu_beacon_t *bbeacon = bsu_beacon_process (t.bsu, b, &brx);
test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL]
== 1);
- test_fail_unless (avln);
+ test_fail_unless (bbeacon);
test_fail_unless (t.bsu->sta_avln->sync.init == false);
blk_release_desc ((blk_t*) b);
+ blk_release (bbeacon);
b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_DISCOVER,
&t.mac_config, &btx);
b->phy_pb.pb_rx.pb_measurement.crc_error = false;
- avln = bsu_beacon_process (t.bsu, b, &brx);
+ bbeacon = bsu_beacon_process (t.bsu, b, &brx);
test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_DISCOVER]
== 1);
- test_fail_unless (avln == NULL);
+ test_fail_unless (bbeacon);
test_fail_unless (t.bsu->sta_avln->sync.init == false);
blk_release_desc ((blk_t*) b);
+ blk_release (bbeacon);
}
test_end;
bsu_test_uninit (&t);
diff --git a/cesar/bsu/test/utest/src/schedules.c b/cesar/bsu/test/utest/src/schedules.c
index 5aaa217f20..234aa8dcd2 100644
--- a/cesar/bsu/test/utest/src/schedules.c
+++ b/cesar/bsu/test/utest/src/schedules.c
@@ -20,6 +20,9 @@
#include "bsu/inc/interface.h"
#include <string.h>
+bsu_avln_t*
+bsu_avln_get (bsu_t *ctx, u64 nid, u8 snid);
+
void
bsu_schedules_merge (bsu_t *ctx, bsu_beacon_t *beacon,
ca_schedule_t *schedules, uint nb);
@@ -254,6 +257,7 @@ test_case_ca_schedules_intellon (test_t test)
bsu_test_t t;
bsu_test_init (&t);
bsu_beacon_t beacon;
+ bsu_beacon_t *bprocessed;
pb_beacon_t *pbbeacon;
bsu_test_create_beacon (&t, &beacon);
beacon.bmis.nps.ns = 0;
@@ -278,14 +282,16 @@ test_case_ca_schedules_intellon (test_t test)
pbbeacon->phy_pb.pb_rx.pb_measurement.crc_error = false;
/* The first time bsu receives a beacon of an AVLN. */
brx.bts = BSU_ACLF_BP_50HZ_TCK / 2;
- bsu_beacon_process (t.bsu, pbbeacon, &brx);
+ bprocessed = bsu_beacon_process (t.bsu, pbbeacon, &brx);
+ blk_release (bprocessed);
/* Control plane request to track this AVLN. */
bsu_track_avln (beacon.vf.nid, brx.snid, 0);
t.bsu->track_new = false;
t.bsu->is_sta = BSU_UPDATE_STA_TYPE_STA;
/* BSU receives the next beacon. */
- bsu_beacon_process (t.bsu, pbbeacon, &brx);
+ bprocessed = bsu_beacon_process (t.bsu, pbbeacon, &brx);
/* Schedules which should be present. */
+ test_fail_unless (bprocessed);
test_fail_unless (t.bsu->sta_avln->beacon.bmis.ps.nb == 1);
test_fail_unless (t.bsu->sta_avln->beacon.bmis.ps.ps[0].pscd == 0);
test_fail_unless (t.bsu->sta_avln->beacon.bmis.ps.ps[0].cscd == 7);
@@ -303,6 +309,7 @@ test_case_ca_schedules_intellon (test_t test)
test_fail_unless (brx.bts + i * BSU_ACLF_BP_50HZ_TCK == bpsd[i] +
t.bsu->sta_avln->sync.ntb_offset_tck);
blk_release_desc ((blk_t*) pbbeacon);
+ blk_release (bprocessed);
bsu_test_uninit (&t);
}
test_end;
@@ -373,9 +380,12 @@ test_case_track_new_beacon (test_t t, bsu_test_t *ctx, bsu_beacon_t *beacon)
ctx->mac_config.tei = 0;
params_rx.bts = ctx->bsu->aclf->bpsd[0] + BSU_ACLF_BP_50HZ_TCK / 2;
params_rx.snid = 1;
- bsu_avln_t *avln = bsu_beacon_process (ctx->bsu, pbbeacon, &params_rx);
+ bsu_beacon_t *bbeacon = bsu_beacon_process (ctx->bsu, pbbeacon, &params_rx);
blk_release_desc (&pbbeacon->blk);
/* Modify the ntb_offset_tck to have a real case. */
+ bsu_avln_t *avln = bsu_avln_get (ctx->bsu, bbeacon->vf.nid,
+ bbeacon->params.rx_parameters.snid);
+ blk_release (bbeacon);
avln->sync.ntb_offset_tck = 0;
avln->beacon.beacon_period_start_date = params_rx.bts;
return avln;