summaryrefslogtreecommitdiff
path: root/test_general/integration/cp_beacon-dp/src/station.c
blob: f1b006fa4a2e05a8d296cde4e8fc65ee8cdc0e79 (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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    station.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */

#include "common/std.h"
#include "host/station.h"

#include "lib/test.h"
#include "lib/trace.h"
#include "lib/read_word.h"
#include "lib/restrack.h"

#include "mac/sar/sar.h"
#include "cl/cl.h"

#include "cp/beacon/beacons.h"
#include "cp/beacon/inc/beacons.h"
#include "cp/beacon/inc/beacons_ctx.h"
#include "cp/beacon/inc/trace.h"

#include "mac/pbproc/inc/context.h"
#include "mac/common/ntb.h"

#include "test_general/station/int_station.h"
#include "test_general/station/int_station_fc.h"

int_station_t *my_sta;

/* Use to keep a list of rx params in the CE */
list_t ce_rx_params_list;


u8 cp_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
cyg_handle_t cp_handle;
cyg_thread cp_thread;

struct ce_rx_params_node_t
{
    list_node_t node;
    pbproc_rx_params_t *rx_params;
};
typedef struct ce_rx_params_node_t ce_rx_params_node_t;

/****************** CALL BACKS DEFINITION ****************/

void maximus_cp_mme_recv (void *user, mfs_rx_t *mfs, u8 *buffer, uint length,
        cl_mme_recv_t *mme_recv, bool encryption)
{
    printf ("/***************************************************/\n");
    printf ("/* STA : %d            CP MME RECEIVED               */\n",
            my_sta->mac_config->tei);
    printf ("/***************************************************/\n");
    cl_mme_recv_done (my_sta->cl, mme_recv);
}

void maximus_cp_mme_get (void *user, u8 *buffer)
{
    printf ("/***************************************************/\n");
    printf (" STA : %d             CP MME BUFFER GOT\n",
            my_sta->mac_config->tei);
    printf ("/***************************************************/\n");

    my_sta->cp.mme_tx_buffer = buffer;
}

/**
 * Reception of a beacon from the SAR coming from the CCo.
 *
 * \param  ctx  the control plane context.
 * \param  pb  the beacon
 * \param  params  the transmission parameters.
 */
void
cp_beacon_recv (cp_t *ctx, pb_beacon_t *pb, pbproc_rx_beacon_params_t *params)
{
    printf ("/***************************************************/\n");
    printf (" STA : %d             CP BEACON RECEVED \n",
            my_sta->mac_config->tei);
    printf ("/***************************************************/\n");

    cp_beacon_process (my_sta->cp.beacon, (cp_beacon_desc_t *)pb);
}


/**
 * CE measurements. To be replace by the CE function to get the measurements
 * 
 * Pb measurement RX callback for Channel estimation.
 * This call back will return one or two block in order to insert all the 
 * measurements contained in each PB of the mpdu received.
 * Two cases can happen, the first the pb_nb is lesser than the blk capacity, 
 * this callback will return only a blk pointed by the first and the last 
 * pointer.
 * In the second case the quantity of PB are greater than one blk capacity, this
 * callback will return two blk (chained) the first pointed by the first pointer
 * and the last one by the last pointer.
 * 
 * \param  user User data 
 * \param  rx_params Frame control information to know date and tonemap used
 * \param  number of pbs
 * \param  first blk to insert the measurements.
 * \param  last blk to insert the measurements.
 * \param  chandata chan data measurements
 * 
 * \return boolean to indicate if a block had been returned or not.
 */
bool ce_measurements (void *user, pbproc_rx_params_t *rx_params, uint pb_nb,
        blk_t **first, blk_t **last, pb_t *chandata, uint nb_chandata)
{
    ce_rx_params_node_t *ce_node;

    *first = NULL;
    *last = NULL;

    dbg_assert (rx_params);

    ce_node = blk_alloc ();
    list_init_node (&ce_node->node);
    list_push (&ce_rx_params_list, &ce_node->node);
    ce_node->rx_params = rx_params;

    if (chandata)
    {
        blk_release (chandata);
    }

    return false;
}

/*********************** FUNCTIONS ***********************/

/**
 * Send a Discover beacon over the PWL.
 *
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_cco_set_status(fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    cp_cco_set_cco_status (my_sta->cp.cco, true);

    fcall_param_reset (*param);
    return true;
}

/**
 * Send a Discover beacon over the PWL.
 *
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_beacon_send_central_beacon (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    if (cp_cco_get_cco_status(my_sta->cp.cco))
    {
        cp_beacon_cco_send_central_beacon (my_sta->cp.beacon);
    }


    fcall_param_reset (*param);
    return true;
}


/**
 * Send a Discover beacon over the PWL.
 *
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_beacon_send_discover_beacon (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    if (cp_cco_get_cco_status(my_sta->cp.cco))
    {
        cp_beacon_cco_send_discover_beacon (my_sta->cp.beacon);

        printf ("[%x] Discover beacon sent\n", mac_ntb());
    }
    fcall_param_reset (*param);
 
    return true;
}

/**
 * Create the default schedules for the sta and activate the pbproc.
 *  
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_station_pbproc_activate (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    fcall_param_reset (*param);

    cp_beacon_create_default_schedule (my_sta->cp.beacon);

    if (!my_sta->cp.beacon->pbproc_activated)
    {
        my_sta->cp.beacon->pbproc_activated = true;
        pbproc_activate(my_sta->pbproc, true);
    }

    return true;
}

/**
 * Recreate the default schedules for the sta.
 *  
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_station_create_default_schedules (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    fcall_param_reset (*param);

    cp_beacon_create_default_schedule (my_sta->cp.beacon);

    return true;
}


/**
 * Uninit the station and returns the result of the memory test
 *  
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_station_uninit (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    static fcall_param_t return_param;
    static sci_msg_t return_msg;
    static unsigned char return_buffer[SCI_MSG_MAX_SIZE];

    ce_rx_params_node_t *ce_node;
    uint result;

    uint msg_id = (*param)->msg_id;

    while (!list_empty (&ce_rx_params_list))
    {
        ce_node = PARENT_OF (ce_rx_params_node_t, node,
                list_pop (&ce_rx_params_list));

        blk_release (ce_node->rx_params);
        blk_release (ce_node);
    }

    /** reset the param list **/
    fcall_param_init (&return_param, "sta_end", msg_id);
    sci_msg_init (&return_msg, return_buffer, SCI_MSG_MAX_SIZE);
    /* init the params */
    fcall_param_reset (&return_param);

    result = blk_check_memory ();
    fcall_param_add (&return_param, &return_msg, "memory", sizeof(uint),
            (unsigned char *) &result);

    int_station_uninit (my_sta);

    /* return */
    fcall_return (my_station.fcall, &return_param, &return_msg);

    return blk_check_memory ();
}

/** Function called by maximus*/
int main (void)
{
    my_sta = int_station_init ();

    /* Configure the CP */
    cl_mme_recv_init (my_sta->cl, maximus_cp_mme_recv, NULL);
    cl_mme_init_buffer_add_cb (my_sta->cl, maximus_cp_mme_get, &my_sta->cp);

    sar_init_measure_context (my_sta->sar, my_sta->sar);
    sar_init_measurement_cb (my_sta->sar, ce_measurements);

    sar_init_measure_context (my_sta->sar, my_sta->sar);
    sar_init_measurement_cb (my_sta->sar, ce_measurements);

    sar_init_beacon_cb (my_sta->sar, (void *) &my_sta->cp, (sar_beacon_cb_t) cp_beacon_recv);

    cp_beacon_acl_frequency_detection(my_sta->cp.beacon);
    cp_beacon_acl_frequency_detection(my_sta->cp.beacon);

    fcall_register (my_station.fcall, "fc_station_init_config",
            &fc_station_init_config, NULL);

    fcall_register (my_station.fcall, "fc_station_uninit",
            &fc_station_uninit, NULL);

    fcall_register (my_station.fcall, "fc_hle_print_trace",
            &fc_hle_print_trace, NULL);

    fcall_register (my_station.fcall, "fc_cl_print_trace",
            &fc_cl_print_trace, NULL);

    fcall_register (my_station.fcall, "fc_sar_print_trace",
            &fc_sar_print_trace, NULL);

    fcall_register (my_station.fcall, "fc_cp_beacon_print_trace",
            &fc_cp_beacon_print_trace, NULL);

    fcall_register (my_station.fcall, "fc_beacon_send_central_beacon",
            &fc_beacon_send_central_beacon, NULL);

    fcall_register (my_station.fcall, "fc_beacon_send_discover_beacon",
            &fc_beacon_send_discover_beacon, NULL);

    fcall_register (my_station.fcall, "fc_station_discover",
            &fc_station_discover, NULL);

    fcall_register (my_station.fcall, "fc_pbproc_print_trace",
            &fc_pbproc_print_trace , NULL);

    fcall_register (my_station.fcall, "fc_station_pbproc_activate",
            &fc_station_pbproc_activate , NULL);

    fcall_register (my_station.fcall, "fc_station_create_default_schedules",
            &fc_station_create_default_schedules , NULL);

    fcall_register (my_station.fcall, "fc_cco_set_status",
            &fc_cco_set_status, NULL);

    list_init (&ce_rx_params_list);

    return true;
}

/**
 * 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)
{
    cp_beacon_cco_send_central_beacon (my_sta->cp.beacon);
}