summaryrefslogtreecommitdiff
path: root/cesar/cp2/beacon/src
diff options
context:
space:
mode:
authorlaranjeiro2008-06-02 15:59:46 +0000
committerlaranjeiro2008-06-02 15:59:46 +0000
commit02e85be6c95a2c2a1a06f8ad027684d4d400b0c2 (patch)
tree7b58e79bbcaffcfe6adbd83f9b048cd6f724f519 /cesar/cp2/beacon/src
parent51e4c64a9703f09cdbecaf918e2e7866b4a3c835 (diff)
* beacon:
* Wrote the function to process received beacons. * Wrote the function to send a discover beacon as STA. * test in progress. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2194 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/beacon/src')
-rw-r--r--cesar/cp2/beacon/src/beacon.c250
-rw-r--r--cesar/cp2/beacon/src/bentry.c12
2 files changed, 255 insertions, 7 deletions
diff --git a/cesar/cp2/beacon/src/beacon.c b/cesar/cp2/beacon/src/beacon.c
index ee60a35259..65c5bcc160 100644
--- a/cesar/cp2/beacon/src/beacon.c
+++ b/cesar/cp2/beacon/src/beacon.c
@@ -17,6 +17,7 @@
*/
#include "common/std.h"
#include "string.h"
+#include "stdio.h"
#include "lib/read_word.h"
@@ -32,6 +33,7 @@
#include "cp2/beacon/inc/beacon.h"
#include "cp2/beacon/inc/beacon_work.h"
+#include "cp2/beacon/inc/bentry_size.h"
#include "cp2/inc/context.h"
/**
@@ -520,7 +522,7 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
// Read the variant fields of the beacon.
cp_beacon_xcco_common_part (ctx, beacon, &beacon_vf, true /* Read. */);
- nid = (u64) (beacon_vf.nid_msb << 22);
+ nid = (((u64)beacon_vf.nid_msb) << 22);
nid |= beacon_vf.nid_lsb;
// Verify beacon SNID and NID as the tracked AVLN.
@@ -552,8 +554,24 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
{
cp_beacon_process_central_read_regions (ctx, beacon, &beacon_vf);
}
-
- blk_release_desc ((blk_t *) beacon);
+ else
+ {
+ cp_sta_t *sta;
+ // Add the station to the net.
+ sta = cp_net_sta_add (net, beacon_vf.stei, 0x0,
+ true /* authentication */,
+ beacon_vf.bt == CP_BEACON_CENTRAL_BEACON ?
+ true : false /* cco */,
+ beacon_vf.bt == CP_BEACON_PROXY_BEACON ?
+ true : false /* pco */,
+ false /* backup CCo */,
+ beacon_vf.bt == CP_BEACON_CENTRAL_BEACON ?
+ true : false /* visible. */);
+
+ sta->cco_cap = beacon_vf.cco_cap;
+ cp_net_commit_to_dataplane (net, ctx);
+ blk_release (sta);
+ }
}
/**
@@ -567,9 +585,144 @@ void
cp_beacon_process_central_proxy (cp_t *ctx, cp_beacon_desc_t *beacon,
cp_beacon_work_beacon_t *beacon_vf)
{
+ cp_beacon_common_t *common;
+ cp_sta_own_data_t *own_data;
+ mac_t mac_address;
+ cp_sta_t *sta;
+ cp_net_t *net;
+ cp_beacon_bentry_t bentry;
+ uint nbe;
+ set_t schedules;
+ uint tei_discover;
+ cp_bentry_discover_info_struct_t info_struct;
+ u8 *bpsto = NULL;
+ u8 snid;
+
dbg_assert (ctx);
dbg_assert (beacon);
dbg_assert (beacon_vf);
+
+ // get the beacon common data.
+ if (beacon_vf->bt == CP_BEACON_CENTRAL_BEACON)
+ common = &ctx->beacon.central;
+ else if (beacon_vf->bt == CP_BEACON_CENTRAL_BEACON)
+ common = &ctx->beacon.proxy;
+
+ // Increase the counter.
+ common->nb_beacon_recv++;
+ // store the current NTB date.
+ common->last_beacon_ntb = mac_ntb();
+
+ // Verify if the central beacon has been received in the current beacon
+ // period.
+ if ((beacon_vf->bt == CP_BEACON_PROXY_BEACON)
+ && less_mod2p32(ctx->beacon.central.last_beacon_ntb,
+ ctx->pwl.bp_avln_ntb[1]))
+ {
+ // The central beacon of this AVLN has already been processed, it is
+ // not necessary to process it again.
+ return ;
+ }
+
+ // Store the data contained in the variant fields.
+ own_data = cp_sta_mgr_get_sta_own_data (ctx);
+ net = cp_sta_mgr_get_our_avln (ctx);
+
+ // Set Hybrid mode.
+ own_data->hybrid_mode = beacon_vf->hm;
+
+ // Store the slot id in the AVLN.
+ cp_net_set_slot_id_and_usage (net, beacon_vf->slot_id,
+ beacon_vf->slot_usage);
+
+ // Processing beacon entries.
+ cp_beacon_discover_info_init (&info_struct);
+ bentry.read_write = CP_BEACON_BENTRY_READ;
+ bentry.bentry_addr = beacon->payload->bmis;
+
+ cp_cco_bw_schedules_init (&schedules);
+ for (nbe = beacon->payload->nbe; nbe; nbe --)
+ {
+ cp_beacon_bentry_mgr_process_header (&bentry);
+
+ switch (bentry.header)
+ {
+ case CP_BENTRY_PERSISTENT_SCHEDULE:
+ case CP_BENTRY_NON_PERSISTENT_SCHEDULE:
+ cp_beacon_bentry_mgr_schedules (ctx, &bentry, &schedules);
+ break;
+ case CP_BENTRY_REGIONS:
+ cp_beacon_bentry_mgr_regions (ctx, &bentry);
+ break;
+ case CP_BENTRY_MAC_ADDRESS:
+ cp_beacon_bentry_mgr_mac_address (&bentry, &mac_address);
+ break;
+ case CP_BENTRY_DISCOVER:
+ cp_beacon_bentry_mgr_discover (&bentry, &tei_discover);
+ break;
+ case CP_BENTRY_DISCOVER_INFO:
+ cp_beacon_bentry_mgr_discover_info_bentry (&bentry, &info_struct);
+ break;
+ case CP_BENTRY_BEACON_PERIOD_START_OFFSET:
+ cp_beacon_bentry_mgr_bpsto (&bentry, &bpsto);
+ break;
+ case CP_BENTRY_ENCRYPTION_KEY_CHANGE:
+ printf ("CP_BENTRY_ENCRYPTION_KEY_CHANGE Not implemented");
+ break;
+ case CP_BENTRY_CCO_HANDOVER:
+ printf ("CP_BENTRY_CCO_HANDOVER Not implemented");
+ break;
+ case CP_BENTRY_BEACON_RELOCATION:
+ printf ("CP_BENTRY_BEACON_RELOCATION Not implemented");
+ break;
+ case CP_BENTRY_AC_LINE_SYNC_COUNTDOWN:
+ printf ("CP_BENTRY_AC_LINE_SYNC_COUNTDOWN Not implemented");
+ break;
+ case CP_BENTRY_CHANGE_NUMSLOTS:
+ printf ("CP_BENTRY_CHANGE_NUMSLOTS Not implemented");
+ break;
+ case CP_BENTRY_CHANGE_HM:
+ printf ("CP_BENTRY_CHANGE_HM Not implemented");
+ break;
+ case CP_BENTRY_CHANGE_SNID:
+ cp_beacon_bentry_mgr_snid_change (&bentry, &snid);
+ break;
+ case CP_BENTRY_VENDOR:
+ break;
+ default:
+ dbg_assert ((bentry.header > CP_BENTRY_CHANGE_SNID)
+ && (bentry.header < CP_BENTRY_VENDOR));
+ }
+ }
+
+ // Add the station to the net.
+ sta = cp_net_sta_add (net, beacon_vf->stei, mac_address,
+ info_struct.authentication,
+ info_struct.cco_status,
+ info_struct.pco_status,
+ info_struct.backup_cco_status,
+ true /* visible. */);
+
+ sta->cco_cap = beacon_vf->cco_cap;
+ sta->pco_cap = info_struct.proxy_net_cap;
+ sta->backup_cco_cap = info_struct.backup_cco_cap;
+ sta->numDisSta = info_struct.num_dis_sta;
+ sta->numDisNet = info_struct.num_dis_net;
+ cp_net_commit_to_dataplane (net, ctx);
+ blk_release (sta);
+
+ // Set the schedules in the station.
+ cp_beacon_compute_ca_schedules (ctx, common, beacon_vf->hm, &schedules,
+ bpsto != NULL ? read_u24_from_word (bpsto)
+ : 0);
+ cp_cco_bw_schedules_uninit (&schedules);
+
+ // If TEI discover corresponds to the current station TEI send a discover
+ // beacon.
+ if (cp_sta_own_data_get_tei (own_data) == tei_discover)
+ cp_beacon_sta_send_discover_beacon (ctx, beacon, *beacon_vf);
+
+ blk_release_desc ((blk_t *) beacon);
}
/**
@@ -598,11 +751,10 @@ cp_beacon_process_discover (cp_t *ctx, cp_beacon_desc_t *beacon,
dbg_assert (net);
// Get the number of beacon entries.
- nbe = read_u8_from_word(beacon->payload->bmis);
bentry.read_write = CP_BEACON_BENTRY_READ;
- bentry.bentry_addr = beacon->payload->bmis + 1;
+ bentry.bentry_addr = beacon->payload->bmis;
- for (stop = 0; nbe && (stop < 2); nbe--)
+ for (nbe = beacon->payload->nbe, stop = 0; nbe && (stop < 2); nbe--)
{
cp_beacon_bentry_mgr_process_header (&bentry);
@@ -622,13 +774,15 @@ cp_beacon_process_discover (cp_t *ctx, cp_beacon_desc_t *beacon,
info_struct.authentication,
info_struct.cco_status,
info_struct.pco_status,
- info_struct.backup_cco_status);
+ info_struct.backup_cco_status,
+ true /* visible. */);
sta->cco_cap = beacon_vf->cco_cap;
sta->pco_cap = info_struct.proxy_net_cap;
sta->backup_cco_cap = info_struct.backup_cco_cap;
sta->numDisSta = info_struct.num_dis_sta;
sta->numDisNet = info_struct.num_dis_net;
+ cp_net_commit_to_dataplane (net, ctx);
blk_release (sta);
}
@@ -649,3 +803,85 @@ cp_beacon_process_central_read_regions (cp_t *ctx, cp_beacon_desc_t *beacon,
dbg_assert (beacon);
dbg_assert (beacon_vf);
}
+
+/** Generate and send a discover beacon from the central or proxy beacon.
+ * \param ctx the CP context.
+ * \param beacon the central or proxy beacon containing the query.
+ * \param beacon_vf the variant filled read from the beacon.
+ */
+void
+cp_beacon_sta_send_discover_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
+ cp_beacon_work_beacon_t beacon_vf)
+{
+ cp_sta_own_data_t *sta;
+ cp_beacon_desc_t *disc_beacon;
+ cp_beacon_bentry_t bentry_read;
+ cp_beacon_bentry_t bentry_write;
+ uint nbe;
+ mac_t mac_address;
+ cp_bentry_discover_info_struct_t info_struct;
+
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+
+ disc_beacon = (cp_beacon_desc_t *) blk_alloc_desc ();
+
+ // Get the station own data.
+ 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,
+ false /* Write. */);
+
+ bentry_read.read_write = CP_BEACON_BENTRY_READ;
+ bentry_read.bentry_addr = beacon->payload->bmis;
+
+ bentry_write.read_write = CP_BEACON_BENTRY_WRITE;
+ bentry_write.bentry_addr = disc_beacon->payload->bmis;
+
+ // Store the mac address.
+ mac_address = cp_sta_own_data_get_mac_address (sta);
+ cp_beacon_bentry_mgr_mac_address (&bentry_write, &mac_address);
+
+ // Store the discover info bentry.
+ cp_beacon_discover_info_init (&info_struct);
+ info_struct.cco_cap= CCO_LEVEL;
+ info_struct.proxy_net_cap= PCO_CAP;
+ info_struct.backup_cco_cap= BACKUP_CCO_CAP;
+ info_struct.cco_status= sta->is_cco;
+ info_struct.pco_status= sta->pco_status;
+ info_struct.backup_cco_status= false;
+ info_struct.num_dis_sta= cp_sta_mgr_get_num_discovered_stas (ctx);
+ info_struct.num_dis_net= cp_sta_mgr_get_num_discovered_net (ctx);
+ info_struct.authentication= sta->authenticated;
+ info_struct.status_user_ap_cco= false;
+
+ cp_beacon_bentry_mgr_discover_info_bentry (&bentry_write, &info_struct);
+
+ // Search for the following data.
+ for (nbe = beacon->payload->nbe; nbe; nbe--)
+ {
+ cp_beacon_bentry_mgr_process_header (&bentry_read);
+
+ switch (bentry_read.header)
+ {
+ case CP_BENTRY_REGIONS:
+ case CP_BENTRY_PERSISTENT_SCHEDULE:
+ case CP_BENTRY_NON_PERSISTENT_SCHEDULE:
+ case CP_BENTRY_BEACON_PERIOD_START_OFFSET:
+ case CP_BENTRY_CCO_HANDOVER:
+ case CP_BENTRY_BEACON_RELOCATION:
+ case CP_BENTRY_CHANGE_NUMSLOTS:
+ case CP_BENTRY_CHANGE_SNID:
+ bitstream_memcpy (bentry_write.bentry_addr,
+ bentry_read.bentry_addr - CP_BEACON_ENTRY_HEADER,
+ bentry_read.length + CP_BEACON_ENTRY_HEADER);
+ bentry_write.bentry_addr += bentry_read.length +
+ CP_BEACON_ENTRY_HEADER;
+ }
+ }
+
+ cp_beacon_send_beacon (ctx, disc_beacon, CP_BEACON_DISCOVER_BEACON,
+ mac_address);
+}
+
diff --git a/cesar/cp2/beacon/src/bentry.c b/cesar/cp2/beacon/src/bentry.c
index 84004c48fa..bb6c219ee4 100644
--- a/cesar/cp2/beacon/src/bentry.c
+++ b/cesar/cp2/beacon/src/bentry.c
@@ -30,6 +30,18 @@
#include "cp2/beacon/inc/bentry.h"
#include "cp2/beacon/inc/bentry_size.h"
+/**
+ * Initialise the discover info structure.
+ * \param ctx the discover info structure.
+ */
+void
+cp_beacon_discover_info_init (cp_bentry_discover_info_struct_t *ctx)
+{
+ dbg_assert (ctx);
+
+ memset (ctx, 0, sizeof (cp_bentry_discover_info_struct_t));
+}
+
/**
* Initialise the bentry mgr.
* \param ctx the module context.