summaryrefslogtreecommitdiff
path: root/cesar/bsu/beacon/src/beacon.c
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-12-03 09:11:06 +0100
committerNélio Laranjeiro2011-01-11 15:39:43 +0100
commitc6a459052635a62ebf4745a75d72dd091a57068c (patch)
tree2178782237d3086921d9458dfdd9cbaac51a1c10 /cesar/bsu/beacon/src/beacon.c
parent224594457d46d928d94ee26990a510db3e301f9e (diff)
cesar/{cp, bsu, interface}: provide a decoded beacon to CP, closes #2127
Diffstat (limited to 'cesar/bsu/beacon/src/beacon.c')
-rw-r--r--cesar/bsu/beacon/src/beacon.c188
1 files changed, 110 insertions, 78 deletions
diff --git a/cesar/bsu/beacon/src/beacon.c b/cesar/bsu/beacon/src/beacon.c
index bb22d960d5..b794543120 100644
--- a/cesar/bsu/beacon/src/beacon.c
+++ b/cesar/bsu/beacon/src/beacon.c
@@ -42,6 +42,8 @@ bsu_beacon_reset (bsu_beacon_t *beacon)
beacon->beacon_period_start_date = 0;
beacon->vf.nid = 0;
beacon->vf.hm = 0;
+ beacon->vf.stei = MAC_TEI_UNASSOCIATED;
+ beacon->vf.bt = BSU_BEACON_TYPE_NB;
beacon->vf.ncnr = 0;
beacon->vf.npsm = 0;
beacon->vf.numslots = 0;
@@ -52,7 +54,6 @@ bsu_beacon_reset (bsu_beacon_t *beacon)
beacon->vf.rtsbf = 0;
beacon->vf.nm = 0;
beacon->vf.ccocap = 0;
- beacon->vf.rsvd = 0;
beacon->bmis.nbe = 0;
beacon->bmis.region.nb = 0;
beacon->bmis.ps.nb = 0;
@@ -80,27 +81,19 @@ bsu_beacon_read_nid (pb_beacon_t *beacon, bitstream_t *stream)
return ((u64) bitstream_read (stream, 22)) << 32
| beacon->first_data_word;
}
-
/**
* Write the beacon variant fields.
* \param phy_beacon the beacon bloc.
* \param stream the bitstream context.
- * \param mac_config the mac config object.
* \param beacon the data to use to write the beacon.
- * \param type the beacon type.
*/
static void
-bsu_beacon_write_variant_fields (pb_beacon_t *phy_beacon,
- bitstream_t *stream,
- mac_config_t *mac_config,
- bsu_beacon_t *beacon,
- bsu_beacon_type_t type)
+bsu_beacon_write_variant_fields_without_nid (
+ bitstream_t *stream, bsu_beacon_t *beacon)
{
- phy_beacon->first_data_word = beacon->vf.nid;
- bitstream_write (stream, beacon->vf.nid >> 32, 22);
bitstream_write (stream, beacon->vf.hm, 2);
- bitstream_write (stream, mac_config->tei, 8);
- bitstream_write (stream, type, 3);
+ bitstream_write (stream, beacon->vf.stei, 8);
+ bitstream_write (stream, beacon->vf.bt, 3);
bitstream_write (stream, beacon->vf.ncnr, 1);
bitstream_write (stream, beacon->vf.npsm, 1);
bitstream_write (stream, beacon->vf.numslots, 3);
@@ -115,6 +108,21 @@ bsu_beacon_write_variant_fields (pb_beacon_t *phy_beacon,
}
/**
+ * Write the beacon variant fields.
+ * \param phy_beacon the beacon bloc.
+ * \param stream the bitstream context.
+ * \param beacon the data to use to write the beacon.
+ */
+static void
+bsu_beacon_write_variant_fields (
+ pb_beacon_t *phy_beacon, bitstream_t *stream, bsu_beacon_t *beacon)
+{
+ phy_beacon->first_data_word = beacon->vf.nid;
+ bitstream_write (stream, beacon->vf.nid >> 32, 22);
+ bsu_beacon_write_variant_fields_without_nid (stream, beacon);
+}
+
+/**
* Write the regions entries in the beacon.
* \param stream the bitstream context.
* \param region the region bentry.
@@ -265,7 +273,7 @@ bsu_beacon_write_bmi_discover (bitstream_t *stream,
bsu_beacon_bmi_discover_t *discover,
bsu_beacon_type_t type)
{
- if (discover->present && type == BSU_BEACON_TYPE_CENTRAL)
+ if (discover->present)
{
bitstream_write (stream, BSU_BEACON_ENTRY_HEADER_DISCOVER, 8);
bitstream_write (stream, BSU_BEACON_ENTRY_SIZE_DISCOVER, 8);
@@ -459,43 +467,38 @@ bsu_beacon_write_bmi_change_snid (bitstream_t *stream,
/**
* Write the Mac address beacon entry.
* \param stream the bitstream context.
- * \param mac_config the mac config object.
* \param mac the beacon entry to store in the beacon.
*/
static void
bsu_beacon_write_bmi_mac_address (bitstream_t *stream,
- mac_config_t *mac_config,
bsu_beacon_bmi_mac_address_t *mac)
{
if (mac->present)
{
bitstream_write (stream, BSU_BEACON_ENTRY_HEADER_MAC_ADDRESS, 8);
bitstream_write (stream, BSU_BEACON_ENTRY_SIZE_MAC_ADDRESS, 8);
- bitstream_write_large (stream, mac_config->sta_mac_address, 48);
+ bitstream_write_large (stream, mac->mac_address, 48);
}
}
/**
* Compute the number of beacon entries are present in the beacon.
* \param beacon the beacon data to store in the beacon.
- * \param type the beacon type.
- * \param mac_config the MAC configuration structure to get the TEI.
* \return the number of Beacon entries present in the beacon.
*/
static inline uint
-bsu_beacon_write_nbe_nb (bsu_beacon_t *beacon, bsu_beacon_type_t type,
- mac_config_t *mac_config)
+bsu_beacon_write_nbe_nb (bsu_beacon_t *beacon)
{
uint nbe = 1;
dbg_assert (beacon->bmis.region.nb);
- dbg_assert ((type == BSU_BEACON_TYPE_DISCOVER &&
+ dbg_assert ((beacon->vf.bt == BSU_BEACON_TYPE_DISCOVER &&
beacon->bmis.discover_info.present)
- || type != BSU_BEACON_TYPE_DISCOVER);
- dbg_assert ((type == BSU_BEACON_TYPE_CENTRAL
- && ((mac_config->tei == beacon->bmis.discover.tei
+ || beacon->vf.bt != BSU_BEACON_TYPE_DISCOVER);
+ dbg_assert ((beacon->vf.bt == BSU_BEACON_TYPE_CENTRAL
+ && ((beacon->vf.stei == beacon->bmis.discover.tei
&& beacon->bmis.discover_info.present)
- || mac_config->tei != beacon->bmis.discover.tei))
- || type != BSU_BEACON_TYPE_CENTRAL);
+ || beacon->vf.stei != beacon->bmis.discover.tei))
+ || beacon->vf.bt != BSU_BEACON_TYPE_CENTRAL);
dbg_assert ((beacon->vf.nm == BSU_BEACON_NM_CSMA_ONLY &&
beacon->bmis.bpsto.present)
|| (beacon->vf.nm != BSU_BEACON_NM_CSMA_ONLY &&
@@ -503,7 +506,7 @@ bsu_beacon_write_nbe_nb (bsu_beacon_t *beacon, bsu_beacon_type_t type,
if (beacon->bmis.ps.nb)
nbe += beacon->bmis.ps.nb;
nbe += beacon->bmis.nps.ns ? 1 : 0;
- if (beacon->bmis.discover.present && type == BSU_BEACON_TYPE_CENTRAL)
+ if (beacon->bmis.discover.present)
nbe++;
if (beacon->bmis.bpsto.present)
nbe++;
@@ -528,6 +531,64 @@ bsu_beacon_write_nbe_nb (bsu_beacon_t *beacon, bsu_beacon_type_t type,
return nbe;
}
+/**
+ * Write the NBE and the beacon entries using the bitstream library.
+ * \param beacon the bsu beacon containing the data.
+ * \param stream the bitstream (initialized) to store data.
+ * \param data the address of the begining of the data in the pb beacon.
+ * \return the btpsto offset.
+ */
+static uint
+bsu_beacon_write_beacon_entries (bsu_beacon_t *beacon, bitstream_t *stream,
+ u8 *data)
+{
+ uint offset;
+ uint nbe = bsu_beacon_write_nbe_nb (beacon);
+ dbg_assert (nbe);
+ bitstream_write (stream, nbe, 8);
+ bsu_beacon_write_bmi_non_persistent (stream, &beacon->bmis.nps,
+ data);
+ bsu_beacon_write_bmi_persistent (stream, &beacon->bmis.ps,
+ data);
+ bsu_beacon_write_bmi_region (stream, &beacon->bmis.region);
+ bsu_beacon_write_bmi_mac_address (
+ stream, &beacon->bmis.mac_address_present);
+ bsu_beacon_write_bmi_discover (
+ stream, &beacon->bmis.discover, beacon->vf.bt);
+ bsu_beacon_write_bmi_discover_info (stream,
+ &beacon->bmis.discover_info);
+ offset = bsu_beacon_write_bmi_bpsto (stream,
+ &beacon->bmis.bpsto);
+ bsu_beacon_write_bmi_eks (stream, &beacon->bmis.eks);
+ bsu_beacon_write_bmi_handover (stream, &beacon->bmis.handover);
+ bsu_beacon_write_bmi_relocation (stream,
+ &beacon->bmis.relocation);
+ bsu_beacon_write_bmi_aclsc (stream, &beacon->bmis.aclsc);
+ bsu_beacon_write_bmi_change_num_slot (stream,
+ &beacon->bmis.cns);
+ bsu_beacon_write_bmi_change_hm (stream,
+ &beacon->bmis.change_hm);
+ bsu_beacon_write_bmi_change_snid (stream,
+ &beacon->bmis.change_snid);
+ return offset;
+}
+
+uint
+bsu_beacon_write_bitstream_initialised_no_nid (
+ bsu_beacon_t *beacon, bitstream_t *stream, u8 *data)
+{
+ bsu_beacon_write_variant_fields_without_nid (stream, beacon);
+ return bsu_beacon_write_beacon_entries (beacon, stream, data);
+}
+
+uint
+bsu_beacon_write_bitstream_initialised (
+ bsu_beacon_t *beacon, bitstream_t *stream, pb_beacon_t *pbbeacon)
+{
+ bsu_beacon_write_variant_fields (pbbeacon, stream, beacon);
+ return bsu_beacon_write_beacon_entries (beacon, stream, pbbeacon->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)
@@ -539,37 +600,13 @@ bsu_beacon_write (bsu_beacon_t *beacon, bsu_beacon_type_t type,
dbg_assert (type < BSU_BEACON_TYPE_NB);
dbg_assert (mac_config);
dbg_assert (params);
+ beacon->vf.bt = type;
+ beacon->vf.stei = mac_config->tei;
/* Allocate the beacon. */
pbbeacon = (pb_beacon_t *) blk_alloc_desc ();
bitstream_write_init (&stream, pbbeacon->data, BSU_BEACON_SIZE);
- bsu_beacon_write_variant_fields (
- pbbeacon, &stream, mac_config, beacon, type);
- uint nbe = bsu_beacon_write_nbe_nb (beacon, type, mac_config);
- dbg_assert (nbe);
- bitstream_write (&stream, nbe, 8);
- bsu_beacon_write_bmi_non_persistent (&stream, &beacon->bmis.nps,
- pbbeacon->data);
- bsu_beacon_write_bmi_persistent (&stream, &beacon->bmis.ps,
- pbbeacon->data);
- bsu_beacon_write_bmi_region (&stream, &beacon->bmis.region);
- bsu_beacon_write_bmi_mac_address (&stream, mac_config,
- &beacon->bmis.mac_address_present);
- bsu_beacon_write_bmi_discover (&stream, &beacon->bmis.discover, type);
- bsu_beacon_write_bmi_discover_info (&stream,
- &beacon->bmis.discover_info);
- offset = bsu_beacon_write_bmi_bpsto (&stream,
- &beacon->bmis.bpsto);
- bsu_beacon_write_bmi_eks (&stream, &beacon->bmis.eks);
- bsu_beacon_write_bmi_handover (&stream, &beacon->bmis.handover);
- bsu_beacon_write_bmi_relocation (&stream,
- &beacon->bmis.relocation);
- bsu_beacon_write_bmi_aclsc (&stream, &beacon->bmis.aclsc);
- bsu_beacon_write_bmi_change_num_slot (&stream,
- &beacon->bmis.cns);
- bsu_beacon_write_bmi_change_hm (&stream,
- &beacon->bmis.change_hm);
- bsu_beacon_write_bmi_change_snid (&stream,
- &beacon->bmis.change_snid);
+ offset =
+ bsu_beacon_write_bitstream_initialised (beacon, &stream, pbbeacon);
bitstream_finalise (&stream);
if (beacon->bmis.bpsto.present)
params->bpsto = pbbeacon->data + offset;
@@ -583,21 +620,18 @@ bsu_beacon_write (bsu_beacon_t *beacon, bsu_beacon_type_t type,
* \param phy_beacon the beacon received from the medium.
* \param stream the bitstream context.
* \param mac_config the mac config object.
- * \param beacon the data to use to write the beacon.
- * \param type the beacon type.
* \param tei the variable to store the TEI.
* \return true on success, false otherwise.
*/
static bool
bsu_beacon_read_variant_fields (pb_beacon_t *phy_beacon,
bitstream_t *stream,
- bsu_beacon_t *beacon,
- bsu_beacon_type_t *type, u8 *tei)
+ bsu_beacon_t *beacon)
{
beacon->vf.nid = bsu_beacon_read_nid (phy_beacon, stream);
beacon->vf.hm = bitstream_read (stream, 2);
- *tei = bitstream_read (stream, 8);
- *type = bitstream_read (stream, 3);
+ beacon->vf.stei = bitstream_read (stream, 8);
+ beacon->vf.bt = bitstream_read (stream, 3);
beacon->vf.ncnr = bitstream_read (stream, 1);
beacon->vf.npsm = bitstream_read (stream, 1);
beacon->vf.numslots = bitstream_read (stream, 3);
@@ -609,7 +643,7 @@ bsu_beacon_read_variant_fields (pb_beacon_t *phy_beacon,
beacon->vf.nm = bitstream_read (stream, 2);
beacon->vf.ccocap = bitstream_read (stream, 2);
bitstream_skip (stream, 4);
- if ((*type < BSU_BEACON_TYPE_NB)
+ if ((beacon->vf.bt < BSU_BEACON_TYPE_NB)
&& (beacon->vf.nm < BSU_BEACON_NM_NB)
&& HPAV_NID_IS_VALID (beacon->vf.nid))
return true;
@@ -726,14 +760,14 @@ bsu_beacon_read_bmi_region (bitstream_t *bitstream,
/**
* Read the beacon mac address entry.
* \param bitstream the bitstream context.
- * \param mac_address to store data,
- * \return true on success, false otherwise.
+ * \param mac_address beacon entry,
*/
-static bool
-bsu_beacon_read_bmi_mac_address (bitstream_t *bitstream, mac_t *mac_address)
+static void
+bsu_beacon_read_bmi_mac_address (
+ bitstream_t *bitstream, bsu_beacon_bmi_mac_address_t *mac_address)
{
- *mac_address = bitstream_read_large (bitstream, 48);
- return MAC_IS_VALID (*mac_address);
+ mac_address->mac_address = bitstream_read_large (bitstream, 48);
+ mac_address->present = MAC_IS_VALID (mac_address->mac_address);
}
/**
@@ -871,8 +905,7 @@ bsu_beacon_read_bmi_change_num_slot (bitstream_t *stream,
}
bool
-bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon,
- bsu_beacon_type_t *type, u8 *tei, mac_t *mac_address)
+bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon)
{
bitstream_t stream;
int nb_persistent = 0;
@@ -887,8 +920,7 @@ bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon,
/* Initialise the data needed for the job. */
bsu_beacon_reset (beacon);
bitstream_read_init (&stream, pbbeacon->data, BSU_BEACON_SIZE);
- ok = bsu_beacon_read_variant_fields (
- pbbeacon, &stream, beacon, type, tei);
+ ok = bsu_beacon_read_variant_fields (pbbeacon, &stream, beacon);
beacon->bmis.nbe = bitstream_read (&stream, 8);
// Processing beacon entries.
for (nbe = 0; ok && nbe < beacon->bmis.nbe; nbe++)
@@ -911,8 +943,8 @@ bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon,
&stream, &beacon->bmis.ps.ps[nb_persistent++]);
break;
case BSU_BEACON_ENTRY_HEADER_MAC_ADDRESS:
- ok = bsu_beacon_read_bmi_mac_address (&stream, mac_address);
- beacon->bmis.mac_address_present.present = ok;
+ bsu_beacon_read_bmi_mac_address (
+ &stream, &beacon->bmis.mac_address_present);
break;
case BSU_BEACON_ENTRY_HEADER_DISCOVER:
bsu_beacon_read_bmi_discover (
@@ -965,7 +997,7 @@ bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon,
/* If the beacon seams still ok check if the mandatory fields are
* present. */
if (ok
- && !((*type == BSU_BEACON_TYPE_CENTRAL)
+ && !((beacon->vf.bt == BSU_BEACON_TYPE_CENTRAL)
&& (beacon->bmis.region.nb != 0)
&& (beacon->bmis.nps.ns != 0 || beacon->bmis.ps.nb != 0)
&& (((beacon->vf.nm == BSU_BEACON_NM_CSMA_ONLY)
@@ -974,12 +1006,12 @@ bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon,
&& (((beacon->vf.hoip == true)
&& (beacon->bmis.handover.present == true))
|| (beacon->vf.hoip == false)))
- && !((*type == BSU_BEACON_TYPE_DISCOVER)
+ && !((beacon->vf.bt == BSU_BEACON_TYPE_DISCOVER)
&& (beacon->bmis.region.nb != 0)
&& (beacon->bmis.mac_address_present.present == true)
&& (beacon->bmis.discover_info.present == true)
&& (beacon->bmis.bpsto.present == true))
- && !((*type == BSU_BEACON_TYPE_PROXY)
+ && !((beacon->vf.bt == BSU_BEACON_TYPE_PROXY)
&& (beacon->bmis.bpsto.present == true)))
ok = false;
return ok;