summaryrefslogtreecommitdiff
path: root/cesar/cl/src/cl_mactotei.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cl/src/cl_mactotei.c')
-rw-r--r--cesar/cl/src/cl_mactotei.c280
1 files changed, 280 insertions, 0 deletions
diff --git a/cesar/cl/src/cl_mactotei.c b/cesar/cl/src/cl_mactotei.c
new file mode 100644
index 0000000000..9e51dd8eab
--- /dev/null
+++ b/cesar/cl/src/cl_mactotei.c
@@ -0,0 +1,280 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/src/cl_mactotei.c
+ * \brief the function implementation of the cl_mactotei module
+ * \ingroup cl/src
+ *
+ */
+
+#include "common/std.h"
+#include "lib/blk.h"
+
+#include "cl/cl.h"
+#include "cl/inc/cl_mactotei.h"
+#include "cl/inc/cl.h"
+
+#define LIB_HEAPSORT_USER_TYPE cl_mactotei_table_t
+#define LIB_HEAPSORT_USER_COMP_LESSER cl_mactotei_table_compare
+#define LIB_HEAPSORT_USER_SWAP cl_mactotei_table_swap
+#define LIB_HEAPSORT_USER_PREFIX cl_mactotei_table
+
+#include "lib/heapsort.h"
+
+/**
+ * Create a new table to be filled by the CP.
+ *
+ * \return a pointer to the new block to be fill with the mac to tei table
+ * data
+ */
+cl_mactotei_blk_t *cl_mactotei_new (void)
+{
+ cl_mactotei_blk_t *table;
+
+ table = (cl_mactotei_blk_t *) blk_alloc_desc ();
+ table->nb_total = 0;
+ table->next = NULL;
+ table->write_pos = table;
+
+ return table;
+}
+
+/**
+ * Request the CL to copy all the data without the coresponding tag provided
+ * in this function paramater.
+ *
+ * \param table_old the table actually use by the CL
+ * \param table the mactotei new table to fill
+ * \param tag the tag to exclude from the copy
+ */
+void cl_mactotei_copy (cl_mactotei_table_t *table_old,
+ cl_mactotei_blk_t *table, u8 tag)
+{
+ cl_mactotei_blk_t *curr;
+ uint count;
+
+ dbg_assert (table_old);
+ dbg_assert (table);
+
+ for (count = 0, curr = table_old->first; count < table_old->nb_total; count ++)
+ {
+ if (count != 0 && count % MAX_NB_MACTOTEI == 0)
+ {
+ curr = curr->next;
+ }
+
+ if (curr->data[count].tag != tag)
+ {
+ cl_mactotei_addr_add (table, curr->data[count].mac,
+ curr->data[count].tei, curr->data[count].tag);
+ }
+ }
+}
+
+/**
+ * Add a new tupple of data to the table.
+ *
+ * \param table the table pointer to add a new mac to tei correspondance.
+ * \param mac_addr the mac addr to add
+ * \param tei the tei corresponding to the STA.
+ * \param tag the CP tag provide to indentifier a network.
+ */
+void cl_mactotei_addr_add (cl_mactotei_blk_t *table, mac_t mac_addr,
+ uint tei, uint tag)
+{
+ dbg_assert (table);
+ uint pos;
+
+ pos = table->nb_total % MAX_NB_MACTOTEI;
+
+ /* if the nb_total is not a multiple of 64 add a the new mac addr to the
+ * current block. */
+ if (table->nb_total != 0 && pos == 0)
+ {
+ table->write_pos->next = (cl_mactotei_blk_t *) blk_alloc_desc ();
+ table->write_pos = table->write_pos->next;
+ table->write_pos->next = NULL;
+ }
+
+ table->write_pos->data[pos].mac = mac_addr;
+ table->write_pos->data[pos].tei = tei;
+ table->write_pos->data[pos].tag = tag;
+
+ table->nb_total ++;
+}
+
+/**
+ * Genrate the table which will be use by the CL.
+ *
+ * \param table the new table to use.
+ * \return the table
+ */
+cl_mactotei_table_t *cl_mactotei_generate_table (cl_mactotei_blk_t *table)
+{
+ dbg_assert (table);
+
+ uint nb_blocks;
+ uint nb_slots_available;
+ uint count;
+ cl_mactotei_table_t *the_table;
+ cl_mactotei_blk_t *mactotei_blk_curr;
+
+ /** Generate the last table */
+
+ if (table->nb_total % MAX_NB_MACTOTEI != 0)
+ {
+ nb_blocks = table->nb_total / MAX_NB_MACTOTEI + 1;
+ }
+ else
+ {
+ nb_blocks = table->nb_total / MAX_NB_MACTOTEI;
+ }
+
+ if ((nb_slots_available = table->nb_total % MAX_NB_MACTOTEI))
+ {
+ nb_slots_available = MAX_NB_MACTOTEI - nb_slots_available;
+ /** the current slots are */
+ nb_slots_available = nb_slots_available << 1;
+ }
+
+ if (nb_slots_available < nb_blocks)
+ {
+ table->write_pos->next = (cl_mactotei_blk_t *) blk_alloc_desc ();
+ table->write_pos = table->write_pos->next;
+ table->write_pos->next = NULL;
+
+ the_table = (cl_mactotei_table_t *) table->write_pos->data;
+ }
+ else
+ {
+ the_table
+ = (cl_mactotei_table_t *) &table->write_pos->data[table->nb_total % MAX_NB_MACTOTEI];
+ }
+
+ /** fill the table */
+ the_table->first = table;
+ the_table->nb_total = table->nb_total;
+ the_table->nb_blocks = nb_blocks;
+
+ for (count = 0, mactotei_blk_curr = table; count < nb_blocks; count ++,
+ mactotei_blk_curr = mactotei_blk_curr->next)
+ {
+ the_table->blk[count] = mactotei_blk_curr;
+ }
+
+ lib_heapsort (the_table, the_table->nb_total);
+ return the_table;
+}
+
+/**
+ * Release the complete table from the memory.
+ *
+ * \param table the table to release
+ */
+void cl_mactotei_release_table_intern (cl_mactotei_table_t *table)
+{
+ cl_mactotei_blk_t *block_curr;
+ cl_mactotei_blk_t *block_next;
+
+ block_next = table->first;
+ block_curr = block_next;
+
+ while (block_curr)
+ {
+ block_next = block_next->next;
+ blk_release_desc ((blk_t *) block_curr);
+ block_curr = block_next;
+ }
+}
+
+/**
+ * Return the cl_mactotei value of the item at the position request.
+ *
+ * \param table the mactotei table
+ * \param position the position request.
+ * \return mac address
+ */
+cl_mactotei_t cl_mactotei_table_get_mactotei_at (cl_mactotei_table_t *table,
+ uint position)
+{
+ uint block_position;
+
+ dbg_assert (table);
+ dbg_assert (position < table->nb_total);
+
+ block_position = position / MAX_NB_MACTOTEI;
+ position = position % MAX_NB_MACTOTEI;
+
+ dbg_assert (table->blk[block_position]);
+
+ return table->blk[block_position]->data[position];
+}
+
+/**
+ * Set the cl_mactotei value at the position request.
+ *
+ * \param table the mactotei table
+ * \param position the position request.
+ * \param mactotei the mac to tei data to set.
+ */
+void cl_mactotei_table_set_mactotei_at (cl_mactotei_table_t *table,
+ uint position, cl_mactotei_t mactotei)
+{
+ uint block_position;
+
+ dbg_assert (table);
+ dbg_assert (position < table->nb_total);
+
+ block_position = position / MAX_NB_MACTOTEI;
+ position = position % MAX_NB_MACTOTEI;
+
+ dbg_assert (table->blk[block_position]);
+
+ table->blk[block_position]->data[position] = mactotei;
+}
+
+/**
+ * Compare two values in the table and return true if the value at the
+ * first position is lesser than the one at the second position.
+ *
+ * \param table the table to make the comparation.
+ * \param position1 the position of the first position.
+ * \param position2 the second position.
+ * \return true if the first value is lesser than the second one.
+ */
+bool cl_mactotei_table_compare (cl_mactotei_table_t *table, uint position1,
+ uint position2)
+{
+ dbg_assert (table);
+
+ if (cl_mactotei_table_get_mac_at (table, position1)
+ < cl_mactotei_table_get_mac_at (table, position2))
+ return true;
+ else
+ return false;
+}
+
+/**
+ * Swap two values in the table.
+ *
+ * \param table the table to make the comparation.
+ * \param position1 the position of the first position.
+ * \param position2 the second position.
+ */
+void cl_mactotei_table_swap (cl_mactotei_table_t *table, uint position1,
+ uint position2)
+{
+ cl_mactotei_t tmp;
+
+ dbg_assert (table);
+
+ tmp = cl_mactotei_table_get_mactotei_at (table, position1);
+ cl_mactotei_table_set_mactotei_at (table, position1,
+ cl_mactotei_table_get_mactotei_at (table, position2));
+ cl_mactotei_table_set_mactotei_at (table, position2, tmp);
+}