Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mac_802_15_4_core_wb.c « src « core « mac_802_15_4 « STM32_WPAN « ST « Middlewares - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bfcb790e93bb62e0236b143ccac5d262f627013e (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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
/**
 ******************************************************************************
 * @file    mac_802_15_4_api_wb.c
 * @author  MCD Application Team
 * @brief   Contains STM32WB specificities requested to control the 802.15.4
 *          MAC interface.
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under Ultimate Liberty license
 * SLA0044, the "License"; You may not use this file except in compliance with
 * the License. You may obtain a copy of the License at:
 *                             www.st.com/SLA0044
 *
 ******************************************************************************
 */


/* Includes ------------------------------------------------------------------*/

#include "802_15_4_mac_errors.h"
#include "802_15_4_mac_config.h"
#include "802_15_4_mac_types.h"
#include "802_15_4_mac_sap.h"
#include "802_15_4_mac_core.h"

#include "dbg_trace.h"
#include "stm_logging.h"

#include "tl.h"
#include "tl_mac_802_15_4.h"


/** @defgroup STM32WB55_MAC STM32WBxx MAC 802.15.4 API
  * @brief Provides MAC 802.15.4 functionalities to address MAC primitives accessed through
  *                  MLME-SAP and MCPS-SAP.<br>
  *                  Once RF-Core is initialized, Zigbee or proprietary network layer address RF-Core
  *                  using MLME or MCPS SAP primitives.<br>
  *                  On completion or on MAC-RF event, RF-Core sends back notification (ie.: MAC confirmation or MAC indication)
  *                  to the running application.<br>
  *                  Zigbee or proprietary network layer is notified (MAC_802_15_4_CallBack_Processing(void)) by the corresponding user defined callback call
  *                  that has been previously initialized in MAC_callbacks_t macCbConfig.<br>
  * @{
  */

/**
 * @brief  MAC Callbacks Structure registering user callback to be notify from MAC layers on
 *         MAC Confirmation and MAC Indications.
 */
extern MAC_callbacks_t macCbConfig;

/**
  * @}
  */

/**
 * @brief   This system function is used to set defined command ID in message between
 *          Application core and Rf core.
 *
 *
 * @param  None
 * @retval None
 */

static void utils_mac_set_cmdCode(uint16_t cmdCode)
{
  /* Set ID of the cmd in cmdcode field */

  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();
  p_mac_cmd_req->cmdserial.cmd.cmdcode = (0x3F << 9) | (MAC_802_15_4_CMD_OPCODE_OFFSET + cmdCode);
}

/** @addtogroup STM32WB55_MAC_CORE
 *
 */

/**
 * @brief  Handle MAC SAP's confirmations and indications coming from
 *         RFCore's MAC layer.
 *         On received RFCore Mac Message, calls upper layer user defined associated callbacks from MAC_callbacks_t macCbConfig .
 *         Important Note: This method is called on every MAC message from RFCore.
 *
 * @param  None
 * @retval None
 */
HAL_StatusTypeDef MAC_802_15_4_CallBack_Processing(void)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Get pointer on received event buffer from M0 */
  TL_Evt_t * p_notif_evt = MAC_802_15_4_GetNotificationBuffer();
  MAC_802_15_4_Notification_t* p_mac_evt = (MAC_802_15_4_Notification_t*)(p_notif_evt->payload);

  uint8_t subEvtCode = p_mac_evt->subEvtCode;

  switch(subEvtCode)
  {
  case MSG_M0TOM4_MAC_MLME_RESET_CNF:
    {
      MAC_resetCnf_t resetCnf;
      memcpy(&resetCnf,p_mac_evt->notPayload, sizeof(MAC_resetCnf_t));
      macCbConfig.mlmeResetCnfCb(&resetCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_ASSOCIATE_CNF:
    {
      MAC_associateCnf_t associateCnf;
      memcpy(&associateCnf,p_mac_evt->notPayload, sizeof(MAC_associateCnf_t));
      macCbConfig.mlmeAssociateCnfCb(&associateCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_DISASSOCIATE_CNF:
    {
      MAC_disassociateCnf_t  disassociateCnf;
      memcpy(&disassociateCnf,p_mac_evt->notPayload, sizeof(MAC_disassociateCnf_t));
      macCbConfig.mlmeDisassociateCnfCb(&disassociateCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_GET_CNF:
    {
      MAC_getCnf_t  getCnf;
      memcpy(&getCnf,p_mac_evt->notPayload, sizeof(MAC_getCnf_t));
      macCbConfig.mlmeGetCnfCb(&getCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_GTS_CNF:
    {
      MAC_gtsCnf_t gtsCnf;
      memcpy(&gtsCnf,p_mac_evt->notPayload, sizeof(MAC_gtsCnf_t));
      macCbConfig.mlmeGtsCnfCb(&gtsCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_RX_ENABLE_CNF:
    {
      MAC_rxEnableCnf_t RxEnable;
      memcpy(&RxEnable,p_mac_evt->notPayload, sizeof(MAC_rxEnableCnf_t));
      macCbConfig.mlmeRxEnableCnfCb(&RxEnable);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_SCAN_CNF:
    {
      MAC_scanCnf_t scanCnf;
      memcpy(&scanCnf,p_mac_evt->notPayload, sizeof(MAC_scanCnf_t));
      macCbConfig.mlmeScanCnfCb(&scanCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_SET_CNF:
    {
      MAC_setCnf_t setCnf;
      memcpy(&setCnf,p_mac_evt->notPayload, sizeof(MAC_setCnf_t));
      macCbConfig.mlmeSetCnfCb(&setCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_START_CNF:
    {
      MAC_startCnf_t startCnf;
      memcpy(&startCnf,p_mac_evt->notPayload, sizeof(MAC_startCnf_t));
      macCbConfig.mlmeStartCnfCb(&startCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_POLL_CNF:
    {
      MAC_pollCnf_t pollCnf;
      memcpy(&pollCnf,p_mac_evt->notPayload, sizeof(MAC_pollCnf_t));
      macCbConfig.mlmePollCnfCb(&pollCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_DPS_CNF:
    {
      MAC_dpsCnf_t dpsCnf;
      memcpy(&dpsCnf,p_mac_evt->notPayload, sizeof(MAC_dpsCnf_t));
      macCbConfig.mlmeDpsCnfCb(&dpsCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_SOUNDING_CNF:
    {
      MAC_soundingCnf_t soudingCnf;
      memcpy(&soudingCnf,p_mac_evt->notPayload, sizeof(MAC_soundingCnf_t));
      macCbConfig.mlmeSoundingCnfCb(&soudingCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_CALIBRATE_CNF:
    {
      MAC_calibrateCnf_t calibrateCnf;
      memcpy(&calibrateCnf,p_mac_evt->notPayload, sizeof(MAC_calibrateCnf_t));
      macCbConfig.mlmeCalibrateCnfCb(&calibrateCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MCPS_DATA_CNF:
    {
      MAC_dataCnf_t dataCnf;
      memcpy(&dataCnf,p_mac_evt->notPayload, sizeof(MAC_dataCnf_t));
      macCbConfig.mcpsDataCnfCb(&dataCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MCPS_PURGE_CNF:
    {
      MAC_purgeCnf_t purgeCnf;
      memcpy(&purgeCnf,p_mac_evt->notPayload, sizeof(MAC_purgeCnf_t));
      macCbConfig.mcpsPurgeCnfCb(&purgeCnf);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_ASSOCIATE_IND:
    {
      MAC_associateInd_t associateInd;
      memcpy(&associateInd,p_mac_evt->notPayload, sizeof(MAC_associateInd_t));
      macCbConfig.mlmeAssociateIndCb(&associateInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_DISASSOCIATE_IND:
    {
      MAC_disassociateInd_t disassociateInd;
      memcpy(&disassociateInd,p_mac_evt->notPayload, sizeof(MAC_disassociateInd_t));
      macCbConfig.mlmeDisassociateIndCb(&disassociateInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_BEACON_NOTIFY_IND:
    {
      MAC_beaconNotifyInd_t beaconNotifyInd;
      memcpy(&beaconNotifyInd,p_mac_evt->notPayload, sizeof(MAC_beaconNotifyInd_t));
      macCbConfig.mlmeBeaconNotifyIndCb(&beaconNotifyInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_COMM_STATUS_IND:
    {
      MAC_commStatusInd_t commStatusInd;
      memcpy(&commStatusInd,p_mac_evt->notPayload, sizeof(MAC_commStatusInd_t));
      macCbConfig.mlmeCommStatusIndCb(&commStatusInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_GTS_IND:
    {
      MAC_GtsInd_t gtsInd;
      memcpy(&gtsInd,p_mac_evt->notPayload, sizeof(MAC_GtsInd_t));
      macCbConfig.mlmeGtsIndCb(&gtsInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_ORPHAN_IND:
    {
      MAC_orphanInd_t orphanInd;
      memcpy(&orphanInd,p_mac_evt->notPayload, sizeof(MAC_orphanInd_t));
      macCbConfig.mlmeOrphanIndCb(&orphanInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_SYNC_LOSS_IND:
    {
      MAC_syncLoss_t syncLoss;
      memcpy(&syncLoss,p_mac_evt->notPayload, sizeof(MAC_syncLoss_t));
      macCbConfig.mlmeSyncLossIndCb(&syncLoss);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_DPS_IND:
    {
      MAC_dpsInd_t dpsInd;
      memcpy(&dpsInd,p_mac_evt->notPayload, sizeof(MAC_dpsInd_t));
      macCbConfig.mlmeDpsIndCb(&dpsInd);
    }
    break;
    case MSG_M0TOM4_MAC_MCPS_DATA_IND:
    {
      MAC_dataInd_t dataInd ;
      memcpy(&dataInd,p_mac_evt->notPayload, sizeof(MAC_dataInd_t));
      macCbConfig.mcpsDataIndCb(&dataInd);
    }
    break;
    case MSG_M0TOM4_MAC_MLME_POLL_IND:
    {
      MAC_pollInd_t pollInd ;
      memcpy(&pollInd,p_mac_evt->notPayload, sizeof(MAC_pollInd_t));
      macCbConfig.mlmePollIndCb(&pollInd);
    }
    break;
  default:
    status = HAL_ERROR;
    break;
  }


  /* Send Ack to M0 */
  TL_MAC_802_15_4_SendAck();
  return status;

}

/**
  * @}
  */


/** \addtogroup STM32WB55_MAC
  * @{
  */

/**
 * @brief  This function is used to handle a MAC MLME Associate REQ as described
 *         in IEEE Std 802.15.4-2011 standard.
 *
 *
 * @param  MAC_associateReq_t ref
 * @retval MAC_Status_t
 */

MAC_Status_t MAC_MLMEAssociateReq( const  MAC_associateReq_t * pAssociateReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_ASSOCIATE_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_associateReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pAssociateReq, sizeof(MAC_associateReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Disassociate REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_disassociateReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEDisassociateReq( const  MAC_disassociateReq_t * pDisassiociateReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_DISASSOCIATE_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_disassociateReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pDisassiociateReq, sizeof(MAC_disassociateReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Get REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_getReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEGetReq( const  MAC_getReq_t * pGetReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_GET_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_getReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pGetReq, sizeof(MAC_getReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME GTS REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_gtsReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEGtsReq( const  MAC_gtsReq_t * pGtsReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_GTS_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_gtsReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pGtsReq, sizeof(MAC_gtsReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Reset REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_resetReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEResetReq( const  MAC_resetReq_t * pResetReq )
{
    MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;


    Mac_802_15_4_PreCmdProcessing();

    /* prepare buffer */
    TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

    utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_RESET_REQ);

    /* plen = pitAttributeValueLen + 1 byte (corresponding to pibAttributeID) */
    p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_resetReq_t);

    /* Here copy to payload */
    memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pResetReq, sizeof(MAC_resetReq_t) );

    Mac_802_15_4_CmdTransfer();

    /* If return parameter */
    TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

    status = p_mac_rsp_evt->payload[0];

    return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Rx Enabled REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_rxEnableReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMERxEnableReq( const  MAC_rxEnableReq_t * pRxEnableReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_RX_ENABLE_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_rxEnableReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pRxEnableReq, sizeof(MAC_rxEnableReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}


/**
* @brief  This function is used to handle a MAC MLME Scan REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_scanReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEScanReq( const  MAC_scanReq_t * pScanReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_SCAN_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_scanReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pScanReq, sizeof(MAC_scanReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
* @brief  This function is used to handle a MAC MLME Set REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_setReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMESetReq( const  MAC_setReq_t * pSetReq)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_SET_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_setReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pSetReq, sizeof(MAC_setReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
* @brief  This function is used to handle a MAC MLME Start REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_startReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEStartReq( const  MAC_startReq_t * pStartReq)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_START_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_startReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pStartReq, sizeof(MAC_startReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
* @brief  This function is used to handle a MAC MLME Sync REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_syncReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMESyncReq( const  MAC_syncReq_t * pSyncReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_SYNC_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_syncReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pSyncReq, sizeof(MAC_syncReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}


/**
* @brief  This function is used to handle a MAC MLME Poll REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 *
 * @param  MAC_pollReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEPollReq( const MAC_pollReq_t * pPollReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_POLL_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_pollReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pPollReq, sizeof(MAC_pollReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Dps REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_dpsReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEDpsReq( const MAC_dpsReq_t * pDpsReq)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_DPS_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_dpsReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pDpsReq, sizeof(MAC_dpsReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Associate REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_soundingReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMESoundingReq( const MAC_soundingReq_t * pSoundingReq)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_SOUNDING_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_soundingReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pSoundingReq, sizeof(MAC_soundingReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Calibrate REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_calibrateReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMECalibrateReq( const MAC_calibrateReq_t * pCalibrateReq)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_CALIBRATE_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_calibrateReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pCalibrateReq, sizeof(MAC_calibrateReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MCPS Data REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_dataReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MCPSDataReq( const MAC_dataReq_t * pDataReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MCPS_DATA_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_dataReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pDataReq, sizeof(MAC_dataReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MCPD Purge REQ as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_purgeReq_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MCPSPurgeReq( const MAC_purgeReq_t * pPurgeReq )
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MCPS_PURGE_REQ);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_purgeReq_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pPurgeReq, sizeof(MAC_purgeReq_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}


/**
 * @brief  This function is used to handle a MAC MLME Associate RES as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_associateRes_t ref
 * @retval MAC_Status_t
 */

MAC_Status_t MAC_MLMEAssociateRes(const MAC_associateRes_t * pAssociateRes)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_ASSOCIATE_RES);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_associateRes_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pAssociateRes, sizeof(MAC_associateRes_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}

/**
 * @brief  This function is used to handle a MAC MLME Orphan RES as described
 *         in IEEE Std 802.15.4-2011 standard
 *
 * @param  MAC_orphanRes_t ref
 * @retval MAC_Status_t
 */
MAC_Status_t MAC_MLMEOrphanRes(const MAC_orphanRes_t * pOrphanRes)
{
  MAC_Status_t status = MAC_NOT_IMPLEMENTED_STATUS;

  Mac_802_15_4_PreCmdProcessing();

  /* prepare buffer */
  TL_CmdPacket_t* p_mac_cmd_req = MAC_802_15_4_GetCmdBuffer();

  utils_mac_set_cmdCode(MSG_M4TOM0_MAC_MLME_ORPHAN_RES);

  p_mac_cmd_req->cmdserial.cmd.plen = sizeof(MAC_orphanRes_t);

  /* Here copy to payload */
  memcpy( p_mac_cmd_req->cmdserial.cmd.payload, pOrphanRes, sizeof(MAC_orphanRes_t) );

  Mac_802_15_4_CmdTransfer();

  /* If return parameter */
  TL_Evt_t* p_mac_rsp_evt = MAC_802_15_4_GetRspPayEvt();

  status = p_mac_rsp_evt->payload[0];

  return status;
}