summaryrefslogtreecommitdiff
path: root/mac/sar/test/src/reassembly_unit_test_functions.c
blob: 7447338f048ed9ceadf09c9ae5d8a325605563bd (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    reassembly_unit_test_functions.c
 * \brief   test to verify the mfs processing function
 * \ingroup mac/sar/src
 *
 */
#include <stdio.h>

#include "common/std.h"
#include "lib/bitstream.h"
#include "lib/read_word.h"

#include "mac/sar/inc/sar_mf.h"
#include "mac/pbproc/pbproc.h"

void test_sar_rx_noise_cb (void *user, const pbproc_rx_params_t *rx_params,
        phy_chandata_t *first, uint nb_chandata)
{

}

static void
write_mfh (u8 *addr, uint length, uint type, uint ats)
{
    bitstream_t bitstream;

    dbg_assert (addr);

    if (type > 1)
    {
        length += SAR_MF_ATS_SIZE - 1;
        
        bitstream_init (&bitstream, addr, 6, BITSTREAM_WRITE);
        bitstream_access (&bitstream, &type, 2);
        bitstream_access (&bitstream, &length, 14);
        bitstream_access (&bitstream, &ats, 32);
    }
    else
    {
        length -= 1;

        bitstream_init (&bitstream, addr, 2, BITSTREAM_WRITE);
        bitstream_access (&bitstream, &type, 2);
        bitstream_access (&bitstream, &length, 14);
    }

    bitstream_finalise (&bitstream);
}

/**
 * Initialize the Reassembly test generating a list of PBs.
 */
void sar_unit_test_generate_pb_list (pb_t **first, pb_t **last)
{
    pb_t *pb_list[14];
    pb_t *pb;

    uint length;
    uint ats;
    uint type;

    uint i;

    *first = (pb_t *) blk_alloc_desc_range (14, (blk_t **) last);
    (*last)->next = NULL;

    for (i = 0, pb = *first; pb; i++, pb = pb->next)
    {
        pb_list[i] = pb;
        pb_list[i]->expiration_ntb = 100;
        pb_list[i]->header.ssn = i;
        pb_list[i]->header.vpbf = true;
        pb_list[i]->header.mmqf = false;
        pb_list[i]->header.opsf = false;
    }

    // fill the first pb
    pb_list[0]->header.mfbf = true;
    pb_list[0]->header.mfbo = 0;

    pb_list[1]->header.mfbf = true;
    pb_list[1]->header.mfbo = 12;

    pb_list[3]->header.mfbf = true;
    pb_list[3]->header.mfbo = 219;

    pb_list[4]->header.mfbf = true;
    pb_list[4]->header.mfbo = 103;

    pb_list[5]->header.mfbf = true;
    pb_list[5]->header.mfbo = 66;

    pb_list[8]->header.mfbf = true;
    pb_list[8]->header.mfbo = 29;

    pb_list[10]->header.mfbf = true;
    pb_list[10]->header.mfbo = 431;

    // MF of 283 bytes => 0x0452 (with type = 2 and ats in length)
    length = 273;
    type = 2;
    write_mfh (pb_list[0]->data, length, type, 0);

    // MF of 241 bytes => 0x398 + 2 = 0x3AA
    length = 231;
    ats = 0x1234;
    write_mfh (pb_list[0]->data + 283, length, type, ats);

    // MF of 1231 bytes => 0x1310 + type = 0x1312
    length = 1221;
    ats = 0x1234;
    write_mfh (pb_list[1]->data + 12, length, type, ats);

    // MF of 169 bytes => 0x278 + type = 0x27A
    length = 159;
    ats = 0x1234;
    write_mfh (pb_list[3]->data + 219, length, type, ats);

    // MF of 227 bytes => 0x360 + type = 0x362
    length = 217;
    ats = 0x1234;
    write_mfh (pb_list[3]->data + 388, length, type, ats);

    // MF of 393 bytes => 0x5f8 + type = 0x5FA
    length = 383;
    ats = 0x1234;
    write_mfh (pb_list[4]->data + 103, length, type, ats);

    // MF of 82 bytes => 0x11C + type = 0x11E
    length = 72;
    ats = 0x1234;
    write_mfh (pb_list[4]->data + 496, length, type, ats);

    // MF of 1499 bytes => 0x1740 + type = 0x1742
    length = 1489;
    ats = 0x1234;
    write_mfh (pb_list[5]->data + 66, length, type, ats);

    // MF of 240 bytes => 0x394 + type = 0x396
    length = 230;
    ats = 0x1234;
    write_mfh (pb_list[8]->data + 29, length, type, ats);

    // MF of 1186 bytes => 0x125C + type = 0x125E
    length = 1176;
    ats = 0x1234;
    write_mfh (pb_list[8]->data + 269, length, type, ats);

    // MF of 185 bytes => 0x2B8 + type = 0x2BA
    length = 175;
    ats = 0x1234;
    write_mfh (pb_list[10]->data + 431, length, type, ats);

    // Repeat the PB with the ssn = 1.
    memcpy (&pb_list[12]->header, &pb_list[1]->header, 4); 
    memcpy (pb_list[12]->data, pb_list[1]->data, 512); 

    memcpy (&pb_list[13]->header, &pb_list[10]->header, 4); 
    memcpy (pb_list[13]->data, pb_list[10]->data, 512); 

    *first = pb_list[6];
    pb_list[6]->next= pb_list[2];
    pb_list[2]->next= pb_list[0];
    pb_list[0]->next= pb_list[1];
    pb_list[1]->next= pb_list[12];
    pb_list[12]->next= pb_list[4];
    pb_list[4]->next= pb_list[10];
    pb_list[10]->next= pb_list[13];
    pb_list[13]->next= pb_list[5];
    pb_list[5]->next= pb_list[9];
    pb_list[9]->next= pb_list[8];
    pb_list[8]->next= pb_list[3];
    pb_list[3]->next= pb_list[7];
    pb_list[7]->next = pb_list[11];
    pb_list[11]->next = NULL;
    *last = pb_list[11];
}

/**
 * Initialize the Reassembly test generating a list of PBs.
 */
void sar_unit_test_generate_mme_pb_list (pb_t **first, pb_t **last)
{
    pb_t *pb_list[12];
    pb_t *pb;

    uint length;
    uint ats;
    uint type;
    uint i;

    *first = (pb_t *) blk_alloc_desc_range (12, (blk_t **) last);
    (*last)->next = NULL;

    for (i = 0, pb = *first; pb; i++, pb = pb->next)
    {
        pb_list[i] = pb;
        pb_list[i]->expiration_ntb = 100;
        pb_list[i]->header.ssn = i;
        pb_list[i]->header.vpbf = true;
        pb_list[i]->header.mmqf = true;
        pb_list[i]->header.opsf = false;
    }

    // fill the first pb
    pb_list[0]->header.mfbf = true;
    pb_list[0]->header.mfbo = 0;

    pb_list[1]->header.mfbf = true;
    pb_list[1]->header.mfbo = 12;

    pb_list[3]->header.mfbf = true;
    pb_list[3]->header.mfbo = 219;

    pb_list[4]->header.mfbf = true;
    pb_list[4]->header.mfbo = 103;

    pb_list[5]->header.mfbf = true;
    pb_list[5]->header.mfbo = 66;

    pb_list[8]->header.mfbf = true;
    pb_list[8]->header.mfbo = 29;

    pb_list[10]->header.mfbf = true;
    pb_list[10]->header.mfbo = 431;

    // MF of 283 bytes => 0x0452 (with type = 2 and ats in length)
    length = 273;
    type = 3;
    write_mfh (pb_list[0]->data, length, type, 0);

    // MF of 241 bytes => 0x398 + 2 = 0x3AA
    length = 231;
    ats = 0x1234;
    write_mfh (pb_list[0]->data + 283, length, type, ats);

    // MF of 1231 bytes => 0x1310 + type = 0x1312
    length = 1221;
    ats = 0x1234;
    write_mfh (pb_list[1]->data + 12, length, type, ats);

    // MF of 169 bytes => 0x278 + type = 0x27A
    length = 159;
    ats = 0x1234;
    write_mfh (pb_list[3]->data + 219, length, type, ats);

    // MF of 227 bytes => 0x360 + type = 0x362
    length = 217;
    ats = 0x1234;
    write_mfh (pb_list[3]->data + 388, length, type, ats);

    // MF of 393 bytes => 0x5f8 + type = 0x5FA
    length = 383;
    ats = 0x1234;
    write_mfh (pb_list[4]->data + 103, length, type, ats);

    // MF of 82 bytes => 0x11C + type = 0x11E
    length = 72;
    ats = 0x1234;
    write_mfh (pb_list[4]->data + 496, length, type, ats);

    // MF of 1499 bytes => 0x1740 + type = 0x1742
    length = 1489;
    ats = 0x1234;
    write_mfh (pb_list[5]->data + 66, length, type, ats);

    // MF of 240 bytes => 0x394 + type = 0x396
    length = 230;
    ats = 0x1234;
    write_mfh (pb_list[8]->data + 29, length, type, ats);

    // MF of 1186 bytes => 0x125C + type = 0x125E
    length = 1176;
    ats = 0x1234;
    write_mfh (pb_list[8]->data + 269, length, type, ats);

    // MF of 185 bytes => 0x2B8 + type = 0x2BA
    length = 175;
    ats = 0x1234;
    write_mfh (pb_list[10]->data + 431, length, type, ats);

    *first = pb_list[0];
    pb_list[0]->next= pb_list[6];
    pb_list[6]->next= pb_list[2];
    pb_list[2]->next= pb_list[1];
    pb_list[1]->next= pb_list[4];
    pb_list[4]->next= pb_list[10];
    pb_list[10]->next= pb_list[5];
    pb_list[5]->next= pb_list[9];
    pb_list[9]->next= pb_list[8];
    pb_list[8]->next= pb_list[3];
    pb_list[3]->next= pb_list[7];
    pb_list[7]->next = pb_list[11];
    pb_list[11]->next = NULL;
    *last = pb_list[11];
}