FAPI code enclosed under FAPI flag
[o-du/l2.git] / src / 5gnrmac / lwr_mac_fsm.c
1  /*******************************************************************************
2  ################################################################################
3  #   Copyright (c) [2017-2019] [Radisys]                                        #
4  #                                                                              #
5  #   Licensed under the Apache License, Version 2.0 (the "License");            #
6  #   you may not use this file except in compliance with the License.           #
7  #   You may obtain a copy of the License at                                    #
8  #                                                                              #
9  #       http://www.apache.org/licenses/LICENSE-2.0                             #
10  #                                                                              #
11  #   Unless required by applicable law or agreed to in writing, software        #
12  #   distributed under the License is distributed on an "AS IS" BASIS,          #
13  #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14  #   See the License for the specific language governing permissions and        #
15  #   limitations under the License.                                             #
16  ################################################################################
17  *******************************************************************************/
18
19 #include <stdlib.h>
20 #include <stdint.h>
21
22 /* header include files -- defines (.h) */
23 #include "envopt.h"        /* environment options */
24 #include "envdep.h"        /* environment dependent */
25 #include "envind.h"        /* environment independent */
26 #include "gen.h"           /* general layer */
27 #include "ssi.h"           /* system service interface */
28 #include "cm_hash.h"       /* common hash list */
29 #include "cm_mblk.h"       /* common memory link list library */
30 #include "cm_llist.h"      /* common linked list library */
31 #include "cm_err.h"        /* common error */
32 #include "cm_lte.h"        /* common LTE */
33 #include "lrg.h"           /* Layer manager interface includes*/
34 #include "crg.h"           /* CRG interface includes*/
35 #include "rgu.h"           /* RGU interface includes*/
36 #include "tfu.h"           /* TFU interface includes */
37 #include "rg_sch_inf.h"    /* SCH interface includes */
38 #include "rg_prg.h"       /* PRG (MAC-MAC) interface includes*/
39 #include "rg_env.h"       /* MAC environmental includes*/
40 #include "rg.h"           /* MAC includes*/
41 #include "rg_err.h"       /* MAC error includes*/
42 #include "du_log.h"
43 #include "lwr_mac_fsm.h"
44
45 /* header/extern include files (.x) */
46 #include "gen.x"           /* general layer typedefs */
47 #include "ssi.x"           /* system services typedefs */
48 #include "cm5.x"           /* common timers */
49 #include "cm_hash.x"       /* common hash list */
50 #include "cm_lib.x"        /* common library */
51 #include "cm_llist.x"      /* common linked list */
52 #include "cm_mblk.x"       /* memory management */
53 #include "cm_tkns.x"       /* common tokens */
54 #include "cm_lte.x"       /* common tokens */
55 #include "rgu.x"           /* RGU types */
56 #include "tfu.x"           /* RGU types */
57 #include "lrg.x"           /* layer management typedefs for MAC */
58 #include "crg.x"           /* CRG interface includes */
59 #include "rg_sch_inf.x"    /* SCH interface typedefs */
60 #include "rg_prg.x"        /* PRG (MAC-MAC) Interface typedefs */
61 #include "du_app_mac_inf.h"
62 #include "mac.h"
63 #include "rg.x"            /* typedefs for MAC */
64
65 #define MIB_SFN_BITMASK 0xFC
66 #define SSB_PDU_TYPE 3
67 #define SETLENGTH(x, size) x += size
68
69
70 EXTERN void sendToPhy ARGS((uint8_t msgType, uint32_t msgLen, void *msg));
71 SlotIndInfo slotIndInfo;   //global variable
72
73  /*******************************************************************
74   *
75   * @brief Handles Invalid Request Event
76   *
77   * @details
78   *
79   *    Function : lwr_mac_handleInvalidEvt
80   *
81   *    Functionality:
82   *         - Displays the PHY state when the invalid event occurs
83   *
84   * @params[in]
85   * @return ROK     - success
86   *         RFAILED - failure
87   *
88   * ****************************************************************/
89 S16 lwr_mac_handleInvalidEvt(void *msg)
90 {
91   printf("\nLOWER MAC: Error Indication Event[%d] received in state [%d]", clGlobalCp.event, clGlobalCp.phyState);
92   RETVALUE(ROK);
93 }
94
95 #ifdef FAPI
96 /*******************************************************************
97   *
98   * @brief Fills FAPI message header
99   *
100   * @details
101   *
102   *    Function : fillMsgHeader
103   *
104   *    Functionality:
105   *         -Fills FAPI message header
106   *
107   * @params[in] Pointer to header
108   *             Number of messages
109   *             Messae Type
110   *             Length of message
111   * @return void
112   *
113   * ****************************************************************/
114 PUBLIC void fillMsgHeader(fapi_msg_t *hdr, uint16_t msgType, uint16_t msgLen)
115 {
116    hdr->message_type_id = msgType;
117    hdr->length = msgLen;
118 }
119
120 /*******************************************************************
121   *
122   * @brief Fills FAPI Config Request message header
123   *
124   * @details
125   *
126   *    Function : fillTlvs
127   *
128   *    Functionality:
129   *         -Fills FAPI Config Request message header
130   *
131   * @params[in] Pointer to TLV
132   *             Tag
133   *             Length
134   *             Value
135   *             MsgLen
136   * @return void
137   *
138   * ****************************************************************/
139 PUBLIC void fillTlvs(fapi_uint16_tlv_t *tlv, uint16_t tag, uint16_t length,
140 uint16_t value, uint32_t *msgLen)
141 {
142    tlv->tl.tag    = tag;
143    tlv->tl.length = length;
144    tlv->value     = value;
145    *msgLen        = *msgLen + sizeof(tag) + sizeof(length) + length;
146 }
147  /*******************************************************************
148   *
149   * @brief fills the cyclic prefix by comparing the bitmask
150   *
151   * @details
152   *
153   *    Function : fillCyclicPrefix
154   *
155   *    Functionality:
156   *         -checks the value with the bitmask and
157   *          fills the cellPtr's cyclic prefix.
158   *
159   * @params[in] Pointer to ClCellParam
160   *             Value to be compared
161   * @return void
162   *
163   ********************************************************************/
164 PUBLIC void fillCyclicPrefix(uint8_t value, ClCellParam **cellPtr)
165 {
166    if((value & FAPI_NORMAL_CYCLIC_PREFIX_MASK) == FAPI_NORMAL_CYCLIC_PREFIX_MASK)
167    {
168       (*cellPtr)->cyclicPrefix   = NORMAL_CYCLIC_PREFIX_MASK;
169    }
170    else if((value & FAPI_EXTENDED_CYCLIC_PREFIX_MASK) == FAPI_EXTENDED_CYCLIC_PREFIX_MASK)
171    {
172       (*cellPtr)->cyclicPrefix   = EXTENDED_CYCLIC_PREFIX_MASK;
173    }
174    else
175    {
176       (*cellPtr)->cyclicPrefix = INVALID_VALUE;
177    }
178 }
179
180  /*******************************************************************
181   *
182   * @brief fills the subcarrier spacing of Downlink by comparing the bitmask
183   *
184   * @details
185   *
186   *    Function : fillSubcarrierSpaceDl
187   *
188   *    Functionality:
189   *         -checks the value with the bitmask and
190   *          fills the cellPtr's subcarrier spacing in DL
191   *
192   * @params[in] Pointer to ClCellParam
193   *             Value to be compared
194   * @return void
195   *
196   * ****************************************************************/
197
198 PUBLIC void fillSubcarrierSpaceDl(uint8_t value, ClCellParam **cellPtr)
199 {
200    if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
201    {
202       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_15_KHZ;
203    }
204    else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
205    {
206       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_30_KHZ;
207    }
208    else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
209    {
210       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_60_KHZ;
211    }
212    else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
213    {
214       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_120_KHZ;
215    }
216    else
217    {
218       (*cellPtr)->supportedSubcarrierSpacingDl = INVALID_VALUE;
219    }
220 }
221
222  /*******************************************************************
223   *
224   * @brief fills the downlink bandwidth by comparing the bitmask
225   *
226   * @details
227   *
228   *    Function : fillBandwidthDl
229   *
230   *    Functionality:
231   *         -checks the value with the bitmask and
232   *         -fills the cellPtr's DL Bandwidth
233   *
234   * @params[in] Pointer to ClCellParam
235   *             Value to be compared
236   * @return void
237   *
238   * ****************************************************************/
239
240 PUBLIC void fillBandwidthDl(uint16_t value, ClCellParam **cellPtr)
241 {
242    if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
243    {
244       (*cellPtr)->supportedBandwidthDl = BW_5MHZ;
245    }
246    else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
247    {
248       (*cellPtr)->supportedBandwidthDl = BW_10MHZ;
249    }
250    else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
251    {
252       (*cellPtr)->supportedBandwidthDl = BW_15MHZ;
253    }
254    else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
255    {
256       (*cellPtr)->supportedBandwidthDl = BW_20MHZ;
257    }
258    else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
259    {
260       (*cellPtr)->supportedBandwidthDl = BW_40MHZ;
261    }
262    else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
263    {
264       (*cellPtr)->supportedBandwidthDl = BW_50MHZ;
265    }
266    else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
267    {
268       (*cellPtr)->supportedBandwidthDl = BW_60MHZ;
269    }
270    else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
271    {
272       (*cellPtr)->supportedBandwidthDl = BW_70MHZ;
273    }
274    else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
275    {
276       (*cellPtr)->supportedBandwidthDl = BW_80MHZ;
277    }
278    else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
279    {
280       (*cellPtr)->supportedBandwidthDl = BW_90MHZ;
281    }
282    else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
283    {
284       (*cellPtr)->supportedBandwidthDl = BW_100MHZ;
285    }
286    else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
287    {
288       (*cellPtr)->supportedBandwidthDl = BW_200MHZ;
289    }
290    else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
291    {
292       (*cellPtr)->supportedBandwidthDl = BW_400MHZ;
293    }
294    else
295    {
296       (*cellPtr)->supportedBandwidthDl = INVALID_VALUE;
297    }
298 }
299
300  /*******************************************************************
301   *
302   * @brief fills the subcarrier spacing of Uplink by comparing the bitmask
303   *
304   * @details
305   *
306   *    Function : fillSubcarrierSpaceUl
307   *
308   *    Functionality:
309   *         -checks the value with the bitmask and
310   *         -fills cellPtr's subcarrier spacing in UL
311   *
312   * @params[in] Pointer to ClCellParam
313   *             Value to be compared
314   * @return void
315   *
316   * ****************************************************************/
317
318 PUBLIC void fillSubcarrierSpaceUl(uint8_t value, ClCellParam **cellPtr)
319 {
320    if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
321    {
322       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_15_KHZ;
323    }
324    else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
325    {
326       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_30_KHZ;
327    }
328    else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
329    {
330       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_60_KHZ;
331    }
332    else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
333    {
334       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_120_KHZ;
335    }
336    else
337    {
338       (*cellPtr)->supportedSubcarrierSpacingsUl = INVALID_VALUE;
339    }
340 }
341
342  /*******************************************************************
343   *
344   * @brief fills the uplink bandwidth by comparing the bitmask
345   *
346   * @details
347   *
348   *    Function : fillBandwidthUl
349   *
350   *    Functionality:
351   *         -checks the value with the bitmask and
352   *          fills the cellPtr's UL Bandwidth
353   *
354   *
355   *
356   * @params[in] Pointer to ClCellParam
357   *             Value to be compared
358   * @return void
359   *
360   *
361   * ****************************************************************/
362
363 PUBLIC void fillBandwidthUl(uint16_t value, ClCellParam **cellPtr)
364 {
365    if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
366    {
367       (*cellPtr)->supportedBandwidthUl = BW_5MHZ;
368    }
369    else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
370    {
371       (*cellPtr)->supportedBandwidthUl = BW_10MHZ;
372    }
373    else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
374    {
375       (*cellPtr)->supportedBandwidthUl = BW_15MHZ;
376    }
377    else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
378    {
379       (*cellPtr)->supportedBandwidthUl = BW_20MHZ;
380    }
381    else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
382    {
383       (*cellPtr)->supportedBandwidthUl = BW_40MHZ;
384    }
385    else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
386    {
387       (*cellPtr)->supportedBandwidthUl = BW_50MHZ;
388    }
389    else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
390    {
391       (*cellPtr)->supportedBandwidthUl = BW_60MHZ;
392    }
393    else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
394    {
395       (*cellPtr)->supportedBandwidthUl = BW_70MHZ;
396    }
397    else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
398    {
399       (*cellPtr)->supportedBandwidthUl = BW_80MHZ;
400    }
401    else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
402    {
403       (*cellPtr)->supportedBandwidthUl = BW_90MHZ;
404    }
405    else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
406    {
407       (*cellPtr)->supportedBandwidthUl = BW_100MHZ;
408    }
409    else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
410    {
411       (*cellPtr)->supportedBandwidthUl = BW_200MHZ;
412    }
413    else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
414    {
415       (*cellPtr)->supportedBandwidthUl = BW_400MHZ;
416    }
417    else
418    {
419       (*cellPtr)->supportedBandwidthUl = INVALID_VALUE;
420    }
421 }
422  /*******************************************************************
423   *
424   * @brief fills the CCE maping by comparing the bitmask
425   *
426   * @details
427   *
428   *    Function : fillCCEmaping
429   *
430   *    Functionality:
431   *         -checks the value with the bitmask and
432   *          fills the cellPtr's CCE Mapping Type
433   *
434   *
435   * @params[in] Pointer to ClCellParam
436   *             Value to be compared
437   * @return void
438   *
439   * ****************************************************************/
440
441 PUBLIC void fillCCEmaping(uint8_t value,  ClCellParam **cellPtr)
442 {
443    if ((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_INTERLEAVED_MASK)
444    {
445       (*cellPtr)->cceMappingType = CCE_MAPPING_INTERLEAVED_MASK;
446    }
447    else if((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_NONINTERLVD_MASK)
448    {
449       (*cellPtr)->cceMappingType = CCE_MAPPING_NONINTERLVD_MASK;
450    }
451    else
452    {
453       (*cellPtr)->cceMappingType = INVALID_VALUE;
454    }
455 }
456
457  /*******************************************************************
458   *
459   * @brief fills the PUCCH format by comparing the bitmask
460   *
461   * @details
462   *
463   *    Function : fillPucchFormat
464   *
465   *    Functionality:
466   *         -checks the value with the bitmask and
467   *          fills the cellPtr's pucch format
468   *
469   *
470   * @params[in] Pointer to ClCellParam
471   *             Value to be compared
472   * @return void
473   *
474   * ****************************************************************/
475
476 PUBLIC void fillPucchFormat(uint8_t value, ClCellParam **cellPtr)
477 {
478    if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
479    {
480       (*cellPtr)->pucchFormats    = FORMAT_0;
481    }
482    else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
483    {
484       (*cellPtr)->pucchFormats    = FORMAT_1;
485    }
486    else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
487    {
488       (*cellPtr)->pucchFormats    = FORMAT_2;
489    }
490    else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
491    {
492       (*cellPtr)->pucchFormats    = FORMAT_3;
493    }
494    else if((value & FAPI_FORMAT_4_MASK) == FAPI_FORMAT_4_MASK)
495    {
496       (*cellPtr)->pucchFormats    = FORMAT_4;
497    }
498    else
499    {
500       (*cellPtr)->pucchFormats    = INVALID_VALUE;
501    }
502 }
503
504  /*******************************************************************
505   *
506   * @brief fills the PDSCH Mapping Type by comparing the bitmask
507   *
508   * @details
509   *
510   *    Function : fillPdschMappingType
511   *
512   *    Functionality:
513   *         -checks the value with the bitmask and
514   *          fills the cellPtr's PDSCH MappingType
515   *
516   * @params[in] Pointer to ClCellParam
517   *             Value to be compared
518   * @return void
519   *
520   * ****************************************************************/
521
522 PUBLIC void fillPdschMappingType(uint8_t value, ClCellParam **cellPtr)
523 {
524    if((value & FAPI_PDSCH_MAPPING_TYPE_A_MASK) == FAPI_PDSCH_MAPPING_TYPE_A_MASK)
525    {
526       (*cellPtr)->pdschMappingType = MAPPING_TYPE_A;
527    }
528    else if((value & FAPI_PDSCH_MAPPING_TYPE_B_MASK) == FAPI_PDSCH_MAPPING_TYPE_B_MASK)
529    {
530       (*cellPtr)->pdschMappingType = MAPPING_TYPE_B;
531    }
532    else
533    {
534       (*cellPtr)->pdschMappingType = INVALID_VALUE;
535    }
536 }
537
538 /*******************************************************************
539   *
540   * @brief fills the PDSCH Allocation Type by comparing the bitmask
541   *
542   * @details
543   *
544   *    Function : fillPdschAllocationType
545   *
546   *    Functionality:
547   *         -checks the value with the bitmask and
548   *          fills the cellPtr's PDSCH AllocationType
549   *
550   * @params[in] Pointer to ClCellParam
551   *             Value to be compared
552   * @return void
553   *
554   * ****************************************************************/
555
556 PUBLIC void fillPdschAllocationType(uint8_t value, ClCellParam **cellPtr)
557 {
558    if((value & FAPI_PDSCH_ALLOC_TYPE_0_MASK) == FAPI_PDSCH_ALLOC_TYPE_0_MASK)
559    {
560       (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_0;
561    }
562    else if((value & FAPI_PDSCH_ALLOC_TYPE_1_MASK) == FAPI_PDSCH_ALLOC_TYPE_1_MASK)
563    {
564       (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_1;
565    }
566    else
567    {
568       (*cellPtr)->pdschAllocationTypes = INVALID_VALUE;
569    }
570 }
571
572 /*******************************************************************
573   *
574   * @brief fills the PDSCH PRB Mapping Type by comparing the bitmask
575   *
576   * @details
577   *
578   *    Function : fillPrbMappingType
579   *
580   *    Functionality:
581   *         -checks the value with the bitmask and
582   *          fills the cellPtr's PRB Mapping Type
583   *
584   * @params[in] Pointer to ClCellParam
585   *             Value to be compared
586   * @return void
587   *
588   ******************************************************************/
589 PUBLIC void fillPrbMappingType(uint8_t value, ClCellParam **cellPtr)
590 {
591    if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
592    {
593       (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
594    }
595    else if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
596    {
597       (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
598    }
599    else
600    {
601       (*cellPtr)->pdschVrbToPrbMapping = INVALID_VALUE;
602    }
603 }
604
605 /*******************************************************************
606   *
607   * @brief fills the PDSCH DmrsConfig Type by comparing the bitmask
608   *
609   * @details
610   *
611   *    Function : fillPdschDmrsConfigType
612   *
613   *    Functionality:
614   *         -checks the value with the bitmask and
615   *          fills the cellPtr's DmrsConfig Type
616   *
617   * @params[in] Pointer to ClCellParam
618   *             Value to be compared
619   * @return void
620   *
621   ******************************************************************/
622
623 PUBLIC void fillPdschDmrsConfigType(uint8_t value, ClCellParam **cellPtr)
624 {
625   if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK)
626   {
627      (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
628   }
629   else if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK)
630   {
631      (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
632   }
633   else
634   {
635      (*cellPtr)->pdschDmrsConfigTypes = INVALID_VALUE;
636   }
637 }
638
639 /*******************************************************************
640   *
641   * @brief fills the PDSCH DmrsLength by comparing the bitmask
642   *
643   * @details
644   *
645   *    Function : fillPdschDmrsLength
646   *
647   *    Functionality:
648   *         -checks the value with the bitmask and
649   *          fills the cellPtr's PdschDmrsLength
650   *
651   * @params[in] Pointer to ClCellParam
652   *             Value to be compared
653   * @return void
654   *
655   ******************************************************************/
656 PUBLIC void fillPdschDmrsLength(uint8_t value, ClCellParam **cellPtr)
657 {
658    if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_1)
659    {
660       (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_1;
661    }
662    else if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_2)
663    {
664       (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_2;
665    }
666    else
667    {
668       (*cellPtr)->pdschDmrsMaxLength = INVALID_VALUE;
669    }
670 }
671
672 /*******************************************************************
673   *
674   * @brief fills the PDSCH Dmrs Additional Pos by comparing the bitmask
675   *
676   * @details
677   *
678   *    Function : fillPdschDmrsAddPos
679   *
680   *    Functionality:
681   *         -checks the value with the bitmask and
682   *          fills the cellPtr's Pdsch DmrsAddPos
683   *
684   * @params[in] Pointer to ClCellParam
685   *             Value to be compared
686   * @return void
687   *
688   ******************************************************************/
689
690 PUBLIC void fillPdschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
691 {
692    if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
693    {
694       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
695    }
696    else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
697    {
698       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
699    }
700    else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
701    {
702       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
703    }
704    else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
705    {
706       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
707    }
708    else
709    {
710       (*cellPtr)->pdschDmrsAdditionalPos = INVALID_VALUE;
711    }
712 }
713
714 /*******************************************************************
715   *
716   * @brief fills the Modulation Order in DL by comparing the bitmask
717   *
718   * @details
719   *
720   *    Function : fillModulationOrderDl
721   *
722   *    Functionality:
723   *         -checks the value with the bitmask and
724   *          fills the cellPtr's ModulationOrder in DL.
725   *
726   * @params[in] Pointer to ClCellParam
727   *             Value to be compared
728   * @return void
729   *
730   ******************************************************************/
731 PUBLIC void fillModulationOrderDl(uint8_t value, ClCellParam **cellPtr)
732 {
733    if(value == 0 )
734    {
735       (*cellPtr)->supportedMaxModulationOrderDl = MOD_QPSK;
736    }
737    else if(value == 1)
738    {
739       (*cellPtr)->supportedMaxModulationOrderDl = MOD_16QAM;
740    }
741    else if(value == 2)
742    {
743       (*cellPtr)->supportedMaxModulationOrderDl = MOD_64QAM;
744    }
745    else if(value == 3)
746    {
747       (*cellPtr)->supportedMaxModulationOrderDl = MOD_256QAM;
748    }
749    else
750    {
751       (*cellPtr)->supportedMaxModulationOrderDl = INVALID_VALUE;
752    }
753 }
754
755 /*******************************************************************
756   *
757   * @brief fills the PUSCH DmrsConfig Type by comparing the bitmask
758   *
759   * @details
760   *
761   *    Function : fillPuschDmrsConfigType
762   *
763   *    Functionality:
764   *         -checks the value with the bitmask and
765   *          fills the cellPtr's PUSCH DmrsConfigType
766   *
767   * @params[in] Pointer to ClCellParam
768   *             Value to be compared
769   * @return void
770   *
771   ******************************************************************/
772
773 PUBLIC void fillPuschDmrsConfig(uint8_t value, ClCellParam **cellPtr)
774 {
775    if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK)
776    {
777       (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
778    }
779    else if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK)
780    {
781       (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
782    }
783    else
784    {
785       (*cellPtr)->puschDmrsConfigTypes = INVALID_VALUE;
786    }
787 }
788
789 /*******************************************************************
790   *
791   * @brief fills the PUSCH DmrsLength by comparing the bitmask
792   *
793   * @details
794   *
795   *    Function : fillPuschDmrsLength
796   *
797   *    Functionality:
798   *         -checks the value with the bitmask and
799   *          fills the cellPtr's PUSCH DmrsLength
800   *
801   * @params[in] Pointer to ClCellParam
802   *             Value to be compared
803   * @return void
804   *
805   ******************************************************************/
806
807 PUBLIC void fillPuschDmrsLength(uint8_t value, ClCellParam **cellPtr)
808 {
809    if(value  == FAPI_PUSCH_DMRS_MAX_LENGTH_1)
810    {
811       (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_1;
812    }
813    else if(value  == FAPI_PUSCH_DMRS_MAX_LENGTH_2)
814    {
815       (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_2;
816    }
817    else
818    {
819       (*cellPtr)->puschDmrsMaxLength = INVALID_VALUE;
820    }
821 }
822
823 /*******************************************************************
824   *
825   * @brief fills the PUSCH Dmrs Additional position by comparing the bitmask
826   *
827   * @details
828   *
829   *    Function : fillPuschDmrsAddPos
830   *
831   *    Functionality:
832   *         -checks the value with the bitmask and
833   *          fills the cellPtr's PUSCH DmrsAddPos
834   *
835   * @params[in] Pointer to ClCellParam
836   *             Value to be compared
837   * @return void
838   *
839   ******************************************************************/
840
841 PUBLIC void fillPuschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
842 {
843    if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
844    {
845       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
846    }
847    else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
848    {
849       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
850    }
851    else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
852    {
853       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
854    }
855    else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
856    {
857       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
858    }
859    else
860    {
861       (*cellPtr)->puschDmrsAdditionalPos = INVALID_VALUE;
862    }
863 }
864
865 /*******************************************************************
866   *
867   * @brief fills the PUSCH Mapping Type by comparing the bitmask
868   *
869   * @details
870   *
871   *    Function : fillPuschMappingType
872   *
873   *    Functionality:
874   *         -checks the value with the bitmask and
875   *          fills the cellPtr's PUSCH MappingType
876   *
877   * @params[in] Pointer to ClCellParam
878   *             Value to be compared
879   * @return void
880   *
881   ******************************************************************/
882
883 PUBLIC void fillPuschMappingType(uint8_t value, ClCellParam **cellPtr)
884 {
885    if((value & FAPI_PUSCH_MAPPING_TYPE_A_MASK) == FAPI_PUSCH_MAPPING_TYPE_A_MASK)
886    {
887       (*cellPtr)->puschMappingType = MAPPING_TYPE_A;
888    }
889    else if((value & FAPI_PUSCH_MAPPING_TYPE_B_MASK) == FAPI_PUSCH_MAPPING_TYPE_B_MASK)
890    {
891       (*cellPtr)->puschMappingType = MAPPING_TYPE_B;
892    }
893    else
894    {
895       (*cellPtr)->puschMappingType = INVALID_VALUE;
896    }
897 }
898
899 /*******************************************************************
900   *
901   * @brief fills the PUSCH Allocation Type by comparing the bitmask
902   *
903   * @details
904   *
905   *    Function : fillPuschAllocationType
906   *
907   *    Functionality:
908   *         -checks the value with the bitmask and
909   *          fills the cellPtr's PUSCH AllocationType
910   *
911   * @params[in] Pointer to ClCellParam
912   *             Value to be compared
913   * @return void
914   *
915   ******************************************************************/
916
917 PUBLIC void fillPuschAllocationType(uint8_t value, ClCellParam **cellPtr)
918 {
919    if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
920    {
921       (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_0;
922    }
923    else if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
924    {
925       (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_1;
926    }
927    else
928    {
929       (*cellPtr)->puschAllocationTypes = INVALID_VALUE;
930    }
931 }
932
933 /*******************************************************************
934   *
935   * @brief fills the PUSCH PRB Mapping Type by comparing the bitmask
936   *
937   * @details
938   *
939   *    Function : fillPuschPrbMappingType
940   *
941   *    Functionality:
942   *         -checks the value with the bitmask and
943   *          fills the cellPtr's PUSCH PRB MApping Type
944   *
945   * @params[in] Pointer to ClCellParam
946   *             Value to be compared
947   * @return void
948   *
949   ******************************************************************/
950
951 PUBLIC void fillPuschPrbMappingType(uint8_t value, ClCellParam **cellPtr)
952 {
953    if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
954    {
955       (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
956    }
957    else if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
958    {
959       (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
960    }
961    else
962    {
963       (*cellPtr)->puschVrbToPrbMapping = INVALID_VALUE;
964    }
965 }
966
967 /*******************************************************************
968   *
969   * @brief fills the Modulation Order in Ul by comparing the bitmask
970   *
971   * @details
972   *
973   *    Function : fillModulationOrderUl
974   *
975   *    Functionality:
976   *         -checks the value with the bitmask and
977   *          fills the cellPtr's Modualtsion Order in UL.
978   *
979   * @params[in] Pointer to ClCellParam
980   *             Value to be compared
981   * @return void
982   *
983   ******************************************************************/
984
985 PUBLIC void fillModulationOrderUl(uint8_t value, ClCellParam **cellPtr)
986 {
987    if(value == 0)
988    {
989       (*cellPtr)->supportedModulationOrderUl = MOD_QPSK;
990    }
991    else if(value == 1)
992    {
993       (*cellPtr)->supportedModulationOrderUl = MOD_16QAM;
994    }
995    else if(value == 2)
996    {
997       (*cellPtr)->supportedModulationOrderUl = MOD_64QAM;
998    }
999    else if(value == 3)
1000    {
1001       (*cellPtr)->supportedModulationOrderUl = MOD_256QAM;
1002    }
1003    else
1004    {
1005       (*cellPtr)->supportedModulationOrderUl = INVALID_VALUE;
1006    }
1007 }
1008
1009 /*******************************************************************
1010   *
1011   * @brief fills the PUSCH Aggregation Factor by comparing the bitmask
1012   *
1013   * @details
1014   *
1015   *    Function : fillPuschAggregationFactor
1016   *
1017   *    Functionality:
1018   *         -checks the value with the bitmask and
1019   *          fills the cellPtr's PUSCH Aggregation Factor
1020   *
1021   * @params[in] Pointer to ClCellParam
1022   *             Value to be compared
1023   * @return void
1024   *
1025   ******************************************************************/
1026
1027 PUBLIC void fillPuschAggregationFactor(uint8_t value, ClCellParam **cellPtr)
1028 {
1029    if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
1030    {
1031       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_1;
1032    }
1033    else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
1034    {
1035       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_2;
1036    }
1037    else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
1038    {
1039       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_4;
1040    }
1041    else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
1042    {
1043       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_8;
1044    }
1045    else
1046    {
1047       (*cellPtr)->puschAggregationFactor    = INVALID_VALUE;
1048    }
1049 }
1050
1051 /*******************************************************************
1052   *
1053   * @brief fills the PRACH Long Format by comparing the bitmask
1054   *
1055   * @details
1056   *
1057   *    Function : fillPrachLongFormat
1058   *
1059   *    Functionality:
1060   *         -checks the value with the bitmask and
1061   *          fills the cellPtr's PRACH Long Format
1062   *
1063   * @params[in] Pointer to ClCellParam
1064   *             Value to be compared
1065   * @return void
1066   *
1067   ******************************************************************/
1068
1069 PUBLIC void fillPrachLongFormat(uint8_t value, ClCellParam **cellPtr)
1070 {
1071    if((value & FAPI_PRACH_LF_FORMAT_0_MASK) == FAPI_PRACH_LF_FORMAT_0_MASK)
1072    {
1073       (*cellPtr)->prachLongFormats    = FORMAT_0;
1074    }
1075    else if((value & FAPI_PRACH_LF_FORMAT_1_MASK) == FAPI_PRACH_LF_FORMAT_1_MASK)
1076    {
1077       (*cellPtr)->prachLongFormats    = FORMAT_1;
1078    }
1079    else if((value & FAPI_PRACH_LF_FORMAT_2_MASK) == FAPI_PRACH_LF_FORMAT_2_MASK)
1080    {
1081       (*cellPtr)->prachLongFormats    = FORMAT_2;
1082    }
1083    else if((value & FAPI_PRACH_LF_FORMAT_3_MASK) == FAPI_PRACH_LF_FORMAT_3_MASK)
1084    {
1085       (*cellPtr)->prachLongFormats    = FORMAT_3;
1086    }
1087    else
1088    {
1089       (*cellPtr)->prachLongFormats    = INVALID_VALUE;
1090    }
1091 }
1092
1093 /*******************************************************************
1094   *
1095   * @brief fills the PRACH Short Format by comparing the bitmask
1096   *
1097   * @details
1098   *
1099   *    Function : fillPrachShortFormat
1100   *
1101   *    Functionality:
1102   *         -checks the value with the bitmask and
1103   *          fills the cellPtr's PRACH ShortFormat
1104   *
1105   * @params[in] Pointer to ClCellParam
1106   *             Value to be compared
1107   * @return void
1108   *
1109   ******************************************************************/
1110
1111 PUBLIC void fillPrachShortFormat(uint8_t value, ClCellParam **cellPtr)
1112 {
1113    if((value & FAPI_PRACH_SF_FORMAT_A1_MASK) == FAPI_PRACH_SF_FORMAT_A1_MASK)
1114    {
1115       (*cellPtr)->prachShortFormats    = SF_FORMAT_A1;
1116    }
1117    else if((value & FAPI_PRACH_SF_FORMAT_A2_MASK) == FAPI_PRACH_SF_FORMAT_A2_MASK)
1118    {
1119       (*cellPtr)->prachShortFormats    = SF_FORMAT_A2;
1120    }
1121    else if((value & FAPI_PRACH_SF_FORMAT_A3_MASK) == FAPI_PRACH_SF_FORMAT_A3_MASK)
1122    {
1123       (*cellPtr)->prachShortFormats    = SF_FORMAT_A3;
1124    }
1125    else if((value & FAPI_PRACH_SF_FORMAT_B1_MASK) == FAPI_PRACH_SF_FORMAT_B1_MASK)
1126    {
1127       (*cellPtr)->prachShortFormats    = SF_FORMAT_B1;
1128    }
1129    else if((value & FAPI_PRACH_SF_FORMAT_B2_MASK) == FAPI_PRACH_SF_FORMAT_B2_MASK)
1130    {
1131       (*cellPtr)->prachShortFormats    = SF_FORMAT_B2;
1132    }
1133    else if((value & FAPI_PRACH_SF_FORMAT_B3_MASK) == FAPI_PRACH_SF_FORMAT_B3_MASK)
1134    {
1135       (*cellPtr)->prachShortFormats    = SF_FORMAT_B3;
1136    }
1137    else if((value & FAPI_PRACH_SF_FORMAT_B4_MASK) == FAPI_PRACH_SF_FORMAT_B4_MASK)
1138    {
1139       (*cellPtr)->prachShortFormats    = SF_FORMAT_B4;
1140    }
1141    else if((value & FAPI_PRACH_SF_FORMAT_C0_MASK) == FAPI_PRACH_SF_FORMAT_C0_MASK)
1142    {
1143       (*cellPtr)->prachShortFormats    = SF_FORMAT_C0;
1144    }
1145    else if((value & FAPI_PRACH_SF_FORMAT_C2_MASK) == FAPI_PRACH_SF_FORMAT_C2_MASK)
1146    {
1147       (*cellPtr)->prachShortFormats    = SF_FORMAT_C2;
1148    }
1149    else
1150    {
1151       (*cellPtr)->prachShortFormats    = INVALID_VALUE;
1152    }
1153 }
1154
1155 /*******************************************************************
1156   *
1157   * @brief fills the Fd Occasions Type by comparing the bitmask
1158   *
1159   * @details
1160   *
1161   *    Function : fillFdOccasions
1162   *
1163   *    Functionality:
1164   *         -checks the value with the bitmask and
1165   *          fills the cellPtr's Fd Occasions
1166   *
1167   * @params[in] Pointer to ClCellParam
1168   *             Value to be compared
1169   * @return void
1170   *
1171   ******************************************************************/
1172
1173 PUBLIC void fillFdOccasions(uint8_t value, ClCellParam **cellPtr)
1174 {
1175    if(value == 0)
1176    {
1177       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_1;
1178    }
1179    else if(value == 1)
1180    {
1181       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_2;
1182    }
1183    else if(value == 3)
1184    {
1185       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_4;
1186    }
1187    else if(value == 4)
1188    {
1189       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_8;
1190    }
1191    else
1192    {
1193       (*cellPtr)->maxPrachFdOccasionsInASlot = INVALID_VALUE;
1194    }
1195 }
1196
1197 /*******************************************************************
1198   *
1199   * @brief fills the RSSI Measurement by comparing the bitmask
1200   *
1201   * @details
1202   *
1203   *    Function : fillRssiMeas
1204   *
1205   *    Functionality:
1206   *         -checks the value with the bitmask and
1207   *          fills the cellPtr's RSSI Measurement report
1208   *
1209   * @params[in] Pointer to ClCellParam
1210   *             Value to be compared
1211   * @return void
1212   *
1213   ******************************************************************/
1214
1215 PUBLIC void fillRssiMeas(uint8_t value, ClCellParam **cellPtr)
1216 {
1217    if((value & FAPI_RSSI_REPORT_IN_DBM_MASK) == FAPI_RSSI_REPORT_IN_DBM_MASK)
1218    {
1219       (*cellPtr)->rssiMeasurementSupport    = RSSI_REPORT_DBM;
1220    }
1221    else if((value & FAPI_RSSI_REPORT_IN_DBFS_MASK) == FAPI_RSSI_REPORT_IN_DBFS_MASK)
1222    {
1223       (*cellPtr)->rssiMeasurementSupport    = RSSI_REPORT_DBFS;
1224    }
1225    else
1226    {
1227       (*cellPtr)->rssiMeasurementSupport    = INVALID_VALUE;
1228    }
1229 }
1230
1231  /*******************************************************************
1232   *
1233   * @brief Returns the TLVs value
1234   *
1235   * @details
1236   *
1237   *    Function : getParamValue
1238   *
1239   *    Functionality:
1240   *         -return TLVs value
1241   *
1242   * @params[in]
1243   * @return ROK     - temp
1244   *         RFAILED - failure
1245   *
1246   * ****************************************************************/
1247
1248 uint32_t getParamValue(fapi_uint16_tlv_t *tlv, uint16_t type)
1249 {
1250     uint16_t valueLen;
1251     void *posPtr;
1252     valueLen = tlv->tl.length;
1253     posPtr   = &tlv->tl.tag;
1254     posPtr   += sizeof(tlv->tl.tag);
1255     posPtr   += sizeof(tlv->tl.length);
1256     /*TO DO: malloc to SSI memory */
1257     if(type == FAPI_UINT_8)
1258     {
1259        //temp = (uint8_t *)malloc(valueLen * sizeof(U8));
1260        //memcpy(temp, posPtr, valueLen);
1261        return(*(uint8_t *)posPtr);
1262     }
1263     else if(type == FAPI_UINT_16)
1264     {
1265        return(*(uint16_t *)posPtr);
1266     }
1267     else if(type == FAPI_UINT_32)
1268     {
1269        return(*(uint32_t *)posPtr);
1270     }
1271     else
1272     {
1273       DU_LOG("\nLOWER MAC: Value Extraction failed" );
1274       return RFAILED;
1275     }
1276 }
1277 #endif /* FAPI */
1278  /*******************************************************************
1279   *
1280   * @brief Sends FAPI Param req to PHY
1281   *
1282   * @details
1283   *
1284   *    Function : lwr_mac_handleParamReqEvt
1285   *
1286   *    Functionality:
1287   *         -Sends FAPI Param req to PHY
1288   *
1289   * @params[in]
1290   * @return ROK     - success
1291   *         RFAILED - failure
1292   *
1293   * ****************************************************************/
1294
1295 S16 lwr_mac_handleParamReqEvt(void *msg)
1296 {
1297 #ifdef FAPI
1298    /* startGuardTimer(); */
1299    uint32_t msgLen;      //Length of message Body
1300    msgLen = 0;
1301    fapi_param_req_t *paramReq;
1302    MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
1303    if(paramReq != NULLP)
1304    {
1305       fillMsgHeader(&paramReq->header, FAPI_PARAM_REQUEST, msgLen);
1306       DU_LOG("\nLOWER MAC: sending param Req to Phy");
1307       sendToPhy(paramReq->header.message_type_id, sizeof(fapi_param_req_t), (void *)paramReq);
1308       MAC_FREE(paramReq, sizeof(fapi_param_req_t));
1309       return ROK;
1310    }
1311    else
1312    {
1313       DU_LOG("\nLOWER MAC: Failed to allocate memory for Param Request");
1314       return RFAILED;
1315    }
1316 #else
1317    return ROK;
1318 #endif
1319 }
1320
1321  /*******************************************************************
1322   *
1323   * @brief Sends FAPI Param Response to MAC via PHY
1324   *
1325   * @details
1326   *
1327   *    Function : lwr_mac_handleParamRspEvt
1328   *
1329   *    Functionality:
1330   *         -Sends FAPI Param rsp to MAC via PHY
1331   *
1332   * @params[in]
1333   * @return ROK     - success
1334   *         RFAILED - failure
1335   *
1336   * ****************************************************************/
1337
1338 S16 lwr_mac_handleParamRspEvt(void *msg)
1339 {
1340 #ifdef FAPI
1341   /* stopGuardTimer(); */
1342    uint8_t index;
1343    uint32_t encodedVal;
1344         fapi_param_resp_t *paramRsp;
1345    ClCellParam *cellParam = NULLP;
1346
1347    paramRsp = (fapi_param_resp_t *)msg;
1348    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1349
1350    if(paramRsp != NULLP)
1351    {
1352       MAC_ALLOC(cellParam, sizeof(ClCellParam));
1353       if(cellParam != NULLP)
1354       {
1355          DU_LOG("\n LOWER MAC: Filling TLVS into MAC API");
1356          if(paramRsp->error_code == MSG_OK)
1357          {
1358             for(index = 0; index < paramRsp->number_of_tlvs; index++)
1359             {
1360                switch(paramRsp->tlvs[index].tl.tag)
1361                {
1362                   case FAPI_RELEASE_CAPABILITY_TAG:
1363                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1364                      if(encodedVal != RFAILED && (encodedVal & RELEASE_15) == RELEASE_15)
1365                      {
1366                         cellParam->releaseCapability = RELEASE_15;
1367                      }
1368                      break;
1369
1370                   case FAPI_PHY_STATE_TAG:
1371                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1372                      if(encodedVal != RFAILED && encodedVal != clGlobalCp.phyState)
1373                      {
1374                         printf("\n PhyState mismatch [%d][%d]", clGlobalCp.phyState, clGlobalCp.event);
1375                         RETVALUE(RFAILED);
1376                      }
1377                      break;
1378
1379                   case FAPI_SKIP_BLANK_DL_CONFIG_TAG:
1380                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1381                      if(encodedVal != RFAILED && encodedVal != 0)
1382                      {
1383                        cellParam->skipBlankDlConfig = SUPPORTED;
1384                      }
1385                      else
1386                      {
1387                        cellParam->skipBlankDlConfig = NOT_SUPPORTED;
1388                      }
1389                      break;
1390
1391                   case FAPI_SKIP_BLANK_UL_CONFIG_TAG:
1392                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1393                      if(encodedVal != RFAILED && encodedVal != 0)
1394                      {
1395                        cellParam->skipBlankUlConfig = SUPPORTED;
1396                      }
1397                      else
1398                      {
1399                        cellParam->skipBlankUlConfig = NOT_SUPPORTED;
1400                      }
1401                      break;
1402
1403                   case FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG:
1404                      cellParam->numTlvsToReport = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1405                      break;
1406
1407                   case FAPI_CYCLIC_PREFIX_TAG:
1408                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1409                      if(encodedVal != RFAILED)
1410                      {
1411                         fillCyclicPrefix(encodedVal, &cellParam);
1412                      }
1413                      break;
1414
1415                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG:
1416                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1417                      if(encodedVal != RFAILED)
1418                      {
1419                         fillSubcarrierSpaceDl(encodedVal, &cellParam);
1420                      }
1421                      break;
1422
1423                   case FAPI_SUPPORTED_BANDWIDTH_DL_TAG:
1424                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1425                      if(encodedVal != RFAILED)
1426                      {
1427                         fillBandwidthDl(encodedVal, &cellParam);
1428                      }
1429                      break;
1430
1431                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG:
1432                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1433                      if(encodedVal != RFAILED)
1434                      {
1435                         fillSubcarrierSpaceUl(encodedVal, &cellParam);
1436                      }
1437                      break;
1438
1439                   case FAPI_SUPPORTED_BANDWIDTH_UL_TAG:
1440                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1441                      if(encodedVal != RFAILED)
1442                      {
1443                         fillBandwidthUl(encodedVal, &cellParam);
1444                      }
1445                      break;
1446
1447                   case FAPI_CCE_MAPPING_TYPE_TAG:
1448                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1449                      if(encodedVal != RFAILED)
1450                      {
1451                         fillCCEmaping(encodedVal, &cellParam);
1452                      }
1453                      break;
1454
1455                   case FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG:
1456                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1457                      if(encodedVal != RFAILED && encodedVal != 0)
1458                      {
1459                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = SUPPORTED;
1460                      }
1461                      else
1462                      {
1463                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = NOT_SUPPORTED;
1464                      }
1465                      break;
1466
1467                   case FAPI_PRECODER_GRANULARITY_CORESET_TAG:
1468                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1469                      if(encodedVal != RFAILED && encodedVal != 0)
1470                      {
1471                         cellParam->precoderGranularityCoreset = SUPPORTED;
1472                      }
1473                      else
1474                      {
1475                         cellParam->precoderGranularityCoreset = NOT_SUPPORTED;
1476                      }
1477                      break;
1478
1479                   case FAPI_PDCCH_MU_MIMO_TAG:
1480                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1481                      if(encodedVal != RFAILED && encodedVal != 0)
1482                      {
1483                         cellParam->pdcchMuMimo = SUPPORTED;
1484                      }
1485                      else
1486                      {
1487                         cellParam->pdcchMuMimo = NOT_SUPPORTED;
1488                      }
1489                      break;
1490
1491                   case FAPI_PDCCH_PRECODER_CYCLING_TAG:
1492                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1493                      if(encodedVal != RFAILED && encodedVal != 0)
1494                      {
1495                         cellParam->pdcchPrecoderCycling = SUPPORTED;
1496                      }
1497                      else
1498                      {
1499                         cellParam->pdcchPrecoderCycling = NOT_SUPPORTED;
1500                      }
1501                      break;
1502
1503                   case FAPI_MAX_PDCCHS_PER_SLOT_TAG:
1504                      cellParam->maxPdcchsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1505                      break;
1506
1507                   case FAPI_PUCCH_FORMATS_TAG:
1508                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1509                      if(encodedVal != RFAILED)
1510                      {
1511                         fillPucchFormat(encodedVal, &cellParam);
1512                      }
1513                      break;
1514
1515                   case FAPI_MAX_PUCCHS_PER_SLOT_TAG:
1516                        cellParam->maxPucchsPerSlot   = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1517                      break;
1518
1519                   case FAPI_PDSCH_MAPPING_TYPE_TAG:
1520                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1521                      if(encodedVal != RFAILED)
1522                      {
1523                         fillPdschMappingType(encodedVal, &cellParam);
1524                      }
1525                      break;
1526
1527                   case FAPI_PDSCH_ALLOCATION_TYPES_TAG:
1528                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1529                      if(encodedVal != RFAILED)
1530                      {
1531                         fillPdschAllocationType(encodedVal, &cellParam);
1532                      }
1533                      break;
1534
1535                   case FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG:
1536                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1537                      if(encodedVal != RFAILED)
1538                      {
1539                         fillPrbMappingType(encodedVal, &cellParam);
1540                      }
1541                      break;
1542
1543                   case FAPI_PDSCH_CBG_TAG:
1544                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1545                      if(encodedVal != RFAILED && encodedVal != 0)
1546                      {
1547                         cellParam->pdschCbg = SUPPORTED;
1548                      }
1549                      else
1550                      {
1551                         cellParam->pdschCbg = NOT_SUPPORTED;
1552                      }
1553                      break;
1554
1555                   case FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG:
1556                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1557                      if(encodedVal != RFAILED)
1558                      {
1559                         fillPdschDmrsConfigType(encodedVal, &cellParam);
1560                      }
1561                      break;
1562
1563                   case FAPI_PDSCH_DMRS_MAX_LENGTH_TAG:
1564                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1565                      if(encodedVal != RFAILED)
1566                      {
1567                         fillPdschDmrsLength(encodedVal, &cellParam);
1568                      }
1569                      break;
1570
1571                   case FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG:
1572                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1573                      if(encodedVal != RFAILED)
1574                      {
1575                         fillPdschDmrsAddPos(encodedVal, &cellParam);
1576                      }
1577                      break;
1578
1579                   case FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG:
1580                      cellParam->maxPdschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1581                      break;
1582
1583                   case FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG:
1584                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1585                      if(encodedVal != RFAILED && encodedVal < FAPI_MAX_NUMBERMIMO_LAYERS_PDSCH)
1586                      {
1587                         cellParam->maxNumberMimoLayersPdsch   = encodedVal;
1588                      }
1589                      break;
1590
1591                   case FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG:
1592                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1593                      if(encodedVal != RFAILED)
1594                      {
1595                         fillModulationOrderDl(encodedVal, &cellParam);
1596                      }
1597                      break;
1598
1599                   case FAPI_MAX_MU_MIMO_USERS_DL_TAG:
1600                      cellParam->maxMuMimoUsersDl         = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1601                      break;
1602
1603                   case FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG:
1604                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1605                      if(encodedVal != RFAILED && encodedVal != 0)
1606                      {
1607                         cellParam->pdschDataInDmrsSymbols = SUPPORTED;
1608                      }
1609                      else
1610                      {
1611                         cellParam->pdschDataInDmrsSymbols = NOT_SUPPORTED;
1612                      }
1613                      break;
1614
1615                   case FAPI_PREMPTIONSUPPORT_TAG:
1616                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1617                      if(encodedVal != RFAILED && encodedVal != 0)
1618                      {
1619                         cellParam->premptionSupport = SUPPORTED;
1620                      }
1621                      else
1622                      {
1623                         cellParam->premptionSupport = NOT_SUPPORTED;
1624                      }
1625                      break;
1626
1627                   case FAPI_PDSCH_NON_SLOT_SUPPORT_TAG:
1628                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1629                      if(encodedVal != RFAILED && encodedVal != 0)
1630                      {
1631                         cellParam->pdschNonSlotSupport = SUPPORTED;
1632                      }
1633                      else
1634                      {
1635                         cellParam->pdschNonSlotSupport = NOT_SUPPORTED;
1636                      }
1637                      break;
1638
1639                   case FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG:
1640                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1641                      if(encodedVal != RFAILED && encodedVal != 0)
1642                      {
1643                         cellParam->uciMuxUlschInPusch = SUPPORTED;
1644                      }
1645                      else
1646                      {
1647                         cellParam->uciMuxUlschInPusch = NOT_SUPPORTED;
1648                      }
1649                      break;
1650
1651                   case FAPI_UCI_ONLY_PUSCH_TAG:
1652                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1653                      if(encodedVal != RFAILED && encodedVal != 0)
1654                      {
1655                         cellParam->uciOnlyPusch = SUPPORTED;
1656                      }
1657                      else
1658                      {
1659                         cellParam->uciOnlyPusch = NOT_SUPPORTED;
1660                      }
1661                      break;
1662
1663                   case FAPI_PUSCH_FREQUENCY_HOPPING_TAG:
1664                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1665                      if(encodedVal != RFAILED && encodedVal != 0)
1666                      {
1667                         cellParam->puschFrequencyHopping = SUPPORTED;
1668                      }
1669                      else
1670                      {
1671                         cellParam->puschFrequencyHopping = NOT_SUPPORTED;
1672                      }
1673                      break;
1674
1675                  case FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG:
1676                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1677                     if(encodedVal != RFAILED)
1678                     {
1679                        fillPuschDmrsConfig(encodedVal, &cellParam);
1680                     }
1681                     break;
1682
1683                  case FAPI_PUSCH_DMRS_MAX_LEN_TAG:
1684                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1685                     if(encodedVal != RFAILED)
1686                     {
1687                        fillPuschDmrsLength(encodedVal, &cellParam);
1688                     }
1689                     break;
1690
1691                  case FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG:
1692                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1693                     if(encodedVal != RFAILED)
1694                     {
1695                        fillPuschDmrsAddPos(encodedVal, &cellParam);
1696                     }
1697                     break;
1698
1699                  case FAPI_PUSCH_CBG_TAG:
1700                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1701                     if(encodedVal != RFAILED && encodedVal != 0)
1702                     {
1703                        cellParam->puschCbg = SUPPORTED;
1704                     }
1705                     else
1706                     {
1707                        cellParam->puschCbg = NOT_SUPPORTED;
1708                     }
1709                     break;
1710
1711                 case FAPI_PUSCH_MAPPING_TYPE_TAG:
1712                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1713                    if(encodedVal != RFAILED)
1714                    {
1715                       fillPuschMappingType(encodedVal, &cellParam);
1716                    }
1717                    break;
1718
1719                 case FAPI_PUSCH_ALLOCATION_TYPES_TAG:
1720                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1721                    if(encodedVal != RFAILED)
1722                    {
1723                       fillPuschAllocationType(encodedVal, &cellParam);
1724                    }
1725                    break;
1726
1727                 case FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG:
1728                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1729                    if(encodedVal != RFAILED)
1730                    {
1731                       fillPuschPrbMappingType(encodedVal, &cellParam);
1732                    }
1733                    break;
1734
1735                 case FAPI_PUSCH_MAX_PTRS_PORTS_TAG:
1736                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1737                    if(encodedVal != RFAILED && encodedVal < FAPI_PUSCH_MAX_PTRS_PORTS_UB)
1738                    {
1739                 cellParam->puschMaxPtrsPorts = encodedVal;
1740                    }
1741                    break;
1742
1743                 case FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG:
1744                    cellParam->maxPduschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1745                    break;
1746
1747                 case FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG:
1748                    cellParam->maxNumberMimoLayersNonCbPusch = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1749                    break;
1750
1751                 case FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG:
1752                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1753                    if(encodedVal != RFAILED)
1754                    {
1755                       fillModulationOrderUl(encodedVal, &cellParam);
1756                    }
1757                    break;
1758
1759                 case FAPI_MAX_MU_MIMO_USERS_UL_TAG:
1760                    cellParam->maxMuMimoUsersUl = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1761                    break;
1762
1763                 case FAPI_DFTS_OFDM_SUPPORT_TAG:
1764                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1765                    if(encodedVal != RFAILED && encodedVal != 0)
1766                    {
1767                       cellParam->dftsOfdmSupport = SUPPORTED;
1768                    }
1769                    else
1770                    {
1771                       cellParam->dftsOfdmSupport = NOT_SUPPORTED;
1772                    }
1773                    break;
1774
1775                 case FAPI_PUSCH_AGGREGATION_FACTOR_TAG:
1776                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1777                    if(encodedVal != RFAILED)
1778                    {
1779                       fillPuschAggregationFactor(encodedVal, &cellParam);
1780                    }
1781                    break;
1782
1783                 case FAPI_PRACH_LONG_FORMATS_TAG:
1784                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1785                    if(encodedVal != RFAILED)
1786                    {
1787                       fillPrachLongFormat(encodedVal, &cellParam);
1788                    }
1789                    break;
1790
1791                 case FAPI_PRACH_SHORT_FORMATS_TAG:
1792                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1793                    if(encodedVal != RFAILED)
1794                    {
1795                       fillPrachShortFormat(encodedVal, &cellParam);
1796                    }
1797                    break;
1798
1799                 case FAPI_PRACH_RESTRICTED_SETS_TAG:
1800                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1801                    if(encodedVal != RFAILED && encodedVal != 0)
1802                    {
1803                       cellParam->prachRestrictedSets = SUPPORTED;
1804                    }
1805                    else
1806                    {
1807                       cellParam->prachRestrictedSets = NOT_SUPPORTED;
1808                    }
1809                    break;
1810
1811                case FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG:
1812                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1813                   if(encodedVal != RFAILED)
1814                   {
1815                      fillFdOccasions(encodedVal, &cellParam);
1816                   }
1817                   break;
1818
1819                case FAPI_RSSI_MEASUREMENT_SUPPORT_TAG:
1820                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1821                   if(encodedVal != RFAILED)
1822                   {
1823                      fillRssiMeas(encodedVal, &cellParam);
1824                   }
1825                   break;
1826                default:
1827                //printf("\n Invalid value for TLV[%x] at index[%d]", paramRsp->tlvs[index].tl.tag, index);
1828                                         break;
1829               }
1830            }
1831            MAC_FREE(cellParam, sizeof(ClCellParam));
1832            MAC_FREE(paramRsp, sizeof(fapi_param_resp_t));
1833            return ROK;
1834          }
1835          else
1836          {
1837             DU_LOG("\n LOWER MAC: Invalid error code %d", paramRsp->error_code);
1838             return RFAILED;
1839          }
1840      }
1841      else
1842      {
1843         DU_LOG("\nLOWER MAC: Failed to allocate memory for cell param");
1844         return RFAILED;
1845      }
1846    }
1847    else
1848    {
1849        DU_LOG("\nLOWER MAC:  Param Response received from PHY is NULL");
1850        return RFAILED;
1851    }
1852 #else
1853    return ROK;
1854 #endif
1855 }
1856
1857  /*******************************************************************
1858   *
1859   * @brief Sends FAPI Config req to PHY
1860   *
1861   * @details
1862   *
1863   *    Function : lwr_mac_handleConfigReqEvt
1864   *
1865   *    Functionality:
1866   *         -Sends FAPI Config Req to PHY
1867   *
1868   * @params[in]
1869   * @return ROK     - success
1870   *         RFAILED - failure
1871   *
1872   * ****************************************************************/
1873
1874 S16 lwr_mac_handleConfigReqEvt(void *msg)
1875 {
1876 #ifdef FAPI
1877    uint8_t index = 0;
1878    uint32_t msgLen = 0;
1879    uint32_t configReqSize;
1880    RgCellCb  *cellParams;
1881    MacCellCfg macCfgParams;
1882    Inst inst = 0;
1883
1884    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1885
1886    fapi_config_req_t *configReq;
1887    cellParams = rgCb[inst].cell;
1888    macCfgParams = cellParams->macCellCfg;
1889    configReqSize = sizeof(fapi_config_req_t) + (macCfgParams.numTlv * sizeof(fapi_uint16_tlv_t));
1890    MAC_ALLOC(configReq, configReqSize);
1891
1892    if(configReq != NULL)
1893    {
1894       configReq->number_of_tlvs = macCfgParams.numTlv;
1895
1896       if(macCfgParams.dlCarrCfg.pres)
1897       {
1898          fillTlvs(&configReq->tlvs[index++], FAPI_DL_BANDWIDTH_TAG,            sizeof(uint16_t), macCfgParams.dlCarrCfg.bw, &msgLen);
1899          fillTlvs(&configReq->tlvs[index++], FAPI_DL_FREQUENCY_TAG,            sizeof(uint32_t), macCfgParams.dlCarrCfg.freq, &msgLen);
1900          fillTlvs(&configReq->tlvs[index++], FAPI_DL_K0_TAG,                   sizeof(uint16_t), macCfgParams.dlCarrCfg.k0[0], &msgLen);
1901          fillTlvs(&configReq->tlvs[index++], FAPI_DL_GRIDSIZE_TAG,             sizeof(uint16_t), macCfgParams.dlCarrCfg.gridSize[0], &msgLen);
1902          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_TX_ANT_TAG,              sizeof(uint16_t), macCfgParams.dlCarrCfg.numAnt, &msgLen);
1903       }
1904       if(macCfgParams.ulCarrCfg.pres)
1905       {
1906          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_BANDWIDTH_TAG,        sizeof(uint16_t), macCfgParams.ulCarrCfg.bw, &msgLen);
1907          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_FREQUENCY_TAG,        sizeof(uint32_t), macCfgParams.ulCarrCfg.freq, &msgLen);
1908          fillTlvs(&configReq->tlvs[index++], FAPI_UL_K0_TAG,                   sizeof(uint16_t), macCfgParams.ulCarrCfg.k0[0], &msgLen);
1909          fillTlvs(&configReq->tlvs[index++], FAPI_UL_GRID_SIZE_TAG,            sizeof(uint16_t), macCfgParams.ulCarrCfg.gridSize[0], &msgLen);
1910          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_RX_ANT_TAG,              sizeof(uint16_t), macCfgParams.ulCarrCfg.numAnt, &msgLen);
1911       }
1912       fillTlvs(&configReq->tlvs[index++], FAPI_FREQUENCY_SHIFT_7P5_KHZ_TAG,    sizeof(uint8_t), macCfgParams.freqShft, &msgLen);
1913
1914       /* fill cell config */
1915       fillTlvs(&configReq->tlvs[index++], FAPI_PHY_CELL_ID_TAG,                sizeof(uint8_t), macCfgParams.phyCellId, &msgLen);
1916       fillTlvs(&configReq->tlvs[index++], FAPI_FRAME_DUPLEX_TYPE_TAG,          sizeof(uint8_t), macCfgParams.dupType, &msgLen);
1917
1918       /* fill SSB configuration */
1919       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_POWER_TAG,              sizeof(uint32_t), macCfgParams.ssbCfg.ssbPbchPwr, &msgLen);
1920       fillTlvs(&configReq->tlvs[index++], FAPI_BCH_PAYLOAD_TAG,                sizeof(uint8_t), macCfgParams.ssbCfg.bchPayloadFlag, &msgLen);
1921       fillTlvs(&configReq->tlvs[index++], FAPI_SCS_COMMON_TAG,                 sizeof(uint8_t), macCfgParams.ssbCfg.scsCmn, &msgLen);
1922
1923       /* fill PRACH configuration */
1924       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SEQUENCE_LENGTH_TAG,      sizeof(uint8_t), macCfgParams.prachCfg.prachSeqLen, &msgLen);
1925       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SUBC_SPACING_TAG,         sizeof(uint8_t), macCfgParams.prachCfg.prachSubcSpacing, &msgLen);
1926       fillTlvs(&configReq->tlvs[index++], FAPI_RESTRICTED_SET_CONFIG_TAG,      sizeof(uint8_t), macCfgParams.prachCfg.prachRstSetCfg, &msgLen);
1927       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_PRACH_FD_OCCASIONS_TAG,     sizeof(uint8_t), macCfgParams.prachCfg.prachFdm, &msgLen);
1928       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ROOT_SEQUENCE_INDEX_TAG,  sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].rootSeqIdx, &msgLen);
1929       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_ROOT_SEQUENCES_TAG,         sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numRootSeq, &msgLen);
1930       fillTlvs(&configReq->tlvs[index++], FAPI_K1_TAG,                         sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].k1, &msgLen);
1931       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ZERO_CORR_CONF_TAG ,      sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].zeroCorrZoneCfg, &msgLen);
1932       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_UNUSED_ROOT_SEQUENCES_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numUnusedRootSeq, &msgLen);
1933       fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG,
1934                 sizeof(uint8_t), *(macCfgParams.prachCfg.fdm[0].unsuedRootSeq), &msgLen);
1935       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PER_RACH_TAG,               sizeof(uint8_t), macCfgParams.prachCfg.ssbPerRach, &msgLen);
1936       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_MULTIPLE_CARRIERS_IN_A_BAND_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.prachMultCarrBand, &msgLen);
1937
1938       /* fill SSB table */
1939       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_OFFSET_POINT_A_TAG,         sizeof(uint16_t), macCfgParams.ssbCfg.ssbOffsetPointA, &msgLen);
1940       fillTlvs(&configReq->tlvs[index++], FAPI_BETA_PSS_TAG,                   sizeof(uint8_t),  macCfgParams.ssbCfg.betaPss, &msgLen);
1941       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PERIOD_TAG,                 sizeof(uint8_t),  macCfgParams.ssbCfg.ssbPeriod, &msgLen);
1942       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_SUBCARRIER_OFFSET_TAG,      sizeof(uint8_t),  macCfgParams.ssbCfg.ssbScOffset, &msgLen);
1943       fillTlvs(&configReq->tlvs[index++], FAPI_MIB_TAG ,                       sizeof(uint32_t), macCfgParams.ssbCfg.mibPdu[0], &msgLen);
1944       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_MASK_TAG,                   sizeof(uint32_t), macCfgParams.ssbCfg.ssbMask[0], &msgLen);
1945       fillTlvs(&configReq->tlvs[index++], FAPI_BEAM_ID_TAG,                    sizeof(uint8_t),  macCfgParams.ssbCfg.beamId[0], &msgLen);
1946       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_MULTIPLE_CARRIERS_IN_A_BAND_TAG, sizeof(uint8_t), macCfgParams.ssbCfg.multCarrBand, &msgLen);
1947       fillTlvs(&configReq->tlvs[index++], FAPI_MULTIPLE_CELLS_SS_PBCH_IN_A_CARRIER_TAG, sizeof(uint8_t), macCfgParams.ssbCfg.multCellCarr, &msgLen);
1948
1949       /* fill TDD table */
1950       fillTlvs(&configReq->tlvs[index++], FAPI_TDD_PERIOD_TAG,                 sizeof(uint8_t), macCfgParams.tddCfg.tddPeriod, &msgLen);
1951       fillTlvs(&configReq->tlvs[index++], FAPI_SLOT_CONFIG_TAG,                sizeof(uint8_t), macCfgParams.tddCfg.slotCfg[0][0], &msgLen);
1952
1953       /* fill measurement config */
1954       fillTlvs(&configReq->tlvs[index++], FAPI_RSSI_MESUREMENT_TAG,            sizeof(uint8_t), macCfgParams.rssiUnit, &msgLen);
1955
1956       fillMsgHeader(&configReq->header, FAPI_CONFIG_REQUEST, msgLen);
1957       DU_LOG("\nLOWER_MAC: Sending Config Request to Phy");
1958       sendToPhy(configReq->header.message_type_id, msgLen, (void *)configReq);
1959       MAC_FREE(configReq, configReqSize);
1960       return ROK;
1961    }
1962    else
1963    {
1964       DU_LOG("\nLOWER_MAC: Failed to allocate memory for config Request");
1965       return RFAILED;
1966    }
1967 #else
1968    return ROK;
1969 #endif
1970 }
1971
1972 S16 lwr_mac_handleConfigRspEvt(void *msg)
1973 {
1974 #ifdef FAPI
1975    fapi_config_resp_t *configRsp;
1976         configRsp = (fapi_config_resp_t *)msg;
1977    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1978
1979    if(configRsp != NULL)
1980    {
1981       if(configRsp->error_code == MSG_OK)
1982       {
1983          DU_LOG("\nLOWER MAC: PHY has moved to Conigured state \n");
1984          clGlobalCp.phyState = PHY_STATE_CONFIGURED;
1985          MAC_FREE(configRsp, sizeof(fapi_config_resp_t));
1986          return ROK;
1987       }
1988       else
1989       {
1990
1991          DU_LOG("\n LOWER MAC: Invalid error code %d", configRsp->error_code);
1992          return RFAILED;
1993       }
1994    }
1995    else
1996    {
1997       DU_LOG("\nLOWER_MAC: Config Response received from PHY is NULL");
1998       return RFAILED;
1999    }
2000 #else
2001    return ROK;
2002 #endif
2003 }
2004
2005 S16 lwr_mac_handleStartReqEvt(void *msg)
2006 {
2007 #ifdef FAPi
2008    uint32_t msgLen = 0;
2009    fapi_start_req_t *startReq;
2010    MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
2011
2012    if(startReq != NULL)
2013    {
2014       fillMsgHeader(&startReq->header, FAPI_START_REQUEST, msgLen);
2015       DU_LOG("\nLOWER MAC: Sending Start Request to PHY");
2016       sendToPhy(startReq->header.message_type_id, sizeof(fapi_start_req_t), (void *)startReq);
2017       MAC_FREE(startReq, sizeof(fapi_start_req_t));
2018       return ROK;
2019    }
2020    else
2021    {
2022       DU_LOG("\nLOWER MAC: Failed to allocate memory for Start Request");
2023       return RFAILED;
2024    }
2025 #else
2026    return ROK;
2027 #endif
2028 }
2029
2030 S16 lwr_mac_handleStopReqEvt(void *msg)
2031 {
2032 #ifdef FAPI
2033    /* stop TX and RX operation return PHy to configured State
2034       send stop.indication to l2/l3 */
2035 #else
2036    RETVALUE(ROK);
2037 #endif
2038 }
2039
2040 /*******************************************************************
2041  *
2042  * @brief Modifes the received mibPdu to uint32 bit
2043  *        and stores it in MacCellCfg
2044  *
2045  * @details
2046  *
2047  *    Function : setMibPdu
2048  *
2049  *    Functionality:
2050  *         -Sets the MibPdu
2051  *
2052  * @params[in] Pointer to mibPdu
2053  *             pointer to modified value
2054  ******************************************************************/
2055
2056 PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val)
2057 {
2058    *mibPdu |= (((uint8_t)(slotIndInfo.sfn >> 2)) & MIB_SFN_BITMASK);
2059    *val = (mibPdu[0] << 24 | mibPdu[1] << 16 | mibPdu[2] << 8);
2060     DU_LOG("\nLOWER MAC: value filled %x", *val);
2061 }
2062
2063 #ifdef FAPI
2064 /*******************************************************************
2065  *
2066  * @brief fills SSB PDU required for DL TTI info in MAC
2067  *
2068  * @details
2069  *
2070  *    Function : fillSsbPdu
2071  *
2072  *    Functionality:
2073  *         -Fills the SSB PDU info
2074  *          stored in MAC
2075  *
2076  * @params[in] Pointer to FAPI DL TTI Req
2077  *             Pointer to RgCellCb
2078  *             Pointer to msgLen of DL TTI Info
2079  * @return ROK
2080  *
2081  ******************************************************************/
2082
2083 S16 fillSsbPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, MacCellCfg *macCellCfg,
2084 uint32_t *msgLen)
2085 {
2086    uint32_t mibPayload = 0;
2087    if(dlTtiReqPdu != NULL)
2088    {
2089       dlTtiReqPdu->pduType = SSB_PDU_TYPE;     /* SSB PDU */
2090       dlTtiReqPdu->u.ssb_pdu.physCellId = macCellCfg->phyCellId;
2091       dlTtiReqPdu->u.ssb_pdu.betaPss = macCellCfg->ssbCfg.betaPss;
2092       dlTtiReqPdu->u.ssb_pdu.ssbBlockIndex = macCb.macCell->dlSlot[0].cellBroadcastInfo.ssbIdxSupported;
2093       dlTtiReqPdu->u.ssb_pdu.ssbSubCarrierOffset = macCellCfg->ssbCfg.ssbScOffset;
2094       /* ssbOfPdufstA to be filled in ssbCfg */
2095       dlTtiReqPdu->u.ssb_pdu.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2096       dlTtiReqPdu->u.ssb_pdu.bchPayloadFlag = macCellCfg->ssbCfg.bchPayloadFlag;
2097       /* Bit manipulation for SFN */
2098       setMibPdu(macCellCfg->ssbCfg.mibPdu, &mibPayload);
2099       dlTtiReqPdu->u.ssb_pdu.bchPayload.v.bchPayload = mibPayload;
2100       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.numPrgs = 0;
2101       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.prgSize = 0;
2102       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.digBfInterfaces = 0;
2103       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.pmi_bfi[0].pmIdx = 0;
2104       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming. \
2105          pmi_bfi[0].beamIdx[0].beamidx = macCellCfg->ssbCfg.beamId[0];
2106       dlTtiReqPdu->pduSize = sizeof(fapi_dl_ssb_pdu_t);  /* Size of SSB PDU */
2107       SETLENGTH(*msgLen, sizeof(fapi_dl_ssb_pdu_t));
2108       return ROK;
2109     }
2110     else
2111     {
2112        return RFAILED;
2113     }
2114 }
2115 #endif
2116 /*******************************************************************
2117  *
2118  * @brief Sends DL TTI Request to PHY
2119  *
2120  * @details
2121  *
2122  *    Function : handleDlTtiReq
2123  *
2124  *    Functionality:
2125  *         -Sends FAPI Param req to PHY
2126  *
2127  * @params[in]    RgDlSf *dlTtiReqSlot
2128  * @return ROK     - success
2129  *         RFAILED - failure
2130  *
2131  * ****************************************************************/
2132 S16 handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
2133 {
2134 #ifdef FAPI
2135    uint32_t msgLen;
2136    fapi_dl_tti_req_t *dlTtiReq;
2137    fapi_dl_tti_req_pdu_t *dlTtiReqPdu;
2138    RgCellCb  *cellCbParams;
2139    MacCellCfg macCellCfg;
2140    Inst inst = 0;
2141
2142    cellCbParams = rgCb[inst].cell;
2143    if(dlTtiReqtimingInfo != NULLP)
2144    {
2145       MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
2146       if(dlTtiReq != NULLP)
2147       {
2148          /* fill the SFN and slot value from crntTime */
2149          dlTtiReq->sfn = dlTtiReqtimingInfo->sfn;
2150          dlTtiReq->slot = dlTtiReqtimingInfo->slot;
2151          dlTtiReq->nPdus = 0;
2152          dlTtiReq->nGroup = 0;
2153          if(macCb.macCell->dlSlot[0].cellBroadcastInfo.ssbTrans)
2154          {
2155             macCellCfg = cellCbParams->macCellCfg;
2156
2157             MAC_ALLOC(dlTtiReqPdu, sizeof(fapi_dl_tti_req_pdu_t));
2158             if(dlTtiReqPdu != NULLP)
2159             {
2160                fillSsbPdu(dlTtiReqPdu, &macCellCfg, &msgLen);
2161                dlTtiReq->pdus = dlTtiReqPdu;
2162             }
2163             (dlTtiReq->nPdus)++;
2164             msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
2165             fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
2166             sendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
2167             MAC_FREE(dlTtiReqPdu, sizeof(fapi_dl_tti_req_pdu_t));
2168          }
2169          MAC_FREE(dlTtiReq, sizeof(fapi_dl_tti_req_t));
2170          return ROK;
2171       }
2172                 else
2173       {
2174          DU_LOG("\nLOWER MAC: Failed to allocate memory for DL TTI Request");
2175          return RFAILED;
2176       }
2177    }
2178         else
2179         {
2180            DU_LOG("\nLOWER MAC: Current TTI Info is NULL");
2181       return RFAILED;
2182    }
2183 #else
2184    return ROK;
2185 #endif
2186 }
2187
2188 lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
2189 {
2190    {
2191       /* PHY_STATE_IDLE */
2192        lwr_mac_handleParamReqEvt,
2193        lwr_mac_handleParamRspEvt,
2194        lwr_mac_handleConfigReqEvt,
2195        lwr_mac_handleConfigRspEvt,
2196        lwr_mac_handleInvalidEvt,
2197    },
2198    {
2199        /* PHY_STATE_CONFIGURED */
2200        lwr_mac_handleParamReqEvt,
2201        lwr_mac_handleParamRspEvt,
2202        lwr_mac_handleConfigReqEvt,
2203        lwr_mac_handleConfigRspEvt,
2204        lwr_mac_handleStartReqEvt,
2205    },
2206    {
2207        /* PHY_STATE_RUNNING */
2208        lwr_mac_handleInvalidEvt,
2209        lwr_mac_handleInvalidEvt,
2210        lwr_mac_handleConfigReqEvt,
2211        lwr_mac_handleConfigRspEvt,
2212        lwr_mac_handleInvalidEvt,
2213    }
2214 };
2215
2216 /*******************************************************************
2217  *
2218  * @brief Sends message to Lower Mac Fsm Event Handler
2219  *
2220  * @details
2221  *
2222  *    Function : sendToLowerMac
2223  *
2224  *    Functionality:
2225  *         -Sends message to LowerMac
2226  *
2227  * @params[in] Message Type
2228  *             Message Length
2229  *             Messaga Pointer
2230  *
2231  * @return void
2232  *
2233 ******************************************************************/
2234 void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg)
2235 {
2236    clGlobalCp.event = msgType;
2237    fapiEvtHdlr[clGlobalCp.phyState][clGlobalCp.event](msg);
2238 }
2239 /**********************************************************************
2240          End of file
2241 **********************************************************************/