summaryrefslogtreecommitdiff
path: root/cp/beacon/test/central_beacon/src/bentry_test.c
blob: 317fdb202cbeebbf288980c1fc73254d7ef0aece (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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/beacon/test/central_beacon/src/bentry_test.c
 * \ingroup cp_beacon
 *
 */
#include "common/std.h"

#include <stdio.h>

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

#include "mac/common/config.h"
#include "mac/common/ntb.h"
#include "mac/common/pb.h"

#include "hal/phy/phy.h"
#include "cp/station/station.h"
#include "cp/secu/secu.h"

#include "cp/beacon/beacons.h"
#include "cp/beacon/inc/beacons.h"
#include "cp/beacon/inc/bentry.h"

#include "cp/beacon/inc/beacons_ctx.h"
#include "cp/beacon/test/central_beacon/inc/phy_stub.h"
#include "cp/cco/inc/context.h"

#include "cp/station/inc/context.h"
#include "cp/secu/inc/secu_types.h"

#include "hal/timer/timer.h"

test_t test;
cp_beacon_desc_t *beacon;
static ca_schedule_t ca_sched;


cp_beacon_t *cp_beacon;
mac_config_t mac_config;
hal_timer_t *timer;
pbproc_t *pbproc;
ca_t *ca;
mac_store_t *mac_store;
cp_cco_t *cco;
phy_t *phy;
cp_sta_t *sta;
cp_secu_t *secu;
mac_config_t mac_config;

void
cp_beacon_expired (void *user_data)
{

}


void
my_test_init (void)
{
    phy = blk_alloc();
    sta = blk_alloc();
    secu = blk_alloc();
    
    pbproc = blk_alloc();
    ca = blk_alloc();
    mac_store = blk_alloc();
    cco = blk_alloc();
    
    sta->mac_config = &mac_config;

    mac_ntb_init ((phy_t *)phy, &mac_config);

    timer = hal_timer_init ((phy_t *) phy);
    cp_beacon = cp_beacon_init ((interface_t *) phy, (phy_t *)phy, sta, secu, ca, pbproc, mac_store, cco, timer, NULL, cp_beacon_expired);

    cp_beacon_acl_frequency_detection (cp_beacon);
    cp_beacon_acl_frequency_detection (cp_beacon);
}

void
test_bentry_fill_header (void)
{
    u8 blk[20];
    uint header;
    uint length;

    cp_bentry_header_fill(blk, CP_BENTRY_BEACON_PERIOD_START_OFFSET,
                          CP_BENTRY_BYTE_SIZEOF (CP_BENTRY_BIT_SIZE_BPSTO));

    header = read_u8_from_word (blk);
    length = read_u8_from_word (blk+1);

    test_case_begin (test, "bentry header fill");
    test_begin (test, "BPSTO header fill")
    {
        test_fail_if (header != CP_BENTRY_BEACON_PERIOD_START_OFFSET, "Wrong \
                      header");
        test_fail_if (length != CP_BENTRY_BYTE_SIZEOF (CP_BENTRY_BIT_SIZE_BPSTO), 
                      "Wrong bentry length");
    }
    test_end;
}

void
test_default_schedule(void)
{
    u8 beacon [10];
    uint header;
    uint length;
    cp_beacon_desc_alloc_t this_sched; 
    cp_bentry_sai_t sai;
    uint ns;
    uint res;
    u8 *next;

    this_sched.ca_sched = &ca_sched;
    memset (beacon, 0, 10);
    next = cp_bentry_default_schedule (cp_beacon, beacon);

    test_case_begin (test, "Default schedule");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_NON_PERSISTENT_SCHEDULE, 
                      "Wrong bentry header");
        test_fail_if (length != 0x5, "Wrong length");
        test_fail_if ((next - beacon) != 7, "Wrong full bentry length");
    }
    test_end;

    // read the number of sessions.
    ns = read_u8_from_word(beacon + 2);
    res = read_u32_from_word (beacon + 3);

    sai.stpf = res & 0x1;
    sai.glid = ((res & 0xFE) >> 1) & 0xFF;
    sai.st = (res >> 8) & 0x0FFF;
    sai.et = (res >> 20) & 0x0FFF;
    test_begin (test, "default schedule")
    {
        test_fail_if (ns != 0x1, "Wrong Number of sessions");

        test_fail_if (sai.stpf != true, "Wrong stpf value");
        test_fail_if (sai.glid != 0x7f, "Wrong glid value");
        test_fail_if (sai.st != 0x0, "Wrong start time");
        test_fail_if (sai.et != CP_BENRTY_MAX_SAI_DATA_VALUE, "Wrong end time");
    }
    test_end;
}


void
test_persistent_schedule (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    cp_beacon_desc_alloc_t this_sched; 
    cp_bentry_persistent_schedule_struct_t pss;
    cp_bentry_sai_t sai;
    uint res;

    this_sched.ca_sched = &ca_sched;

    cp_beacon->bentries_data.pscd = 7;
    cp_beacon->bentries_data.cscd = 5;
    cp_beacon_estimate_bts_bto_bp (cp_beacon, &cp_beacon->cbeacon);
    cp_bentry_persistent_schedule (cp_beacon, beacon, &this_sched);

    test_case_begin (test, "Default schedule");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_PERSISTENT_SCHEDULE, 
                      "Wrong bentry header");
        test_fail_if (length != 0x6, "Wrong length");
    }
    test_end;

    // read the number of sessions.
    res = read_u32_from_word(beacon + 2);
    pss.pscd = res & 0x7;
    pss.cscd = (res >> 3) & 0x7;
    pss.ns = (res >> 8) & 0x3F;

    res = read_u32_from_word (beacon + 4);
    sai.stpf = res & 0x1;
    sai.glid = ((res & 0xFE) >> 1) & 0xFF;
    sai.st = (res >> 8) & 0x0FFF;
    sai.et = (res >> 20) & 0x0FFF;

    test_begin (test, "default schedule")
    {
        test_fail_if (pss.pscd != cp_beacon->bentries_data.pscd, "Wrong PSCD");
        test_fail_if (pss.cscd != cp_beacon->bentries_data.cscd, "Wrong CSCD");
        test_fail_if (pss.ns != 0x1, "Wrong Number of sessions");

        test_fail_if (sai.stpf != true, "Wrong stpf value");
        test_fail_if (sai.glid != 0x7f, "Wrong glid value");
        test_fail_if (sai.st != 0x0, "Wrong start time");
        test_fail_if (sai.et != 3906, "Wrong end time");
    }
    test_end;
}

void
test_regions (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    uint res;
    uint nr;
    cp_bentry_regions_struct_t region;


    cp_bentry_regions (cp_beacon, beacon);

    test_case_begin (test, "Regions");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_REGIONS, 
                      "Wrong bentry header");
        test_fail_if (length != 0x3, "Wrong length");
    }
    test_end;

    nr = read_u8_from_word (beacon + 2) & 0x3F;
    res = read_u32_from_word (beacon + 3);
    region.rt = res & 0xF;
    region.ret = (res >> 4) & 0xFFF;

    test_begin (test, "Regions delimatation")
    {
        test_fail_if (region.rt != CP_BENTRY_REGIONS_LOCAL_CSMA,
                      "Wrong Region type");
        test_fail_if (region.ret != 3906, "Wrong regione end time");
    }
    test_end;
}

void
test_mac_address (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    u8 *next;
    mac_t mac;

    sta->mac_config->sta_mac_address = 0x123456789ABC;
    next = cp_bentry_mac_address (cp_beacon, beacon);

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_case_begin (test, "Mac address bentry");

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_MAC_ADDRESS, 
                      "Wrong bentry header");
        test_fail_if (length != 0x6, "Wrong length");
        test_fail_if ((next - beacon) != 8, "Wrong full bentry length");
    }
    test_end;

    mac = read_u16_from_word (beacon + 6);
    mac = mac << 32;
    mac = mac | read_u32_from_word (beacon + 2);

    test_begin (test, "Mac address")
    {
        test_fail_if (mac != sta->mac_config->sta_mac_address, "Wrong mac address");
    }
    test_end;
}

void
test_discover (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    uint tei;
    u8 *next;

    next = cp_bentry_discover (cp_beacon, beacon, 0xA);

    test_case_begin (test, "Discover bentry");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);
    tei = read_u8_from_word (beacon + 2);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_DISCOVER, 
                      "Wrong bentry header");
        test_fail_if (length != 0x1, "Wrong length");
        test_fail_if (tei != 0xA, "Wrong tei");
        test_fail_if ((next - beacon) != 0x3, "Wron bentry full length");
    }
    test_end;
}

void
test_discover_info (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    u8 *next;
    uint res;
    cp_bentry_discover_info_struct_t data;

    // Configuring the station
    sta->numDisSta = 20;
    sta->numDisNet = 10;
    sta->authentication = true;
    cco->user_appointed_cco_status = true;

    // copy it to the bentries data modifying the num_dis_net value
    ((cp_bentry_discover_info_struct_t *) &cp_beacon->bentries_data.discover_info)->num_dis_sta++;

    next = cp_bentry_discover_info (cp_beacon, beacon);

    test_case_begin (test, "Discover info bentry");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_DISCOVER_INFO, 
                      "Wrong bentry header");
        test_fail_if (length != 0x4, "Wrong length");
        test_fail_if ((next - beacon) != 6, "Wrong full bentry length");
    }
    test_end;

    res = read_u32_from_word (beacon + 2);

    data.updated = res & 0x1;
    res = res >> 1;

    data.cco_cap = res & 0x3;
    res = res >> 2;

    data.proxy_net_cap = res & 0x1;
    res = res >> 1;

    data.backup_cco_cap = res & 0x1;
    res = res >> 1;

    data.cco_status = res & 0x1;
    res = res >> 1;
 
    data.pco_status = res & 0x1;
    res = res >> 1;
 
    data.backup_cco_status = res & 0x1;
    res = res >> 1;

    data.num_dis_sta = read_u8_from_word (beacon + 3);
    data.num_dis_net = read_u8_from_word (beacon + 4);

    res = read_u8_from_word (beacon + 5);
    data.authentication = res & 0x1;
    res = res >> 1;

    data.status_user_ap_cco = res & 0x1;

    test_begin (test, "Discover info bentry")
    {
        test_fail_if (data.updated != true, "Wrong updated boolean value");
        test_fail_if (data.cco_cap != cco->cco_cap, "Wrong cco_cap");
        test_fail_if (data.proxy_net_cap != cco->proxy_cap, "Wrong proxy net cap");
        test_fail_if (data.backup_cco_cap != cco->backup_cap, "Wrong backup cco cap");
        test_fail_if (data.cco_status != cco->cco_status, "Wrong CCo status"); 
        test_fail_if (data.pco_status != cco->pco_status, "Wrong PCo status");
        test_fail_if (data.backup_cco_status != cco->backup_cco, "Wrong backup CCo Status");  
        test_fail_if (data.num_dis_sta != sta->numDisSta, "Wrong num discover station"); 
        test_fail_if (data.num_dis_net != sta->numDisNet, "Wrong num discover network");
        test_fail_if (data.authentication != sta->authentication, "Wrong authentification status");
        test_fail_if (data.status_user_ap_cco != cco->user_appointed_cco_status, "Wrong user ap cco status");
    }
    test_end;

}

void
test_bpsto (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    u8 *next;
    uint bentry_len;

    next = cp_bentry_bpsto (cp_beacon, &cp_beacon->cbeacon, beacon);

    test_case_begin (test, "BPSTO bentry");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "BPSTO bentry")
    {
        test_fail_if (header != CP_BENTRY_BEACON_PERIOD_START_OFFSET, 
                      "Wrong bentry header");
        bentry_len = CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_BPSTO);
        test_fail_if (length != bentry_len, "Wrong length");
        test_fail_if ((next - beacon) != CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_BPSTO)
                      + CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_HEADER), "Wrong full bentry length");
    }
    test_end;
}

void
test_security_key_change (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    u8 *next;
    uint res;
    uint bentry_len;
    cp_bentry_key_change_struct_t data;


    // security key change.
    secu->eks = 0xC;
    secu->kbc = true;
    cp_beacon->bentries_data.kccd = 0x4;

    next = cp_bentry_encryption_key_change (cp_beacon, beacon);
    test_case_begin (test, "Security key change bentry");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_ENCRYPTION_KEY_CHANGE, 
                      "Wrong bentry header");
        bentry_len = CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_EKC);
        test_fail_if (length != bentry_len, "Wrong length");
        test_fail_if ((next - beacon) != CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_EKC)
                      + CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_HEADER), "Wrong full bentry length");
    }
    test_end;

    res = read_u32_from_word (beacon + 2);
    data.kccd = res & 0x3F;
    res = res >> 6;
    data.kbc = res & true;
    res = res >> 2;
    data.new_eks = res & 0xF;


    test_begin (test, "Key change")
    {
        test_fail_if (data.kccd != cp_beacon->bentries_data.kccd, "Wrong kccd countdown");

        /* TODO not tested cause of the modifications of the CP
         * 03/04/2008. 
         * Laranjeiro 
         */
        /*test_fail_if (data.kbc != secu->kbc, "Wrong kbc");
        test_fail_if (data.new_eks != secu->eks, "Wrong eks");
        */
    }
    test_end;
}

void
test_handover (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    u8 *next;
    cp_bentry_handover_struct_t data;

    // test handover in progress.
    cp_beacon->bentries_data.hcd = 0x4;

    next = cp_bentry_handover (cp_beacon, beacon, 0xFD);

    test_case_begin (test, "Handover bentry");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_CCO_HANDOVER, 
                      "Wrong bentry header");
        test_fail_if (length != CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_HANDOVER),
                      "Wrong length");
        test_fail_if ((next - beacon) != CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_HANDOVER)
                      + CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_HEADER), "Wrong full bentry length");
    }
    test_end;

    data.hcd = read_u8_from_word (beacon + 2) & 0x3F;
    data.nctei = read_u8_from_word (beacon + 3);

    test_begin (test, "handover")
    {
        test_fail_if (data.hcd != cp_beacon->bentries_data.hcd,
                      "Wrong  handover countdown value");
        test_fail_if (data.nctei != 0xFD, "Wrong new CCo tei");
    }
    test_end;

}

void
test_hybrid_mode (void)
{
    u8 beacon [20];
    uint header;
    uint length;
    u8 *next;
    uint res;
    cp_bentry_hm_struct_t data;

    cp_beacon->bentries_data.hmccd = 0x3;
    cp_beacon->hm = 1;

    next = cp_bentry_change_hm (cp_beacon, beacon);

    test_case_begin (test, "HM bentry");

    header = read_u8_from_word (beacon);
    length = read_u8_from_word (beacon + 1);

    test_begin (test, "header and length")
    {
        test_fail_if (header != CP_BENTRY_CHANGE_HM, 
                      "Wrong bentry header");
        test_fail_if (length != CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_HM),
                      "Wrong length");
        test_fail_if ((next - beacon) != CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_BIT_SIZE_HM)
                      + CP_BENTRY_BYTE_SIZEOF(CP_BENTRY_HEADER), "Wrong full bentry length");
    }
    test_end;

    res = read_u8_from_word (beacon + 2);
    data.hmccd = res & 0x3f;
    data.new_hm = res >> 6;

    test_begin (test, "hybrid mode")
    {
        test_fail_if (data.hmccd != cp_beacon->bentries_data.hmccd,
                      "Wrong  hybrid mode countdown value");
        test_fail_if (data.new_hm != cp_beacon->hm, "Wrong Hybrid mode");
    }
    test_end;

}

int
main (void)
{
    test_init (test, 0, NULL);
    trace_init ();

    my_test_init ();
    test_bentry_fill_header ();
    test_default_schedule ();
    test_persistent_schedule ();
    test_regions (); 
    test_mac_address ();
    test_discover (); 
    test_discover_info ();
    test_bpsto(); 
    test_security_key_change (); 
    test_handover(); 
    test_hybrid_mode (); 
    trace_uninit();

    cp_beacon_uninit(cp_beacon);
    hal_timer_uninit (timer);
    mac_ntb_uninit();

    blk_release (phy);
    blk_release (sta);
    blk_release (secu);

    blk_release (pbproc);
    blk_release (ca);
    blk_release (mac_store);
    blk_release (cco);


    test_begin(test, "memory test")
    {
        test_fail_if(blk_check_memory() == false, "Memory not freed");
    }
    test_end;

    test_result (test);
    HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
    return test_nb_failed (test) == 0 ? 0 : 1;
}

/**
 * Get date of last zero-cross.
 * \param  ctx  phy context
 * \return  last zero-cross date
 * set errno to:
 * - EINVAL if ctx is null
 */
u32
phy_clock_get_zero_cross_captured_date (phy_t *ctx)
{
    phy_test_t *phy;
    dbg_assert(ctx);

    phy = (phy_test_t *) ctx;

    if(phy->freq_test == 50)
    {
        // Add a jitter on the 20 beacon.
        if (phy->ntb >= 20e6 && phy->ntb <= 21e6)
        {
            phy->ntb += 1e6 + 200;
        }
        // Add a jitter on the 40 beacon.
        if (phy->ntb >= 40e6 && phy->ntb <= 41e6)
        {
            phy->ntb += 1e6 - 200;
        }
        else
        {
            phy->ntb += 1e6;
        }
    }
    else if (phy->freq_test == 60)
    {
        phy->ntb += 833333;
    }

    return phy->ntb;
}

/**
 * Prepare a beacon for transmission.
 * \param  ctx  pbproc context
 * \param  mfs  corresponding special MFS
 * \param  pb  beacon payload
 * \param  params  extra parameters for beacon transmission
 *
 * There can only be one beacon prepared in advance (for a given MFS).
 *
 * This will cancel the preceding prepared beacon if it was not sent.
 *
 * PB reference is transfered to PB Processing.  Extra parameters are copied.
 */
void
pbproc_mfs_beacon_prepare (pbproc_t *ctx, mfs_tx_t *mfs, pb_beacon_t *pb,
                           const pbproc_tx_beacon_params_t *params)
{
    cp_beacon_desc_t *dbeacon;
    uint c_payload;
    uint d_payload;
    uint i;

    dbg_assert (pb);
    dbg_assert (beacon);

    test_case_begin (test, "Discover beacon verifycation");
    dbeacon = (cp_beacon_desc_t *) pb;

    test_begin (test, "Verify NID")
    {
        test_fail_if (beacon->nid_msb != dbeacon->nid_msb, "Wrong nid MSB");
        test_fail_if ((beacon->payload->beacon_mpdu_payload[0] & 0x3FFFFF)
                      != (dbeacon->payload->beacon_mpdu_payload[0] & 0x3FFFFFF),
                      "Wrong nid lsb");
    }
    test_end;

    test_begin (test, "Paylaod")
    {
        memcpy (&c_payload, beacon->payload + 8, 4);
        memcpy (&d_payload, dbeacon->payload + 8, 4);

        test_fail_if ((c_payload & 0x1FFFFFF0) != (d_payload & 0x1FFFFFF0), "Wrong \
                      payload copy from the central beacon");
        test_fail_if (dbeacon->payload->nbe != beacon->payload->nbe + 1,
                      "Wrong quantity of bentries");
        test_fail_if (*(dbeacon->payload->bmis) != CP_BENTRY_DISCOVER_INFO,
                      "Wrong bentruy header for the discover info");

        for (i = 0; i < 122; i++)
        {
            test_fail_if (dbeacon->payload->bmis[6 + i] != beacon->payload->bmis[i],
                      "Bentry %d copied from central beacon is false", i);
        }
    }
    test_end;

    blk_release_desc ((blk_t *) pb);
}

//----------------- Stubing the CA functions ------------------

ca_schedule_t *
ca_alloc_get_schedule (ca_t *ctx, uint index)
{
    return &ca_sched;
}

void
ca_alloc_update_beacon_periods (ca_t *ctx,
                                ca_beacon_period_t *beacon_periods,
                                uint beacon_periods_nb)
{
    uint i;
    uint bp = 1000000;

    // Verifying the shedule and beacon periods data.
    test_case_begin (test, "Check schedule");

    test_begin(test, "checking beacon periods")
    {
        for (i = 0; i < beacon_periods_nb; i++)
        {
            test_fail_if (beacon_periods[i].start_date != 200 + (i+1)*bp, "Wrong bp value");
        }
    }
    test_end;

    // Global variable declared in this test.
    test_begin (test, "Checking schedules")
    {
        test_fail_if (ca_sched.coexistence_mode != 0x0, "Wrong coexistence mode");
        test_fail_if (ca_sched.nek_switch != 0, "Wrong NEK switch"); //TODO
        test_fail_if (ca_sched.allocations[0].end_offset_tck / 256 != 3906, "Wrong schedule");
        test_fail_if (ca_sched.allocations[0].glid != 0xFF, "Wrong GLID");
    }
    test_end;
}

bool
ca_mfs_remove (ca_t *ctx, mfs_tx_t *mfs)
{
    return true;
}

void
ca_mfs_add (ca_t *ctx, mfs_tx_t *mfs)
{
    dbg_assert (ctx);
    dbg_assert (mfs);
}


void
ca_mfs_update (ca_t *ctx, mfs_tx_t *mfs)
{
}

void
ca_mfs_hold (ca_t *ctx, mfs_tx_t *mfs)
{
}

void
pbproc_activate (pbproc_t *ctx, bool flag)
{
    dbg_assert (ctx);
}