summaryrefslogtreecommitdiff
path: root/cesar/cp/sta/mgr/src/sta.c
blob: 521070ff77146e05f07502bf3815ca3dca0f375f (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/sta/mgr/src/sta.c
 * \brief   Station API implementation.
 * \ingroup cp_sta_mgr
 *
 */
#include "common/std.h"
#include "string.h"

#include "lib/slab.h"

#include "cp/sta/mgr/sta.h"

#include "cp/sta/mgr/inc/sta.h"
#include "cp/inc/context.h"
#include "cp/cp.h"

#include "config/cp/eoc.h"

#if CONFIG_CP_EOC
#include "cp/eoc/sta/mgr/sta_mgr.h"
#endif

cp_sta_t *
cp_sta_init (slab_cache_t *cache)
{
    cp_sta_private_t *sta;

    sta = slab_alloc (cache);
    memset (sta, 0, sizeof (cp_sta_private_t));

    set_node_init (&sta->public_data.node_net);
    set_node_init (&sta->public_data.node_sta_mgr);

    sta->association_confirmed = true;
    sta->visible = CP_STA_VISIBLE_STATE_VISIBLE;

#if CONFIG_CP_EOC && CONFIG_CP_EOC_IS_MASTER
    /* Station authorization is initially set to false. It can be changed by adding the station
       into the White List and setting the authorization to true. */
    ((cp_sta_t *) sta)->multi_sta.allowed = false;
    ((cp_sta_t *) sta)->multi_sta.ports.port[0].enabled = true;
    ((cp_sta_t *) sta)->authenticated_to_unassociated = false;
    ((cp_sta_t *) sta)->sta_in_wl = false;
#endif /* CONFIG_CP_EOC && CONFIG_CP_EOC_IS_MASTER */

    return (cp_sta_t *) sta;
}

void
cp_sta_uninit (cp_sta_t *sta)
{
    blk_t *current;

    while (sta->reassembly_ctx.head)
    {
        current = (blk_t *) sta->reassembly_ctx.head;
        sta->reassembly_ctx.head = sta->reassembly_ctx.head->next;
        blk_release_desc (current);
    }
}

cp_tei_t
cp_sta_get_tei (cp_sta_t *ctx)
{
    dbg_assert (ctx);

    return ((cp_sta_private_t *)ctx)->tei;
}

mac_t
cp_sta_get_mac_address (cp_sta_t *ctx)
{
    dbg_assert (ctx);

    return ((cp_sta_private_t *)ctx)->mac_address;
}

void
cp_sta_get_peer (cp_sta_t *ctx, cp_mme_peer_t *peer)
{
    dbg_assert (ctx);
    cp_sta_private_t *sta = (cp_sta_private_t *) ctx;
    *peer = CP_MME_PEER (sta->mac_address, sta->tei);
}

bool
cp_sta_get_cco_status (cp_sta_t *ctx)
{
    dbg_assert (ctx);

    return ((cp_sta_private_t *)ctx)->is_cco;
}

void
cp_sta_set_pco_glid (cp_sta_t *ctx, u8 glid)
{
    dbg_assert (ctx);
    dbg_assert ((glid >= MAC_GLID_MIN) || (glid == 0));

    ((cp_sta_private_t *)ctx)->pco_glid = glid;
}

bool
cp_sta_get_pco_status (cp_sta_t *ctx)
{
    dbg_assert (ctx);

    return ((cp_sta_private_t *)ctx)->pco_glid;
}

u8
cp_sta_get_pco_glid (cp_sta_t *ctx)
{
    dbg_assert (ctx);

    return (((cp_sta_private_t *)ctx)->pco_glid);
}

void
cp_sta_set_visible_status (cp_t *ctx, cp_sta_t * sta,
                           cp_sta_visible_status_t status)
{
    sta_t *sta_store;
    dbg_assert (sta);
    dbg_assert (status < CP_STA_VISIBLE_STATE_ASSERT);
    dbg_assert (ctx);

    if (((cp_sta_private_t *) sta)->visible ^ status)
    {
        ((cp_sta_private_t *) sta)->visible = status;

        if (status)
            ((cp_sta_private_t *) sta)->net->num_visible_stas ++;
        else
            ((cp_sta_private_t *) sta)->net->num_visible_stas --;
    }

    if ((((cp_sta_private_t *) sta)->net == ctx->sta_mgr.our_avln)
        && (MAC_TEI_IS_STA(((cp_sta_private_t *) sta)->tei)))
    {
        dbg_assert (ctx->mac_store);
        /* Update the flag in the mac store. */
        sta_store = mac_store_sta_get (ctx->mac_store, cp_sta_get_tei (sta));
        dbg_assert (sta_store);
        sta_store->multi_unicast_receiver = status &
            ((cp_sta_private_t *) sta)->association_confirmed;
        blk_release (sta_store);
    }
}

cp_sta_visible_status_t
cp_sta_get_visible_status (cp_sta_t * sta)
{
    dbg_assert (sta);

    return ((cp_sta_private_t *) sta)->visible;
}

bool
cp_sta_get_authenticated (cp_t *ctx, cp_sta_t *sta)
{
    bool state;
    dbg_assert (ctx);
    dbg_assert (sta);
    dbg_assert (ctx->mac_store);

    cp_sta_private_t *cp_sta_p = PARENT_OF (cp_sta_private_t, public_data,
                                            sta);

    /* If our AVLN. */
    if ((cp_sta_p->net == ctx->sta_mgr.our_avln)
        && (ctx->sta_mgr.our_avln))
    {
        if (cp_sta_p->tei == MAC_TEI_UNASSOCIATED
#if CONFIG_CP_EOC
            || (CONFIG_CP_EOC_IS_MASTER
                && !cp_eoc_sta_mgr_sta_is_assoc (ctx, ctx->sta_mgr.our_avln,
                                             cp_sta_p->tei))
#endif
            )
            state = false;
        else
        {
            sta_t *sta_store;

            sta_store = mac_store_sta_get (ctx->mac_store, cp_sta_p->tei);
            dbg_check (sta_store);
            state = sta_store->authenticated;

            blk_release (sta_store);
        }
    }
    else
    {
        /* If the station is CCo. */
        state = cp_sta_get_cco_status (sta)
            || cp_sta_get_pco_status (sta)
            || sta->is_backup_cco;
    }

    return state;
}

void
cp_sta_set_authenticated_ (
    cp_t *ctx, cp_sta_t *sta, bool auth __FL)
{
    dbg_assert (ctx);
    dbg_assert (sta);

    /* If our AVLN. */
    if ((((cp_sta_private_t *)sta)->net == ctx->sta_mgr.our_avln)
        &&  (MAC_TEI_IS_STA (cp_sta_get_tei (sta))))
    {
        sta_t *sta_store;
        dbg_assert (ctx->mac_store);


        sta_store = mac_store_sta_get (ctx->mac_store, cp_sta_get_tei (sta));
        dbg_blame (sta_store);
        sta_store->authenticated = auth;
        blk_release (sta_store);
    }
}

void
cp_sta_set_assoc_confirmed (cp_t *ctx, cp_sta_t *sta, bool state)
{
    sta_t *sta_store;
    dbg_assert (ctx);
    dbg_assert (sta);
    dbg_assert (ctx->mac_store);

    /* Store the flag to true in the station and in the mac store. */
    sta_store = mac_store_sta_get (ctx->mac_store, cp_sta_get_tei (sta));
    dbg_check (sta_store);

    if ((((cp_sta_private_t*) sta)->visible == CP_STA_VISIBLE_STATE_VISIBLE)
        || !state)
        sta_store->multi_unicast_receiver = state;

    ((cp_sta_private_t *) sta)->association_confirmed = state;

    blk_release (sta_store);
}

bool
cp_sta_get_assoc_confirmed (cp_t *ctx, cp_sta_t *sta)
{
    dbg_assert (ctx);
    dbg_assert (sta);
    dbg_assert (((cp_sta_private_t*)sta)->net == ctx->sta_mgr.our_avln);

    return ((cp_sta_private_t *) sta)->association_confirmed;
}