summaryrefslogtreecommitdiff
path: root/cesar/test_general/station/src
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/test_general/station/src')
-rw-r--r--cesar/test_general/station/src/int_station.c736
1 files changed, 736 insertions, 0 deletions
diff --git a/cesar/test_general/station/src/int_station.c b/cesar/test_general/station/src/int_station.c
new file mode 100644
index 0000000000..dc937cbbee
--- /dev/null
+++ b/cesar/test_general/station/src/int_station.c
@@ -0,0 +1,736 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file int_station.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "host/station.h"
+
+#include "lib/blk.h"
+#include "lib/read_word.h"
+#include "lib/trace.h"
+#include "cl/cl_mactotei.h"
+
+#include "test_general/station/int_station.h"
+#include "test_general/station/int_station_fc.h"
+
+#include "test_general/station/inc/int_context.h"
+
+#include "mac/sar/inc/trace.h"
+#include "cl/inc/trace.h"
+#include "hle/inc/trace.h"
+#include "cp/beacon/inc/trace.h"
+#include "cp/station/station.h"
+
+#include "mac/common/ntb.h"
+#include "mac/pbproc/inc/context.h"
+
+#include "hal/timer/timer.h"
+
+int_station_t int_sta_global;
+
+/**
+ * Cp beacon call back when the leon timer expires.
+ * It shall call the add event function of the Visual state FSM.
+ *
+ * \param user_data the user_data provided on the cp_beacon_init function.
+ */
+void
+cp_beacon_timer_expires (void *user_data) __attribute__((weak));
+
+
+/**
+ * Init the station and returns the result of the memory test
+ *
+ * \return ctx the int_station context.
+ */
+int_station_t *int_station_init (void)
+{
+ my_station.pipe_log_fd = 1;
+
+ trace_init ();
+
+ int_sta_global.mac_store = mac_store_init ();
+ int_sta_global.pbproc_activate = false;
+
+ int_sta_global.mac_config = blk_alloc ();
+ int_sta_global.mac_config->rts_broadcast = false;
+ int_sta_global.mac_config->fc_symbols_nb = 1;
+ int_sta_global.mac_config->ntb_offset_tck = 0;
+ tonemask_default ((u8*) &int_sta_global.mac_config->tonemask_info);
+ tonemask_update (&int_sta_global.mac_config->tonemask_info);
+
+ int_sta_global.pbproc = pbproc_init (int_sta_global.mac_config,
+ int_sta_global.mac_store);
+
+ // Initialise the hal_timer
+ int_sta_global.timer =
+ hal_timer_init(pbproc_get_phy(int_sta_global.pbproc));
+
+ mac_ntb_init (pbproc_get_phy(int_sta_global.pbproc),
+ int_sta_global.mac_config);
+
+ int_sta_global.sar = sar_init (int_sta_global.mac_store,
+ int_sta_global.pbproc, pbproc_get_ca (int_sta_global.pbproc));
+
+ int_sta_global.cl
+ = cl_init (int_sta_global.mac_store, int_sta_global.sar,
+ int_sta_global.mac_config);
+
+ int_sta_global.hle = hle_init (int_sta_global.cl);
+
+ int_sta_global.interface = interface_init (int_sta_global.hle,
+ int_sta_global.cl,
+ int_sta_global.sar,
+ int_sta_global.mac_config);
+
+ int_sta_global.cp.sta = cp_station_init (int_sta_global.mac_store,
+ int_sta_global.cl,
+ int_sta_global.pbproc,
+ int_sta_global.mac_config);
+
+ int_sta_global.cp.secu = cp_secu_init ();
+ int_sta_global.cp.cco = cp_cco_init ();
+
+ int_sta_global.cp.beacon = cp_beacon_init(int_sta_global.interface,
+ pbproc_get_phy(int_sta_global.pbproc),
+ int_sta_global.cp.sta, int_sta_global.cp.secu,
+ pbproc_get_ca (int_sta_global.pbproc),
+ int_sta_global.pbproc, int_sta_global.mac_store,
+ int_sta_global.cp.cco,
+ int_sta_global.timer, NULL,
+ cp_beacon_timer_expires);
+
+ list_init (&int_sta_global.tei_list);
+
+ int_sta_global.mac_config->sta_mac_address = 0x123456789abcull;
+ int_sta_global.mac_config->authenticated = true;
+
+ /* Activate the hle. */
+ hle_activate (int_sta_global.hle, true);
+
+ return &int_sta_global;
+}
+
+/**
+ * Uninit the station and returns the result of the memory test
+ *
+ * \param ctx the station context.
+ */
+void int_station_uninit (int_station_t *ctx)
+{
+ tei_node_t *tei_node;
+ uint now;
+
+ dbg_assert (ctx);
+ dbg_assert (ctx->mac_config);
+ dbg_assert (ctx->mac_store);
+ dbg_assert (ctx->pbproc);
+ dbg_assert (ctx->sar);
+ dbg_assert (ctx->cl);
+ dbg_assert (ctx->hle);
+
+ dbg_assert (ctx->cp.secu);
+ dbg_assert (ctx->cp.cco);
+ dbg_assert (ctx->cp.sta);
+ dbg_assert (ctx->cp.beacon);
+
+ dbg_assert (ctx->timer);
+
+ pbproc_activate (ctx->pbproc, false);
+
+ now = mac_ntb();
+ pbproc_uninit (ctx->pbproc);
+ sar_uninit (ctx->sar);
+ cl_uninit (ctx->cl);
+ hle_uninit (ctx->hle);
+
+ cp_secu_uninit (ctx->cp.secu);
+ cp_station_uninit (ctx->cp.sta);
+ cp_cco_uninit (ctx->cp.cco);
+ cp_beacon_uninit(ctx->cp.beacon);
+
+ blk_release (ctx->mac_config);
+
+ while (!list_empty (&ctx->tei_list))
+ {
+ tei_node = PARENT_OF (tei_node_t, node, list_pop (&ctx->tei_list));
+ mac_store_sta_remove (ctx->mac_store, tei_node->tei);
+
+ blk_release (tei_node);
+ }
+
+ mac_store_uninit (ctx->mac_store);
+ hal_timer_uninit (ctx->timer);
+ trace_uninit();
+
+ blk_print_memory ();
+}
+
+/**
+ * Provides the Tei of the STA and the SNID
+ *
+ * \param ctx the station context
+ * \param tei the tei of the station
+ * \param snid the snid of the AVLN
+ * \param beacon_period_auto generation automatic of the beacon period for
+ * the CA scheduling
+ * \param cco boolean informing if the sta is cco or not
+ * \param authenticated boolean informing if the sta is authenticated or
+ * not.
+ */
+void int_station_config (int_station_t *ctx, uint tei, uint snid,
+ bool beacon_period_auto, bool cco, bool authenticated, mac_t mac_addr)
+{
+ dbg_assert (ctx);
+ dbg_assert (ctx->mac_config);
+ dbg_assert (ctx->cp.cco);
+ dbg_assert (ctx->cp.sta);
+
+ ctx->mac_config->snid = snid;
+ ctx->mac_config->tei = tei;
+
+ if (mac_addr == 0)
+ {
+ ctx->mac_config->sta_mac_address = 0x123456789abcull;
+ }
+ else
+ ctx->mac_config->sta_mac_address = mac_addr;
+
+ if (beacon_period_auto)
+ {
+ // Create the Thread for the pbproc.
+ cyg_thread_create (9, &pbproc_sched, (cyg_addrword_t) ctx, "Sched",
+ sched_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &ctx->sched_handle, &ctx->sched_thread);
+ cyg_thread_resume (ctx->sched_handle);
+
+ printf ("[STATION] PBproc Activated\n");
+ }
+
+ if (cco)
+ {
+ cp_cco_set_cco_status (ctx->cp.cco, cco);
+ cp_station_set_authenticated (ctx->cp.sta, authenticated);
+ }
+
+ if (authenticated)
+ {
+ cp_station_set_authenticated (ctx->cp.sta, authenticated);
+ }
+}
+
+/**
+ * Provides the TEI of all the station in the AVLN.
+ *
+ * \param ctx the station context.
+ * \param tei the tei list of the stations
+ * \param macs the list of mac address of the STAs.
+ * \param qte the quantity of TEIs in the list.
+ */
+void int_station_discover (int_station_t *ctx, uint *tei, mac_t *macs,
+ uint qte)
+{
+ tei_node_t *node;
+ uint i;
+
+ for (i = 0; i < qte; i++)
+ {
+ if (tei[i] != 0)
+ {
+ node = blk_alloc ();
+ list_init_node (&node->node);
+ node->tei = tei[i];
+ list_push (&ctx->tei_list, &node->node);
+
+ mac_store_sta_add (ctx->mac_store, tei[i]);
+ }
+ }
+
+ if (macs != NULL)
+ {
+ dbg_assert (ctx->cl);
+
+ cl_mactotei_blk_t *table;
+ table = cl_mactotei_new ();
+
+ for (i = 0; i < qte; i++)
+ {
+ cl_mactotei_addr_add (table, macs[i], tei[i], tei[i]);
+ }
+
+ cl_mactotei_use_table (ctx->cl, table);
+ }
+}
+
+/**
+ * Add a link to the STAtion i.e. will create a MFS
+ *
+ * \param ctx the station context.
+ * \param type TX or RX link, it is a short 1 for TX 0 for RX.
+ * \param bcast short indicating if the link is a broadcast link
+ * \param mme short indicating if the link will be use to transmit MMEs
+ * \param lid short indicating if it is a link identitier.
+ * \param tei short the destination station.
+ */
+void int_station_link_add (int_station_t *ctx, uint type, uint bcast,
+ uint mme, uint lid, uint tei)
+{
+ bool added;
+ mfs_t *mfs;
+
+ dbg_assert (ctx);
+ dbg_assert (ctx->mac_store);
+ dbg_assert (ctx->sar);
+
+ mfs = mac_store_mfs_add (ctx->mac_store, type, bcast, mme, lid, tei,
+ &added);
+ dbg_assert (added);
+
+ // add the link to the sar.
+ sar_mfs_add (ctx->sar, mfs);
+
+ blk_release (mfs);
+}
+
+/**
+ * Remove a link to the STAtion i.e. will create a MFS
+ *
+ * \param ctx the station context.
+ * \param type TX or RX link, it is a short 1 for TX 0 for RX.
+ * \param bcast short indicating if the link is a broadcast link
+ * \param mme short indicating if the link will be use to transmit MMEs
+ * \param lid short indicating if it is a link identitier.
+ * \param tei short the destination station.
+ */
+void int_station_link_remove (int_station_t *ctx, uint type, uint bcast,
+ uint mme, uint lid, uint tei)
+{
+ mfs_t *mfs;
+ pb_t *pb;
+
+ dbg_assert (ctx);
+ dbg_assert (ctx->mac_store);
+ dbg_assert (ctx->sar);
+
+ mfs = mac_store_mfs_get (ctx->mac_store, type, bcast, mme, lid, tei);
+
+ if (mfs != NULL)
+ {
+ while (type && mfs->tx.head)
+ {
+ pb = mfs->tx.head;
+ mfs->tx.head = mfs->tx.head->next;
+ blk_release_desc ((blk_t *) pb);
+ }
+
+ while (!type && mfs->rx.head)
+ {
+ pb = mfs->rx.head;
+ mfs->rx.head = mfs->rx.head->next;
+ blk_release_desc ((blk_t *) pb);
+ }
+
+ // remove the MFS from the sar
+ sar_mfs_remove (ctx->sar, mfs);
+
+ blk_release (mfs);
+ }
+}
+
+/**
+ * Thread entry finction
+ *
+ * \param int_sta the sta context.
+ */
+void pbproc_sched (cyg_addrword_t int_sta)
+{
+ while (true)
+ {
+ create_schedule_csma_only ((int_station_t *) int_sta, 14);
+ ((int_station_t *) int_sta)->sched_index ++;
+
+ //create the second schedule.
+ create_schedule_csma_only ((int_station_t *) int_sta, 14);
+ ((int_station_t *) int_sta)->sched_index ++;
+
+ //create the third schedule.
+ create_schedule_csma_only ((int_station_t *) int_sta, 14);
+ ((int_station_t *) int_sta)->sched_index ++;
+
+ cyg_thread_delay (500);
+ }
+}
+
+/**
+ * Create a schedule for the Channel Access (beacon period) in CSMA only mode.
+ * Shall always be used to send or receive data.
+ *
+ * \param int_sta the pbproc context
+ * \param beacon_period_nb the quantity of beacon periods for the test.
+ */
+void create_schedule_csma_only (int_station_t *int_sta, uint beacon_period_nb)
+{
+ pbproc_t *pbproc;
+
+ dbg_assert (int_sta);
+
+ pbproc = int_sta->pbproc;
+ ca_beacon_period_t beacons_periods[beacon_period_nb];
+ uint i;
+
+ dbg_assert (pbproc);
+ dbg_assert (beacon_period_nb < CA_BEACON_PERIOD_NB);
+
+ /* Get and fill the schedule */
+ ca_schedule_t *sched = ca_alloc_get_schedule (pbproc_get_ca (pbproc),
+ int_sta->sched_index);
+
+ sched->coexistence_mode = MAC_COEXISTENCE_SHARED_CSMA_HYBRID_MODE;
+ sched->nek_switch = 0; //TODO
+ sched->allocations_nb = 1;
+ sched->allocations[0].end_offset_tck = 10000000;
+ sched->allocations[0].glid = 0xff;
+
+ /* Create a schedule for 14 beacon period */
+ for (i = 0; i < beacon_period_nb; i++)
+ {
+ beacons_periods[i].start_date = 1000000 * i
+ + my_station.current_tick_tck;
+ beacons_periods[i].schedule_index = int_sta->sched_index;
+ }
+
+ /* Use the new schedule */
+ ca_alloc_update_beacon_periods (pbproc_get_ca (pbproc), beacons_periods,
+ beacon_period_nb);
+
+ /* Activate the pbproc */
+ if (!int_sta->pbproc_activate)
+ {
+ pbproc_activate (pbproc, true);
+ int_sta->pbproc_activate = true;
+ }
+
+ int_sta->sched_index++;
+}
+
+/**
+ * Cp beacon call back when the leon timer expires.
+ * It shall call the add event function of the Visual state FSM.
+ *
+ * \param user_data the user_data provided on the cp_beacon_init function.
+ */
+void
+cp_beacon_timer_expires (void *user_data)
+{
+}
+
+
+//----------------------------------------------------------------------------
+
+/**
+ * Initialize the configuration of the STA.
+ * The parameters we must provide are the TEI of the STA, the SNID and the
+ * boolean to indicate the auto generation of the beacon periods.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_station_init_config (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ uint tei;
+ uint snid;
+ uint beacon_period_auto;
+ uint cco;
+ uint auth;
+ mac_t mac;
+
+ tei = 0;
+ snid = 0;
+ beacon_period_auto = 0;
+ auth = 0;
+ cco = 0;
+
+ fcall_param_bind_short (*param, *msg, "tei", &tei);
+ fcall_param_bind_short (*param, *msg, "snid", &snid);
+ fcall_param_bind_short (*param, *msg, "auto_sched", &beacon_period_auto);
+ fcall_param_bind_short (*param, *msg, "cco", &cco);
+ fcall_param_bind_short (*param, *msg, "authenticated", &auth);
+
+ int_station_config (&int_sta_global, tei, snid, beacon_period_auto, cco,
+ auth, mac);
+
+ fcall_param_reset (*param);
+
+ return true;
+}
+
+/**
+ * Provide to the STA using the parameters of the function call the station
+ * use for the test. Each STA shall known the TEI of the others present in the
+ * AVLN.
+ *
+ * The function call parameters must be
+ * - qte the quantity of TEIs present in the paramters. One for each STA
+ * without this one.
+ * - tei The list of TEIs.
+ * - mac the list of mac address.
+ *
+ * This will be use to add the STA's to the mac store, the STA will keep a
+ * list of theses TEI to remove the STA during the uninit procedure.
+ *
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_station_discover (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ uint tei[256];
+ mac_t macs[256];
+ uint qte;
+ char val [2];
+ char id[5];
+ uint count;
+ uint error;
+
+ qte = 0;
+ fcall_param_bind_short (*param, *msg, "qte", &qte);
+
+ count = 0;
+ error = 0;
+ for (count = 0; count < qte; count ++)
+ {
+ tei[count] = 0;
+ macs[count] = 0;
+ sprintf (val, "%d", count);
+ strcpy (id, "tei");
+ strcat (id, val);
+ fcall_param_bind_short (*param, *msg, id, &tei[count]);
+ strcpy (id, "mac");
+ strcat (id, val);
+ fcall_param_bind (*param, *msg, id, sizeof(mac_t), &macs[count]);
+ }
+
+ int_station_discover (&int_sta_global, tei, macs, qte);
+
+ fcall_param_reset (*param);
+
+ return true;
+}
+
+/**
+ * Add a link to the Station in order to receive or transmit data.
+ *
+ * - type TX or RX link, it is a short 1 for TX 0 for RX.
+ * - bcast short indicating if the link is a broadcast link
+ * - mme short indicating if the link will be use to transmit MMEs
+ * - lid short indicating if it is a link identitier.
+ * - tei short the destination station.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_station_link_add (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ uint type;
+ uint bcast;
+ uint mme;
+ uint lid;
+ uint tei;
+
+ type = 0;
+ bcast = 0;
+ mme = 0;
+ lid = 0;
+ tei = 0;
+
+ fcall_param_bind_short (*param, *msg, "type", &type);
+ fcall_param_bind_short (*param, *msg, "bcast", &bcast);
+ fcall_param_bind_short (*param, *msg, "mme", &mme);
+ fcall_param_bind_short (*param, *msg, "lid", &lid);
+ fcall_param_bind_short (*param, *msg, "tei", &tei);
+
+ if (type)
+ printf (
+ "[STATION : %d] TX link added, bcast : %d, mme : %d, lid : %d, tei : %d\n",
+ int_sta_global.mac_config->tei, bcast, mme, lid, tei);
+ else
+ printf (
+ "[STATION : %d] RX link added, bcast : %d, mme : %d, lid : %d, tei : %d\n",
+ int_sta_global.mac_config->tei, bcast, mme, lid, tei);
+
+ int_station_link_add (&int_sta_global, type, bcast, mme, lid, tei);
+
+ fcall_param_reset (*param);
+
+ return true;
+}
+
+/**
+ * Remove a link to the Station in order to receive or transmit data.
+ *
+ * - type TX or RX link, it is a short 1 for TX 0 for RX.
+ * - bcast short indicating if the link is a broadcast link
+ * - mme short indicating if the link will be use to transmit MMEs
+ * - lid short indicating if it is a link identitier.
+ * - tei short the destination station.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_station_link_remove (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ uint type;
+ uint bcast;
+ uint mme;
+ uint lid;
+ uint tei;
+
+ type = 0;
+ bcast = 0;
+ mme = 0;
+ lid = 0;
+ tei = 0;
+
+ fcall_param_bind_short (*param, *msg, "type", &type);
+ fcall_param_bind_short (*param, *msg, "bcast", &bcast);
+ fcall_param_bind_short (*param, *msg, "mme", &mme);
+ fcall_param_bind_short (*param, *msg, "lid", &lid);
+ fcall_param_bind_short (*param, *msg, "tei", &tei);
+
+ if (type)
+ printf (
+ "[STATION : %d] TX link removed, bcast : %d, mme : %d, lid : %d, tei : %d\n",
+ int_sta_global.mac_config->tei, bcast, mme, lid, tei);
+ else
+ printf (
+ "[STATION : %d] RX link removed, bcast : %d, mme : %d, lid : %d, tei : %d\n",
+ int_sta_global.mac_config->tei, bcast, mme, lid, tei);
+
+ int_station_link_remove (&int_sta_global, type, bcast, mme, lid, tei);
+
+ fcall_param_reset (*param);
+
+ return true;
+}
+
+/**
+ * print the sar traces for the tests.
+ * if the trace_config == y the traces are printed to the stdio.
+ * otherwise nothing is printed.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_sar_print_trace (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ fcall_param_reset (*param);
+
+ sar_trace_print (int_sta_global.sar);
+
+ return true;
+}
+
+/**
+ * print the cl traces for the tests.
+ * if the trace_config == y the traces are printed to the stdio.
+ * otherwise nothing is printed.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_cl_print_trace (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ fcall_param_reset (*param);
+
+ cl_trace_print (int_sta_global.cl);
+
+ return true;
+}
+
+/**
+ * print the hle traces for the tests.
+ * if the trace_config == y the traces are printed to the stdio.
+ * otherwise nothing is printed.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_hle_print_trace (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ fcall_param_reset (*param);
+
+ hle_trace_print (int_sta_global.hle);
+
+ return true;
+}
+
+/**
+ * Send a central beacon over the PWL.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_pbproc_print_trace (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ fcall_param_reset (*param);
+
+#if CONFIG_TRACE
+ trace_buffer_dbg_dump (&int_sta_global.pbproc->trace);
+#endif
+
+ return true;
+}
+
+
+/**
+ * Request the cp_beacon to print its trace buffer.
+ *
+ * \param fcall the fcall context.
+ * \param param the fcall param
+ * \param msg the message
+ * \param data anything
+ */
+int fc_cp_beacon_print_trace (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ fcall_param_reset (*param);
+
+ cp_beacon_trace_print (int_sta_global.cp.beacon);
+
+ return true;
+}
+