summaryrefslogtreecommitdiff
path: root/test_general/integration/sar-pbproc/src/sar-pbproc.c
blob: ec49452eca235d7bd0ac8fcad1e71e042c1a83d8 (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    sar-pbproc.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "common/std.h"
#include "host/station.h"

#include "lib/test.h"

#include "mac/sar/sar.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;

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 ****************/

/**
 * Call back called by the SAR each time a packet is segmented.
 * In this test it will only display a message.
 * The buffer is a static buffer not a allocated one it does not need to be
 * freed.
 *
 * \param user, User data
 * \param  buffer the address of the buffer.
 */
void sar_segmentation_ul_done (void *user, u8* buffer)
{
    printf ("******************************************\n");
    printf ("         sar Segmentation done\n   \n");
    printf ("******************************************\n");
}

/**
 * Implementation of the sar_reassembly_done_cb_t call back.
 * Only used in this test.
 * The buffer and the mfs shall be release.
 *
 * \param user, User data
 * \param  buffer the buffer address containing the data
 * \param  length  the data length
 * \param  mfs  the mfs used
 */
void sar_reassembly_ul_done (void *user, u8* buffer, uint length,
        mfs_rx_t *mfs)
{
    dbg_assert (buffer);
    dbg_assert (length >= 60 && length <= 1518);
    dbg_assert (mfs);

    printf ("******************************************\n");
    printf ("          sar Reassembly done\n     \n");
    printf ("******************************************\n");

    free (buffer);
}

/**
 * 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)
{
    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;
}

//----------------------------------------------------------------------------

/**
 * Add a data buffer to the SAR.
 * 
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_sar_data_buffer_add (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    u8 *buffer;

    buffer = (u8*) malloc (2048 * sizeof(u8));
    sar_data_buffer_add (my_sta->sar, buffer);

    fcall_param_reset (*param);

    return true;
}

/**
 * Add a mme buffer to the SAR.
 * 
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_sar_mme_buffer_add (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    u8 *buffer;

    buffer = (u8*) malloc (2048 * sizeof(u8));
    sar_mme_buffer_add (my_sta->sar, buffer);

    fcall_param_reset (*param);

    return true;
}

/**
 * Add Msdu to send
 * 
 * - lid  the link to use
 * - tei  the destination
 * - bcast  if the link is a bcast link
 * - mme  if it is a mme
 * - buffer  the buffer containing a frame
 * - length  the buffer length
 * 
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_sar_msdu_add (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    uint tei;
    uint lid;
    uint bcast;
    uint mme;
    uint length;
    u8 *buffer;

    mfs_tx_t *mfs;

    tei = 0;
    lid = 0;
    bcast = 0;
    mme = 0;
    length = 0;

    fcall_param_bind_short (*param, *msg, "tei", &tei);
    fcall_param_bind_short (*param, *msg, "lid", &lid);
    fcall_param_bind_short (*param, *msg, "bcast", &bcast);
    fcall_param_bind_short (*param, *msg, "mme", &mme);
    fcall_param_bind_short (*param, *msg, "length", &length);

    buffer = (u8 *) malloc (length * sizeof (length));
    fcall_param_bind (*param, *msg, "buffer", length * sizeof(u8), buffer);

    mfs = mac_store_mfs_get_tx (my_sta->mac_store, bcast, mme, lid, tei);
    dbg_assert (mfs);

    sar_msdu_add (my_sta->sar, buffer, length, sar_get_ntb (my_sta->sar), mfs);

    blk_release (mfs);

    fcall_param_reset (*param);

    return true;
}

/**
 * uninit the test
 * 
 * \param  fcall the fcall context.
 * \param  param  the fcall param
 * \param  msg  the message
 * \param  data  anything
 */
int fc_test_uninit (fcall_ctx_t *fcall, fcall_param_t **param,
        sci_msg_t **msg, void *data)
{
    ce_rx_params_node_t *ce_node;

    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);
    }

    int_station_uninit (my_sta);

    return true;
}

//----------------------------------------------------------------------------

int main (void)
{
    test_t test;

    test_init (test, 0, NULL);

    my_sta = int_station_init ();

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

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

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

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

    fcall_register (my_station.fcall, "fc_sar_mme_buffer_add",
            &fc_sar_data_buffer_add, NULL);

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

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

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

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

    sar_init_data_context (my_sta->sar, my_sta->sar);
    sar_init_mme_context (my_sta->sar, my_sta->sar);

    sar_init_segmentation_data_cb (my_sta->sar, sar_segmentation_ul_done);
    sar_init_reassembly_ul (my_sta->sar, sar_reassembly_ul_done, true);
    sar_init_reassembly_ul (my_sta->sar, sar_reassembly_ul_done, false);

    sar_init_data_context (my_sta->sar, my_sta->sar);

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

    list_init (&ce_rx_params_list);

    return true;
}