summaryrefslogtreecommitdiff
path: root/cesar/cp/src/cp.c
blob: 45c001d7164ed60096700487262539ffe7f716a3 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/src/cp.c
 * \brief   CP functions.
 * \ingroup cp
 *
 */
#include "common/std.h"

#include "cp/cp.h"

#include "cp/inc/context.h"

/** Static data. */
static cp_t cp_global;

/**
 * Initialise the Control plane.
 * \param  mac_config  Mac configuration context.
 * \param  interface  Interface context.
 * \param  hal_timer  the HAL timer context.
 * \param  pbproc  the PBProcessing context.
 * \param  mac_store  the mac store context.
 * \param  sar  the SAR context.
 * \param  cl  the CL context.
 * \param  ce_rx  the CE in RX context.
 * \param  bufmgr  the buffer manager context.
 * \param  seed  the seed to initialise the random generator.
 * \return  The control plane context.
 *
 */
cp_t *
cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config,
         interface_t * interface, hal_timer_t *hal_timer, pbproc_t *pbproc,
         mac_store_t *mac_store, sar_t *sar, cl_t *cl, ce_rx_t *ce_rx,
         bufmgr_t *bufmgr, u32 seed)
{
    dbg_assert (mac_config);
    dbg_assert (interface);
    dbg_assert (hal_timer);
    dbg_assert (pbproc);
    dbg_assert (sar);
    dbg_assert (cl);
    dbg_assert (ce_rx);
    dbg_assert (bufmgr);

    cp_global.mac_config = mac_config;
    cp_global.interface = interface;
    cp_global.hal_timer = hal_timer;
    cp_global.pbproc = pbproc;
    cp_global.phy = pbproc_get_phy (pbproc);
    cp_global.ca = pbproc_get_ca (pbproc);
    cp_global.mac_store = mac_store;
    cp_global.sar = sar;
    cp_global.cl = cl;
    cp_global.ce_rx = ce_rx;
    cp_global.bsu = bsu;
    cp_global.bsu_aclf = aclf;

    /** Initialise buffer manager. */
    cp_global.bufmgr = bufmgr;

    /* Init the random generator. */
    lib_rnd_init (&cp_global.rnd, seed ^ 0x87543571);

    /* Initialise traces. */
    cp_trace_init (&cp_global);

    /* Initialise the beacon module. */
    cp_beacon_init (&cp_global);

    /* Initialise the bandwidth manager. */
    cp_cco_bw_init (&cp_global);

    /* Initialise the region manager. */
    cp_cco_region_init (&cp_global);

    /* Initialise the Control plane. */
    cp_cl_interf_init (&cp_global);

    /* Initialise the Connection manager. */
    //cp_conn_mgr_init (&cp_global);

    /* Initialise the MSG module. */
    cp_msg_init (&cp_global);

    /* Initialise the Station. */
    cp_sta_action_init (&cp_global);

    /* Initialise the CCo module. */
    cp_cco_action_init (&cp_global);

    /* Initialise the station core. */
    cp_sta_core_init (&cp_global);

    /* Initialise the station manager.  */
    cp_sta_mgr_init (&cp_global);

    /* Initialise the FSM. */
    cp_fsm_init (&cp_global);

    /* Init CE in TX. */
    ce_tx_init (&cp_global);

    return &cp_global;
}

void
cp_uninit (cp_t *ctx)
{
    dbg_assert (ctx);

    cp_fsm_uninit (ctx);
    cp_sta_core_uninit (ctx);
    cp_sta_mgr_uninit (ctx);
    cp_beacon_uninit (ctx);
    cp_cco_action_uninit (ctx);
    cp_cco_bw_uninit (ctx);
    cp_cco_region_uninit (ctx);
    cp_cl_interf_uninit (ctx);
    cp_msg_uninit (ctx);
    cp_trace_uninit (ctx);
}

/**
 * Compute the NID and the NMK from the network password.
 * \param  ctx  the CP context.
 * \param  npw  the network password.
 * \param  sl the security level of the station.
 *
 * This function will generate the NID and the NMK from the NPW and store it
 * in the station own data.
 */
void
cp_compute_nmk_and_nid_from_npw (cp_t *ctx, const char *npw,
                                 cp_security_level_t sl)
{
    u64 nid;
    cp_key_t nmk;
    uint length;

    dbg_assert (ctx);
    dbg_assert (npw);

    length = strlen (npw);

    nmk = cp_secu_npw2nmk (ctx, (const u8*) npw, length);
    nid = cp_secu_nmk2nid (ctx, nmk, sl);

    /* Store the nid and the nmk to the station own data. */
    cp_sta_own_data_set_nid (ctx, nid);
    cp_sta_own_data_set_nmk (ctx, nmk,
                             CP_MSG_DRV_STA_SET_KEY_TYPE_CHANGE_NID);
}