summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/test/src')
-rw-r--r--cesar/mac/sar/test/src/ce.c140
-rw-r--r--cesar/mac/sar/test/src/reassembly_unit_test_functions.c304
-rw-r--r--cesar/mac/sar/test/src/sar_unit_test_functions.c100
3 files changed, 544 insertions, 0 deletions
diff --git a/cesar/mac/sar/test/src/ce.c b/cesar/mac/sar/test/src/ce.c
new file mode 100644
index 0000000000..a56c7019c9
--- /dev/null
+++ b/cesar/mac/sar/test/src/ce.c
@@ -0,0 +1,140 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce.c
+ * \brief Context of the CE
+ * \ingroup mac/sar/test/src
+ *
+ * contains a minimum of the CE data to take the measurement of the PBs.
+ *
+ */
+
+#include "common/std.h"
+#include "mac/sar/test/inc/ce.h"
+
+/**
+ * Init the CE and get the context pointer.
+ */
+ce_t *ce_init (void)
+{
+ ce_ctx.measurement_head = NULL;
+ ce_ctx.measurement_tail = NULL;
+
+ ce_ctx.rx_params_head = NULL;
+ ce_ctx.rx_params_tail = NULL;
+
+ return &ce_ctx;
+}
+
+/**
+ * Pb measurement RX callback for Channel estimation.
+ * This call back will return one or two block in order to insert all the
+ * measurements contained in each PB of the mpdu received.
+ * Two cases can happen, the first the pb_nb is lesser than the blk capacity,
+ * this callback will return only a blk pointed by the first and the last
+ * pointer.
+ * In the second case the quantity of PB are greater than one blk capacity, this
+ * callback will return two blk (chained) the first pointed by the first pointer
+ * and the last one by the last pointer.
+ *
+ * \param user User data
+ * \param rx_params Frame control information to know date and tonemap used
+ * \param number of pbs
+ * \param first blk to insert the measurements.
+ * \param last blk to insert the measurements.
+ * \param chandata chan data measurements
+ *
+ * \return boolean to indicate if a block had been returned or not.
+ */
+bool ce_measurements (void *user, pbproc_rx_params_t *rx_params, uint pb_nb,
+ blk_t **first, blk_t **last, pb_t *chandata, uint nb_chandata, uint
+ *blk_offset)
+{
+ ce_store_rx_params_t *ce_rx_params = NULL;
+
+ /*
+ * author nelio
+ * 26 sept. 07 - 09:56:56
+ *
+ * Not use by the SAR the rx_params are only copied from the CA to provide
+ * it to the CE.
+ */
+
+ dbg_assert (rx_params);
+ ce_rx_params = blk_alloc ();
+
+ /* If the quantity of PBs are greater than 128 allocates two BLK */
+ if (pb_nb > 128)
+ {
+ *first = blk_alloc_desc ();
+ *last = blk_alloc_desc ();
+ ((blk_t *)*first)->next = *last;
+ }
+ else
+ {
+ *first = blk_alloc_desc ();
+ *last = *first;
+ }
+
+ /* Keep it in the structure */
+ if (ce_ctx.measurement_head == NULL)
+ {
+ ce_ctx.measurement_head = *first;
+ ce_ctx.measurement_tail = *last;
+ }
+ else
+ {
+ ce_ctx.measurement_tail->next = *first;
+ ce_ctx.measurement_tail = *last;
+ }
+
+ /* allocate the structure to store the rx_params */
+ ce_rx_params->rx_params = rx_params;
+
+ /* Store the rx_params to the structure */
+ if (ce_ctx.rx_params_head == NULL)
+ {
+ ce_ctx.rx_params_head = ce_rx_params;
+ ce_ctx.rx_params_tail = ce_rx_params;
+ }
+ else
+ {
+ ce_ctx.rx_params_tail->next = ce_rx_params;
+ ce_ctx.rx_params_tail = ce_rx_params;
+ }
+ ce_ctx.rx_params_tail->next = NULL;
+
+ ce_ctx.chandata = chandata;
+
+ ((blk_t *)*last)->next = NULL;
+ *blk_offset = 0;
+
+ return true;
+}
+
+void ce_uninit (void)
+{
+ ce_store_rx_params_t *tmp;
+
+ blk_t *curr;
+ while (ce_ctx.measurement_head)
+ {
+ curr = ce_ctx.measurement_head;
+ ce_ctx.measurement_head = ce_ctx.measurement_head->next;
+
+ blk_release_desc (curr);
+ }
+
+ while (ce_ctx.rx_params_head)
+ {
+ tmp = ce_ctx.rx_params_head;
+ ce_ctx.rx_params_head = ce_ctx.rx_params_head->next;
+ blk_release (tmp->rx_params);
+ blk_release (tmp);
+ }
+}
diff --git a/cesar/mac/sar/test/src/reassembly_unit_test_functions.c b/cesar/mac/sar/test/src/reassembly_unit_test_functions.c
new file mode 100644
index 0000000000..7447338f04
--- /dev/null
+++ b/cesar/mac/sar/test/src/reassembly_unit_test_functions.c
@@ -0,0 +1,304 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file reassembly_unit_test_functions.c
+ * \brief test to verify the mfs processing function
+ * \ingroup mac/sar/src
+ *
+ */
+#include <stdio.h>
+
+#include "common/std.h"
+#include "lib/bitstream.h"
+#include "lib/read_word.h"
+
+#include "mac/sar/inc/sar_mf.h"
+#include "mac/pbproc/pbproc.h"
+
+void test_sar_rx_noise_cb (void *user, const pbproc_rx_params_t *rx_params,
+ phy_chandata_t *first, uint nb_chandata)
+{
+
+}
+
+static void
+write_mfh (u8 *addr, uint length, uint type, uint ats)
+{
+ bitstream_t bitstream;
+
+ dbg_assert (addr);
+
+ if (type > 1)
+ {
+ length += SAR_MF_ATS_SIZE - 1;
+
+ bitstream_init (&bitstream, addr, 6, BITSTREAM_WRITE);
+ bitstream_access (&bitstream, &type, 2);
+ bitstream_access (&bitstream, &length, 14);
+ bitstream_access (&bitstream, &ats, 32);
+ }
+ else
+ {
+ length -= 1;
+
+ bitstream_init (&bitstream, addr, 2, BITSTREAM_WRITE);
+ bitstream_access (&bitstream, &type, 2);
+ bitstream_access (&bitstream, &length, 14);
+ }
+
+ bitstream_finalise (&bitstream);
+}
+
+/**
+ * Initialize the Reassembly test generating a list of PBs.
+ */
+void sar_unit_test_generate_pb_list (pb_t **first, pb_t **last)
+{
+ pb_t *pb_list[14];
+ pb_t *pb;
+
+ uint length;
+ uint ats;
+ uint type;
+
+ uint i;
+
+ *first = (pb_t *) blk_alloc_desc_range (14, (blk_t **) last);
+ (*last)->next = NULL;
+
+ for (i = 0, pb = *first; pb; i++, pb = pb->next)
+ {
+ pb_list[i] = pb;
+ pb_list[i]->expiration_ntb = 100;
+ pb_list[i]->header.ssn = i;
+ pb_list[i]->header.vpbf = true;
+ pb_list[i]->header.mmqf = false;
+ pb_list[i]->header.opsf = false;
+ }
+
+ // fill the first pb
+ pb_list[0]->header.mfbf = true;
+ pb_list[0]->header.mfbo = 0;
+
+ pb_list[1]->header.mfbf = true;
+ pb_list[1]->header.mfbo = 12;
+
+ pb_list[3]->header.mfbf = true;
+ pb_list[3]->header.mfbo = 219;
+
+ pb_list[4]->header.mfbf = true;
+ pb_list[4]->header.mfbo = 103;
+
+ pb_list[5]->header.mfbf = true;
+ pb_list[5]->header.mfbo = 66;
+
+ pb_list[8]->header.mfbf = true;
+ pb_list[8]->header.mfbo = 29;
+
+ pb_list[10]->header.mfbf = true;
+ pb_list[10]->header.mfbo = 431;
+
+ // MF of 283 bytes => 0x0452 (with type = 2 and ats in length)
+ length = 273;
+ type = 2;
+ write_mfh (pb_list[0]->data, length, type, 0);
+
+ // MF of 241 bytes => 0x398 + 2 = 0x3AA
+ length = 231;
+ ats = 0x1234;
+ write_mfh (pb_list[0]->data + 283, length, type, ats);
+
+ // MF of 1231 bytes => 0x1310 + type = 0x1312
+ length = 1221;
+ ats = 0x1234;
+ write_mfh (pb_list[1]->data + 12, length, type, ats);
+
+ // MF of 169 bytes => 0x278 + type = 0x27A
+ length = 159;
+ ats = 0x1234;
+ write_mfh (pb_list[3]->data + 219, length, type, ats);
+
+ // MF of 227 bytes => 0x360 + type = 0x362
+ length = 217;
+ ats = 0x1234;
+ write_mfh (pb_list[3]->data + 388, length, type, ats);
+
+ // MF of 393 bytes => 0x5f8 + type = 0x5FA
+ length = 383;
+ ats = 0x1234;
+ write_mfh (pb_list[4]->data + 103, length, type, ats);
+
+ // MF of 82 bytes => 0x11C + type = 0x11E
+ length = 72;
+ ats = 0x1234;
+ write_mfh (pb_list[4]->data + 496, length, type, ats);
+
+ // MF of 1499 bytes => 0x1740 + type = 0x1742
+ length = 1489;
+ ats = 0x1234;
+ write_mfh (pb_list[5]->data + 66, length, type, ats);
+
+ // MF of 240 bytes => 0x394 + type = 0x396
+ length = 230;
+ ats = 0x1234;
+ write_mfh (pb_list[8]->data + 29, length, type, ats);
+
+ // MF of 1186 bytes => 0x125C + type = 0x125E
+ length = 1176;
+ ats = 0x1234;
+ write_mfh (pb_list[8]->data + 269, length, type, ats);
+
+ // MF of 185 bytes => 0x2B8 + type = 0x2BA
+ length = 175;
+ ats = 0x1234;
+ write_mfh (pb_list[10]->data + 431, length, type, ats);
+
+ // Repeat the PB with the ssn = 1.
+ memcpy (&pb_list[12]->header, &pb_list[1]->header, 4);
+ memcpy (pb_list[12]->data, pb_list[1]->data, 512);
+
+ memcpy (&pb_list[13]->header, &pb_list[10]->header, 4);
+ memcpy (pb_list[13]->data, pb_list[10]->data, 512);
+
+ *first = pb_list[6];
+ pb_list[6]->next= pb_list[2];
+ pb_list[2]->next= pb_list[0];
+ pb_list[0]->next= pb_list[1];
+ pb_list[1]->next= pb_list[12];
+ pb_list[12]->next= pb_list[4];
+ pb_list[4]->next= pb_list[10];
+ pb_list[10]->next= pb_list[13];
+ pb_list[13]->next= pb_list[5];
+ pb_list[5]->next= pb_list[9];
+ pb_list[9]->next= pb_list[8];
+ pb_list[8]->next= pb_list[3];
+ pb_list[3]->next= pb_list[7];
+ pb_list[7]->next = pb_list[11];
+ pb_list[11]->next = NULL;
+ *last = pb_list[11];
+}
+
+/**
+ * Initialize the Reassembly test generating a list of PBs.
+ */
+void sar_unit_test_generate_mme_pb_list (pb_t **first, pb_t **last)
+{
+ pb_t *pb_list[12];
+ pb_t *pb;
+
+ uint length;
+ uint ats;
+ uint type;
+ uint i;
+
+ *first = (pb_t *) blk_alloc_desc_range (12, (blk_t **) last);
+ (*last)->next = NULL;
+
+ for (i = 0, pb = *first; pb; i++, pb = pb->next)
+ {
+ pb_list[i] = pb;
+ pb_list[i]->expiration_ntb = 100;
+ pb_list[i]->header.ssn = i;
+ pb_list[i]->header.vpbf = true;
+ pb_list[i]->header.mmqf = true;
+ pb_list[i]->header.opsf = false;
+ }
+
+ // fill the first pb
+ pb_list[0]->header.mfbf = true;
+ pb_list[0]->header.mfbo = 0;
+
+ pb_list[1]->header.mfbf = true;
+ pb_list[1]->header.mfbo = 12;
+
+ pb_list[3]->header.mfbf = true;
+ pb_list[3]->header.mfbo = 219;
+
+ pb_list[4]->header.mfbf = true;
+ pb_list[4]->header.mfbo = 103;
+
+ pb_list[5]->header.mfbf = true;
+ pb_list[5]->header.mfbo = 66;
+
+ pb_list[8]->header.mfbf = true;
+ pb_list[8]->header.mfbo = 29;
+
+ pb_list[10]->header.mfbf = true;
+ pb_list[10]->header.mfbo = 431;
+
+ // MF of 283 bytes => 0x0452 (with type = 2 and ats in length)
+ length = 273;
+ type = 3;
+ write_mfh (pb_list[0]->data, length, type, 0);
+
+ // MF of 241 bytes => 0x398 + 2 = 0x3AA
+ length = 231;
+ ats = 0x1234;
+ write_mfh (pb_list[0]->data + 283, length, type, ats);
+
+ // MF of 1231 bytes => 0x1310 + type = 0x1312
+ length = 1221;
+ ats = 0x1234;
+ write_mfh (pb_list[1]->data + 12, length, type, ats);
+
+ // MF of 169 bytes => 0x278 + type = 0x27A
+ length = 159;
+ ats = 0x1234;
+ write_mfh (pb_list[3]->data + 219, length, type, ats);
+
+ // MF of 227 bytes => 0x360 + type = 0x362
+ length = 217;
+ ats = 0x1234;
+ write_mfh (pb_list[3]->data + 388, length, type, ats);
+
+ // MF of 393 bytes => 0x5f8 + type = 0x5FA
+ length = 383;
+ ats = 0x1234;
+ write_mfh (pb_list[4]->data + 103, length, type, ats);
+
+ // MF of 82 bytes => 0x11C + type = 0x11E
+ length = 72;
+ ats = 0x1234;
+ write_mfh (pb_list[4]->data + 496, length, type, ats);
+
+ // MF of 1499 bytes => 0x1740 + type = 0x1742
+ length = 1489;
+ ats = 0x1234;
+ write_mfh (pb_list[5]->data + 66, length, type, ats);
+
+ // MF of 240 bytes => 0x394 + type = 0x396
+ length = 230;
+ ats = 0x1234;
+ write_mfh (pb_list[8]->data + 29, length, type, ats);
+
+ // MF of 1186 bytes => 0x125C + type = 0x125E
+ length = 1176;
+ ats = 0x1234;
+ write_mfh (pb_list[8]->data + 269, length, type, ats);
+
+ // MF of 185 bytes => 0x2B8 + type = 0x2BA
+ length = 175;
+ ats = 0x1234;
+ write_mfh (pb_list[10]->data + 431, length, type, ats);
+
+ *first = pb_list[0];
+ pb_list[0]->next= pb_list[6];
+ pb_list[6]->next= pb_list[2];
+ pb_list[2]->next= pb_list[1];
+ pb_list[1]->next= pb_list[4];
+ pb_list[4]->next= pb_list[10];
+ pb_list[10]->next= pb_list[5];
+ pb_list[5]->next= pb_list[9];
+ pb_list[9]->next= pb_list[8];
+ pb_list[8]->next= pb_list[3];
+ pb_list[3]->next= pb_list[7];
+ pb_list[7]->next = pb_list[11];
+ pb_list[11]->next = NULL;
+ *last = pb_list[11];
+}
+
diff --git a/cesar/mac/sar/test/src/sar_unit_test_functions.c b/cesar/mac/sar/test/src/sar_unit_test_functions.c
new file mode 100644
index 0000000000..085c267cec
--- /dev/null
+++ b/cesar/mac/sar/test/src/sar_unit_test_functions.c
@@ -0,0 +1,100 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file sar_unit_test_functions.c
+ * \brief function for the unit tests.
+ * \ingroup mac/sar/src
+ *
+ */
+#include "common/std.h"
+#include "mac/sar/test/inc/sar_unit_test_functions.h"
+
+/** TODO REMOVE THIS FUNCTIONS **/
+
+static sar_pbproc_t pbproc_global;
+
+/**
+ * Initialise pbproc and return its context.
+ * \param config global mac configuration
+ * \param store MFS and STA store
+ * \param user_data user data passed to any callback
+ * \param rx_cb MPDU RX callback
+ * \return pbproc context
+ */
+pbproc_t *
+pbproc_init (mac_config_t *config, mac_store_t *store)
+{
+ pbproc_global.cpt_expiration = 0;
+ return (pbproc_t *) &pbproc_global;
+}
+
+void
+pbproc_init_cb (pbproc_t *ctx, void *user_data, pbproc_rx_cb_t rx_cb,
+ pbproc_rx_beacon_cb_t rx_beacon_cb)
+{
+
+}
+
+void
+pbproc_uninit(pbproc_t *ctx)
+{
+
+}
+
+/**
+ * Give segments back to pbproc for reception.
+ * \param ctx pbproc context
+ * \param first first segment
+ * \param last last segment
+ * \param nb number of segment
+ */
+void pbproc_rx_segment_refill (pbproc_t *ctx, pb_t *first, pb_t *last, uint nb)
+{
+ pb_t *pb_curr;
+ while (first != last)
+ {
+ pb_curr = first;
+ first = first->next;
+ blk_release_desc ((blk_t *)pb_curr);
+ }
+
+ blk_release_desc ((blk_t *) first);
+}
+
+
+/**
+* Unregister an MFS from the Channel Access, so that it can no longer be
+* sent.
+* \param ctx ca context
+* \param mfs the MFS to remove
+* \return true if successful
+*
+* If unsuccessful, the caller should try later because the MFS is currently
+* been used for a transmission.
+*/
+bool
+ca_mfs_remove (ca_t *ctx, mfs_tx_t *mfs)
+{
+ return true;
+}
+
+/**
+* Register an MFS with the Channel Access, so it can be sent.
+* \param ctx ca context
+* \param mfs the MFS to add
+*/
+void
+ca_mfs_add (ca_t *ctx, mfs_tx_t *mfs)
+{
+}
+
+void
+ca_mfs_update (ca_t *ctx, mfs_tx_t *mfs)
+{
+
+}