summaryrefslogtreecommitdiff
path: root/cesar/cp/eoc/cco/action/src/cco_action.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/eoc/cco/action/src/cco_action.c')
-rw-r--r--cesar/cp/eoc/cco/action/src/cco_action.c286
1 files changed, 286 insertions, 0 deletions
diff --git a/cesar/cp/eoc/cco/action/src/cco_action.c b/cesar/cp/eoc/cco/action/src/cco_action.c
new file mode 100644
index 0000000000..4b2bc189fc
--- /dev/null
+++ b/cesar/cp/eoc/cco/action/src/cco_action.c
@@ -0,0 +1,286 @@
+/* Cesar EOC project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/eoc/cco/action/src/cco_action.c
+ * \brief CCo Action functions.
+ * \ingroup cp_eoc_cco_action
+ *
+ */
+#include "common/std.h"
+
+/* Private headers. */
+#include "cp/inc/context.h"
+#include "cp/eoc/inc/dbg_print.h"
+#include "cp/sta/mgr/inc/sta.h"
+#include "cp/sta/mgr/inc/net.h"
+#include "mac/pbproc/inc/context.h"
+#include "cp/eoc/cco/action/inc/cco_action.h"
+
+/* Public headers. */
+#include "mac/common/defs.h"
+#include "cp/beacon/beacon.h"
+#include "cp/eoc/cco/bw/bw.h"
+#include "cp/eoc/cco/action/cco_action.h"
+#include "cp/eoc/sta/mgr/sta_mgr.h"
+#include "cp/eoc/sta/action/drv.h"
+#include "cp/sta/mgr/sta_mgr.h"
+#include "cp/sta/mgr/sta.h"
+#if CONFIG_CP_EOC_IS_MASTER
+#include "cp/eoc/multi_sta/action/multi_sta_action.h"
+#endif
+
+/* Config headers. */
+#include "config/cp/eoc/cco/action.h"
+
+#if CONFIG_CP_EOC_CCO_ACTION_CON_ALLOWED
+
+#include "mac/sar/inc/context.h"
+
+#define CONFIG_CP_EOC_CCO_CON_TIMEOUT_TCK MAC_MS_TO_TCK (950)
+#define SUB_STAT_ATTR(a, b, c) ((a).c - (b).c)
+#define SUB_STAT(c) SUB_STAT_ATTR (ctx->sar->stats, sar_offset, c)
+
+static int mem = 0, auth_time = 0;
+static sar_stats_t sar_offset;
+#endif
+
+
+void
+cp_eoc_cco_action__change_nek (cp_t *ctx)
+{
+ /* Program the timer to periodically change the NEK. */
+ cp_fsm_event_t * event = cp_fsm_event_bare_new (
+ ctx, CP_FSM_EVENT_TYPE_cco__nek_change);
+ cp_sta_core_gen_timed_event (ctx, &ctx->cco_action.nek_change,
+ event, HPAV_NEK_CHANGE_MS);
+}
+
+void
+cp_eoc_cco_action__power_on_no_beacons (cp_t *ctx)
+{
+ cp_tei_t tei;
+ cp_net_t *net;
+ cp_nid_t nid;
+ cp_snid_t snid;
+ cp_sta_own_data_t *own;
+ dbg_assert (ctx);
+ ctx->cco_action.last_date = phy_date ();
+ tei = MAC_TEI_CCO_MIN;
+ cp_sta_own_data_set_tei (ctx, tei);
+ cp_sta_own_data_set_authenticated_status (ctx, true);
+
+ cp_eoc_sta_action_drv__drv_sta_get_status_ind (ctx);
+
+ /* Set our AVLN. */
+ snid = cp_sta_own_data_get_snid (ctx);
+ nid = cp_sta_own_data_get_nid (ctx);
+
+ net = cp_sta_mgr_add_avln (ctx, snid, nid);
+ cp_sta_mgr_set_our_avln (ctx, net);
+
+ /* Set the CCo status in the station own data. */
+ own = cp_sta_mgr_get_sta_own_data (ctx);
+ own->nid_track = cp_sta_own_data_get_nid (ctx);
+ cp_sta_own_data_set_cco_status (ctx, true);
+ /* Set the NEK. */
+ cp_cco_action_gen_nek (ctx);
+ cp_beacon_change_nek (ctx, ctx->cco_action.new_nek.eks,
+ ctx->cco_action.new_nek.nek_enc, true /* now. */);
+ /* Start timer for periodic NEK exchange */
+ cp_eoc_cco_action__change_nek (ctx);
+ /* set wl status. In maximus accept all stations */
+#if MODULE_INCLUDED (hal_phy_maximus)
+ ctx->cco_action.wl_accept_all = 1;
+ ctx->cco_action.gm_default_output_power = 0;
+ cp_key_t key = cp_secu_generate_keys (ctx, (u8 *) MASTER_GOLDEN_DPW,
+ strlen (MASTER_GOLDEN_DPW), CP_SECU_SALT_KEY_DAK);
+ cp_sta_own_data_set_dak (ctx, key);
+#endif
+}
+
+void
+cp_eoc_cco_action_poweron__idle__to_poweron (cp_t *ctx)
+{
+ /* simulated call to setup cp status */
+ cp_eoc_cco_action__power_on_no_beacons (ctx);
+ cp_eoc_cco_bw_bp_allocations (ctx);
+ cp_beacon_poweron_init (ctx);
+ bsu_init_scheduler_prepare (ctx->bsu, cp_eoc_scheduler_prepare, ctx);
+ bsu_power_on (ctx->bsu, cp_sta_own_data_get_snid (ctx));
+ bsu_activate (ctx->bsu, true);
+ cp_beacon_cco_update_beacon_data (ctx);
+ sar_activate (ctx->sar, true);
+ pbproc_activate (ctx->pbproc, true);
+ ctx->sta_action.assoc.peer = CP_MME_PEER (MAC_BROADCAST,
+ MAC_TEI_UNASSOCIATED);
+ cp_fsm_post_new_event (ctx, bare, BEACON_NOT_RECEIVED);
+}
+
+void
+cp_eoc_cco_action__power_on_rx_beacon (cp_t *ctx)
+{
+}
+
+void
+cp_eoc_cco_action__cco_drv_mac_stop (cp_t *ctx)
+{
+}
+
+void
+cp_eoc_cco_action__bcco_drv_mac_stop (cp_t *ctx)
+{
+}
+
+void
+cp_eoc_cco_action__bcco_no_beacons (cp_t *ctx)
+{
+}
+
+/**
+ * bw scheduler
+ * \param user_data cp * context provided to BSU.
+ * call in DSR context on timer to assure that scheduling will be called
+ * in each beacon period.
+*/
+void
+cp_eoc_scheduler_prepare (void * user_data)
+{
+ /* only Master compilation */
+#if CONFIG_CP_EOC_IS_MASTER
+ cp_t * ctx = (cp_t *)user_data;
+ dbg_assert (ctx);
+ cp_eoc_cco_bw_scheduler (ctx);
+#endif
+}
+
+void
+cp_eoc_cco_action_send_central_beacon (cp_t *ctx)
+{
+ dbg_assert (ctx);
+ arch_dsr_lock ();
+ cp_eoc_cco_bw_bp_allocations (ctx);
+ arch_dsr_unlock ();
+#if CONFIG_CP_EOC_CCO_ACTION_CON_ALLOWED
+ if (++mem >= 10)
+ {
+ auth_time++;
+ mem = 0;
+ }
+ if (less_mod2p32 (ctx->cco_action.last_date, phy_date ()))
+ {
+ char temp[128];
+ sprintf (temp, "cco=%d blk=%d sar[%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]"
+ " pb[%d,%d]\n",
+ auth_time, blk_free_nb (),
+ SUB_STAT (rx_jobs_nb),
+ ctx->sar->stats.rx_jobs_waiting_nb,
+ SUB_STAT (rx_pb_count),
+ SUB_STAT (pb_data_before_ssn_min),
+ SUB_STAT (pb_data_duplicated),
+ SUB_STAT (pb_mme_before_ssn_min),
+ SUB_STAT (pb_mme_duplicated),
+ SUB_STAT (rx_pb_crc_error_count),
+ SUB_STAT (mfs_tx_data_pb_expired_nb),
+ SUB_STAT (mfs_rx_data_pb_expired_nb),
+ SUB_STAT (mfs_tx_mme_pb_expired_nb),
+ SUB_STAT (mfs_rx_mme_pb_expired_nb),
+ ctx->pbproc->stats.tx_data_cancel,
+ ctx->pbproc->stats.tx_data_wack_noack);
+ int pos = 0, len = strlen (temp), len1;
+ while (pos < len)
+ {
+ char * temp1 = temp + pos, tmpa[32];
+ len1 = MIN (len, pos + 10);
+ strncpy (tmpa, temp1, len1 - pos);
+ tmpa[len1 - pos] = '\0';
+ printf (tmpa);
+ pos = len1;
+ }
+ sar_offset = ctx->sar->stats;
+ ctx->cco_action.last_date = phy_date ()
+ + CONFIG_CP_EOC_CCO_CON_TIMEOUT_TCK;
+ }
+#endif
+}
+
+void
+cp_eoc_cco_action_init (cp_t *ctx)
+{
+ dbg_assert (ctx);
+
+ memset (&ctx->cco_action, 0, sizeof (cp_cco_action_t));
+
+ ctx->cco_action.new_nek.eks = MAC_EKS_MAX; /* Initialized to MAC_EKS_MAX in
+ order to have MAC_EKS_MIN as the EKS of the first generated NEK. */
+}
+
+void
+cp_eoc_cco_action_uninit (cp_t *ctx)
+{
+ dbg_assert (ctx);
+}
+
+void
+cp_eoc_cco_action_garbage (cp_t *ctx)
+{
+ int i, released_sta_nb = 0, released_sta_tei[CCO_STA_CON];
+ dbg_assert (ctx);
+ cp_net_t *net = cp_sta_mgr_get_our_avln (ctx);
+
+ /* Check if associated sta got disconnected */
+ for (i = MAC_TEI_STA_MIN_EOC; i < MAC_TEI_STA_MAX; i++)
+ {
+ cp_sta_t * station = cp_sta_mgr_sta_get_assoc (ctx, net, i);
+ if (!station)
+ continue;
+ sta_t *sta = mac_store_sta_get (ctx->mac_store, i);
+ /* cp sta is assoc but no mac store sta? Really wrong. */
+ dbg_assert (sta);
+ /* station is declared dead by lower layers? */
+ if(!sta->tdma_poll && sta->authenticated)
+ station->authenticated_to_unassociated = true;
+ /* release station, no answers + to long in assoc. state */
+ if ((!sta->tdma_poll && sta->authenticated)
+ || (!sta->authenticated
+ && (station->associated_date_ms
+ + CP_EOC_STA_ASSOCIATED_TIMEOUT_MS
+ < cp_sta_core_get_date_ms (ctx))))
+ {
+#if CONFIG_CP_EOC_IS_MASTER
+ /* only Master compilation */
+ cp_eoc_multi_sta_action_put_sta_unassociated (ctx, station);
+#endif
+ /* Start release procedure */
+ cp_sta_mgr_release_station (ctx, i);
+
+ if (sta->authenticated)
+ {
+ if (released_sta_nb < CCO_STA_CON)
+ released_sta_tei[released_sta_nb] = i;
+ released_sta_nb ++;
+ DBG_PRINT_2 ("sta: rel, tei=%d", i);
+ }
+ else
+ DBG_PRINT ("sta: auth fail, tei=%d", i);
+ }
+ slab_release (station);
+ blk_release (sta);
+ }
+ /* Check if unassociated sta is still in the network */
+ cp_net_garbage_station_list (ctx, cp_sta_mgr_get_our_avln (ctx),
+ cp_sta_core_get_date_ms (ctx),
+ CP_NET_STA_UNASSOC);
+
+ if (released_sta_nb)
+ {
+ DBG_PRINTC ("rel: %d; TEI:", released_sta_nb);
+ for (i = 0; ((i < released_sta_nb) && (i < CCO_STA_CON)); i++)
+ DBG_PRINTC (" %d", released_sta_tei[i]);
+ DBG_PRINTC (released_sta_nb > CCO_STA_CON ? " ...\n" : "\n");
+ }
+}