summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/unit_test/ecos/tests.h
blob: a4646dc766599998042636a3c42bbfc054d00983 (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
#ifndef mac_sar_test_unit_test_ecos_tests_h
#define mac_sar_test_unit_test_ecos_tests_h
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    mac/sar/test/unit_test/ecos/tests.h
 * \brief   Library tests
 * \ingroup mac_sar
 */
#include "mac/sar/inc/sar_context.h"
#include "lib/bitstream.h"
#include "ce/rx/rx.h"

struct sar_test_bitstream_change_data_t
{
    /* current PB. */
    pb_t *pb_current;
    /* Previous PB. */
    pb_t *pb_prev;
};
typedef struct sar_test_bitstream_change_data_t
sar_test_bitstream_change_data_t;

struct sar_test_segmentation_complete_t
{
    u8 *buffer;
    void *data;
};

struct sar_test_reassembly_complete_t
{
    u8 *buffer;
    uint length;
    mfs_rx_t *mfs;
    bool encrypted;
};

struct sar_test_beacon_recv_t
{
    pb_beacon_t *pb;
    pbproc_rx_beacon_params_t *params;
};

struct sar_test_t
{
    /* SAR context. */
    sar_t *sar;
    /* MAC store context. */
    mac_store_t *mac_store;
    /* Mac config. */
    mac_config_t mac_config;
    /* Phy pointer. */
    void *phy;
    /* Ce context. */
    ce_rx_t *ce;
    /* Segmentation done context. */
    struct sar_test_segmentation_complete_t seg_done;
    /* Reassembly done context. */
    struct sar_test_reassembly_complete_t rea_done;
    /* Beacon reception context. */
    struct sar_test_beacon_recv_t beacon_recv;
};
typedef struct sar_test_t sar_test_t;

BEGIN_DECLS

/**
 * Initialise the SAR test context.
 * \param  t  the test context.
 * \param  phy  a pointer to a simulated phy context.
 * \param  pbproc  a pointer to a simulated phy context.
 *
 * phy can be INVALID_PTR or NULL, in this case a static uint is used with a
 * value set to 0 and the address is stored in sar test context.
 * pbproc the same use as phy.
 */
void
sar_test_init (sar_test_t *t, void *phy, void *pbproc);

/**
 * Uninitialise the SAR test context.
 * \param  t  the test context.
 */
void
sar_test_uninit (sar_test_t *t);

/**
 * Compute the CRC of a frame contained in buffer.
 * \param  buffer  the buffer containing the frame.
 * \param  length  the frame length.
 *
 * Only for non ATS frames.
 */
u32
sar_test_compute_crc (u8 *buffer, uint length);

/**
 * Compute the CRC of a frame containing the same symbol inside.
 * \param  length  the frame length.
 * \param  data_inside  the symbol inside the frame.
 *
 * Only for non ATS frames.
 */
u32
sar_test_compute_frame_crc (uint length, uint data_inside);

/**
 * Fill a default MPDU.
 * \param  mpdu  the mpdu to fill by default.
 * \param  tei  the TEI to use.
 * \param  lid  the LID of the link.
 */
void
sar_test_mpdu_default_fill (sar_mpdu_t *mpdu, u8 tei, u8 lid);

/**
 * Change PB to store data in it with bitstream.
 * \param  ctx  bitstream context.
 * \param  user_data  PB to use if the current one if full.
 */
void
sar_test_bitstream_change_pb (bitstream_t *ctx, void *user_data);

/**
 * Create a list of continuous PBs.
 * \param  first  the first PB created.
 * \param  last  the last PB created.
 * \param  pb_nb  the number of PBs
 * \param  ssn  the SSN of the first PB.
 * \param  mme  the  MME flag.
 * \param  crc_error  the crc error flag for all PBs.
 */
void
sar_test_create_pb_list (pb_t **first, pb_t **last, uint pb_nb,
                         u16 ssn, bool mme, bool crc_error);

/**
 * Create a list of continuous PBs.
 * \param  first  the first PB created.
 * \param  last  the last PB created.
 * \param  pb_nb  the number of PBs
 * \param  ssn  the SSN of the first PB.
 * \param  mme  the  MME flag.
 * \param  seed  used to initialise the randomizer for the CRC error in PBs.
 */
void
sar_test_create_pb_list_crc_error_rand (pb_t **first, pb_t **last, uint pb_nb,
                                        u16 ssn, bool mme, u32 seed);

/**
 * Create a PB.
 * \param  ssn  the SSN of the first PB.
 * \param  mme  the  MME flag.
 * \param  crc_error  the crc error flag for all PBs.
 */
pb_t *
sar_test_create_pb (u16 ssn, bool mme, bool crc_error);

/**
 * Create a list of 3 PBs.
 * \param  ssn_first  the SSN of the first PB.
 * \param  first  the pointer to the first PB.
 * \param  last  the pointer to the last PB.
 */
extern inline void
sar_test_create_list_3pbs (u16 ssn_first, pb_t **first, pb_t **last)
{
    sar_test_create_pb_list (first, last, 3, ssn_first, false, false);
}

/**
 * Create an MPDU.
 * \param  mpdu  the MPDU context.
 * \param  pb_nb  the number of PBs.
 * \param  ssn  the SSN of the first PB.
 * \param  tei  the TEI to simulate the sender.
 * \param  lid  the link use (MAC_LID_NONE if MME only).
 * \param  crc_error  the CRC error flag value for all PBs.
 */
void
sar_test_create_mpdu (sar_mpdu_t *mpdu, uint pb_nb, u16 ssn,
                      u8 tei, u8 lid, bool crc_error);

/**
 * Create a list of PBs with mac frames inside.
 * \param  first  the first PB pointer address.
 * \param  last  the last PB pointer address.
 * \param  pb_nb  the number of desired PBs.
 * \param  ssn  the SSN of the first PB.
 * \param  seed  the seed for the random generator.
 * \param  rnd_crc_opsf  activate the randomisation of the false CRC on for
 * each PB.
 */
void
sar_test_data_create (pb_t **first, pb_t **last, uint pb_nb, u16 ssn,
                      u32 seed, bool rnd_crc_error);

/**
 * Fill the mpdu structure with PBs containing MF inside.
 * \param  mpdu  the MPDU to fill.
 * \param  pb_nb  number of disired PBs.
 * \param  ssn  the SSN to start with.
 * \param  seed  the seed to initialise the random generator (used if
 * rnd_crc_error is true).
 * \param  rnd_crc_error  active the CRC flag random.
 */
void
sar_test_mpdu_data_create (sar_mpdu_t *mpdu, uint pb_nb, u16 ssn,
                           u32 seed, bool rnd_crc_error);

/**
 * Create a list of PBs mixed up with crc errors and opsf randomly generated.
 * \param  pb_nb  the number of PBs wanted.
 * \param  ssn  the ssn of the first PB.
 * \param  first  the first PB generated.
 * \param  last  the last PB generated.
 * \param  seed  the seed for the random generator.
 * \param  rnd_crc_error  set the crc flag randomly in the PB list if this
 * flag is set.
 */
void
sar_test_create_data_pb_list_mixed_up (uint pb_nb, u16 ssn,
                                       pb_t **first, pb_t **last,
                                       u32 seed, bool rnd_crc_error);

/**
 * Duplicate the chain and remove the CRC error from the PBs.
 * \param  first  the first PB created in the new chain.
 * \param  last  the last  PB created in the new chain.
 * \param  old_chain_first  the first PB of the chain to duplicate
 * \param  old_chain_last  the last PB of the old chain to duplicate.
 * \param  nb  number of elements in the chain.
 */
void
sar_test_create_data_pb_duplicate_store_crc_false (pb_t **first, pb_t **last,
                                                   pb_t *old_chain_first,
                                                   pb_t *old_chain_last,
                                                   uint nb);
/**
 * Duplicate the chain of PBs.
 * \param  first  the first PB created in the new chain.
 * \param  last  the last  PB created in the new chain.
 * \param  old_chain_first  the first PB of the chain to duplicate
 * \param  old_chain_last  the last PB of the old chain to duplicate.
 * \param  nb  number of elements in the chain.
 */
void
sar_test_create_data_pb_duplicate (pb_t **first, pb_t **last,
                                   pb_t *old_chain_first,
                                   pb_t *old_chain_last,
                                   uint nb);

/**
 * Shuffle a list of PBs.
 * \param  pb_nb  the number of PBs to shuffle.
 * \param  first  the first PB pointer.
 * \param  last  the last PB pointer.
 * \param  seed  the seed for the random generator.
 */
void
sar_test_shuffle_pb_list (uint pb_nb, pb_t **first,
                          pb_t **last, u32 seed);


/**
 * Remove the PB corresponding to the PB to remove in the chain.
 * \param  pb_first  the first PB of the chain.
 * \param  pb_last  the last PB of the chain.
 * \param  ssn  the SSN of the PB.
 */
void
sar_test_remove_pbs_from_chain (pb_t **pb_first, pb_t **pb_last,
                                const u16 ssn);

/**
 * Remove the PB from the MPDU with the SSN provided.
 * \param  mpdu  the MPDU to use.
 * \param  ssn  the PB's SSN to remove.
 */
extern inline void
sar_test_remove_pbs_from_mpdu (sar_mpdu_t *mpdu, const u16 ssn)
{
    sar_test_remove_pbs_from_chain (&mpdu->rx.pb_first,
                                    &mpdu->rx.pb_last,
                                    ssn);
}

/**
 * Set the OPSF flag on the PB corresponding to the SSN.
 * \param  mpdu  the MPDU to use.
 * \param  ssn  the PB's SSN to set the OPSF.
 */
void
sar_test_set_opsf (sar_mpdu_t *mpdu, const u16 ssn);

END_DECLS

#endif /* mac_sar_test_unit_test_ecos_tests_h */