summaryrefslogtreecommitdiff
path: root/cesar/cp2/msg/src/msg_cc.c
blob: 0434b8cd274e80190c9d30220d8e9c734cbae7de (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
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp2/msg/src/msg_cc.c
 * \brief   CC family MME.
 * \ingroup cp2_msg
 */
#include "common/std.h"
#include "common/defs/homeplugAV.h"
#include "lib/slab.h"

#include "cp2/cp.h"
#include "cp2/cl_interf/cl_interf.h"
#include "cp2/msg/msg.h"

#include "cp2/sta/mgr/net.h"
#include "cp2/sta/mgr/sta_mgr.h"

#include "cp2/msg/inc/msg_cc.h"

/**
 * Send a CC_WHO_RU.REQ.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  nid  NID of the requested AVLN
 */
void
cp_msg_cc_who_ru_req_send (cp_t *ctx, cp_mme_peer_t *peer, cp_nid_t nid)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (nid);

    msg = cp_msg_mme_init (ctx, peer, CC_WHO_RU_REQ);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, &nid, 56);

    msg->length = 7;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_WHO_RU.REQ.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  nid  received NID of the requested AVLN
 * \return  true on success
 */
bool
cp_msg_cc_who_ru_req_receive (cp_t *ctx, cp_mme_rx_t *mme, cp_nid_t *nid)
{
    cp_net_t *net;
    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (nid);

    bitstream_access (&mme->bitstream, nid, 56);

    net = cp_sta_mgr_get_our_avln (ctx);
    if (*nid != cp_net_get_nid (ctx, net))
        return false;
    return true;
}

/**
 * Send a CC_WHO_RU.CNF.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  data  MME data to send
 */
void
cp_msg_cc_who_ru_cnf_send (cp_t *ctx, cp_mme_peer_t *peer,
                           const cp_msg_cc_who_ru_cnf_t *data)
{
    uint i;
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (data);

    dbg_assert (data->nid);
    dbg_assert (data->cco_mac);

    msg = cp_msg_mme_init (ctx, peer, CC_WHO_RU_CNF);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, (cp_nid_t *) &data->nid, 56);
    bitstream_access (&msg->bitstream, (mac_t *) &data->cco_mac, 48);

    for (i = 0; i < CP_HFID_SIZE; i++)
        bitstream_access (&msg->bitstream, (u8*) &data->avln_hfid[i], 8);

    msg->length = 77;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_WHO_RU.CNF.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  data  received MME data
 * \return  true on success
 */
bool
cp_msg_cc_who_ru_cnf_receive (cp_t *ctx, cp_mme_rx_t *mme,
                              cp_msg_cc_who_ru_cnf_t *data)
{
    uint i;
    cp_net_t *net;
    cp_sta_t *cco;
    cp_sta_own_data_t *own;

    mac_t mac;
    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (data);

    bitstream_access (&mme->bitstream, (cp_nid_t *) &data->nid, 56);
    bitstream_access (&mme->bitstream, (mac_t *) &data->cco_mac, 48);

    for ( i = 0; i < CP_HFID_SIZE; i++)
        bitstream_access (&mme->bitstream, &data->avln_hfid[i], 8);

    own = cp_sta_mgr_get_sta_own_data (ctx);
    net = cp_sta_mgr_get_our_avln (ctx);
    dbg_check (net);

    if (own->is_cco)
        mac = cp_sta_own_data_get_mac_address (ctx);
    else
    {
        cco = cp_net_get_cco (ctx, net);
        dbg_check (cco);
        mac = cp_sta_get_mac_address (cco);
    }

    if ((cp_net_get_nid (ctx, net) != data->nid)
        || mac != data->cco_mac)
        return false;

    return true;
}

/**
 * Send a CC_ASSOC.REQ.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  data  MME data to send
 */
void
cp_msg_cc_assoc_req_send (cp_t *ctx, cp_mme_peer_t *peer,
                          const cp_msg_cc_assoc_req_t *data)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (data);

    dbg_assert ((data->request_type < CP_MSG_CC_ASSOC_REQ_TYPE_NB)
        || (data->cco_cap < 4)
        || (data->proxy_cap < 2));


    msg = cp_msg_mme_init (ctx, peer, CC_ASSOC_REQ);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, (u8 *) &data->request_type, 8);
    bitstream_access (&msg->bitstream, (cp_nid_t *) &data->nid, 56);
    bitstream_access (&msg->bitstream, (u8 *) &data->cco_cap, 8);
    bitstream_access (&msg->bitstream, (u8 *) &data->proxy_cap, 8);

    msg->length = 10;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_ASSOC.REQ.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  data  received MME data
 * \return  true on success
 */
bool
cp_msg_cc_assoc_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             cp_msg_cc_assoc_req_t *data)
{
    cp_net_t *net;
    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (data);

    bitstream_access (&mme->bitstream, &data->request_type, 8);
    bitstream_access (&mme->bitstream, &data->nid, 56);
    bitstream_access (&mme->bitstream, &data->cco_cap, 8);
    bitstream_access (&mme->bitstream, &data->proxy_cap, 8);

    // Verify the data read.
    net = cp_sta_mgr_get_our_avln (ctx);
    dbg_check (net);

    if ((data->request_type >= CP_MSG_CC_ASSOC_REQ_TYPE_NB)
        || (cp_net_get_nid(ctx, net) != data->nid)
        || (data->cco_cap >= 4)
        || (data->proxy_cap >= 2))
    {
        return false;
    }

    return true;
}

/**
 * Send a CC_ASSOC.CNF.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  data  MME data to send
 */
void
cp_msg_cc_assoc_cnf_send (cp_t *ctx, cp_mme_peer_t *peer,
                          const cp_msg_cc_assoc_cnf_t *data)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (data);

    dbg_assert ((data->result < CP_MSG_CC_ASSOC_CNF_RESULT_NB)
                || data->nid
                || data->sta_tei
                || data->lease_time_min);

    msg = cp_msg_mme_init (ctx, peer, CC_ASSOC_CNF);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, (u8 *) &data->result, 8);
    bitstream_access (&msg->bitstream, (cp_nid_t *) &data->nid, 56);
    bitstream_access (&msg->bitstream, (cp_snid_t *) &data->snid, 8);
    bitstream_access (&msg->bitstream, (cp_tei_t *) &data->sta_tei, 8);
    bitstream_access (&msg->bitstream, (u16 *) &data->lease_time_min, 16);

    msg->length = 12;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_ASSOC.CNF.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  data  received MME data
 * \return  true on success
 */
bool
cp_msg_cc_assoc_cnf_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             cp_msg_cc_assoc_cnf_t *data)
{
    cp_net_t *net;

    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (data);

    bitstream_access (&mme->bitstream, &data->result, 8);
    bitstream_access (&mme->bitstream, &data->nid, 56);
    bitstream_access (&mme->bitstream, &data->snid, 8);
    bitstream_access (&mme->bitstream, &data->sta_tei, 8);
    bitstream_access (&mme->bitstream, &data->lease_time_min, 16);

    /* Verify. */
    net = cp_sta_mgr_get_our_avln (ctx);
    dbg_check (net);

    if ((cp_net_get_nid (ctx, net) != data->nid)
        || (cp_net_get_snid (ctx, net) != data->snid)
        || (data->result < CP_MSG_CC_ASSOC_CNF_RESULT_NB))
    {
        return false;
    }

    return true;
}

/**
 * Send a CC_LEAVE.REQ.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  reason  reason for the disassociation
 */
void
cp_msg_cc_leave_req_send (cp_t *ctx, cp_mme_peer_t *peer,
                          enum cp_msg_cc_leave_req_reason_t reason)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (reason < CP_MSG_CC_LEAVE_IND_REASON_NB);

    msg = cp_msg_mme_init (ctx, peer, CC_LEAVE_REQ);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, &reason, 8);

    msg->length = 1;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_LEAVE.REQ.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  reason  received reason for the disassociation
 * \return  true on success
 */
bool
cp_msg_cc_leave_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             enum cp_msg_cc_leave_req_reason_t *reason)
{
    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (reason);

    bitstream_access (&mme->bitstream, reason, 8);


    if (*reason >= CP_MSG_CC_LEAVE_IND_REASON_NB)
        return false;
    return true;
}

/**
 * Send a CC_LEAVE.CNF.
 * \param  ctx  control plane context
 * \param  peer  peer information
 */
void
cp_msg_cc_leave_cnf_send (cp_t *ctx, cp_mme_peer_t *peer)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);

    msg = cp_msg_mme_init (ctx, peer, CC_LEAVE_CNF);
    dbg_check (msg);

    msg->length = 0;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_LEAVE.CNF.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \return  true on success
 */
bool
cp_msg_cc_leave_cnf_receive (cp_t *ctx, cp_mme_rx_t *mme)
{
    dbg_assert (ctx);
    dbg_assert (mme);

    return true;
}

/**
 * Send a CC_LEAVE.IND.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  reason  reason for the disassociation
 * \param  nid  NID
 */
void
cp_msg_cc_leave_ind_send (cp_t *ctx, cp_mme_peer_t *peer,
                          enum cp_msg_cc_leave_ind_reason_t reason,
                          cp_nid_t nid)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (reason < CP_MSG_CC_LEAVE_IND_REASON_NB);
    dbg_assert (nid);

    msg = cp_msg_mme_init (ctx, peer, CC_LEAVE_IND);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, &reason, 8);
    bitstream_access (&msg->bitstream, &nid, 56);

    msg->length = 8;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_LEAVE.IND.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  reason  received reason for the disassociation
 * \param  nid  received NID
 * \return  true on success
 */
bool
cp_msg_cc_leave_ind_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             enum cp_msg_cc_leave_ind_reason_t *reason,
                             cp_nid_t *nid)
{
    cp_net_t *net;

    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (reason);
    dbg_assert (nid);

    bitstream_access (&mme->bitstream, reason, 8);
    bitstream_access (&mme->bitstream, nid, 56);

    /* Verify. */
    net = cp_sta_mgr_get_our_avln (ctx);
    dbg_check (net);

    if ((cp_net_get_nid (ctx, net) != *nid)
        || (*reason < CP_MSG_CC_LEAVE_IND_REASON_NB))
    {
        return false;
    }

    return true;
}

/**
 * Send a CC_LEAVE.RSP.
 * \param  ctx  control plane context
 * \param  peer  peer information
 */
void
cp_msg_cc_leave_rsp_send (cp_t *ctx, cp_mme_peer_t *peer)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);

    msg = cp_msg_mme_init (ctx, peer, CC_LEAVE_RSP);
    dbg_check (msg);

    msg->length = 0;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_LEAVE.RSP.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \return  true on success
 */
bool
cp_msg_cc_leave_rsp_receive (cp_t *ctx, cp_mme_rx_t *mme)
{
    dbg_assert (ctx);
    dbg_assert (mme);

    return true;
}

/**
 * Send a CC_SET_TEI_MAP.REQ.
 * \param  ctx  control plane context
 * \param  peer  peer information
 */
void
cp_msg_cc_set_tei_map_req_send (cp_t *ctx, cp_mme_peer_t *peer)
{
    cp_mme_tx_t *msg;

    dbg_assert (ctx);
    dbg_assert (peer);

    msg = cp_msg_mme_init (ctx, peer, CC_SET_TEI_MAP_REQ);
    dbg_check (msg);

    msg->length = 0;
    cp_msg_mme_send (ctx, msg);
}

/**
 * Receive a CC_SET_TEI_MAP.REQ.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \return  true on success
 */
bool
cp_msg_cc_set_tei_map_req_receive (cp_t *ctx, cp_mme_rx_t *mme)
{
    dbg_assert (ctx);
    dbg_assert (mme);

    return true;
}

/** CC_SET_TEI_MAP Function to call when the buffer is full.
 * \param ctx  the bitstream context.
 * \param  data  the structure registered.
 */
static void
cp_msg_set_tei_map_change_buffer (bitstream_t *ctx,
                                  cp_msg_cc_set_tei_map_change_buffer_t *data)
{
    dbg_assert (ctx);
    dbg_assert (data);
    dbg_assert (data->cp);
    dbg_assert (data->msg);

    // Finalise the MME.
    slab_addref (data->msg);
    cp_msg_mme_send (data->cp, data->msg);

    // Initialise the header of the new buffer.
    data->msg->p_mme = cp_cl_interf_get_buffer_tx (data->cp);

    cp_msg_mme_write_frag_header (data->cp, data->msg, &data->msg->peer,
                                  CC_SET_TEI_MAP_IND, data->fmi_nbFrag,
                                  data->fmi_fnmi, data->fmi_ssn);
}


/**
 * Begin a CC_SET_TEI_MAP.IND construction.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  mode  update, add or delete
 * \param  sta_nb  number of stations sent
 * \return  the MME being constructed
 */
cp_mme_tx_t *
cp_msg_cc_set_tei_map_ind_send_begin (
    cp_t *ctx, cp_mme_peer_t *peer,
    enum cp_msg_cc_set_tei_map_ind_mode_t mode, uint sta_nb)
{
    cp_mme_tx_t *msg;
    cp_msg_cc_set_tei_map_change_buffer_t *data = NULL;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (mode < CP_MSG_CC_SET_TEI_MAP_IND_MODE_NB);
    dbg_assert (sta_nb);

    if (sta_nb * 8 > (peer->vlan_tag ? CP_MME_PAYLOAD_MAX_SIZE_WITH_VLAN :
        CP_MME_PAYLOAD_MAX_SIZE) - 2)
    {
        data = blk_alloc ();
        data->cp = ctx;
        data->fmi_nbFrag = 1;
        data->fmi_fnmi = 0;
        data->fmi_ssn = 0;

        msg = cp_msg_mme_init_frag (ctx, peer, CC_SET_TEI_MAP_IND, 1, 0, 0);
        data->msg = msg;
        bitstream_buffer_full_init_cb (&msg->bitstream,
                  (bitstream_buffer_cb_t) cp_msg_set_tei_map_change_buffer,
                  data);
    }
    else
        msg = cp_msg_mme_init (ctx, peer, CC_SET_TEI_MAP_IND);
    dbg_check (msg);

    bitstream_access (&msg->bitstream, &mode, 8);
    bitstream_access (&msg->bitstream, &sta_nb, 8);

    return msg;
}

/**
 * Write a station to a CC_SET_TEI_MAP.IND being constructed.
 * \param  ctx  control plane context
 * \param  mme  MME being constructed
 * \param  tei  STA TEI
 * \param  mac  STA mac address
 * \param  status  STA status
 */
void
cp_msg_cc_set_tei_map_ind_send_sta (
    cp_t *ctx, cp_mme_tx_t *mme, cp_tei_t tei, mac_t mac,
    enum cp_msg_cc_set_tei_map_ind_status_t status)
{
    dbg_assert (mme);
    dbg_assert (tei);
    dbg_assert (mac);
    dbg_assert (status < CP_MSG_CC_SET_TEI_MAP_IND_STATUS_NB);

    bitstream_access (&mme->bitstream, &tei, 8);
    bitstream_access (&mme->bitstream, &mac, 48);
    bitstream_access (&mme->bitstream, &status, 8);
}

/**
 * Finalise and send a CC_SET_TEI_MAP.IND message.
 * \param  ctx  control plane context
 * \param  mme  MME being constructed
 */
void
cp_msg_cc_set_tei_map_ind_send_end (cp_t *ctx, cp_mme_tx_t *mme)
{
    dbg_assert (ctx);
    dbg_assert (mme);

    if (mme->bitstream.buffer_cb_present)
        blk_release (mme->bitstream.user_data);
    cp_msg_mme_send (ctx, mme);
}

/**
 * Begin a CC_SET_TEI_MAP.IND reception.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  mode  received mode: update, add or delete
 * \param  sta_nb  received number of STA
 * \return  true on success
 */
bool
cp_msg_cc_set_tei_map_ind_receive_begin (
    cp_t *ctx, cp_mme_rx_t *mme,
    enum cp_msg_cc_set_tei_map_ind_mode_t *mode, uint *sta_nb)
{
    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (mode);
    dbg_assert (sta_nb);

    bitstream_access (&mme->bitstream, mode, 8);
    bitstream_access (&mme->bitstream, sta_nb, 8);

    if (*mode >= CP_MSG_CC_SET_TEI_MAP_IND_MODE_NB)
        return false;
    return true;
}

/**
 * Read a station from a received CC_SET_TEI_MAP.IND.
 * \param  ctx  control plane context
 * \param  mme  MME being received
 * \param  tei  received STA TEI
 * \param  mac  received STA mac address
 * \param  status  received STA status
 * \return  true on success
 */
bool
cp_msg_cc_set_tei_map_ind_receive_sta (
    cp_t *ctx, cp_mme_rx_t *mme, cp_tei_t *tei, mac_t *mac,
    enum cp_msg_cc_set_tei_map_ind_status_t *status)
{
    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (tei);
    dbg_assert (mac);
    dbg_assert (status);

    bitstream_access (&mme->bitstream, tei, 8);
    bitstream_access (&mme->bitstream, mac, 48);
    bitstream_access (&mme->bitstream, status, 8);

    if (*status >= CP_MSG_CC_SET_TEI_MAP_IND_STATUS_NB)
        return false;
    return true;
}

/**
 * Finalise a CC_SET_TEI_MAP.IND reception.
 * \param  ctx  control plane context
 * \param  mme  MME being received
 * \return  true on success
 */
bool
cp_msg_cc_set_tei_map_ind_receive_end (cp_t *ctx, cp_mme_rx_t *mme)
{
    dbg_assert (ctx);
    dbg_assert (mme);

    return true;
}

/**
 * Write the header of a CC_RELAY MME.
 * \param  ctx  the module context.
 * \param  peer  the peer information.
 * \param  mmtype  the MMType of the MME CC_RELAY_REQ or CC_RELAY_IND.
 * \param  prun  if the MME shall be encrypted.
 * \param  peks  the Payload encryption key select.
 * \param  fda  the final destination mac address.
 * \param  ftei  the final TEI.
 */
cp_mme_tx_t *
cp_msg_cc_relay_send_begin (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
                            const cp_secu_protocol_run_t *prun,
                            cp_mme_peks_t peks,
                            mac_t fda, cp_tei_t ftei)
{
    cp_mme_tx_t * msg;

    dbg_assert (ctx);
    dbg_assert (peer);
    dbg_assert (fda);
    dbg_assert (ftei);

    dbg_assert ((mmtype != CC_RELAY_REQ) || (mmtype != CC_RELAY_IND));

    // Get a TX buffer.
    if (peks == CP_MME_PEKS_SPC_NOT_EMBEDDED)
        msg = cp_msg_mme_init (ctx, peer, mmtype);
    else
        msg = cp_msg_mme_init_encrypted (ctx, peer, mmtype, peks, prun);

    // Fill the data of the MME.
    bitstream_access (&msg->bitstream, &fda, 48);
    // Fill the TEI of the final destination station.
    bitstream_access (&msg->bitstream, &ftei, 8);
    // Go forward inserting a zero length MME payload length.
    bitstream_write (&msg->bitstream, 0, 16);

    return msg;
}

/**
 * Finalise the MME CC_RELAY.*.
 * \param  ctx  the module context.
 * \param  msg  the MME to send.
 * \param  length  the MME length corresponding (header included).
 *
 * Patch the Length of the MME payload in the MSG CC_RELAY.REQ MME.
 */
void
cp_msg_cc_relay_send_finalise (cp_t *ctx, cp_mme_tx_t *msg, uint length)
{
    uint word;

    dbg_assert (ctx);
    dbg_assert (msg);
    dbg_assert (length);

    // Get the word containing the length of MME relay payload length field.
    word = *((uint *) (msg->p_mme + (msg->peer.vlan_tag ? 28 : 24)));
    // Add the length to the 16bits MSB in the word.
    word = (word & 0xFFFF) | (length << 16);
    // Store the word at the same address.
    *((uint *) (msg->p_mme + (msg->peer.vlan_tag ? 28 : 24))) = word;
}

/**
 * Receive a CC_RELAY.*
 * \param  ctx  the control plane context.
 * \param  msg  the MME context.
 * \param  length  the MME payload length contained.
 *
 * Initialise the Relay MME.
 */
void
cp_msg_cc_relay_receive (cp_t *ctx, cp_mme_rx_t *msg, uint *length)
{
    dbg_assert (ctx);
    dbg_assert (msg);
    dbg_assert (length);

    // Read the FDA.
    bitstream_access (&msg->bitstream, &msg->relay.mac_fa, 48);
    bitstream_access (&msg->bitstream, &msg->relay.ftei, 8);
    bitstream_access (&msg->bitstream, length, 16);
}