summaryrefslogtreecommitdiff
path: root/cesar/cp/eoc/sta/action/src/poweron.c
blob: 3a8926927d96e17846d7a155c2a4cdbca68e12a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/eoc/sta/action/src/poweron.c
 * \brief   EoC STA action, power on procedure related definitions.
 * \ingroup cp_eoc_sta_action
 */
#include "common/std.h"

/* Private headers. */
#include "cp/inc/context.h"

/* Public headers.  */
#include "cp/defs.h"
#include "cp/eoc/cco/bw/bw.h"
#include "cp/sta/action/action.h"
#include "cp/sta/mgr/sta_mgr.h"
#include "cp/beacon/beacon.h"

/*
 * Initial settings for all Master and slave
 * \param  ctx  the module context.
 */
PRIVATE void
cp_eoc_sta_action__power_on_no_beacons (cp_t *ctx)
{
    cp_net_t *net;
    cp_nid_t nid;
    cp_snid_t snid;
    cp_sta_own_data_t *own;
    dbg_assert (ctx);

    cp_sta_own_data_set_tei (ctx, MAC_TEI_UNASSOCIATED);
    cp_sta_own_data_set_authenticated_status (ctx, false);

    /* 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, false);
    own->tei_track = MAC_TEI_UNASSOCIATED;
    /* set start values */
    ctx->sta_action.assoc.retry = 0;
    ctx->sta_action.assoc.beacon_loss = 0;
}

void
cp_eoc_sta_action_poweron__many__to_idle (cp_t *ctx)
{
    dbg_assert (ctx);
    /* Cleanup. */
    pbproc_activate (ctx->pbproc, false);
    sar_activate (ctx->sar, false);
    sar_cleanup (ctx->sar);
    cp_beacon_deactivate (ctx);
    /* Signal station is stopped. */
    cp_fsm_trigger_new_event (ctx, bare, stopped);
}

void
cp_eoc_sta_action_poweron__idle__to_poweron (cp_t *ctx)
{
    dbg_assert (ctx);
    cp_eoc_sta_action__power_on_no_beacons (ctx);
    cp_eoc_cco_bw_sta_allocations (ctx);
    cp_beacon_poweron_init (ctx);
    bsu_power_on (ctx->bsu, cp_sta_own_data_get_snid (ctx));
    bsu_activate (ctx->bsu, true);
    /* force beacon tracking on startup */
    cp_beacon_process_untracked_avln (ctx);
    cp_beacon_reconfigure_timer (ctx, false);
    sar_activate (ctx->sar, true);
    pbproc_activate (ctx->pbproc, true);
    ctx->sta_action.assoc.peer = CP_MME_PEER (MAC_BROADCAST,
                                              MAC_TEI_UNASSOCIATED);
}