summaryrefslogtreecommitdiff
path: root/cesar/cp2/beacon/src
diff options
context:
space:
mode:
authorlaranjeiro2008-06-10 06:47:33 +0000
committerlaranjeiro2008-06-10 06:47:33 +0000
commit5423d469a9eeefc7519bee8732aa481bd0fc27ad (patch)
treef34cae29fa22a63890cf9b52637d4b4fa973dbb1 /cesar/cp2/beacon/src
parent0ee8354b16d8dbc280acb4b0bbef45d6d3eefc37 (diff)
* beacon
* tested the snid change on received beacons. * rename cp_beacon_xcco_common_part by cp_beacon_variant_fields. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2262 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/beacon/src')
-rw-r--r--cesar/cp2/beacon/src/beacon.c163
-rw-r--r--cesar/cp2/beacon/src/bentry.c15
-rw-r--r--cesar/cp2/beacon/src/bentry_msg.c6
3 files changed, 128 insertions, 56 deletions
diff --git a/cesar/cp2/beacon/src/beacon.c b/cesar/cp2/beacon/src/beacon.c
index e1af2cf5c8..390d6605ef 100644
--- a/cesar/cp2/beacon/src/beacon.c
+++ b/cesar/cp2/beacon/src/beacon.c
@@ -183,7 +183,7 @@ cp_beacon_cco_send_beacon (cp_t *ctx, uint beacon_type)
data.nm = CP_BEACON_NM_CSMA_ONLY;
data.cco_cap = CP_CCO_LEVEL;
- cp_beacon_xcco_common_part (ctx, beacon, &data, false /* Write. */);
+ cp_beacon_variant_fields (ctx, beacon, &data, false /* Write. */);
// Fill the bentries.
cp_cco_bw_schedules_init (&schedules);
@@ -278,7 +278,13 @@ cp_beacon_create_default_schedules (cp_t *ctx)
* in the station own data and in the mac config
*/
void
-cp_beacon_change_snid (cp_t *ctx, u8 snid);
+cp_beacon_change_snid (cp_t *ctx, u8 snid)
+{
+ dbg_assert (ctx);
+
+ ctx->beacon.bentry.snid_cd = CP_BENTRY_COUNTDOWN_DEFAULT;
+ ctx->beacon.bentry.snid_new = snid;
+}
/**
* The beacon received from the AVLN.
@@ -296,7 +302,6 @@ cp_beacon_receive (cp_t *ctx, cp_beacon_desc_t * beacon)
circular_buffer_add (&ctx->beacon.list, beacon);
-
// TODO Raise the event in the FSM.
}
@@ -338,7 +343,7 @@ cp_beacon_timer_expires (cyg_handle_t alarm, cyg_addrword_t data)
* - the discover beacon when acting as a UCCo.
*/
void
-cp_beacon_xcco_common_part (cp_t *ctx, cp_beacon_desc_t *beacon,
+cp_beacon_variant_fields (cp_t *ctx, cp_beacon_desc_t *beacon,
cp_beacon_work_beacon_t *data, bool read_write)
{
bitstream_t bitstream;
@@ -463,73 +468,94 @@ cp_beacon_compute_ca_schedules (cp_t *ctx, cp_beacon_common_t *common,
ca_schedule_t *ca_sched;
cp_cco_bw_alloc_conn_t *alloc;
uint i;
+ uint sched_index_start;
cp_beacon_bentry_sched_data_t snid_change_data;
+ cp_net_t *our_net;
dbg_assert (ctx);
dbg_assert (common);
dbg_assert (schedules);
- ca_sched = ca_alloc_get_schedule (ctx->ca,
- ctx->beacon.ca_schedule_index);
- ca_sched->allocations_nb = 0;
- ca_sched->coexistence_mode = hybrid_mode;
- ca_sched->nek_switch = 0; //TODO
+ sched_index_start = ctx->beacon.ca_schedule_index;
+ our_net = cp_sta_mgr_get_our_avln(ctx);
+
+ snid_change_data.cd = ctx->beacon.bentry.snid_cd;
+ snid_change_data.value_at_end = ctx->beacon.bentry.snid_new;
+ snid_change_data.value = cp_net_get_snid (our_net);
- alloc = cp_cco_bw_schedules_get_first (schedules);
- while (alloc)
+ for (i = 0; i < CP_SCHED_BEACON_PERIODS_MAC; i++)
{
- // If the allocation has a start time present flag a hole must be
- // added before this time.
- if (alloc->stpf
- && (MAC_ATU_TO_TCK(alloc->st_atu)
- != ca_sched->allocations[
+ ca_sched = ca_alloc_get_schedule (ctx->ca,
+ ctx->beacon.ca_schedule_index + i);
+ ca_sched->allocations_nb = 0;
+ ca_sched->coexistence_mode = hybrid_mode;
+ ca_sched->nek_switch = 0; //TODO
+
+ snid_change_data.dest = (uint *)&ca_sched->snid;
+ cp_beacon_bentry_mgr_schedule_data (&snid_change_data, i);
+
+ alloc = cp_cco_bw_schedules_get_first (schedules);
+ while (alloc)
+ {
+ // If the allocation has a start time present flag a hole must be
+ // added before this time.
+ if (alloc->stpf
+ && (MAC_ATU_TO_TCK(alloc->st_atu)
+ != ca_sched->allocations[
ca_sched->allocations_nb - 1].end_offset_tck))
+ {
+ ca_sched->allocations[
+ ca_sched->allocations_nb].end_offset_tck =
+ MAC_ATU_TO_TCK(alloc->st_atu);
+ ca_sched->allocations[ca_sched->allocations_nb].glid =
+ MAC_LID_SPC_HOLE;
+ ca_sched->allocations_nb ++;
+ }
+
+ ca_sched->allocations
+ [ca_sched->allocations_nb].end_offset_tck =
+ MAC_ATU_TO_TCK (alloc->et_atu);
+ ca_sched->allocations[ca_sched->allocations_nb].glid =
+ alloc->glid;
+
+ ca_sched->allocations_nb ++;
+ alloc = cp_cco_bw_schedules_get_next (schedules, alloc);
+ }
+
+ // Fill the end of the beacon period with an empty allocation.
+ if (less_mod2p32(ca_sched->allocations
+ [ca_sched->allocations_nb - 1]
+ .end_offset_tck, ctx->pwl.bp_ntb))
{
- ca_sched->allocations[ca_sched->allocations_nb].end_offset_tck =
- MAC_ATU_TO_TCK(alloc->st_atu);
ca_sched->allocations[ca_sched->allocations_nb].glid =
MAC_LID_SPC_HOLE;
- ca_sched->allocations_nb ++;
+ ca_sched->allocations
+ [ca_sched->allocations_nb].end_offset_tck =
+ ctx->pwl.bp_ntb;
+ ca_sched->allocations_nb++;
}
-
- ca_sched->allocations[ca_sched->allocations_nb].end_offset_tck =
- MAC_ATU_TO_TCK (alloc->et_atu);
- ca_sched->allocations[ca_sched->allocations_nb].glid = alloc->glid;
-
- ca_sched->allocations_nb ++;
- alloc = cp_cco_bw_schedules_get_next (schedules, alloc);
- }
-
- // Fill the end of the beacon period with an empty allocation.
- if (less_mod2p32(ca_sched->allocations[ca_sched->allocations_nb - 1]
- .end_offset_tck, ctx->pwl.bp_ntb))
- {
- ca_sched->allocations[ca_sched->allocations_nb].glid = MAC_LID_SPC_HOLE;
- ca_sched->allocations[ca_sched->allocations_nb].end_offset_tck =
- ctx->pwl.bp_ntb;
- ca_sched->allocations_nb++;
}
beacon_period[0].start_date = ctx->pwl.bp_avln_ntb[0];
beacon_period[0].schedule_index =
(ctx->beacon.ca_schedule_index == 0) ? 0 :
- ctx->beacon.ca_schedule_index - 1;
+ sched_index_start - 1;
// ADD the schedule to the CA.
- snid_change_data.
-
+
for (i = 1; i < CP_SCHED_BEACON_PERIODS_MAC; i++)
{
beacon_period[i].start_date = ctx->pwl.bp_avln_ntb[i]
+ ctx->pwl.bto[i]
- bpsto;
- beacon_period[i].schedule_index = ctx->beacon.ca_schedule_index;
- cp_beacon_bentry_mgr_schedule_data (&sched_data, i);
+ beacon_period[i].schedule_index = sched_index_start;
+ sched_index_start ++;
}
+ ctx->beacon.ca_schedule_index = sched_index_start;
+
ca_alloc_update_beacon_periods (ctx->ca, beacon_period,
CP_SCHED_BEACON_PERIODS_MAC);
- ctx->beacon.ca_schedule_index ++;
}
/**
@@ -544,6 +570,7 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
cp_sta_own_data_t *own_sta;
cp_net_t *net;
cp_net_t *our_net;
+ cp_sta_t *sta;
u64 nid;
dbg_assert (ctx);
@@ -552,7 +579,7 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
dbg_check (beacon);
// Read the variant fields of the beacon.
- cp_beacon_xcco_common_part (ctx, beacon, &beacon_vf, true /* Read. */);
+ cp_beacon_variant_fields (ctx, beacon, &beacon_vf, true /* Read. */);
nid = (((u64)beacon_vf.nid_msb) << 22);
nid |= beacon_vf.nid_lsb;
@@ -571,6 +598,16 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
// Add the AVLN to the net list.
net = cp_sta_mgr_add_avln (ctx, beacon->payload->fc.snid, nid);
+ // Add the station to the net.
+ sta = cp_net_sta_add (net, beacon_vf.stei, 0x0);
+ cp_sta_set_state (sta, CP_STA_STATE_AUTHENTICATED);
+ cp_net_sta_set_visible_status (net, sta,
+ CP_STA_VISIBLE_STATE_VISIBLE);
+
+ // TODO raise the event in the FSM for station action.
+ // TODO remove the blk_alloc once this is corrected.
+ blk_release (sta);
+
// Get our network.
our_net = cp_sta_mgr_get_our_avln (ctx);
@@ -588,12 +625,7 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
}
else
{
- cp_sta_t *sta;
// Add the station to the net.
- sta = cp_net_sta_add (net, beacon_vf.stei, 0x0);
- cp_net_sta_set_visible_status (net, sta, true);
- cp_sta_set_state (sta, CP_STA_STATE_AUTHENTICATED);
-
if (beacon_vf.bt == CP_BEACON_CENTRAL_BEACON)
cp_net_set_cco (net, ctx, beacon_vf.stei);
@@ -602,7 +634,6 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
sta->cco_cap = beacon_vf.cco_cap;
cp_net_commit_to_dataplane (net, ctx);
- blk_release (sta);
}
// Release the beacon.
@@ -631,7 +662,9 @@ cp_beacon_process_central_proxy (cp_t *ctx, cp_beacon_desc_t *beacon,
uint tei_discover;
cp_bentry_discover_info_struct_t info_struct;
u8 *bpsto = NULL;
- u8 snid;
+ cp_snid_t snid;
+ uint snid_cd;
+
dbg_assert (ctx);
dbg_assert (beacon);
@@ -639,7 +672,10 @@ cp_beacon_process_central_proxy (cp_t *ctx, cp_beacon_desc_t *beacon,
// get the beacon common data.
if (beacon_vf->bt == CP_BEACON_CENTRAL_BEACON)
+ {
common = &ctx->beacon.central;
+ cp_beacon_bentry_mgr_countdown (ctx);
+ }
else if (beacon_vf->bt == CP_BEACON_CENTRAL_BEACON)
common = &ctx->beacon.proxy;
@@ -720,7 +756,7 @@ cp_beacon_process_central_proxy (cp_t *ctx, cp_beacon_desc_t *beacon,
printf ("CP_BENTRY_CHANGE_HM Not implemented");
break;
case CP_BENTRY_CHANGE_SNID:
- cp_beacon_bentry_mgr_snid_change (&bentry, &snid);
+ cp_beacon_bentry_mgr_snid_change (&bentry, &snid, &snid_cd);
break;
case CP_BENTRY_VENDOR:
break;
@@ -735,6 +771,11 @@ cp_beacon_process_central_proxy (cp_t *ctx, cp_beacon_desc_t *beacon,
cp_sta_set_state (sta, CP_STA_STATE_AUTHENTICATED);
cp_net_sta_set_visible_status (net, sta, true);
+ // Store the snid.
+ ctx->beacon.bentry.snid_cd = snid_cd;
+ ctx->beacon.bentry.snid_new = snid;
+
+
if (beacon_vf->bt == CP_BEACON_CENTRAL_BEACON)
cp_net_set_cco (net, ctx, beacon_vf->stei);
@@ -878,7 +919,7 @@ cp_beacon_sta_send_discover_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
sta = cp_sta_mgr_get_sta_own_data (ctx);
beacon_vf.stei = cp_sta_own_data_get_tei (sta);
- cp_beacon_xcco_common_part (ctx, disc_beacon, &beacon_vf,
+ cp_beacon_variant_fields (ctx, disc_beacon, &beacon_vf,
false /* Write. */);
bentry_read.read_write = CP_BEACON_BENTRY_READ;
@@ -933,3 +974,21 @@ cp_beacon_sta_send_discover_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
mac_address);
}
+/**
+ * Process a tracked network using the central beacon or the proxy beacon.
+ * \param ctx the CP module context.
+ * \param beacon the beacon received and tracked.
+ */
+void
+cp_beacon_process_tracked_avln (cp_t *ctx, cp_beacon_desc_t *beacon)
+{
+ cp_beacon_work_beacon_t beacon_vf;
+
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+
+ cp_beacon_variant_fields (ctx, beacon, &beacon_vf, true /* read */);
+
+ cp_beacon_process_central_proxy (ctx, beacon, &beacon_vf);
+}
+
diff --git a/cesar/cp2/beacon/src/bentry.c b/cesar/cp2/beacon/src/bentry.c
index a150b3f6bc..918c90cfe8 100644
--- a/cesar/cp2/beacon/src/bentry.c
+++ b/cesar/cp2/beacon/src/bentry.c
@@ -64,7 +64,18 @@ cp_beacon_bentry_mgr_uninit (cp_t *ctx)
* event is raise in the FSM
*/
void
-cp_beacon_bentry_mgr_countdown (cp_t *ctx);
+cp_beacon_bentry_mgr_countdown (cp_t *ctx)
+{
+ dbg_assert (ctx);
+
+ /** Change snid countdown. */
+ if(ctx->beacon.bentry.snid_cd)
+ {
+ ctx->beacon.bentry.snid_cd --;
+ if (ctx->beacon.bentry.snid_cd == 0)
+ cp_sta_mgr_update_our_avln_snid(ctx, ctx->beacon.bentry.snid_new);
+ }
+}
/**
* Read the bentries in the beacon.
@@ -182,7 +193,7 @@ cp_beacon_bentry_mgr_schedule_data (cp_beacon_bentry_sched_data_t *data,
dbg_assert (data);
dbg_assert (data->dest);
- if (data->cd != 0 && (data->cd <= index + 1))
+ if (data->cd != 0 && (data->cd <= index))
*data->dest = data->value_at_end;
else
*data->dest = data->value;
diff --git a/cesar/cp2/beacon/src/bentry_msg.c b/cesar/cp2/beacon/src/bentry_msg.c
index b1ee42167e..573d2fc5ef 100644
--- a/cesar/cp2/beacon/src/bentry_msg.c
+++ b/cesar/cp2/beacon/src/bentry_msg.c
@@ -473,13 +473,14 @@ cp_beacon_bentry_mgr_hm_change (cp_t *ctx, u8 * bentry,
* \param ctx the module context.
* \param bentry The start address bentry.
* \param snid Read or write SNID value.
+ * \param snidcd the SNID countdown
*
* on write it use the data stored in the context. On read it shall update
* the context data
*/
void
cp_beacon_bentry_mgr_snid_change (cp_beacon_bentry_t *bentry,
- u8 *snid)
+ cp_snid_t *snid, uint *snidcd)
{
bitstream_t bitstream;
dbg_assert (bentry);
@@ -493,7 +494,8 @@ cp_beacon_bentry_mgr_snid_change (cp_beacon_bentry_t *bentry,
(bentry->read_write == CP_BEACON_BENTRY_WRITE) ?
BITSTREAM_WRITE : BITSTREAM_READ);
- bitstream_access (&bitstream, snid, 8);
+ bitstream_access (&bitstream, snidcd, 4);
+ bitstream_access (&bitstream, snid, 4);
bitstream_finalise (&bitstream);