Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
/*
 * Copyright 2008-2015 Freescale Semiconductor Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Freescale Semiconductor nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 *
 * ALTERNATIVELY, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") as published by the Free Software
 * Foundation, either version 2 of that License or (at your option) any
 * later version.
 *
 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/******************************************************************************
 @File          fm_macsec_secy.c

 @Description   FM MACSEC SECY driver routines implementation.
*//***************************************************************************/

#include "std_ext.h"
#include "error_ext.h"
#include "xx_ext.h"
#include "string_ext.h"
#include "sprint_ext.h"

#include "fm_macsec_secy.h"


/****************************************/
/*       static functions               */
/****************************************/
static void FmMacsecSecYExceptionsIsr(t_Handle h_FmMacsecSecY, uint32_t id)
{
    t_FmMacsecSecY *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    UNUSED(id);
    SANITY_CHECK_RETURN(p_FmMacsecSecY, E_INVALID_HANDLE);

    if (p_FmMacsecSecY->exceptions & FM_MACSEC_SECY_EX_FRAME_DISCARDED)
        p_FmMacsecSecY->f_Exception(p_FmMacsecSecY->h_App, e_FM_MACSEC_SECY_EX_FRAME_DISCARDED);
}

static void FmMacsecSecYEventsIsr(t_Handle h_FmMacsecSecY, uint32_t id)
{
    t_FmMacsecSecY *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    UNUSED(id);
    SANITY_CHECK_RETURN(p_FmMacsecSecY, E_INVALID_HANDLE);

    if (p_FmMacsecSecY->events & FM_MACSEC_SECY_EV_NEXT_PN)
        p_FmMacsecSecY->f_Event(p_FmMacsecSecY->h_App, e_FM_MACSEC_SECY_EV_NEXT_PN);
}

static t_Error CheckFmMacsecSecYParameters(t_FmMacsecSecY *p_FmMacsecSecY)
{
    if (!p_FmMacsecSecY->f_Exception)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exceptions callback not provided"));

    if (!p_FmMacsecSecY->f_Event)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Events callback not provided"));

    if (!p_FmMacsecSecY->numOfRxSc)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Num of Rx Scs must be greater than '0'"));


    return E_OK;
}

static t_Handle FmMacsecSecYCreateSc(t_FmMacsecSecY             *p_FmMacsecSecY,
                                     macsecSCI_t                sci,
                                     e_FmMacsecSecYCipherSuite  cipherSuite,
                                     e_ScType                   type)
{
    t_SecYSc        *p_ScTable;
    void            *p_Params;
    uint32_t        numOfSc,i;
    t_Error         err = E_OK;
    t_RxScParams    rxScParams;
    t_TxScParams    txScParams;

    ASSERT_COND(p_FmMacsecSecY);
    ASSERT_COND(p_FmMacsecSecY->h_FmMacsec);

    if (type == e_SC_RX)
    {
        memset(&rxScParams, 0, sizeof(rxScParams));
        i                                   = (NUM_OF_RX_SC - 1);
        p_ScTable                           = p_FmMacsecSecY->p_RxSc;
        numOfSc                             = p_FmMacsecSecY->numOfRxSc;
        rxScParams.confidentialityOffset    = p_FmMacsecSecY->confidentialityOffset;
        rxScParams.replayProtect            = p_FmMacsecSecY->replayProtect;
        rxScParams.replayWindow             = p_FmMacsecSecY->replayWindow;
        rxScParams.validateFrames           = p_FmMacsecSecY->validateFrames;
        rxScParams.cipherSuite              = cipherSuite;
        p_Params = &rxScParams;
    }
    else
    {
        memset(&txScParams, 0, sizeof(txScParams));
        i                                   = (NUM_OF_TX_SC - 1);
        p_ScTable                           = p_FmMacsecSecY->p_TxSc;
        numOfSc                             = p_FmMacsecSecY->numOfTxSc;
        txScParams.sciInsertionMode         = p_FmMacsecSecY->sciInsertionMode;
        txScParams.protectFrames            = p_FmMacsecSecY->protectFrames;
        txScParams.confidentialityEnable    = p_FmMacsecSecY->confidentialityEnable;
        txScParams.confidentialityOffset    = p_FmMacsecSecY->confidentialityOffset;
        txScParams.cipherSuite              = cipherSuite;
        p_Params = &txScParams;
    }

    for (i=0;i<numOfSc;i++)
        if (!p_ScTable[i].inUse)
            break;
    if (i == numOfSc)
    {
        REPORT_ERROR(MAJOR, E_FULL, ("FM MACSEC SECY SC"));
        return NULL;
    }

    if (type == e_SC_RX)
    {
        ((t_RxScParams *)p_Params)->scId = p_ScTable[i].scId;
        ((t_RxScParams *)p_Params)->sci  = sci;
        if ((err = FmMacsecCreateRxSc(p_FmMacsecSecY->h_FmMacsec, (t_RxScParams *)p_Params)) != E_OK)
        {
            REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM MACSEC SECY RX SC"));
            return NULL;
        }
    }
    else
    {
        ((t_TxScParams *)p_Params)->scId = p_ScTable[i].scId;
        ((t_TxScParams *)p_Params)->sci  = sci;
        if ((err = FmMacsecCreateTxSc(p_FmMacsecSecY->h_FmMacsec, (t_TxScParams *)p_Params)) != E_OK)
        {
            REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM MACSEC SECY TX SC"));
            return NULL;
        }
    }

    p_ScTable[i].inUse = TRUE;
    return &p_ScTable[i];
}

static t_Error FmMacsecSecYDeleteSc(t_FmMacsecSecY *p_FmMacsecSecY, t_SecYSc *p_FmSecYSc, e_ScType type)
{
    t_Error         err = E_OK;

    ASSERT_COND(p_FmMacsecSecY);
    ASSERT_COND(p_FmMacsecSecY->h_FmMacsec);
    ASSERT_COND(p_FmSecYSc);

    if (type == e_SC_RX)
    {
        if ((err = FmMacsecDeleteRxSc(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
    }
    else
        if ((err = FmMacsecDeleteTxSc(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->inUse = FALSE;

    return err;
}

/****************************************/
/*       API Init unit functions        */
/****************************************/
t_Handle FM_MACSEC_SECY_Config(t_FmMacsecSecYParams *p_FmMacsecSecYParam)
{
    t_FmMacsecSecY  *p_FmMacsecSecY;

    /* Allocate FM MACSEC structure */
    p_FmMacsecSecY = (t_FmMacsecSecY *) XX_Malloc(sizeof(t_FmMacsecSecY));
    if (!p_FmMacsecSecY)
    {
        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM MACSEC SECY driver structure"));
        return NULL;
    }
    memset(p_FmMacsecSecY, 0, sizeof(t_FmMacsecSecY));

    /* Allocate the FM MACSEC driver's parameters structure */
    p_FmMacsecSecY->p_FmMacsecSecYDriverParam = (t_FmMacsecSecYDriverParam *)XX_Malloc(sizeof(t_FmMacsecSecYDriverParam));
    if (!p_FmMacsecSecY->p_FmMacsecSecYDriverParam)
    {
        XX_Free(p_FmMacsecSecY);
        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM MACSEC SECY driver parameters"));
        return NULL;
    }
    memset(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, 0, sizeof(t_FmMacsecSecYDriverParam));

    /* Initialize FM MACSEC SECY parameters which will be kept by the driver */
    p_FmMacsecSecY->h_FmMacsec              = p_FmMacsecSecYParam->h_FmMacsec;
    p_FmMacsecSecY->f_Event                 = p_FmMacsecSecYParam->f_Event;
    p_FmMacsecSecY->f_Exception             = p_FmMacsecSecYParam->f_Exception;
    p_FmMacsecSecY->h_App                   = p_FmMacsecSecYParam->h_App;
    p_FmMacsecSecY->confidentialityEnable   = DEFAULT_confidentialityEnable;
    p_FmMacsecSecY->confidentialityOffset   = DEFAULT_confidentialityOffset;
    p_FmMacsecSecY->validateFrames          = DEFAULT_validateFrames;
    p_FmMacsecSecY->replayProtect           = DEFAULT_replayEnable;
    p_FmMacsecSecY->replayWindow            = DEFAULT_replayWindow;
    p_FmMacsecSecY->protectFrames           = DEFAULT_protectFrames;
    p_FmMacsecSecY->sciInsertionMode        = DEFAULT_sciInsertionMode;
    p_FmMacsecSecY->isPointToPoint          = DEFAULT_ptp;
    p_FmMacsecSecY->numOfRxSc               = p_FmMacsecSecYParam->numReceiveChannels;
    p_FmMacsecSecY->numOfTxSc               = DEFAULT_numOfTxSc;
    p_FmMacsecSecY->exceptions              = DEFAULT_exceptions;
    p_FmMacsecSecY->events                  = DEFAULT_events;

    memcpy(&p_FmMacsecSecY->p_FmMacsecSecYDriverParam->txScParams,
           &p_FmMacsecSecYParam->txScParams,
           sizeof(t_FmMacsecSecYSCParams));
    return p_FmMacsecSecY;
}

t_Error FM_MACSEC_SECY_Init(t_Handle h_FmMacsecSecY)
{
    t_FmMacsecSecY              *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_FmMacsecSecYDriverParam   *p_FmMacsecSecYDriverParam = NULL;
    uint32_t                    rxScIds[NUM_OF_RX_SC], txScIds[NUM_OF_TX_SC], i, j;
    t_Error                     err;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_HANDLE);

    CHECK_INIT_PARAMETERS(p_FmMacsecSecY, CheckFmMacsecSecYParameters);

    p_FmMacsecSecYDriverParam = p_FmMacsecSecY->p_FmMacsecSecYDriverParam;

    if ((p_FmMacsecSecY->isPointToPoint) &&
        ((err = FmMacsecSetPTP(p_FmMacsecSecY->h_FmMacsec, TRUE)) != E_OK))
        RETURN_ERROR(MAJOR, err, ("Can't set Poin-to-Point"));

    /* Rx Sc Allocation */
    p_FmMacsecSecY->p_RxSc = (t_SecYSc *)XX_Malloc(sizeof(t_SecYSc) * p_FmMacsecSecY->numOfRxSc);
    if (!p_FmMacsecSecY->p_RxSc)
        RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FM MACSEC SECY RX SC"));
    memset(p_FmMacsecSecY->p_RxSc, 0, sizeof(t_SecYSc) * p_FmMacsecSecY->numOfRxSc);
    if ((err = FmMacsecAllocScs(p_FmMacsecSecY->h_FmMacsec, e_SC_RX, p_FmMacsecSecY->isPointToPoint, p_FmMacsecSecY->numOfRxSc, rxScIds)) != E_OK)
    {
        if (p_FmMacsecSecY->p_TxSc)
            XX_Free(p_FmMacsecSecY->p_TxSc);
        if (p_FmMacsecSecY->p_RxSc)
            XX_Free(p_FmMacsecSecY->p_RxSc);
        return ERROR_CODE(err);
    }
    for (i=0; i<p_FmMacsecSecY->numOfRxSc; i++)
    {
        p_FmMacsecSecY->p_RxSc[i].scId  = rxScIds[i];
        p_FmMacsecSecY->p_RxSc[i].type  = e_SC_RX;
        for (j=0; j<MAX_NUM_OF_SA_PER_SC;j++)
            p_FmMacsecSecY->p_RxSc[i].sa[j].saId = (e_ScSaId)SECY_AN_FREE_VALUE;
    }

    /* Tx Sc Allocation */
    p_FmMacsecSecY->p_TxSc = (t_SecYSc *)XX_Malloc(sizeof(t_SecYSc) * p_FmMacsecSecY->numOfTxSc);
    if (!p_FmMacsecSecY->p_TxSc)
        RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FM MACSEC SECY TX SC"));
    memset(p_FmMacsecSecY->p_TxSc, 0, sizeof(t_SecYSc) * p_FmMacsecSecY->numOfTxSc);

    if ((err = FmMacsecAllocScs(p_FmMacsecSecY->h_FmMacsec, e_SC_TX, p_FmMacsecSecY->isPointToPoint, p_FmMacsecSecY->numOfTxSc, txScIds)) != E_OK)
    {
        if (p_FmMacsecSecY->p_TxSc)
            XX_Free(p_FmMacsecSecY->p_TxSc);
        if (p_FmMacsecSecY->p_RxSc)
            XX_Free(p_FmMacsecSecY->p_RxSc);
        return ERROR_CODE(err);
    }
    for (i=0; i<p_FmMacsecSecY->numOfTxSc; i++)
    {
        p_FmMacsecSecY->p_TxSc[i].scId  = txScIds[i];
        p_FmMacsecSecY->p_TxSc[i].type  = e_SC_TX;
        for (j=0; j<MAX_NUM_OF_SA_PER_SC;j++)
            p_FmMacsecSecY->p_TxSc[i].sa[j].saId = (e_ScSaId)SECY_AN_FREE_VALUE;
        FmMacsecRegisterIntr(p_FmMacsecSecY->h_FmMacsec,
                             e_FM_MACSEC_MOD_SC_TX,
                             (uint8_t)txScIds[i],
                             e_FM_INTR_TYPE_ERR,
                             FmMacsecSecYExceptionsIsr,
                             p_FmMacsecSecY);
        FmMacsecRegisterIntr(p_FmMacsecSecY->h_FmMacsec,
                             e_FM_MACSEC_MOD_SC_TX,
                             (uint8_t)txScIds[i],
                             e_FM_INTR_TYPE_NORMAL,
                             FmMacsecSecYEventsIsr,
                             p_FmMacsecSecY);

        if (p_FmMacsecSecY->exceptions & FM_MACSEC_SECY_EX_FRAME_DISCARDED)
            FmMacsecSetException(p_FmMacsecSecY->h_FmMacsec, e_FM_MACSEC_EX_TX_SC, txScIds[i], TRUE);
        if (p_FmMacsecSecY->events & FM_MACSEC_SECY_EV_NEXT_PN)
            FmMacsecSetEvent(p_FmMacsecSecY->h_FmMacsec, e_FM_MACSEC_EV_TX_SC_NEXT_PN, txScIds[i], TRUE);
    }

    FmMacsecSecYCreateSc(p_FmMacsecSecY,
                         p_FmMacsecSecYDriverParam->txScParams.sci,
                         p_FmMacsecSecYDriverParam->txScParams.cipherSuite,
                         e_SC_TX);
    XX_Free(p_FmMacsecSecYDriverParam);
    p_FmMacsecSecY->p_FmMacsecSecYDriverParam = NULL;

    return E_OK;
}

t_Error FM_MACSEC_SECY_Free(t_Handle h_FmMacsecSecY)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_Error         err             = E_OK;
    uint32_t        rxScIds[NUM_OF_RX_SC], txScIds[NUM_OF_TX_SC], i;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    if (p_FmMacsecSecY->isPointToPoint)
        FmMacsecSetPTP(p_FmMacsecSecY->h_FmMacsec, FALSE);
    if (p_FmMacsecSecY->p_RxSc)
    {
        for (i=0; i<p_FmMacsecSecY->numOfRxSc; i++)
            rxScIds[i] = p_FmMacsecSecY->p_RxSc[i].scId;
        if ((err = FmMacsecFreeScs(p_FmMacsecSecY->h_FmMacsec, e_SC_RX, p_FmMacsecSecY->numOfRxSc, rxScIds)) != E_OK)
            return ERROR_CODE(err);
        XX_Free(p_FmMacsecSecY->p_RxSc);
    }
    if (p_FmMacsecSecY->p_TxSc)
    {
       FmMacsecSecYDeleteSc(p_FmMacsecSecY, &p_FmMacsecSecY->p_TxSc[0], e_SC_TX);

       for (i=0; i<p_FmMacsecSecY->numOfTxSc; i++) {
             txScIds[i] = p_FmMacsecSecY->p_TxSc[i].scId;
            FmMacsecUnregisterIntr(p_FmMacsecSecY->h_FmMacsec,
                                 e_FM_MACSEC_MOD_SC_TX,
                                 (uint8_t)txScIds[i],
                                 e_FM_INTR_TYPE_ERR);
            FmMacsecUnregisterIntr(p_FmMacsecSecY->h_FmMacsec,
                                 e_FM_MACSEC_MOD_SC_TX,
                                 (uint8_t)txScIds[i],
                                 e_FM_INTR_TYPE_NORMAL);

            if (p_FmMacsecSecY->exceptions & FM_MACSEC_SECY_EX_FRAME_DISCARDED)
                FmMacsecSetException(p_FmMacsecSecY->h_FmMacsec, e_FM_MACSEC_EX_TX_SC, txScIds[i], FALSE);
            if (p_FmMacsecSecY->events & FM_MACSEC_SECY_EV_NEXT_PN)
                FmMacsecSetEvent(p_FmMacsecSecY->h_FmMacsec, e_FM_MACSEC_EV_TX_SC_NEXT_PN, txScIds[i], FALSE);
       }

        if ((err = FmMacsecFreeScs(p_FmMacsecSecY->h_FmMacsec, e_SC_TX, p_FmMacsecSecY->numOfTxSc, txScIds)) != E_OK)
            return ERROR_CODE(err);
        XX_Free(p_FmMacsecSecY->p_TxSc);
    }

    XX_Free(p_FmMacsecSecY);

    return err;
}

t_Error FM_MACSEC_SECY_ConfigSciInsertionMode(t_Handle h_FmMacsecSecY, e_FmMacsecSciInsertionMode sciInsertionMode)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    p_FmMacsecSecY->sciInsertionMode = sciInsertionMode;

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigProtectFrames(t_Handle h_FmMacsecSecY, bool protectFrames)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    p_FmMacsecSecY->protectFrames = protectFrames;

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigReplayWindow(t_Handle h_FmMacsecSecY, bool replayProtect, uint32_t replayWindow)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    p_FmMacsecSecY->replayProtect   = replayProtect;
    p_FmMacsecSecY->replayWindow    = replayWindow;

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigValidationMode(t_Handle h_FmMacsecSecY, e_FmMacsecValidFrameBehavior validateFrames)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    p_FmMacsecSecY->validateFrames = validateFrames;

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigConfidentiality(t_Handle h_FmMacsecSecY, bool confidentialityEnable, uint16_t confidentialityOffset)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    p_FmMacsecSecY->confidentialityEnable = confidentialityEnable;
    p_FmMacsecSecY->confidentialityOffset = confidentialityOffset;

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigPointToPoint(t_Handle h_FmMacsecSecY)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    p_FmMacsecSecY->numOfRxSc = 1;
    p_FmMacsecSecY->isPointToPoint = TRUE;
    p_FmMacsecSecY->sciInsertionMode = e_FM_MACSEC_SCI_INSERTION_MODE_IMPLICT_PTP;

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigException(t_Handle h_FmMacsecSecY, e_FmMacsecSecYExceptions exception, bool enable)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    uint32_t        bitMask         = 0;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    GET_EXCEPTION_FLAG(bitMask, exception);
    if (bitMask)
    {
        if (enable)
            p_FmMacsecSecY->exceptions |= bitMask;
        else
            p_FmMacsecSecY->exceptions &= ~bitMask;
    }
    else
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));

    return E_OK;
}

t_Error FM_MACSEC_SECY_ConfigEvent(t_Handle h_FmMacsecSecY, e_FmMacsecSecYEvents event, bool enable)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    uint32_t        bitMask         = 0;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);

    GET_EVENT_FLAG(bitMask, event);
    if (bitMask)
    {
        if (enable)
            p_FmMacsecSecY->events |= bitMask;
        else
            p_FmMacsecSecY->events &= ~bitMask;
    }
    else
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined event"));

    return E_OK;
}

t_Handle FM_MACSEC_SECY_CreateRxSc(t_Handle h_FmMacsecSecY, t_FmMacsecSecYSCParams *p_ScParams)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;

    SANITY_CHECK_RETURN_VALUE(p_FmMacsecSecY, E_INVALID_HANDLE, NULL);
    SANITY_CHECK_RETURN_VALUE(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE, NULL);
    SANITY_CHECK_RETURN_VALUE(p_ScParams, E_NULL_POINTER, NULL);
    SANITY_CHECK_RETURN_VALUE(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE, NULL);

    return FmMacsecSecYCreateSc(p_FmMacsecSecY, p_ScParams->sci, p_ScParams->cipherSuite, e_SC_RX);
}

t_Error FM_MACSEC_SECY_DeleteRxSc(t_Handle h_FmMacsecSecY, t_Handle h_Sc)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);

    return FmMacsecSecYDeleteSc(p_FmMacsecSecY, p_FmSecYSc, e_SC_RX);
}

t_Error FM_MACSEC_SECY_CreateRxSa(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an, uint32_t lowestPn, macsecSAKey_t key)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId != SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is already assigned",an));

    if ((err = FmMacsecCreateRxSa(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, (e_ScSaId)p_FmSecYSc->numOfSa, an, lowestPn, key)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->sa[an].saId = (e_ScSaId)p_FmSecYSc->numOfSa++;
    return err;
}

t_Error FM_MACSEC_SECY_DeleteRxSa(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err             = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is already deleted",an));

    if ((err = FmMacsecDeleteRxSa(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->numOfSa--;
    p_FmSecYSc->sa[an].saId = (e_ScSaId)SECY_AN_FREE_VALUE;
    /* TODO - check if statistics need to be read*/
    return err;
}

t_Error FM_MACSEC_SECY_RxSaEnableReceive(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is not configured",an));

    if ((err = FmMacsecRxSaSetReceive(p_FmMacsecSecY->h_FmMacsec,p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, TRUE)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->sa[an].active = TRUE;
    return err;
}

t_Error FM_MACSEC_SECY_RxSaDisableReceive(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is not configured",an));

    if ((err = FmMacsecRxSaSetReceive(p_FmMacsecSecY->h_FmMacsec,p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, FALSE)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->sa[an].active = FALSE;
    return err;
}

t_Error FM_MACSEC_SECY_RxSaUpdateNextPn(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an, uint32_t updtNextPN)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is not configured",an));

    if ((err = FmMacsecRxSaUpdateNextPn(p_FmMacsecSecY->h_FmMacsec,p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, updtNextPN)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    return err;
}

t_Error FM_MACSEC_SECY_RxSaUpdateLowestPn(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an, uint32_t updtLowestPN)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is not configured",an));

    if ((err = FmMacsecRxSaUpdateLowestPn(p_FmMacsecSecY->h_FmMacsec,p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, updtLowestPN)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    return err;
}

t_Error FM_MACSEC_SECY_RxSaModifyKey(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an, macsecSAKey_t key)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc     = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is not configured",an));

    if (p_FmSecYSc->sa[an].active)
        if ((err = FmMacsecRxSaSetReceive(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, FALSE)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);

    /* TODO - statistics should be read */

    if ((err = FmMacsecCreateRxSa(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, an, 1, key)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    if (p_FmSecYSc->sa[an].active)
        if ((err = FmMacsecRxSaSetReceive(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId, TRUE)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
    return err;
}


t_Error FM_MACSEC_SECY_CreateTxSa(t_Handle h_FmMacsecSecY, macsecAN_t an, macsecSAKey_t key)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    p_FmSecYSc = &p_FmMacsecSecY->p_TxSc[0];
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId != SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, err, ("An %d is already assigned",an));

    if ((err = FmMacsecCreateTxSa(p_FmMacsecSecY->h_FmMacsec,p_FmSecYSc->scId, (e_ScSaId)p_FmSecYSc->numOfSa, key)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->sa[an].saId = (e_ScSaId)p_FmSecYSc->numOfSa++;
    return err;
}

t_Error FM_MACSEC_SECY_DeleteTxSa(t_Handle h_FmMacsecSecY, macsecAN_t an)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    p_FmSecYSc = &p_FmMacsecSecY->p_TxSc[0];
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is already deleted",an));

    if ((err = FmMacsecDeleteTxSa(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, p_FmSecYSc->sa[an].saId)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    p_FmSecYSc->numOfSa--;
    p_FmSecYSc->sa[an].saId = (e_ScSaId)SECY_AN_FREE_VALUE;
    /* TODO - check if statistics need to be read*/
    return err;
}

t_Error FM_MACSEC_SECY_TxSaModifyKey(t_Handle h_FmMacsecSecY, macsecAN_t nextActiveAn, macsecSAKey_t key)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc;
    macsecAN_t      currentAn;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    p_FmSecYSc = &p_FmMacsecSecY->p_TxSc[0];
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(nextActiveAn < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if ((err = FmMacsecTxSaGetActive(p_FmMacsecSecY->h_FmMacsec,
                                     p_FmSecYSc->scId,
                                     &currentAn)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    if ((err = FmMacsecTxSaSetActive(p_FmMacsecSecY->h_FmMacsec,
                                     p_FmSecYSc->scId,
                                     p_FmSecYSc->sa[nextActiveAn].saId,
                                     nextActiveAn)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    /* TODO - statistics should be read */

    if ((err = FmMacsecCreateTxSa(p_FmMacsecSecY->h_FmMacsec, p_FmSecYSc->scId, p_FmSecYSc->sa[currentAn].saId, key)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    return err;
}

t_Error FM_MACSEC_SECY_TxSaSetActive(t_Handle h_FmMacsecSecY, macsecAN_t an)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    p_FmSecYSc = &p_FmMacsecSecY->p_TxSc[0];
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(an < MAX_NUM_OF_SA_PER_SC, E_INVALID_STATE);

    if (p_FmSecYSc->sa[an].saId == SECY_AN_FREE_VALUE)
        RETURN_ERROR(MINOR, E_INVALID_STATE, ("An %d is not configured",an));

    if ((err = FmMacsecTxSaSetActive(p_FmMacsecSecY->h_FmMacsec,
                                     p_FmSecYSc->scId,
                                     p_FmSecYSc->sa[an].saId,
                                     an)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    return err;
}

t_Error FM_MACSEC_SECY_TxSaGetActive(t_Handle h_FmMacsecSecY, macsecAN_t *p_An)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    p_FmSecYSc = &p_FmMacsecSecY->p_TxSc[0];
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_An, E_INVALID_HANDLE);

    if ((err = FmMacsecTxSaGetActive(p_FmMacsecSecY->h_FmMacsec,
                                     p_FmSecYSc->scId,
                                     p_An)) != E_OK)
        RETURN_ERROR(MINOR, err, NO_MSG);

    return err;
}

t_Error FM_MACSEC_SECY_GetRxScPhysId(t_Handle h_FmMacsecSecY, t_Handle h_Sc, uint32_t *p_ScPhysId)
{
    t_SecYSc        *p_FmSecYSc = (t_SecYSc *)h_Sc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(h_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(((t_FmMacsecSecY *)h_FmMacsecSecY)->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!((t_FmMacsecSecY *)h_FmMacsecSecY)->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);
#ifdef DISABLE_SANITY_CHECKS
    UNUSED(h_FmMacsecSecY);
#endif /* DISABLE_SANITY_CHECKS */

    *p_ScPhysId = p_FmSecYSc->scId;
    return err;
}

t_Error FM_MACSEC_SECY_GetTxScPhysId(t_Handle h_FmMacsecSecY, uint32_t *p_ScPhysId)
{
    t_FmMacsecSecY  *p_FmMacsecSecY = (t_FmMacsecSecY *)h_FmMacsecSecY;
    t_SecYSc        *p_FmSecYSc;
    t_Error         err = E_OK;

    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_FmMacsecSecY->h_FmMacsec, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_FmMacsecSecY->p_FmMacsecSecYDriverParam, E_INVALID_STATE);
    p_FmSecYSc = &p_FmMacsecSecY->p_TxSc[0];
    SANITY_CHECK_RETURN_ERROR(p_FmSecYSc, E_INVALID_HANDLE);

    *p_ScPhysId = p_FmSecYSc->scId;
    return err;
}

t_Error FM_MACSEC_SECY_SetException(t_Handle h_FmMacsecSecY, e_FmMacsecExceptions exception, bool enable)
{
   UNUSED(h_FmMacsecSecY);UNUSED(exception);UNUSED(enable);
   RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}

t_Error FM_MACSEC_SECY_SetEvent(t_Handle h_FmMacsecSecY, e_FmMacsecSecYEvents event, bool enable)
{
    UNUSED(h_FmMacsecSecY);UNUSED(event);UNUSED(enable);
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}

t_Error FM_MACSEC_SECY_GetStatistics(t_Handle h_FmMacsecSecY, t_FmMacsecSecYStatistics *p_Statistics)
{
    UNUSED(h_FmMacsecSecY);UNUSED(p_Statistics);
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}

t_Error FM_MACSEC_SECY_RxScGetStatistics(t_Handle h_FmMacsecSecY, t_Handle h_Sc, t_FmMacsecSecYRxScStatistics *p_Statistics)
{
    UNUSED(h_FmMacsecSecY);UNUSED(h_Sc);UNUSED(p_Statistics);
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}

t_Error FM_MACSEC_SECY_RxSaGetStatistics(t_Handle h_FmMacsecSecY, t_Handle h_Sc, macsecAN_t an, t_FmMacsecSecYRxSaStatistics *p_Statistics)
{
    UNUSED(h_FmMacsecSecY);UNUSED(h_Sc);UNUSED(an);UNUSED(p_Statistics);
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}

t_Error FM_MACSEC_SECY_TxScGetStatistics(t_Handle h_FmMacsecSecY, t_FmMacsecSecYTxScStatistics *p_Statistics)
{
    UNUSED(h_FmMacsecSecY);UNUSED(p_Statistics);
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}

t_Error FM_MACSEC_SECY_TxSaGetStatistics(t_Handle h_FmMacsecSecY, macsecAN_t an, t_FmMacsecSecYTxSaStatistics *p_Statistics)
{
    UNUSED(h_FmMacsecSecY);UNUSED(an);UNUSED(p_Statistics);
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, NO_MSG);
}