Moving all common header file into common_def.h file
[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
20 /* header include files -- defines (.h) */
21 #include "common_def.h"
22 #include "lrg.h"           /* Layer manager interface includes*/
23 #include "crg.h"           /* CRG interface includes*/
24 #include "rgu.h"           /* RGU interface includes*/
25 #include "tfu.h"           /* TFU interface includes */
26 #include "rg_sch_inf.h"    /* SCH interface includes */
27 #include "rg_prg.h"       /* PRG (MAC-MAC) interface includes*/
28 #include "rg_env.h"       /* MAC environmental includes*/
29 #include "rg.h"           /* MAC includes*/
30 #include "rg_err.h"       /* MAC error includes*/
31 #include "du_log.h"
32 #include "lwr_mac_fsm.h"
33
34 /* header/extern include files (.x) */
35 #include "rgu.x"           /* RGU types */
36 #include "tfu.x"           /* RGU types */
37 #include "lrg.x"           /* layer management typedefs for MAC */
38 #include "crg.x"           /* CRG interface includes */
39 #include "rg_sch_inf.x"    /* SCH interface typedefs */
40 #include "rg_prg.x"        /* PRG (MAC-MAC) Interface typedefs */
41 #include "du_app_mac_inf.h"
42 #include "mac.h"
43 #include "rg.x"            /* typedefs for MAC */
44 #include "lwr_mac_phy.h"
45
46 #define MIB_SFN_BITMASK 0xFC
47 #define PDCCH_PDU_TYPE 0
48 #define PDSCH_PDU_TYPE 1
49 #define SSB_PDU_TYPE 3
50 #define PRACH_PDU_TYPE 0
51 #define PUSCH_PDU_TYPE 1
52 #define PUCCH_PDU_TYPE 2
53 #define PDU_PRESENT 1
54 #define SET_MSG_LEN(x, size) x += size
55
56 extern void fapiMacConfigRsp();
57 extern uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX];
58
59 /* Global variables */
60 uint8_t slotIndIdx;
61 uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo);
62
63 void lwrMacInit()
64 {
65 #ifdef INTEL_WLS
66    uint8_t  idx;
67
68    /* Initializing WLS free mem list */
69    slotIndIdx = 1;
70    for(idx = 0; idx < WLS_MEM_FREE_PRD; idx++)
71    {
72       cmLListInit(&wlsBlockToFreeList[idx]);
73    }
74 #endif
75 }
76
77  /*******************************************************************
78   *
79   * @brief Handles Invalid Request Event
80   *
81   * @details
82   *
83   *    Function : lwr_mac_handleInvalidEvt
84   *
85   *    Functionality:
86   *         - Displays the PHY state when the invalid event occurs
87   *
88   * @params[in]
89   * @return ROK     - success
90   *         RFAILED - failure
91   *
92   * ****************************************************************/
93 S16 lwr_mac_handleInvalidEvt(void *msg)
94 {
95    printf("\nLWR_MAC: Error Indication Event[%d] received in state [%d]", clGlobalCp.event, clGlobalCp.phyState);
96    RETVALUE(ROK);
97 }
98
99 #ifdef INTEL_FAPI
100 /*******************************************************************
101   *
102   * @brief Fills FAPI message header
103   *
104   * @details
105   *
106   *    Function : fillMsgHeader
107   *
108   *    Functionality:
109   *         -Fills FAPI message header
110   *
111   * @params[in] Pointer to header
112   *             Number of messages
113   *             Messae Type
114   *             Length of message
115   * @return void
116   *
117   * ****************************************************************/
118 PUBLIC void fillMsgHeader(fapi_msg_t *hdr, uint16_t msgType, uint16_t msgLen)
119 {
120    hdr->message_type_id = msgType;
121    hdr->length = msgLen;
122 }
123
124 /*******************************************************************
125   *
126   * @brief Fills FAPI Config Request message header
127   *
128   * @details
129   *
130   *    Function : fillTlvs
131   *
132   *    Functionality:
133   *         -Fills FAPI Config Request message header
134   *
135   * @params[in] Pointer to TLV
136   *             Tag
137   *             Length
138   *             Value
139   *             MsgLen
140   * @return void
141   *
142   * ****************************************************************/
143 PUBLIC void fillTlvs(fapi_uint16_tlv_t *tlv, uint16_t tag, uint16_t length,
144 uint16_t value, uint32_t *msgLen)
145 {
146    tlv->tl.tag    = tag;
147    tlv->tl.length = length;
148    tlv->value     = value;
149    *msgLen        = *msgLen + sizeof(tag) + sizeof(length) + length;
150 }
151  /*******************************************************************
152   *
153   * @brief fills the cyclic prefix by comparing the bitmask
154   *
155   * @details
156   *
157   *    Function : fillCyclicPrefix
158   *
159   *    Functionality:
160   *         -checks the value with the bitmask and
161   *          fills the cellPtr's cyclic prefix.
162   *
163   * @params[in] Pointer to ClCellParam
164   *             Value to be compared
165   * @return void
166   *
167   ********************************************************************/
168 PUBLIC void fillCyclicPrefix(uint8_t value, ClCellParam **cellPtr)
169 {
170    if((value & FAPI_NORMAL_CYCLIC_PREFIX_MASK) == FAPI_NORMAL_CYCLIC_PREFIX_MASK)
171    {
172       (*cellPtr)->cyclicPrefix   = NORMAL_CYCLIC_PREFIX_MASK;
173    }
174    else if((value & FAPI_EXTENDED_CYCLIC_PREFIX_MASK) == FAPI_EXTENDED_CYCLIC_PREFIX_MASK)
175    {
176       (*cellPtr)->cyclicPrefix   = EXTENDED_CYCLIC_PREFIX_MASK;
177    }
178    else
179    {
180       (*cellPtr)->cyclicPrefix = INVALID_VALUE;
181    }
182 }
183
184  /*******************************************************************
185   *
186   * @brief fills the subcarrier spacing of Downlink by comparing the bitmask
187   *
188   * @details
189   *
190   *    Function : fillSubcarrierSpaceDl
191   *
192   *    Functionality:
193   *         -checks the value with the bitmask and
194   *          fills the cellPtr's subcarrier spacing in DL
195   *
196   * @params[in] Pointer to ClCellParam
197   *             Value to be compared
198   * @return void
199   *
200   * ****************************************************************/
201
202 PUBLIC void fillSubcarrierSpaceDl(uint8_t value, ClCellParam **cellPtr)
203 {
204    if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
205    {
206       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_15_KHZ;
207    }
208    else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
209    {
210       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_30_KHZ;
211    }
212    else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
213    {
214       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_60_KHZ;
215    }
216    else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
217    {
218       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_120_KHZ;
219    }
220    else
221    {
222       (*cellPtr)->supportedSubcarrierSpacingDl = INVALID_VALUE;
223    }
224 }
225
226  /*******************************************************************
227   *
228   * @brief fills the downlink bandwidth by comparing the bitmask
229   *
230   * @details
231   *
232   *    Function : fillBandwidthDl
233   *
234   *    Functionality:
235   *         -checks the value with the bitmask and
236   *         -fills the cellPtr's DL Bandwidth
237   *
238   * @params[in] Pointer to ClCellParam
239   *             Value to be compared
240   * @return void
241   *
242   * ****************************************************************/
243
244 PUBLIC void fillBandwidthDl(uint16_t value, ClCellParam **cellPtr)
245 {
246    if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
247    {
248       (*cellPtr)->supportedBandwidthDl = BW_5MHZ;
249    }
250    else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
251    {
252       (*cellPtr)->supportedBandwidthDl = BW_10MHZ;
253    }
254    else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
255    {
256       (*cellPtr)->supportedBandwidthDl = BW_15MHZ;
257    }
258    else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
259    {
260       (*cellPtr)->supportedBandwidthDl = BW_20MHZ;
261    }
262    else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
263    {
264       (*cellPtr)->supportedBandwidthDl = BW_40MHZ;
265    }
266    else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
267    {
268       (*cellPtr)->supportedBandwidthDl = BW_50MHZ;
269    }
270    else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
271    {
272       (*cellPtr)->supportedBandwidthDl = BW_60MHZ;
273    }
274    else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
275    {
276       (*cellPtr)->supportedBandwidthDl = BW_70MHZ;
277    }
278    else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
279    {
280       (*cellPtr)->supportedBandwidthDl = BW_80MHZ;
281    }
282    else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
283    {
284       (*cellPtr)->supportedBandwidthDl = BW_90MHZ;
285    }
286    else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
287    {
288       (*cellPtr)->supportedBandwidthDl = BW_100MHZ;
289    }
290    else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
291    {
292       (*cellPtr)->supportedBandwidthDl = BW_200MHZ;
293    }
294    else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
295    {
296       (*cellPtr)->supportedBandwidthDl = BW_400MHZ;
297    }
298    else
299    {
300       (*cellPtr)->supportedBandwidthDl = INVALID_VALUE;
301    }
302 }
303
304  /*******************************************************************
305   *
306   * @brief fills the subcarrier spacing of Uplink by comparing the bitmask
307   *
308   * @details
309   *
310   *    Function : fillSubcarrierSpaceUl
311   *
312   *    Functionality:
313   *         -checks the value with the bitmask and
314   *         -fills cellPtr's subcarrier spacing in UL
315   *
316   * @params[in] Pointer to ClCellParam
317   *             Value to be compared
318   * @return void
319   *
320   * ****************************************************************/
321
322 PUBLIC void fillSubcarrierSpaceUl(uint8_t value, ClCellParam **cellPtr)
323 {
324    if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
325    {
326       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_15_KHZ;
327    }
328    else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
329    {
330       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_30_KHZ;
331    }
332    else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
333    {
334       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_60_KHZ;
335    }
336    else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
337    {
338       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_120_KHZ;
339    }
340    else
341    {
342       (*cellPtr)->supportedSubcarrierSpacingsUl = INVALID_VALUE;
343    }
344 }
345
346  /*******************************************************************
347   *
348   * @brief fills the uplink bandwidth by comparing the bitmask
349   *
350   * @details
351   *
352   *    Function : fillBandwidthUl
353   *
354   *    Functionality:
355   *         -checks the value with the bitmask and
356   *          fills the cellPtr's UL Bandwidth
357   *
358   *
359   *
360   * @params[in] Pointer to ClCellParam
361   *             Value to be compared
362   * @return void
363   *
364   *
365   * ****************************************************************/
366
367 PUBLIC void fillBandwidthUl(uint16_t value, ClCellParam **cellPtr)
368 {
369    if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
370    {
371       (*cellPtr)->supportedBandwidthUl = BW_5MHZ;
372    }
373    else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
374    {
375       (*cellPtr)->supportedBandwidthUl = BW_10MHZ;
376    }
377    else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
378    {
379       (*cellPtr)->supportedBandwidthUl = BW_15MHZ;
380    }
381    else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
382    {
383       (*cellPtr)->supportedBandwidthUl = BW_20MHZ;
384    }
385    else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
386    {
387       (*cellPtr)->supportedBandwidthUl = BW_40MHZ;
388    }
389    else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
390    {
391       (*cellPtr)->supportedBandwidthUl = BW_50MHZ;
392    }
393    else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
394    {
395       (*cellPtr)->supportedBandwidthUl = BW_60MHZ;
396    }
397    else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
398    {
399       (*cellPtr)->supportedBandwidthUl = BW_70MHZ;
400    }
401    else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
402    {
403       (*cellPtr)->supportedBandwidthUl = BW_80MHZ;
404    }
405    else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
406    {
407       (*cellPtr)->supportedBandwidthUl = BW_90MHZ;
408    }
409    else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
410    {
411       (*cellPtr)->supportedBandwidthUl = BW_100MHZ;
412    }
413    else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
414    {
415       (*cellPtr)->supportedBandwidthUl = BW_200MHZ;
416    }
417    else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
418    {
419       (*cellPtr)->supportedBandwidthUl = BW_400MHZ;
420    }
421    else
422    {
423       (*cellPtr)->supportedBandwidthUl = INVALID_VALUE;
424    }
425 }
426  /*******************************************************************
427   *
428   * @brief fills the CCE maping by comparing the bitmask
429   *
430   * @details
431   *
432   *    Function : fillCCEmaping
433   *
434   *    Functionality:
435   *         -checks the value with the bitmask and
436   *          fills the cellPtr's CCE Mapping Type
437   *
438   *
439   * @params[in] Pointer to ClCellParam
440   *             Value to be compared
441   * @return void
442   *
443   * ****************************************************************/
444
445 PUBLIC void fillCCEmaping(uint8_t value,  ClCellParam **cellPtr)
446 {
447    if ((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_INTERLEAVED_MASK)
448    {
449       (*cellPtr)->cceMappingType = CCE_MAPPING_INTERLEAVED_MASK;
450    }
451    else if((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_NONINTERLVD_MASK)
452    {
453       (*cellPtr)->cceMappingType = CCE_MAPPING_NONINTERLVD_MASK;
454    }
455    else
456    {
457       (*cellPtr)->cceMappingType = INVALID_VALUE;
458    }
459 }
460
461  /*******************************************************************
462   *
463   * @brief fills the PUCCH format by comparing the bitmask
464   *
465   * @details
466   *
467   *    Function : fillPucchFormat
468   *
469   *    Functionality:
470   *         -checks the value with the bitmask and
471   *          fills the cellPtr's pucch format
472   *
473   *
474   * @params[in] Pointer to ClCellParam
475   *             Value to be compared
476   * @return void
477   *
478   * ****************************************************************/
479
480 PUBLIC void fillPucchFormat(uint8_t value, ClCellParam **cellPtr)
481 {
482    if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
483    {
484       (*cellPtr)->pucchFormats    = FORMAT_0;
485    }
486    else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
487    {
488       (*cellPtr)->pucchFormats    = FORMAT_1;
489    }
490    else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
491    {
492       (*cellPtr)->pucchFormats    = FORMAT_2;
493    }
494    else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
495    {
496       (*cellPtr)->pucchFormats    = FORMAT_3;
497    }
498    else if((value & FAPI_FORMAT_4_MASK) == FAPI_FORMAT_4_MASK)
499    {
500       (*cellPtr)->pucchFormats    = FORMAT_4;
501    }
502    else
503    {
504       (*cellPtr)->pucchFormats    = INVALID_VALUE;
505    }
506 }
507
508  /*******************************************************************
509   *
510   * @brief fills the PDSCH Mapping Type by comparing the bitmask
511   *
512   * @details
513   *
514   *    Function : fillPdschMappingType
515   *
516   *    Functionality:
517   *         -checks the value with the bitmask and
518   *          fills the cellPtr's PDSCH MappingType
519   *
520   * @params[in] Pointer to ClCellParam
521   *             Value to be compared
522   * @return void
523   *
524   * ****************************************************************/
525
526 PUBLIC void fillPdschMappingType(uint8_t value, ClCellParam **cellPtr)
527 {
528    if((value & FAPI_PDSCH_MAPPING_TYPE_A_MASK) == FAPI_PDSCH_MAPPING_TYPE_A_MASK)
529    {
530       (*cellPtr)->pdschMappingType = MAPPING_TYPE_A;
531    }
532    else if((value & FAPI_PDSCH_MAPPING_TYPE_B_MASK) == FAPI_PDSCH_MAPPING_TYPE_B_MASK)
533    {
534       (*cellPtr)->pdschMappingType = MAPPING_TYPE_B;
535    }
536    else
537    {
538       (*cellPtr)->pdschMappingType = INVALID_VALUE;
539    }
540 }
541
542 /*******************************************************************
543   *
544   * @brief fills the PDSCH Allocation Type by comparing the bitmask
545   *
546   * @details
547   *
548   *    Function : fillPdschAllocationType
549   *
550   *    Functionality:
551   *         -checks the value with the bitmask and
552   *          fills the cellPtr's PDSCH AllocationType
553   *
554   * @params[in] Pointer to ClCellParam
555   *             Value to be compared
556   * @return void
557   *
558   * ****************************************************************/
559
560 PUBLIC void fillPdschAllocationType(uint8_t value, ClCellParam **cellPtr)
561 {
562    if((value & FAPI_PDSCH_ALLOC_TYPE_0_MASK) == FAPI_PDSCH_ALLOC_TYPE_0_MASK)
563    {
564       (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_0;
565    }
566    else if((value & FAPI_PDSCH_ALLOC_TYPE_1_MASK) == FAPI_PDSCH_ALLOC_TYPE_1_MASK)
567    {
568       (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_1;
569    }
570    else
571    {
572       (*cellPtr)->pdschAllocationTypes = INVALID_VALUE;
573    }
574 }
575
576 /*******************************************************************
577   *
578   * @brief fills the PDSCH PRB Mapping Type by comparing the bitmask
579   *
580   * @details
581   *
582   *    Function : fillPrbMappingType
583   *
584   *    Functionality:
585   *         -checks the value with the bitmask and
586   *          fills the cellPtr's PRB Mapping Type
587   *
588   * @params[in] Pointer to ClCellParam
589   *             Value to be compared
590   * @return void
591   *
592   ******************************************************************/
593 PUBLIC void fillPrbMappingType(uint8_t value, ClCellParam **cellPtr)
594 {
595    if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
596    {
597       (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
598    }
599    else if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
600    {
601       (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
602    }
603    else
604    {
605       (*cellPtr)->pdschVrbToPrbMapping = INVALID_VALUE;
606    }
607 }
608
609 /*******************************************************************
610   *
611   * @brief fills the PDSCH DmrsConfig Type by comparing the bitmask
612   *
613   * @details
614   *
615   *    Function : fillPdschDmrsConfigType
616   *
617   *    Functionality:
618   *         -checks the value with the bitmask and
619   *          fills the cellPtr's DmrsConfig Type
620   *
621   * @params[in] Pointer to ClCellParam
622   *             Value to be compared
623   * @return void
624   *
625   ******************************************************************/
626
627 PUBLIC void fillPdschDmrsConfigType(uint8_t value, ClCellParam **cellPtr)
628 {
629    if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK)
630    {
631       (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
632    }
633    else if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK)
634    {
635       (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
636    }
637    else
638    {
639       (*cellPtr)->pdschDmrsConfigTypes = INVALID_VALUE;
640    }
641 }
642
643 /*******************************************************************
644   *
645   * @brief fills the PDSCH DmrsLength by comparing the bitmask
646   *
647   * @details
648   *
649   *    Function : fillPdschDmrsLength
650   *
651   *    Functionality:
652   *         -checks the value with the bitmask and
653   *          fills the cellPtr's PdschDmrsLength
654   *
655   * @params[in] Pointer to ClCellParam
656   *             Value to be compared
657   * @return void
658   *
659   ******************************************************************/
660 PUBLIC void fillPdschDmrsLength(uint8_t value, ClCellParam **cellPtr)
661 {
662    if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_1)
663    {
664       (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_1;
665    }
666    else if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_2)
667    {
668       (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_2;
669    }
670    else
671    {
672       (*cellPtr)->pdschDmrsMaxLength = INVALID_VALUE;
673    }
674 }
675
676 /*******************************************************************
677   *
678   * @brief fills the PDSCH Dmrs Additional Pos by comparing the bitmask
679   *
680   * @details
681   *
682   *    Function : fillPdschDmrsAddPos
683   *
684   *    Functionality:
685   *         -checks the value with the bitmask and
686   *          fills the cellPtr's Pdsch DmrsAddPos
687   *
688   * @params[in] Pointer to ClCellParam
689   *             Value to be compared
690   * @return void
691   *
692   ******************************************************************/
693
694 PUBLIC void fillPdschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
695 {
696    if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
697    {
698       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
699    }
700    else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
701    {
702       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
703    }
704    else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
705    {
706       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
707    }
708    else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
709    {
710       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
711    }
712    else
713    {
714       (*cellPtr)->pdschDmrsAdditionalPos = INVALID_VALUE;
715    }
716 }
717
718 /*******************************************************************
719   *
720   * @brief fills the Modulation Order in DL by comparing the bitmask
721   *
722   * @details
723   *
724   *    Function : fillModulationOrderDl
725   *
726   *    Functionality:
727   *         -checks the value with the bitmask and
728   *          fills the cellPtr's ModulationOrder in DL.
729   *
730   * @params[in] Pointer to ClCellParam
731   *             Value to be compared
732   * @return void
733   *
734   ******************************************************************/
735 PUBLIC void fillModulationOrderDl(uint8_t value, ClCellParam **cellPtr)
736 {
737    if(value == 0 )
738    {
739       (*cellPtr)->supportedMaxModulationOrderDl = MOD_QPSK;
740    }
741    else if(value == 1)
742    {
743       (*cellPtr)->supportedMaxModulationOrderDl = MOD_16QAM;
744    }
745    else if(value == 2)
746    {
747       (*cellPtr)->supportedMaxModulationOrderDl = MOD_64QAM;
748    }
749    else if(value == 3)
750    {
751       (*cellPtr)->supportedMaxModulationOrderDl = MOD_256QAM;
752    }
753    else
754    {
755       (*cellPtr)->supportedMaxModulationOrderDl = INVALID_VALUE;
756    }
757 }
758
759 /*******************************************************************
760   *
761   * @brief fills the PUSCH DmrsConfig Type by comparing the bitmask
762   *
763   * @details
764   *
765   *    Function : fillPuschDmrsConfigType
766   *
767   *    Functionality:
768   *         -checks the value with the bitmask and
769   *          fills the cellPtr's PUSCH DmrsConfigType
770   *
771   * @params[in] Pointer to ClCellParam
772   *             Value to be compared
773   * @return void
774   *
775   ******************************************************************/
776
777 PUBLIC void fillPuschDmrsConfig(uint8_t value, ClCellParam **cellPtr)
778 {
779    if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK)
780    {
781       (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
782    }
783    else if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK)
784    {
785       (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
786    }
787    else
788    {
789       (*cellPtr)->puschDmrsConfigTypes = INVALID_VALUE;
790    }
791 }
792
793 /*******************************************************************
794   *
795   * @brief fills the PUSCH DmrsLength by comparing the bitmask
796   *
797   * @details
798   *
799   *    Function : fillPuschDmrsLength
800   *
801   *    Functionality:
802   *         -checks the value with the bitmask and
803   *          fills the cellPtr's PUSCH DmrsLength
804   *
805   * @params[in] Pointer to ClCellParam
806   *             Value to be compared
807   * @return void
808   *
809   ******************************************************************/
810
811 PUBLIC void fillPuschDmrsLength(uint8_t value, ClCellParam **cellPtr)
812 {
813    if(value  == FAPI_PUSCH_DMRS_MAX_LENGTH_1)
814    {
815       (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_1;
816    }
817    else if(value  == FAPI_PUSCH_DMRS_MAX_LENGTH_2)
818    {
819       (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_2;
820    }
821    else
822    {
823       (*cellPtr)->puschDmrsMaxLength = INVALID_VALUE;
824    }
825 }
826
827 /*******************************************************************
828   *
829   * @brief fills the PUSCH Dmrs Additional position by comparing the bitmask
830   *
831   * @details
832   *
833   *    Function : fillPuschDmrsAddPos
834   *
835   *    Functionality:
836   *         -checks the value with the bitmask and
837   *          fills the cellPtr's PUSCH DmrsAddPos
838   *
839   * @params[in] Pointer to ClCellParam
840   *             Value to be compared
841   * @return void
842   *
843   ******************************************************************/
844
845 PUBLIC void fillPuschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
846 {
847    if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
848    {
849       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
850    }
851    else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
852    {
853       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
854    }
855    else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
856    {
857       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
858    }
859    else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
860    {
861       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
862    }
863    else
864    {
865       (*cellPtr)->puschDmrsAdditionalPos = INVALID_VALUE;
866    }
867 }
868
869 /*******************************************************************
870   *
871   * @brief fills the PUSCH Mapping Type by comparing the bitmask
872   *
873   * @details
874   *
875   *    Function : fillPuschMappingType
876   *
877   *    Functionality:
878   *         -checks the value with the bitmask and
879   *          fills the cellPtr's PUSCH MappingType
880   *
881   * @params[in] Pointer to ClCellParam
882   *             Value to be compared
883   * @return void
884   *
885   ******************************************************************/
886
887 PUBLIC void fillPuschMappingType(uint8_t value, ClCellParam **cellPtr)
888 {
889    if((value & FAPI_PUSCH_MAPPING_TYPE_A_MASK) == FAPI_PUSCH_MAPPING_TYPE_A_MASK)
890    {
891       (*cellPtr)->puschMappingType = MAPPING_TYPE_A;
892    }
893    else if((value & FAPI_PUSCH_MAPPING_TYPE_B_MASK) == FAPI_PUSCH_MAPPING_TYPE_B_MASK)
894    {
895       (*cellPtr)->puschMappingType = MAPPING_TYPE_B;
896    }
897    else
898    {
899       (*cellPtr)->puschMappingType = INVALID_VALUE;
900    }
901 }
902
903 /*******************************************************************
904   *
905   * @brief fills the PUSCH Allocation Type by comparing the bitmask
906   *
907   * @details
908   *
909   *    Function : fillPuschAllocationType
910   *
911   *    Functionality:
912   *         -checks the value with the bitmask and
913   *          fills the cellPtr's PUSCH AllocationType
914   *
915   * @params[in] Pointer to ClCellParam
916   *             Value to be compared
917   * @return void
918   *
919   ******************************************************************/
920
921 PUBLIC void fillPuschAllocationType(uint8_t value, ClCellParam **cellPtr)
922 {
923    if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
924    {
925       (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_0;
926    }
927    else if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
928    {
929       (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_1;
930    }
931    else
932    {
933       (*cellPtr)->puschAllocationTypes = INVALID_VALUE;
934    }
935 }
936
937 /*******************************************************************
938   *
939   * @brief fills the PUSCH PRB Mapping Type by comparing the bitmask
940   *
941   * @details
942   *
943   *    Function : fillPuschPrbMappingType
944   *
945   *    Functionality:
946   *         -checks the value with the bitmask and
947   *          fills the cellPtr's PUSCH PRB MApping Type
948   *
949   * @params[in] Pointer to ClCellParam
950   *             Value to be compared
951   * @return void
952   *
953   ******************************************************************/
954
955 PUBLIC void fillPuschPrbMappingType(uint8_t value, ClCellParam **cellPtr)
956 {
957    if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
958    {
959       (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
960    }
961    else if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
962    {
963       (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
964    }
965    else
966    {
967       (*cellPtr)->puschVrbToPrbMapping = INVALID_VALUE;
968    }
969 }
970
971 /*******************************************************************
972   *
973   * @brief fills the Modulation Order in Ul by comparing the bitmask
974   *
975   * @details
976   *
977   *    Function : fillModulationOrderUl
978   *
979   *    Functionality:
980   *         -checks the value with the bitmask and
981   *          fills the cellPtr's Modualtsion Order in UL.
982   *
983   * @params[in] Pointer to ClCellParam
984   *             Value to be compared
985   * @return void
986   *
987   ******************************************************************/
988
989 PUBLIC void fillModulationOrderUl(uint8_t value, ClCellParam **cellPtr)
990 {
991    if(value == 0)
992    {
993       (*cellPtr)->supportedModulationOrderUl = MOD_QPSK;
994    }
995    else if(value == 1)
996    {
997       (*cellPtr)->supportedModulationOrderUl = MOD_16QAM;
998    }
999    else if(value == 2)
1000    {
1001       (*cellPtr)->supportedModulationOrderUl = MOD_64QAM;
1002    }
1003    else if(value == 3)
1004    {
1005       (*cellPtr)->supportedModulationOrderUl = MOD_256QAM;
1006    }
1007    else
1008    {
1009       (*cellPtr)->supportedModulationOrderUl = INVALID_VALUE;
1010    }
1011 }
1012
1013 /*******************************************************************
1014   *
1015   * @brief fills the PUSCH Aggregation Factor by comparing the bitmask
1016   *
1017   * @details
1018   *
1019   *    Function : fillPuschAggregationFactor
1020   *
1021   *    Functionality:
1022   *         -checks the value with the bitmask and
1023   *          fills the cellPtr's PUSCH Aggregation Factor
1024   *
1025   * @params[in] Pointer to ClCellParam
1026   *             Value to be compared
1027   * @return void
1028   *
1029   ******************************************************************/
1030
1031 PUBLIC void fillPuschAggregationFactor(uint8_t value, ClCellParam **cellPtr)
1032 {
1033    if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
1034    {
1035       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_1;
1036    }
1037    else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
1038    {
1039       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_2;
1040    }
1041    else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
1042    {
1043       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_4;
1044    }
1045    else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
1046    {
1047       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_8;
1048    }
1049    else
1050    {
1051       (*cellPtr)->puschAggregationFactor    = INVALID_VALUE;
1052    }
1053 }
1054
1055 /*******************************************************************
1056   *
1057   * @brief fills the PRACH Long Format by comparing the bitmask
1058   *
1059   * @details
1060   *
1061   *    Function : fillPrachLongFormat
1062   *
1063   *    Functionality:
1064   *         -checks the value with the bitmask and
1065   *          fills the cellPtr's PRACH Long Format
1066   *
1067   * @params[in] Pointer to ClCellParam
1068   *             Value to be compared
1069   * @return void
1070   *
1071   ******************************************************************/
1072
1073 PUBLIC void fillPrachLongFormat(uint8_t value, ClCellParam **cellPtr)
1074 {
1075    if((value & FAPI_PRACH_LF_FORMAT_0_MASK) == FAPI_PRACH_LF_FORMAT_0_MASK)
1076    {
1077       (*cellPtr)->prachLongFormats    = FORMAT_0;
1078    }
1079    else if((value & FAPI_PRACH_LF_FORMAT_1_MASK) == FAPI_PRACH_LF_FORMAT_1_MASK)
1080    {
1081       (*cellPtr)->prachLongFormats    = FORMAT_1;
1082    }
1083    else if((value & FAPI_PRACH_LF_FORMAT_2_MASK) == FAPI_PRACH_LF_FORMAT_2_MASK)
1084    {
1085       (*cellPtr)->prachLongFormats    = FORMAT_2;
1086    }
1087    else if((value & FAPI_PRACH_LF_FORMAT_3_MASK) == FAPI_PRACH_LF_FORMAT_3_MASK)
1088    {
1089       (*cellPtr)->prachLongFormats    = FORMAT_3;
1090    }
1091    else
1092    {
1093       (*cellPtr)->prachLongFormats    = INVALID_VALUE;
1094    }
1095 }
1096
1097 /*******************************************************************
1098   *
1099   * @brief fills the PRACH Short Format by comparing the bitmask
1100   *
1101   * @details
1102   *
1103   *    Function : fillPrachShortFormat
1104   *
1105   *    Functionality:
1106   *         -checks the value with the bitmask and
1107   *          fills the cellPtr's PRACH ShortFormat
1108   *
1109   * @params[in] Pointer to ClCellParam
1110   *             Value to be compared
1111   * @return void
1112   *
1113   ******************************************************************/
1114
1115 PUBLIC void fillPrachShortFormat(uint8_t value, ClCellParam **cellPtr)
1116 {
1117    if((value & FAPI_PRACH_SF_FORMAT_A1_MASK) == FAPI_PRACH_SF_FORMAT_A1_MASK)
1118    {
1119       (*cellPtr)->prachShortFormats    = SF_FORMAT_A1;
1120    }
1121    else if((value & FAPI_PRACH_SF_FORMAT_A2_MASK) == FAPI_PRACH_SF_FORMAT_A2_MASK)
1122    {
1123       (*cellPtr)->prachShortFormats    = SF_FORMAT_A2;
1124    }
1125    else if((value & FAPI_PRACH_SF_FORMAT_A3_MASK) == FAPI_PRACH_SF_FORMAT_A3_MASK)
1126    {
1127       (*cellPtr)->prachShortFormats    = SF_FORMAT_A3;
1128    }
1129    else if((value & FAPI_PRACH_SF_FORMAT_B1_MASK) == FAPI_PRACH_SF_FORMAT_B1_MASK)
1130    {
1131       (*cellPtr)->prachShortFormats    = SF_FORMAT_B1;
1132    }
1133    else if((value & FAPI_PRACH_SF_FORMAT_B2_MASK) == FAPI_PRACH_SF_FORMAT_B2_MASK)
1134    {
1135       (*cellPtr)->prachShortFormats    = SF_FORMAT_B2;
1136    }
1137    else if((value & FAPI_PRACH_SF_FORMAT_B3_MASK) == FAPI_PRACH_SF_FORMAT_B3_MASK)
1138    {
1139       (*cellPtr)->prachShortFormats    = SF_FORMAT_B3;
1140    }
1141    else if((value & FAPI_PRACH_SF_FORMAT_B4_MASK) == FAPI_PRACH_SF_FORMAT_B4_MASK)
1142    {
1143       (*cellPtr)->prachShortFormats    = SF_FORMAT_B4;
1144    }
1145    else if((value & FAPI_PRACH_SF_FORMAT_C0_MASK) == FAPI_PRACH_SF_FORMAT_C0_MASK)
1146    {
1147       (*cellPtr)->prachShortFormats    = SF_FORMAT_C0;
1148    }
1149    else if((value & FAPI_PRACH_SF_FORMAT_C2_MASK) == FAPI_PRACH_SF_FORMAT_C2_MASK)
1150    {
1151       (*cellPtr)->prachShortFormats    = SF_FORMAT_C2;
1152    }
1153    else
1154    {
1155       (*cellPtr)->prachShortFormats    = INVALID_VALUE;
1156    }
1157 }
1158
1159 /*******************************************************************
1160   *
1161   * @brief fills the Fd Occasions Type by comparing the bitmask
1162   *
1163   * @details
1164   *
1165   *    Function : fillFdOccasions
1166   *
1167   *    Functionality:
1168   *         -checks the value with the bitmask and
1169   *          fills the cellPtr's Fd Occasions
1170   *
1171   * @params[in] Pointer to ClCellParam
1172   *             Value to be compared
1173   * @return void
1174   *
1175   ******************************************************************/
1176
1177 PUBLIC void fillFdOccasions(uint8_t value, ClCellParam **cellPtr)
1178 {
1179    if(value == 0)
1180    {
1181       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_1;
1182    }
1183    else if(value == 1)
1184    {
1185       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_2;
1186    }
1187    else if(value == 3)
1188    {
1189       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_4;
1190    }
1191    else if(value == 4)
1192    {
1193       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_8;
1194    }
1195    else
1196    {
1197       (*cellPtr)->maxPrachFdOccasionsInASlot = INVALID_VALUE;
1198    }
1199 }
1200
1201 /*******************************************************************
1202   *
1203   * @brief fills the RSSI Measurement by comparing the bitmask
1204   *
1205   * @details
1206   *
1207   *    Function : fillRssiMeas
1208   *
1209   *    Functionality:
1210   *         -checks the value with the bitmask and
1211   *          fills the cellPtr's RSSI Measurement report
1212   *
1213   * @params[in] Pointer to ClCellParam
1214   *             Value to be compared
1215   * @return void
1216   *
1217   ******************************************************************/
1218
1219 PUBLIC void fillRssiMeas(uint8_t value, ClCellParam **cellPtr)
1220 {
1221    if((value & FAPI_RSSI_REPORT_IN_DBM_MASK) == FAPI_RSSI_REPORT_IN_DBM_MASK)
1222    {
1223       (*cellPtr)->rssiMeasurementSupport    = RSSI_REPORT_DBM;
1224    }
1225    else if((value & FAPI_RSSI_REPORT_IN_DBFS_MASK) == FAPI_RSSI_REPORT_IN_DBFS_MASK)
1226    {
1227       (*cellPtr)->rssiMeasurementSupport    = RSSI_REPORT_DBFS;
1228    }
1229    else
1230    {
1231       (*cellPtr)->rssiMeasurementSupport    = INVALID_VALUE;
1232    }
1233 }
1234
1235  /*******************************************************************
1236   *
1237   * @brief Returns the TLVs value
1238   *
1239   * @details
1240   *
1241   *    Function : getParamValue
1242   *
1243   *    Functionality:
1244   *         -return TLVs value
1245   *
1246   * @params[in]
1247   * @return ROK     - temp
1248   *         RFAILED - failure
1249   *
1250   * ****************************************************************/
1251
1252 uint32_t getParamValue(fapi_uint16_tlv_t *tlv, uint16_t type)
1253 {
1254    //uint16_t valueLen;
1255    void *posPtr;
1256    //valueLen = tlv->tl.length;
1257    posPtr   = &tlv->tl.tag;
1258    posPtr   += sizeof(tlv->tl.tag);
1259    posPtr   += sizeof(tlv->tl.length);
1260    /*TO DO: malloc to SSI memory */
1261    if(type == FAPI_UINT_8)
1262    {
1263       //temp = (uint8_t *)malloc(valueLen * sizeof(U8));
1264       //memcpy(temp, posPtr, valueLen);
1265       return(*(uint8_t *)posPtr);
1266    }
1267    else if(type == FAPI_UINT_16)
1268    {
1269       return(*(uint16_t *)posPtr);
1270    }
1271    else if(type == FAPI_UINT_32)
1272    {
1273       return(*(uint32_t *)posPtr);
1274    }
1275    else
1276    {
1277      DU_LOG("\nLWR_MAC: Value Extraction failed" );
1278      return RFAILED;
1279    }
1280 }
1281 #endif /* FAPI */
1282  /*******************************************************************
1283   *
1284   * @brief Sends FAPI Param req to PHY
1285   *
1286   * @details
1287   *
1288   *    Function : lwr_mac_handleParamReqEvt
1289   *
1290   *    Functionality:
1291   *         -Sends FAPI Param req to PHY
1292   *
1293   * @params[in]
1294   * @return ROK     - success
1295   *         RFAILED - failure
1296   *
1297   * ****************************************************************/
1298
1299 S16 lwr_mac_handleParamReqEvt(void *msg)
1300 {
1301 #ifdef INTEL_FAPI
1302    /* startGuardTimer(); */
1303    uint32_t msgLen = 0;             //Length of message Body
1304    fapi_param_req_t *paramReq = NULL;
1305
1306    LWR_MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
1307    if(paramReq != NULL)
1308    {
1309       fillMsgHeader(&paramReq->header, FAPI_PARAM_REQUEST, msgLen);
1310
1311       DU_LOG("\nLWR_MAC: Sending Param Request to Phy");
1312       LwrMacSendToPhy(paramReq->header.message_type_id, \
1313          sizeof(fapi_param_req_t), (void *)paramReq);
1314    }
1315    else
1316    {
1317       DU_LOG("\nLWR_MAC: Failed to allocate memory for Param Request");
1318       return RFAILED;
1319    }
1320 #endif
1321    return ROK;
1322 }
1323
1324  /*******************************************************************
1325   *
1326   * @brief Sends FAPI Param Response to MAC via PHY
1327   *
1328   * @details
1329   *
1330   *    Function : lwr_mac_handleParamRspEvt
1331   *
1332   *    Functionality:
1333   *         -Sends FAPI Param rsp to MAC via PHY
1334   *
1335   * @params[in]
1336   * @return ROK     - success
1337   *         RFAILED - failure
1338   *
1339   * ****************************************************************/
1340
1341 S16 lwr_mac_handleParamRspEvt(void *msg)
1342 {
1343 #ifdef INTEL_FAPI
1344   /* stopGuardTimer(); */
1345    uint8_t index;
1346    uint32_t encodedVal;
1347    fapi_param_resp_t *paramRsp;
1348    ClCellParam *cellParam = NULLP;
1349
1350    paramRsp = (fapi_param_resp_t *)msg;
1351    DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1352
1353    if(paramRsp != NULLP)
1354    {
1355       MAC_ALLOC(cellParam, sizeof(ClCellParam));
1356       if(cellParam != NULLP)
1357       {
1358          DU_LOG("\n LWR_MAC: Filling TLVS into MAC API");
1359          if(paramRsp->error_code == MSG_OK)
1360          {
1361             for(index = 0; index < paramRsp->number_of_tlvs; index++)
1362             {
1363                switch(paramRsp->tlvs[index].tl.tag)
1364                {
1365                   case FAPI_RELEASE_CAPABILITY_TAG:
1366                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1367                      if(encodedVal != RFAILED && (encodedVal & RELEASE_15) == RELEASE_15)
1368                      {
1369                         cellParam->releaseCapability = RELEASE_15;
1370                      }
1371                      break;
1372
1373                   case FAPI_PHY_STATE_TAG:
1374                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1375                      if(encodedVal != RFAILED && encodedVal != clGlobalCp.phyState)
1376                      {
1377                         printf("\n PhyState mismatch [%d][%d]", clGlobalCp.phyState, clGlobalCp.event);
1378                         RETVALUE(RFAILED);
1379                      }
1380                      break;
1381
1382                   case FAPI_SKIP_BLANK_DL_CONFIG_TAG:
1383                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1384                      if(encodedVal != RFAILED && encodedVal != 0)
1385                      {
1386                         cellParam->skipBlankDlConfig = SUPPORTED;
1387                      }
1388                      else
1389                      {
1390                         cellParam->skipBlankDlConfig = NOT_SUPPORTED;
1391                      }
1392                      break;
1393
1394                   case FAPI_SKIP_BLANK_UL_CONFIG_TAG:
1395                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1396                      if(encodedVal != RFAILED && encodedVal != 0)
1397                      {
1398                         cellParam->skipBlankUlConfig = SUPPORTED;
1399                      }
1400                      else
1401                      {
1402                         cellParam->skipBlankUlConfig = NOT_SUPPORTED;
1403                      }
1404                      break;
1405
1406                   case FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG:
1407                      cellParam->numTlvsToReport = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1408                      break;
1409
1410                   case FAPI_CYCLIC_PREFIX_TAG:
1411                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1412                      if(encodedVal != RFAILED)
1413                      {
1414                         fillCyclicPrefix(encodedVal, &cellParam);
1415                      }
1416                      break;
1417
1418                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG:
1419                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1420                      if(encodedVal != RFAILED)
1421                      {
1422                         fillSubcarrierSpaceDl(encodedVal, &cellParam);
1423                      }
1424                      break;
1425
1426                   case FAPI_SUPPORTED_BANDWIDTH_DL_TAG:
1427                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1428                      if(encodedVal != RFAILED)
1429                      {
1430                         fillBandwidthDl(encodedVal, &cellParam);
1431                      }
1432                      break;
1433
1434                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG:
1435                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1436                      if(encodedVal != RFAILED)
1437                      {
1438                         fillSubcarrierSpaceUl(encodedVal, &cellParam);
1439                      }
1440                      break;
1441
1442                   case FAPI_SUPPORTED_BANDWIDTH_UL_TAG:
1443                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1444                      if(encodedVal != RFAILED)
1445                      {
1446                         fillBandwidthUl(encodedVal, &cellParam);
1447                      }
1448                      break;
1449
1450                   case FAPI_CCE_MAPPING_TYPE_TAG:
1451                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1452                      if(encodedVal != RFAILED)
1453                      {
1454                         fillCCEmaping(encodedVal, &cellParam);
1455                      }
1456                      break;
1457
1458                   case FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG:
1459                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1460                      if(encodedVal != RFAILED && encodedVal != 0)
1461                      {
1462                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = SUPPORTED;
1463                      }
1464                      else
1465                      {
1466                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = NOT_SUPPORTED;
1467                      }
1468                      break;
1469
1470                   case FAPI_PRECODER_GRANULARITY_CORESET_TAG:
1471                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1472                      if(encodedVal != RFAILED && encodedVal != 0)
1473                      {
1474                         cellParam->precoderGranularityCoreset = SUPPORTED;
1475                      }
1476                      else
1477                      {
1478                         cellParam->precoderGranularityCoreset = NOT_SUPPORTED;
1479                      }
1480                      break;
1481
1482                   case FAPI_PDCCH_MU_MIMO_TAG:
1483                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1484                      if(encodedVal != RFAILED && encodedVal != 0)
1485                      {
1486                         cellParam->pdcchMuMimo = SUPPORTED;
1487                      }
1488                      else
1489                      {
1490                         cellParam->pdcchMuMimo = NOT_SUPPORTED;
1491                      }
1492                      break;
1493
1494                   case FAPI_PDCCH_PRECODER_CYCLING_TAG:
1495                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1496                      if(encodedVal != RFAILED && encodedVal != 0)
1497                      {
1498                         cellParam->pdcchPrecoderCycling = SUPPORTED;
1499                      }
1500                      else
1501                      {
1502                         cellParam->pdcchPrecoderCycling = NOT_SUPPORTED;
1503                      }
1504                      break;
1505
1506                   case FAPI_MAX_PDCCHS_PER_SLOT_TAG:
1507                      cellParam->maxPdcchsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1508                      break;
1509
1510                   case FAPI_PUCCH_FORMATS_TAG:
1511                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1512                      if(encodedVal != RFAILED)
1513                      {
1514                         fillPucchFormat(encodedVal, &cellParam);
1515                      }
1516                      break;
1517
1518                   case FAPI_MAX_PUCCHS_PER_SLOT_TAG:
1519                    cellParam->maxPucchsPerSlot   = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1520                      break;
1521
1522                   case FAPI_PDSCH_MAPPING_TYPE_TAG:
1523                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1524                      if(encodedVal != RFAILED)
1525                      {
1526                         fillPdschMappingType(encodedVal, &cellParam);
1527                      }
1528                      break;
1529
1530                   case FAPI_PDSCH_ALLOCATION_TYPES_TAG:
1531                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1532                      if(encodedVal != RFAILED)
1533                      {
1534                         fillPdschAllocationType(encodedVal, &cellParam);
1535                      }
1536                      break;
1537
1538                   case FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG:
1539                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1540                      if(encodedVal != RFAILED)
1541                      {
1542                         fillPrbMappingType(encodedVal, &cellParam);
1543                      }
1544                      break;
1545
1546                   case FAPI_PDSCH_CBG_TAG:
1547                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1548                      if(encodedVal != RFAILED && encodedVal != 0)
1549                      {
1550                         cellParam->pdschCbg = SUPPORTED;
1551                      }
1552                      else
1553                      {
1554                         cellParam->pdschCbg = NOT_SUPPORTED;
1555                      }
1556                      break;
1557
1558                   case FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG:
1559                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1560                      if(encodedVal != RFAILED)
1561                      {
1562                         fillPdschDmrsConfigType(encodedVal, &cellParam);
1563                      }
1564                      break;
1565
1566                   case FAPI_PDSCH_DMRS_MAX_LENGTH_TAG:
1567                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1568                      if(encodedVal != RFAILED)
1569                      {
1570                         fillPdschDmrsLength(encodedVal, &cellParam);
1571                      }
1572                      break;
1573
1574                   case FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG:
1575                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1576                      if(encodedVal != RFAILED)
1577                      {
1578                         fillPdschDmrsAddPos(encodedVal, &cellParam);
1579                      }
1580                      break;
1581
1582                   case FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG:
1583                      cellParam->maxPdschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1584                      break;
1585
1586                   case FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG:
1587                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1588                      if(encodedVal != RFAILED && encodedVal < FAPI_MAX_NUMBERMIMO_LAYERS_PDSCH)
1589                      {
1590                         cellParam->maxNumberMimoLayersPdsch   = encodedVal;
1591                      }
1592                      break;
1593
1594                   case FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG:
1595                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1596                      if(encodedVal != RFAILED)
1597                      {
1598                         fillModulationOrderDl(encodedVal, &cellParam);
1599                      }
1600                      break;
1601
1602                   case FAPI_MAX_MU_MIMO_USERS_DL_TAG:
1603                      cellParam->maxMuMimoUsersDl         = \
1604                                                            getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1605                      break;
1606
1607                   case FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG:
1608                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1609                      if(encodedVal != RFAILED && encodedVal != 0)
1610                      {
1611                         cellParam->pdschDataInDmrsSymbols = SUPPORTED;
1612                      }
1613                      else
1614                      {
1615                         cellParam->pdschDataInDmrsSymbols = NOT_SUPPORTED;
1616                      }
1617                      break;
1618
1619                   case FAPI_PREMPTIONSUPPORT_TAG:
1620                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1621                      if(encodedVal != RFAILED && encodedVal != 0)
1622                      {
1623                         cellParam->premptionSupport = SUPPORTED;
1624                      }
1625                      else
1626                      {
1627                         cellParam->premptionSupport = NOT_SUPPORTED;
1628                      }
1629                      break;
1630
1631                   case FAPI_PDSCH_NON_SLOT_SUPPORT_TAG:
1632                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1633                      if(encodedVal != RFAILED && encodedVal != 0)
1634                      {
1635                         cellParam->pdschNonSlotSupport = SUPPORTED;
1636                      }
1637                      else
1638                      {
1639                         cellParam->pdschNonSlotSupport = NOT_SUPPORTED;
1640                      }
1641                      break;
1642
1643                   case FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG:
1644                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1645                      if(encodedVal != RFAILED && encodedVal != 0)
1646                      {
1647                         cellParam->uciMuxUlschInPusch = SUPPORTED;
1648                      }
1649                      else
1650                      {
1651                         cellParam->uciMuxUlschInPusch = NOT_SUPPORTED;
1652                      }
1653                      break;
1654
1655                   case FAPI_UCI_ONLY_PUSCH_TAG:
1656                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1657                      if(encodedVal != RFAILED && encodedVal != 0)
1658                      {
1659                         cellParam->uciOnlyPusch = SUPPORTED;
1660                      }
1661                      else
1662                      {
1663                         cellParam->uciOnlyPusch = NOT_SUPPORTED;
1664                      }
1665                      break;
1666
1667                   case FAPI_PUSCH_FREQUENCY_HOPPING_TAG:
1668                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1669                      if(encodedVal != RFAILED && encodedVal != 0)
1670                      {
1671                         cellParam->puschFrequencyHopping = SUPPORTED;
1672                      }
1673                      else
1674                      {
1675                         cellParam->puschFrequencyHopping = NOT_SUPPORTED;
1676                      }
1677                      break;
1678
1679                  case FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG:
1680                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1681                     if(encodedVal != RFAILED)
1682                     {
1683                        fillPuschDmrsConfig(encodedVal, &cellParam);
1684                     }
1685                     break;
1686
1687                  case FAPI_PUSCH_DMRS_MAX_LEN_TAG:
1688                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1689                     if(encodedVal != RFAILED)
1690                     {
1691                        fillPuschDmrsLength(encodedVal, &cellParam);
1692                     }
1693                     break;
1694
1695                  case FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG:
1696                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1697                     if(encodedVal != RFAILED)
1698                     {
1699                        fillPuschDmrsAddPos(encodedVal, &cellParam);
1700                     }
1701                     break;
1702
1703                  case FAPI_PUSCH_CBG_TAG:
1704                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1705                     if(encodedVal != RFAILED && encodedVal != 0)
1706                     {
1707                        cellParam->puschCbg = SUPPORTED;
1708                     }
1709                     else
1710                     {
1711                        cellParam->puschCbg = NOT_SUPPORTED;
1712                     }
1713                     break;
1714
1715                 case FAPI_PUSCH_MAPPING_TYPE_TAG:
1716                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1717                    if(encodedVal != RFAILED)
1718                    {
1719                       fillPuschMappingType(encodedVal, &cellParam);
1720                    }
1721                    break;
1722
1723                 case FAPI_PUSCH_ALLOCATION_TYPES_TAG:
1724                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1725                    if(encodedVal != RFAILED)
1726                    {
1727                       fillPuschAllocationType(encodedVal, &cellParam);
1728                    }
1729                    break;
1730
1731                 case FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG:
1732                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1733                    if(encodedVal != RFAILED)
1734                    {
1735                       fillPuschPrbMappingType(encodedVal, &cellParam);
1736                    }
1737                    break;
1738
1739                 case FAPI_PUSCH_MAX_PTRS_PORTS_TAG:
1740                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1741                    if(encodedVal != RFAILED && encodedVal < FAPI_PUSCH_MAX_PTRS_PORTS_UB)
1742                    {
1743                       cellParam->puschMaxPtrsPorts = encodedVal;
1744                    }
1745                    break;
1746
1747                 case FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG:
1748                    cellParam->maxPduschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1749                    break;
1750
1751                 case FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG:
1752                    cellParam->maxNumberMimoLayersNonCbPusch = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1753                    break;
1754
1755                 case FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG:
1756                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1757                    if(encodedVal != RFAILED)
1758                    {
1759                       fillModulationOrderUl(encodedVal, &cellParam);
1760                    }
1761                    break;
1762
1763                 case FAPI_MAX_MU_MIMO_USERS_UL_TAG:
1764                    cellParam->maxMuMimoUsersUl = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1765                    break;
1766
1767                 case FAPI_DFTS_OFDM_SUPPORT_TAG:
1768                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1769                    if(encodedVal != RFAILED && encodedVal != 0)
1770                    {
1771                       cellParam->dftsOfdmSupport = SUPPORTED;
1772                    }
1773                    else
1774                    {
1775                       cellParam->dftsOfdmSupport = NOT_SUPPORTED;
1776                    }
1777                    break;
1778
1779                 case FAPI_PUSCH_AGGREGATION_FACTOR_TAG:
1780                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1781                    if(encodedVal != RFAILED)
1782                    {
1783                       fillPuschAggregationFactor(encodedVal, &cellParam);
1784                    }
1785                    break;
1786
1787                 case FAPI_PRACH_LONG_FORMATS_TAG:
1788                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1789                    if(encodedVal != RFAILED)
1790                    {
1791                       fillPrachLongFormat(encodedVal, &cellParam);
1792                    }
1793                    break;
1794
1795                 case FAPI_PRACH_SHORT_FORMATS_TAG:
1796                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1797                    if(encodedVal != RFAILED)
1798                    {
1799                       fillPrachShortFormat(encodedVal, &cellParam);
1800                    }
1801                    break;
1802
1803                 case FAPI_PRACH_RESTRICTED_SETS_TAG:
1804                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1805                    if(encodedVal != RFAILED && encodedVal != 0)
1806                    {
1807                       cellParam->prachRestrictedSets = SUPPORTED;
1808                    }
1809                    else
1810                    {
1811                       cellParam->prachRestrictedSets = NOT_SUPPORTED;
1812                    }
1813                    break;
1814
1815                case FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG:
1816                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1817                   if(encodedVal != RFAILED)
1818                   {
1819                      fillFdOccasions(encodedVal, &cellParam);
1820                   }
1821                   break;
1822
1823                case FAPI_RSSI_MEASUREMENT_SUPPORT_TAG:
1824                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1825                   if(encodedVal != RFAILED)
1826                   {
1827                      fillRssiMeas(encodedVal, &cellParam);
1828                   }
1829                   break;
1830                default:
1831                //printf("\n Invalid value for TLV[%x] at index[%d]", paramRsp->tlvs[index].tl.tag, index);
1832                break;
1833               }
1834            }
1835            MAC_FREE(cellParam, sizeof(ClCellParam));
1836            sendToLowerMac(FAPI_CONFIG_REQUEST, 0, (void *)NULL);
1837            return ROK;
1838          }
1839          else
1840          {
1841             DU_LOG("\n LWR_MAC: Invalid error code %d", paramRsp->error_code);
1842             return RFAILED;
1843          }
1844      }
1845      else
1846      {
1847         DU_LOG("\nLWR_MAC: Failed to allocate memory for cell param");
1848         return RFAILED;
1849      }
1850    }
1851    else
1852    {
1853        DU_LOG("\nLWR_MAC:  Param Response received from PHY is NULL");
1854        return RFAILED;
1855    }
1856 #else
1857    return ROK;
1858 #endif
1859 }
1860
1861  /*******************************************************************
1862   *
1863   * @brief Sends FAPI Config req to PHY
1864   *
1865   * @details
1866   *
1867   *    Function : lwr_mac_handleConfigReqEvt
1868   *
1869   *    Functionality:
1870   *         -Sends FAPI Config Req to PHY
1871   *
1872   * @params[in]
1873   * @return ROK     - success
1874   *         RFAILED - failure
1875   *
1876   * ****************************************************************/
1877
1878 S16 lwr_mac_handleConfigReqEvt(void *msg)
1879 {
1880 #ifdef INTEL_FAPI
1881    Inst inst = 0;
1882    uint8_t idx = 0;
1883    uint8_t index = 0;
1884    uint32_t msgLen = 0;
1885    uint32_t configReqSize;
1886    RgCellCb  *cellParams;
1887    MacCellCfg macCfgParams;
1888    fapi_config_req_t *configReq;
1889
1890    DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, \
1891       clGlobalCp.phyState);
1892
1893    cellParams = rgCb[inst].cell;
1894    macCfgParams = cellParams->macCellCfg;
1895
1896    configReqSize = sizeof(fapi_config_req_t);
1897    LWR_MAC_ALLOC(configReq, configReqSize);
1898    if(configReq != NULL)
1899    {
1900       msgLen = sizeof(macCfgParams.numTlv);
1901       configReq->number_of_tlvs = macCfgParams.numTlv;
1902
1903       if(macCfgParams.dlCarrCfg.pres)
1904       {
1905          fillTlvs(&configReq->tlvs[index++], FAPI_DL_BANDWIDTH_TAG,           \
1906             sizeof(uint16_t), macCfgParams.dlCarrCfg.bw, &msgLen);
1907          fillTlvs(&configReq->tlvs[index++], FAPI_DL_FREQUENCY_TAG,           \
1908             sizeof(uint32_t), macCfgParams.dlCarrCfg.freq, &msgLen);
1909          fillTlvs(&configReq->tlvs[index++], FAPI_DL_K0_TAG,                  \
1910             sizeof(uint16_t), macCfgParams.dlCarrCfg.k0[0], &msgLen);
1911          fillTlvs(&configReq->tlvs[index++], FAPI_DL_GRIDSIZE_TAG,            \
1912             sizeof(uint16_t), macCfgParams.dlCarrCfg.gridSize[0], &msgLen);
1913          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_TX_ANT_TAG,             \
1914             sizeof(uint16_t), macCfgParams.dlCarrCfg.numAnt, &msgLen);
1915       }
1916       if(macCfgParams.ulCarrCfg.pres)
1917       {
1918          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_BANDWIDTH_TAG,       \
1919             sizeof(uint16_t), macCfgParams.ulCarrCfg.bw, &msgLen);
1920          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_FREQUENCY_TAG,       \
1921             sizeof(uint32_t), macCfgParams.ulCarrCfg.freq, &msgLen);
1922          fillTlvs(&configReq->tlvs[index++], FAPI_UL_K0_TAG,                  \
1923             sizeof(uint16_t), macCfgParams.ulCarrCfg.k0[0], &msgLen);
1924          fillTlvs(&configReq->tlvs[index++], FAPI_UL_GRID_SIZE_TAG,           \
1925             sizeof(uint16_t), macCfgParams.ulCarrCfg.gridSize[0], &msgLen);
1926          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_RX_ANT_TAG,             \
1927             sizeof(uint16_t), macCfgParams.ulCarrCfg.numAnt, &msgLen);
1928       }
1929       fillTlvs(&configReq->tlvs[index++], FAPI_FREQUENCY_SHIFT_7P5_KHZ_TAG,   \
1930          sizeof(uint8_t), macCfgParams.freqShft, &msgLen);
1931
1932       /* fill cell config */
1933       fillTlvs(&configReq->tlvs[index++], FAPI_PHY_CELL_ID_TAG,               \
1934          sizeof(uint8_t), macCfgParams.phyCellId, &msgLen);
1935       fillTlvs(&configReq->tlvs[index++], FAPI_FRAME_DUPLEX_TYPE_TAG,         \
1936          sizeof(uint8_t), macCfgParams.dupType, &msgLen);
1937
1938       /* fill SSB configuration */
1939       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_POWER_TAG,             \
1940          sizeof(uint32_t), macCfgParams.ssbCfg.ssbPbchPwr, &msgLen);
1941       fillTlvs(&configReq->tlvs[index++], FAPI_BCH_PAYLOAD_TAG,               \
1942          sizeof(uint8_t), macCfgParams.ssbCfg.bchPayloadFlag, &msgLen);
1943       fillTlvs(&configReq->tlvs[index++], FAPI_SCS_COMMON_TAG,                \
1944          sizeof(uint8_t), macCfgParams.ssbCfg.scsCmn, &msgLen);
1945
1946       /* fill PRACH configuration */
1947       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SEQUENCE_LENGTH_TAG,     \
1948          sizeof(uint8_t), macCfgParams.prachCfg.prachSeqLen, &msgLen);
1949       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SUBC_SPACING_TAG,        \
1950          sizeof(uint8_t), macCfgParams.prachCfg.prachSubcSpacing, &msgLen);
1951       fillTlvs(&configReq->tlvs[index++], FAPI_RESTRICTED_SET_CONFIG_TAG,     \
1952          sizeof(uint8_t), macCfgParams.prachCfg.prachRstSetCfg, &msgLen);
1953       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_PRACH_FD_OCCASIONS_TAG,
1954          sizeof(uint8_t), macCfgParams.prachCfg.msg1Fdm, &msgLen);
1955       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ROOT_SEQUENCE_INDEX_TAG, \
1956          sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].rootSeqIdx, &msgLen);
1957       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_ROOT_SEQUENCES_TAG,        \
1958          sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numRootSeq, &msgLen);
1959       fillTlvs(&configReq->tlvs[index++], FAPI_K1_TAG,                        \
1960          sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].k1, &msgLen);
1961       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ZERO_CORR_CONF_TAG ,     \
1962          sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].zeroCorrZoneCfg, &msgLen);
1963       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_UNUSED_ROOT_SEQUENCES_TAG, \
1964          sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numUnusedRootSeq, &msgLen);
1965       if(macCfgParams.prachCfg.fdm[0].numUnusedRootSeq)
1966       {
1967          for(idx = 0; idx < macCfgParams.prachCfg.fdm[0].numUnusedRootSeq; idx++)
1968             fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG,   \
1969                sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].unsuedRootSeq[idx], \
1970                &msgLen);
1971       }
1972       else
1973       {
1974          macCfgParams.prachCfg.fdm[0].unsuedRootSeq = NULL;
1975       }
1976
1977       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PER_RACH_TAG,              \
1978          sizeof(uint8_t), macCfgParams.prachCfg.ssbPerRach, &msgLen);
1979       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_MULTIPLE_CARRIERS_IN_A_BAND_TAG,  \
1980          sizeof(uint8_t), macCfgParams.prachCfg.prachMultCarrBand, &msgLen);
1981
1982       /* fill SSB table */
1983       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_OFFSET_POINT_A_TAG,        \
1984          sizeof(uint16_t), macCfgParams.ssbCfg.ssbOffsetPointA, &msgLen);
1985       fillTlvs(&configReq->tlvs[index++], FAPI_BETA_PSS_TAG,                  \
1986          sizeof(uint8_t),  macCfgParams.ssbCfg.betaPss, &msgLen);
1987       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PERIOD_TAG,                \
1988          sizeof(uint8_t),  macCfgParams.ssbCfg.ssbPeriod, &msgLen);
1989       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_SUBCARRIER_OFFSET_TAG,     \
1990          sizeof(uint8_t),  macCfgParams.ssbCfg.ssbScOffset, &msgLen);
1991       fillTlvs(&configReq->tlvs[index++], FAPI_MIB_TAG ,                      \
1992          sizeof(uint32_t), macCfgParams.ssbCfg.mibPdu[0], &msgLen);
1993       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_MASK_TAG,                  \
1994          sizeof(uint32_t), macCfgParams.ssbCfg.ssbMask[0], &msgLen);
1995       fillTlvs(&configReq->tlvs[index++], FAPI_BEAM_ID_TAG,                   \
1996          sizeof(uint8_t),  macCfgParams.ssbCfg.beamId[0], &msgLen);
1997       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_MULTIPLE_CARRIERS_IN_A_BAND_TAG, \
1998          sizeof(uint8_t), macCfgParams.ssbCfg.multCarrBand, &msgLen);
1999       fillTlvs(&configReq->tlvs[index++], FAPI_MULTIPLE_CELLS_SS_PBCH_IN_A_CARRIER_TAG, \
2000          sizeof(uint8_t), macCfgParams.ssbCfg.multCellCarr, &msgLen);
2001
2002       /* fill TDD table */
2003       fillTlvs(&configReq->tlvs[index++], FAPI_TDD_PERIOD_TAG,                \
2004          sizeof(uint8_t), macCfgParams.tddCfg.tddPeriod, &msgLen);
2005       fillTlvs(&configReq->tlvs[index++], FAPI_SLOT_CONFIG_TAG,               \
2006          sizeof(uint8_t), macCfgParams.tddCfg.slotCfg[0][0], &msgLen);
2007
2008       /* fill measurement config */
2009       fillTlvs(&configReq->tlvs[index++], FAPI_RSSI_MESUREMENT_TAG,           \
2010          sizeof(uint8_t), macCfgParams.rssiUnit, &msgLen);
2011
2012       /* fill DMRS Type A Pos */
2013                 fillTlvs(&configReq->tlvs[index++], FAPI_DMRS_TYPE_A_POS_TAG,           \
2014                    sizeof(uint8_t), macCfgParams.dmrsTypeAPos, &msgLen);
2015
2016       fillMsgHeader(&configReq->header, FAPI_CONFIG_REQUEST, msgLen);
2017
2018       DU_LOG("\nLWR_MAC: Sending Config Request to Phy");
2019       LwrMacSendToPhy(configReq->header.message_type_id, configReqSize, (void *)configReq);
2020    }
2021    else
2022    {
2023       DU_LOG("\nLWR_MAC: Failed to allocate memory for config Request");
2024       return RFAILED;
2025    }
2026 #endif
2027
2028    return ROK;
2029 } /* lwr_mac_handleConfigReqEvt */
2030
2031 /*******************************************************************
2032  *
2033  * @brief Processes config response from phy
2034  *
2035  * @details
2036  *
2037  *    Function : lwr_mac_handleConfigRspEvt
2038  *
2039  *    Functionality:
2040  *          Processes config response from phy
2041  *
2042  * @params[in] FAPI message pointer 
2043  * @return ROK     - success
2044  *         RFAILED - failure
2045  *
2046  * ****************************************************************/
2047
2048 S16 lwr_mac_handleConfigRspEvt(void *msg)
2049 {
2050 #ifdef INTEL_FAPI
2051    fapi_config_resp_t *configRsp;
2052    configRsp = (fapi_config_resp_t *)msg;
2053
2054    DU_LOG("\nLWR_MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, \
2055       clGlobalCp.phyState);
2056
2057    if(configRsp != NULL)
2058    {
2059       if(configRsp->error_code == MSG_OK)
2060       {
2061          DU_LOG("\nLWR_MAC: PHY has moved to Configured state \n");
2062          clGlobalCp.phyState = PHY_STATE_CONFIGURED;
2063          /* TODO : 
2064           * Store config response into an intermediate struture and send to MAC
2065           * Support LC and LWLC for sending config rsp to MAC 
2066           */
2067          fapiMacConfigRsp();
2068       }
2069       else
2070       {
2071          DU_LOG("\n LWR_MAC: Invalid error code %d", configRsp->error_code);
2072          return RFAILED;
2073       }
2074    }
2075    else
2076    {
2077       DU_LOG("\nLWR_MAC: Config Response received from PHY is NULL");
2078       return RFAILED;
2079    }
2080 #endif
2081
2082    return ROK;
2083 } /* lwr_mac_handleConfigRspEvt */
2084
2085 /*******************************************************************
2086  *
2087  * @brief Build and send start request to phy
2088  *
2089  * @details
2090  *
2091  *    Function : lwr_mac_handleStartReqEvt
2092  *
2093  *    Functionality:
2094  *       Build and send start request to phy
2095  *
2096  * @params[in] FAPI message pointer
2097  * @return ROK     - success
2098  *         RFAILED - failure
2099  *
2100  * ****************************************************************/
2101 S16 lwr_mac_handleStartReqEvt(void *msg)
2102 {
2103 #ifdef INTEL_FAPI
2104    uint32_t msgLen = 0;
2105    fapi_start_req_t *startReq;
2106
2107    LWR_MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
2108    if(startReq != NULL)
2109    {
2110       fillMsgHeader(&startReq->header, FAPI_START_REQUEST, msgLen);
2111
2112       DU_LOG("\nLWR_MAC: Sending Start Request to PHY");
2113       LwrMacSendToPhy(startReq->header.message_type_id, sizeof(fapi_start_req_t),\
2114          (void *)startReq);
2115    }
2116    else
2117    {
2118       DU_LOG("\nLWR_MAC: Failed to allocate memory for Start Request");
2119       return RFAILED;
2120    }
2121 #endif
2122    return ROK;
2123 } /* lwr_mac_handleStartReqEvt */
2124
2125  /*******************************************************************
2126   *
2127   * @brief Sends FAPI Stop Req to PHY
2128   *
2129   * @details
2130   *
2131   *    Function : lwr_mac_handleStopReqEvt
2132   *
2133   *    Functionality:
2134   *         -Sends FAPI Stop Req to PHY
2135   *
2136   * @params[in]
2137   * @return ROK     - success
2138   *         RFAILED - failure
2139   *
2140   ********************************************************************/
2141
2142 S16 lwr_mac_handleStopReqEvt(void *msg)
2143 {
2144 #ifdef INTEL_FAPI
2145    uint32_t msgLen = 0;
2146    fapi_stop_req_t *stopReq = NULLP;
2147    LWR_MAC_ALLOC(stopReq, sizeof(fapi_stop_req_t));
2148    if(stopReq != NULLP)
2149    {
2150       fillMsgHeader(&stopReq->header, FAPI_STOP_REQUEST, msgLen);
2151       DU_LOG("\nLOWER MAC: Sending Stop Request to PHY");
2152       LwrMacSendToPhy(stopReq->header.message_type_id, sizeof(fapi_stop_req_t), (void *)stopReq);
2153    }
2154    else
2155    {
2156       DU_LOG("\nLOWER MAC: Failed to allocate memory for Stop Request");
2157       return RFAILED;
2158    }
2159 #endif
2160    return ROK;
2161 }
2162
2163 /*******************************************************************
2164  *
2165  * @brief Modifes the received mibPdu to uint32 bit
2166  *        and stores it in MacCellCfg
2167  *
2168  * @details
2169  *
2170  *    Function : setMibPdu
2171  *
2172  *    Functionality:
2173  *         -Sets the MibPdu
2174  *
2175  * @params[in] Pointer to mibPdu
2176  *             pointer to modified value
2177  ******************************************************************/
2178
2179 PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val, uint16_t sfn)
2180 {
2181    *mibPdu |= (((uint8_t)(sfn >> 2)) & MIB_SFN_BITMASK);
2182    *val = (mibPdu[0] << 24 | mibPdu[1] << 16 | mibPdu[2] << 8);
2183     DU_LOG("\nLWR_MAC: MIB PDU %x", *val);
2184 }
2185
2186 #ifdef INTEL_FAPI
2187 /*******************************************************************
2188  *
2189  * @brief fills SSB PDU required for DL TTI info in MAC
2190  *
2191  * @details
2192  *
2193  *    Function : fillSsbPdu
2194  *
2195  *    Functionality:
2196  *         -Fills the SSB PDU info
2197  *          stored in MAC
2198  *
2199  * @params[in] Pointer to FAPI DL TTI Req
2200  *             Pointer to RgCellCb
2201  *             Pointer to msgLen of DL TTI Info
2202  * @return ROK
2203  *
2204  ******************************************************************/
2205
2206 S16 fillSsbPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, MacCellCfg *macCellCfg,
2207    MacDlSlot *currDlSlot, uint32_t *msgLen, uint8_t ssbIdxCount, uint16_t sfn)
2208 {
2209    uint32_t mibPayload = 0;
2210    if(dlTtiReqPdu != NULL)
2211    {
2212       dlTtiReqPdu->pduType = SSB_PDU_TYPE;     /* SSB PDU */
2213       dlTtiReqPdu->u.ssb_pdu.physCellId = macCellCfg->phyCellId;
2214       dlTtiReqPdu->u.ssb_pdu.betaPss = macCellCfg->ssbCfg.betaPss;
2215       dlTtiReqPdu->u.ssb_pdu.ssbBlockIndex = currDlSlot->dlInfo.brdcstAlloc.ssbInfo[ssbIdxCount].ssbIdx;
2216       dlTtiReqPdu->u.ssb_pdu.ssbSubCarrierOffset = macCellCfg->ssbCfg.ssbScOffset;
2217       /* ssbOfPdufstA to be filled in ssbCfg */
2218       dlTtiReqPdu->u.ssb_pdu.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2219       dlTtiReqPdu->u.ssb_pdu.bchPayloadFlag = macCellCfg->ssbCfg.bchPayloadFlag;
2220       /* Bit manipulation for SFN */
2221       setMibPdu(macCellCfg->ssbCfg.mibPdu, &mibPayload, sfn);
2222       dlTtiReqPdu->u.ssb_pdu.bchPayload.v.bchPayload = mibPayload;
2223       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.numPrgs = 0;
2224       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.prgSize = 0;
2225       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.digBfInterfaces = 0;
2226       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.pmi_bfi[0].pmIdx = 0;
2227       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming. \
2228          pmi_bfi[0].beamIdx[0].beamidx = macCellCfg->ssbCfg.beamId[0];
2229       dlTtiReqPdu->pduSize = sizeof(fapi_dl_ssb_pdu_t);  /* Size of SSB PDU */
2230       SET_MSG_LEN(*msgLen, (sizeof(dlTtiReqPdu->pduType) + \
2231          sizeof(dlTtiReqPdu->pduSize) + sizeof(fapi_dl_ssb_pdu_t)));
2232       return ROK;
2233     }
2234     else
2235     {
2236        return RFAILED;
2237     }
2238 }
2239
2240 /*******************************************************************
2241  *
2242  * @brief fills Dl DCI PDU required for DL TTI info in MAC
2243  *
2244  * @details
2245  *
2246  *    Function : fillSib1DlDciPdu
2247  *
2248  *    Functionality:
2249  *         -Fills the Dl DCI PDU
2250  *
2251  * @params[in] Pointer to fapi_dl_dci_t
2252  *             Pointer to PdcchCfg
2253  * @return ROK
2254  *
2255  ******************************************************************/
2256
2257 void fillSib1DlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *sib1PdcchInfo)
2258 {
2259    if(dlDciPtr != NULLP)
2260    {
2261       uint8_t numBytes;
2262       uint8_t bytePos;
2263       uint8_t bitPos;
2264       
2265       uint16_t coreset0Size;
2266       uint16_t rbStart;
2267       uint16_t rbLen;
2268       uint32_t freqDomResAssign;
2269       uint32_t timeDomResAssign;
2270       uint8_t  VRB2PRBMap;
2271       uint32_t modNCodScheme;
2272       uint8_t  redundancyVer;
2273       uint32_t sysInfoInd;
2274       uint32_t reserved;
2275
2276       /* Size(in bits) of each field in DCI format 0_1 
2277        * as mentioned in spec 38.214 */
2278       uint8_t freqDomResAssignSize;
2279       uint8_t timeDomResAssignSize = 4;
2280       uint8_t VRB2PRBMapSize       = 1;
2281       uint8_t modNCodSchemeSize    = 5;
2282       uint8_t redundancyVerSize    = 2;
2283       uint8_t sysInfoIndSize       = 1;
2284       uint8_t reservedSize         = 15;
2285
2286       dlDciPtr->rnti = sib1PdcchInfo->dci.rnti;
2287       dlDciPtr->scramblingId = sib1PdcchInfo->dci.scramblingId;    
2288       dlDciPtr->scramblingRnti = sib1PdcchInfo->dci.scramblingRnti;
2289       dlDciPtr->cceIndex = sib1PdcchInfo->dci.cceIndex;
2290       dlDciPtr->aggregationLevel = sib1PdcchInfo->dci.aggregLevel;
2291       dlDciPtr->pc_and_bform.numPrgs = sib1PdcchInfo->dci.beamPdcchInfo.numPrgs;
2292       dlDciPtr->pc_and_bform.prgSize = sib1PdcchInfo->dci.beamPdcchInfo.prgSize;
2293       dlDciPtr->pc_and_bform.digBfInterfaces = sib1PdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2294       dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = sib1PdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2295       dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = sib1PdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2296       dlDciPtr->beta_pdcch_1_0 = sib1PdcchInfo->dci.txPdcchPower.powerValue;           
2297       dlDciPtr->powerControlOfssetSS = sib1PdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2298
2299       /* Calculating freq domain resource allocation field value and size
2300        * coreset0Size = Size of coreset 0
2301        * RBStart = Starting Virtual Rsource block
2302        * RBLen = length of contiguously allocted RBs
2303        * Spec 38.214 Sec 5.1.2.2.2
2304        */
2305       coreset0Size= sib1PdcchInfo->coreset0Cfg.coreSet0Size;
2306       rbStart = 0;              /* For SIB1 */
2307       //rbStart = sib1PdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.startPrb;
2308       rbLen = sib1PdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2309
2310       if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2311       {
2312          if((rbLen - 1) <= floor(coreset0Size / 2))
2313             freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2314          else
2315             freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2316                + (coreset0Size - 1 - rbStart);
2317
2318          freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2319       }
2320
2321       /* Fetching DCI field values */
2322       timeDomResAssign = sib1PdcchInfo->dci.pdschCfg->pdschTimeAlloc.
2323                          rowIndex -1;
2324       VRB2PRBMap       = sib1PdcchInfo->dci.pdschCfg->pdschFreqAlloc.\
2325                          vrbPrbMapping;
2326       modNCodScheme    = sib1PdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2327       redundancyVer    = sib1PdcchInfo->dci.pdschCfg->codeword[0].rvIndex;
2328       sysInfoInd       = 0;           /* 0 for SIB1; 1 for SI messages */
2329       reserved         = 0;
2330
2331       /* Reversing bits in each DCI field */
2332       freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2333       timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2334       VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2335       modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2336       redundancyVer    = reverseBits(redundancyVer, redundancyVerSize);
2337       sysInfoInd       = reverseBits(sysInfoInd, sysInfoIndSize);
2338
2339      /* Calulating total number of bytes in buffer */
2340      dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2341               + VRB2PRBMapSize + modNCodSchemeSize + redundancyVerSize\
2342               + sysInfoIndSize + reservedSize;
2343
2344      numBytes = dlDciPtr->payloadSizeBits / 8;
2345      if(dlDciPtr->payloadSizeBits % 8)
2346         numBytes += 1;
2347
2348      if(numBytes > DCI_PAYLOAD_BYTE_LEN)
2349      {
2350         DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2351         return;
2352      }
2353
2354      /* Initialize buffer */
2355      for(bytePos = 0; bytePos < numBytes; bytePos++)
2356         dlDciPtr->payload[bytePos] = 0;
2357
2358      bytePos = numBytes - 1;
2359      bitPos = 0;
2360
2361      /* Packing DCI format fields */
2362      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2363         freqDomResAssign, freqDomResAssignSize);
2364      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2365         timeDomResAssign, timeDomResAssignSize);
2366      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2367         VRB2PRBMap, VRB2PRBMapSize);
2368      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2369         modNCodScheme, modNCodSchemeSize);
2370      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2371         redundancyVer, redundancyVerSize);
2372      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2373         sysInfoInd, sysInfoIndSize);
2374      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2375         reserved, reservedSize);
2376
2377    }
2378 } /* fillSib1DlDciPdu */
2379
2380 /*******************************************************************
2381  *
2382  * @brief fills Dl DCI PDU required for DL TTI info in MAC
2383  *
2384  * @details
2385  *
2386  *    Function : fillRarDlDciPdu
2387  *
2388  *    Functionality:
2389  *         -Fills the Dl DCI PDU
2390  *
2391  * @params[in] Pointer to fapi_dl_dci_t
2392  *             Pointer to PdcchCfg
2393  * @return ROK
2394  *
2395  ******************************************************************/
2396
2397 void fillRarDlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *rarPdcchInfo)
2398 {
2399    if(dlDciPtr != NULLP)
2400    {
2401       uint8_t numBytes;
2402       uint8_t bytePos;
2403       uint8_t bitPos;
2404
2405       uint16_t coreset0Size;
2406       uint16_t rbStart;
2407       uint16_t rbLen;
2408       uint32_t freqDomResAssign;
2409       uint8_t timeDomResAssign;
2410       uint8_t  VRB2PRBMap;
2411       uint8_t modNCodScheme;
2412       uint8_t tbScaling;
2413       uint32_t reserved;
2414
2415       /* Size(in bits) of each field in DCI format 1_0 */
2416       uint8_t freqDomResAssignSize;
2417       uint8_t timeDomResAssignSize = 4;
2418       uint8_t VRB2PRBMapSize       = 1;
2419       uint8_t modNCodSchemeSize    = 5;
2420       uint8_t tbScalingSize        = 2;
2421       uint8_t reservedSize         = 16;
2422
2423       dlDciPtr->rnti = rarPdcchInfo->dci.rnti;
2424       dlDciPtr->scramblingId = rarPdcchInfo->dci.scramblingId;    
2425       dlDciPtr->scramblingRnti = rarPdcchInfo->dci.scramblingRnti;
2426       dlDciPtr->cceIndex = rarPdcchInfo->dci.cceIndex;
2427       dlDciPtr->aggregationLevel = rarPdcchInfo->dci.aggregLevel;
2428       dlDciPtr->pc_and_bform.numPrgs = rarPdcchInfo->dci.beamPdcchInfo.numPrgs;
2429       dlDciPtr->pc_and_bform.prgSize = rarPdcchInfo->dci.beamPdcchInfo.prgSize;
2430       dlDciPtr->pc_and_bform.digBfInterfaces = rarPdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2431       dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = rarPdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2432       dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = rarPdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2433       dlDciPtr->beta_pdcch_1_0 = rarPdcchInfo->dci.txPdcchPower.powerValue;           
2434       dlDciPtr->powerControlOfssetSS = rarPdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2435
2436       /* Calculating freq domain resource allocation field value and size
2437        * coreset0Size = Size of coreset 0
2438        * RBStart = Starting Virtual Rsource block
2439        * RBLen = length of contiguously allocted RBs
2440        * Spec 38.214 Sec 5.1.2.2.2
2441        */
2442
2443       /* TODO: Fill values of coreset0Size, rbStart and rbLen */
2444       coreset0Size= rarPdcchInfo->coreset0Cfg.coreSet0Size;
2445       rbStart = 0;              /* For SIB1 */
2446       //rbStart = rarPdcchInfo->dci.pdschCfg->freqAlloc.rbStart;
2447       rbLen = rarPdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2448
2449       if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2450       {
2451          if((rbLen - 1) <= floor(coreset0Size / 2))
2452             freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2453          else
2454             freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2455                                + (coreset0Size - 1 - rbStart);
2456
2457          freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2458       }
2459
2460       /* Fetching DCI field values */
2461       timeDomResAssign = rarPdcchInfo->dci.pdschCfg->pdschTimeAlloc.rowIndex -1;
2462       VRB2PRBMap       = rarPdcchInfo->dci.pdschCfg->pdschFreqAlloc.vrbPrbMapping;
2463       modNCodScheme    = rarPdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2464       tbScaling        = 0; /* configured to 0 scaling */
2465       reserved         = 0;
2466
2467       /* Reversing bits in each DCI field */
2468       freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2469       timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2470       VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2471       modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2472       tbScaling        = reverseBits(tbScaling, tbScalingSize); 
2473
2474       /* Calulating total number of bytes in buffer */
2475       dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2476                                   + VRB2PRBMapSize + modNCodSchemeSize + tbScalingSize + reservedSize;
2477
2478       numBytes = dlDciPtr->payloadSizeBits / 8;
2479       if(dlDciPtr->payloadSizeBits % 8)
2480          numBytes += 1;
2481
2482       if(numBytes > DCI_PAYLOAD_BYTE_LEN)
2483       {
2484          DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2485          return;
2486       }
2487
2488       /* Initialize buffer */
2489       for(bytePos = 0; bytePos < numBytes; bytePos++)
2490          dlDciPtr->payload[bytePos] = 0;
2491
2492       bytePos = numBytes - 1;
2493       bitPos = 0;
2494
2495       /* Packing DCI format fields */
2496       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2497             freqDomResAssign, freqDomResAssignSize);
2498       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2499             timeDomResAssign, timeDomResAssignSize);
2500       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2501             VRB2PRBMap, VRB2PRBMapSize);
2502       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2503             modNCodScheme, modNCodSchemeSize);
2504       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2505             tbScaling, tbScalingSize);
2506       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2507             reserved, reservedSize);
2508    }
2509 } /* fillRarDlDciPdu */
2510
2511 /*******************************************************************
2512  *
2513  * @brief fills msg4 Dl DCI PDU required for DL TTI info in MAC
2514  *
2515  * @details
2516  *
2517  *    Function : fillMsg4DlDciPdu
2518  *
2519  *    Functionality:
2520  *         -Fills the Msg4 Dl DCI PDU
2521  *
2522  * @params[in] Pointer to fapi_dl_dci_t
2523  *             Pointer to PdcchCfg
2524  * @return ROK
2525  *
2526  ******************************************************************/
2527 void fillMsg4DlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *msg4PdcchInfo,\
2528 Msg4Info *msg4Info)
2529 {
2530    if(dlDciPtr != NULLP)
2531    {
2532       uint8_t numBytes;
2533       uint8_t bytePos;
2534       uint8_t bitPos;
2535
2536       uint16_t coreset0Size = 0;
2537       uint16_t rbStart = 0;
2538       uint16_t rbLen = 0;
2539       uint8_t  dciFormatId;
2540       uint32_t freqDomResAssign;
2541       uint8_t  timeDomResAssign;
2542       uint8_t  VRB2PRBMap;
2543       uint8_t  modNCodScheme;
2544       uint8_t  ndi = 0;
2545       uint8_t  redundancyVer = 0;
2546       uint8_t  harqProcessNum = 0;
2547       uint8_t  dlAssignmentIdx = 0;
2548       uint8_t  pucchTpc = 0;
2549       uint8_t  pucchResoInd = 0;
2550       uint8_t  harqFeedbackInd = 0;
2551
2552       /* Size(in bits) of each field in DCI format 1_0 */
2553       uint8_t dciFormatIdSize    = 1;
2554       uint8_t freqDomResAssignSize;
2555       uint8_t timeDomResAssignSize = 4;
2556       uint8_t VRB2PRBMapSize       = 1;
2557       uint8_t modNCodSchemeSize    = 5;
2558       uint8_t ndiSize              = 1;
2559       uint8_t redundancyVerSize    = 2;
2560       uint8_t harqProcessNumSize   = 4;
2561       uint8_t dlAssignmentIdxSize  = 2;
2562       uint8_t pucchTpcSize         = 2;
2563       uint8_t pucchResoIndSize     = 3;
2564       uint8_t harqFeedbackIndSize  = 3;
2565
2566       dlDciPtr->rnti = msg4PdcchInfo->dci.rnti;
2567       dlDciPtr->scramblingId = msg4PdcchInfo->dci.scramblingId;    
2568       dlDciPtr->scramblingRnti = msg4PdcchInfo->dci.scramblingRnti;
2569       dlDciPtr->cceIndex = msg4PdcchInfo->dci.cceIndex;
2570       dlDciPtr->aggregationLevel = msg4PdcchInfo->dci.aggregLevel;
2571       dlDciPtr->pc_and_bform.numPrgs = msg4PdcchInfo->dci.beamPdcchInfo.numPrgs;
2572       dlDciPtr->pc_and_bform.prgSize = msg4PdcchInfo->dci.beamPdcchInfo.prgSize;
2573       dlDciPtr->pc_and_bform.digBfInterfaces = msg4PdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2574       dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = msg4PdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2575       dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = msg4PdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2576       dlDciPtr->beta_pdcch_1_0 = msg4PdcchInfo->dci.txPdcchPower.powerValue;           
2577       dlDciPtr->powerControlOfssetSS = msg4PdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2578
2579       /* Calculating freq domain resource allocation field value and size
2580        * coreset0Size = Size of coreset 0
2581        * RBStart = Starting Virtual Rsource block
2582        * RBLen = length of contiguously allocted RBs
2583        * Spec 38.214 Sec 5.1.2.2.2
2584        */
2585
2586       /* TODO: Fill values of coreset0Size, rbStart and rbLen */
2587       coreset0Size = msg4PdcchInfo->coreset0Cfg.coreSet0Size;
2588       //rbStart = msg4PdcchInfo->dci.pdschCfg->freqAlloc.rbStart;
2589       rbLen = msg4PdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2590
2591       if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2592       {
2593          if((rbLen - 1) <= floor(coreset0Size / 2))
2594             freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2595          else
2596             freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2597                                + (coreset0Size - 1 - rbStart);
2598
2599          freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2600       }
2601
2602       /* Fetching DCI field values */
2603       dciFormatId      = msg4Info->dciFormatId; /* DCI indentifier for DL */
2604       timeDomResAssign = msg4PdcchInfo->dci.pdschCfg->pdschTimeAlloc.rowIndex -1;
2605       VRB2PRBMap       = msg4PdcchInfo->dci.pdschCfg->pdschFreqAlloc.vrbPrbMapping;
2606       modNCodScheme    = msg4PdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2607       ndi              = msg4Info->ndi;      
2608       redundancyVer    = msg4PdcchInfo->dci.pdschCfg->codeword[0].rvIndex;
2609       harqProcessNum   = msg4Info->harqProcNum; 
2610       dlAssignmentIdx  = msg4Info->dlAssignIdx;
2611       pucchTpc         = msg4Info->pucchTpc;
2612       pucchResoInd     = msg4Info->pucchResInd;
2613       harqFeedbackInd  = msg4Info->harqFeedbackInd;
2614
2615       /* Reversing bits in each DCI field */
2616       dciFormatId      = reverseBits(dciFormatId, dciFormatIdSize);
2617       freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2618       timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2619       VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2620       modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2621       ndi              = reverseBits(ndi, ndiSize);
2622       redundancyVer    = reverseBits(redundancyVer, redundancyVerSize);
2623       harqProcessNum   = reverseBits(harqProcessNum, harqProcessNumSize);
2624       dlAssignmentIdx  = reverseBits(dlAssignmentIdx , dlAssignmentIdxSize);
2625       pucchTpc         = reverseBits(pucchTpc, pucchTpcSize);
2626       pucchResoInd     = reverseBits(pucchResoInd, pucchResoIndSize);
2627       harqFeedbackInd  = reverseBits(harqFeedbackInd, harqFeedbackIndSize);
2628
2629
2630       /* Calulating total number of bytes in buffer */
2631       dlDciPtr->payloadSizeBits = (dciFormatIdSize + freqDomResAssignSize\
2632       + timeDomResAssignSize + VRB2PRBMapSize + modNCodSchemeSize\
2633       + ndiSize + redundancyVerSize + harqProcessNumSize + dlAssignmentIdxSize\
2634       + pucchTpcSize + pucchResoIndSize + harqFeedbackIndSize);
2635
2636       numBytes = dlDciPtr->payloadSizeBits / 8;
2637       if(dlDciPtr->payloadSizeBits % 8)
2638          numBytes += 1;
2639
2640       if(numBytes > DCI_PAYLOAD_BYTE_LEN)
2641       {
2642          DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2643          return;
2644       }
2645
2646       /* Initialize buffer */
2647       for(bytePos = 0; bytePos < numBytes; bytePos++)
2648          dlDciPtr->payload[bytePos] = 0;
2649
2650       bytePos = numBytes - 1;
2651       bitPos = 0;
2652
2653       /* Packing DCI format fields */
2654       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2655             dciFormatId, dciFormatIdSize);
2656       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2657             freqDomResAssign, freqDomResAssignSize);
2658       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2659             timeDomResAssign, timeDomResAssignSize);
2660       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2661             VRB2PRBMap, VRB2PRBMapSize);
2662       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2663             modNCodScheme, modNCodSchemeSize);
2664       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2665             ndi, ndiSize);
2666       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2667             redundancyVer, redundancyVerSize);
2668       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2669             redundancyVer, redundancyVerSize);
2670       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2671             harqProcessNum, harqProcessNumSize);
2672       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2673             dlAssignmentIdx, dlAssignmentIdxSize);
2674       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2675             pucchTpc, pucchTpcSize);
2676       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2677             pucchResoInd, pucchResoIndSize);
2678       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2679             harqFeedbackInd, harqFeedbackIndSize);
2680    }
2681 } /* fillMsg4DlDciPdu */
2682
2683 /*******************************************************************
2684  *
2685  * @brief fills PDCCH PDU required for DL TTI info in MAC
2686  *
2687  * @details
2688  *
2689  *    Function : fillPdcchPdu
2690  *
2691  *    Functionality:
2692  *         -Fills the Pdcch PDU info
2693  *          stored in MAC
2694  *
2695  * @params[in] Pointer to FAPI DL TTI Req
2696  *             Pointer to PdcchCfg
2697  *             Pointer to msgLen of DL TTI Info
2698  * @return ROK
2699  *
2700  ******************************************************************/
2701 S16 fillPdcchPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, DlSchedInfo *dlInfo, uint32_t *msgLen, RntiType rntiType)
2702 {
2703    if(dlTtiReqPdu != NULLP)
2704    {
2705       PdcchCfg *pdcchInfo = NULLP;
2706       BwpCfg *bwp = NULLP;
2707
2708       dlTtiReqPdu->u.pdcch_pdu.dlDci = (fapi_dl_dci_t *)(dlTtiReqPdu + \
2709          (sizeof(fapi_dl_tti_req_pdu_t) - sizeof(dlTtiReqPdu->u)) + \
2710          (sizeof(fapi_dl_pdcch_pdu_t) - sizeof(fapi_dl_dci_t*)));
2711
2712       if(rntiType == SI_RNTI_TYPE)
2713       {
2714          pdcchInfo = &dlInfo->brdcstAlloc.sib1Alloc.sib1PdcchCfg;
2715          bwp = &dlInfo->brdcstAlloc.sib1Alloc.bwp;
2716          fillSib1DlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, pdcchInfo);
2717       }
2718       else if(rntiType == RA_RNTI_TYPE)
2719       {
2720          pdcchInfo = &dlInfo->rarAlloc->rarPdcchCfg;
2721          bwp = &dlInfo->rarAlloc->bwp;
2722          fillRarDlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, pdcchInfo);
2723       }
2724       else if(rntiType == TC_RNTI_TYPE)
2725       {
2726          pdcchInfo = &dlInfo->msg4Alloc->msg4PdcchCfg;
2727          bwp = &dlInfo->msg4Alloc->bwp;
2728          fillMsg4DlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, pdcchInfo,\
2729             &dlInfo->msg4Alloc->msg4Info);
2730       }
2731       else
2732       {
2733          DU_LOG("\nLWR_MAC: Failed filling PDCCH Pdu");
2734          return RFAILED;;
2735       }
2736       dlTtiReqPdu->pduType = PDCCH_PDU_TYPE;
2737       dlTtiReqPdu->u.pdcch_pdu.bwpSize = bwp->freqAlloc.numPrb;
2738       dlTtiReqPdu->u.pdcch_pdu.bwpPart = bwp->freqAlloc.startPrb;
2739       dlTtiReqPdu->u.pdcch_pdu.subCarrierSpacing = bwp->subcarrierSpacing; 
2740       dlTtiReqPdu->u.pdcch_pdu.cyclicPrefix = bwp->cyclicPrefix; 
2741       dlTtiReqPdu->u.pdcch_pdu.startSymbolIndex = pdcchInfo->coreset0Cfg.startSymbolIndex;
2742       dlTtiReqPdu->u.pdcch_pdu.durationSymbols = pdcchInfo->coreset0Cfg.durationSymbols;
2743       memcpy(dlTtiReqPdu->u.pdcch_pdu.freqDomainResource, pdcchInfo->coreset0Cfg.freqDomainResource, 6);
2744       dlTtiReqPdu->u.pdcch_pdu.cceRegMappingType = pdcchInfo->coreset0Cfg.cceRegMappingType;
2745       dlTtiReqPdu->u.pdcch_pdu.regBundleSize = pdcchInfo->coreset0Cfg.regBundleSize;
2746       dlTtiReqPdu->u.pdcch_pdu.interleaverSize = pdcchInfo->coreset0Cfg.interleaverSize;
2747       dlTtiReqPdu->u.pdcch_pdu.coreSetSize = pdcchInfo->coreset0Cfg.coreSetType;
2748       dlTtiReqPdu->u.pdcch_pdu.shiftIndex =  pdcchInfo->coreset0Cfg.shiftIndex;
2749       dlTtiReqPdu->u.pdcch_pdu.precoderGranularity = pdcchInfo->coreset0Cfg.precoderGranularity;
2750       dlTtiReqPdu->u.pdcch_pdu.numDlDci = pdcchInfo->numDlDci;
2751
2752       /* Calculating PDU length. Considering only one dl dci pdu for now */
2753       dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdcch_pdu_t) + sizeof(fapi_dl_dci_t);
2754       SET_MSG_LEN(*msgLen, (sizeof(dlTtiReqPdu->pduType) + \
2755          sizeof(dlTtiReqPdu->pduSize) + dlTtiReqPdu->pduSize));
2756
2757     }
2758
2759     return ROK;
2760 }
2761
2762 /*******************************************************************
2763  *
2764  * @brief fills PDSCH PDU required for DL TTI info in MAC
2765  *
2766  * @details
2767  *
2768  *    Function : fillPdschPdu
2769  *
2770  *    Functionality:
2771  *         -Fills the Pdsch PDU info
2772  *          stored in MAC
2773  *
2774  * @params[in] Pointer to FAPI DL TTI Req
2775  *             Pointer to PdschCfg
2776  *             Pointer to msgLen of DL TTI Info
2777  * @return ROK
2778  *
2779  ******************************************************************/
2780
2781 void fillPdschPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, PdschCfg *pdschInfo,
2782    BwpCfg bwp,uint32_t *msgLen, uint16_t pduIndex)
2783 {
2784     uint8_t idx;
2785
2786     if(dlTtiReqPdu != NULLP)
2787     {
2788        dlTtiReqPdu->pduType = PDSCH_PDU_TYPE;
2789        dlTtiReqPdu->u.pdsch_pdu.pduBitMap = pdschInfo->pduBitmap;
2790        dlTtiReqPdu->u.pdsch_pdu.rnti = pdschInfo->rnti;         
2791        dlTtiReqPdu->u.pdsch_pdu.pduIndex = pduIndex;
2792        dlTtiReqPdu->u.pdsch_pdu.bwpSize = bwp.freqAlloc.numPrb;       
2793        dlTtiReqPdu->u.pdsch_pdu.bwpStart = bwp.freqAlloc.startPrb;
2794        dlTtiReqPdu->u.pdsch_pdu.subCarrierSpacing = bwp.subcarrierSpacing;
2795        dlTtiReqPdu->u.pdsch_pdu.cyclicPrefix = bwp.cyclicPrefix;
2796        dlTtiReqPdu->u.pdsch_pdu.nrOfCodeWords = pdschInfo->numCodewords;
2797        for(idx = 0; idx < MAX_CODEWORDS ; idx++)
2798        { 
2799           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].targetCodeRate = pdschInfo->codeword[idx].targetCodeRate;
2800           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].qamModOrder = pdschInfo->codeword[idx].qamModOrder;
2801           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].mcsIndex = pdschInfo->codeword[idx].mcsIndex;
2802           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].mcsTable = pdschInfo->codeword[idx].mcsTable;
2803           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].rvIndex = pdschInfo->codeword[idx].rvIndex;
2804           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].tbSize = pdschInfo->codeword[idx].tbSize;
2805        }
2806        dlTtiReqPdu->u.pdsch_pdu.dataScramblingId = pdschInfo->dataScramblingId;       
2807        dlTtiReqPdu->u.pdsch_pdu.nrOfLayers = pdschInfo->numLayers;
2808        dlTtiReqPdu->u.pdsch_pdu.transmissionScheme = pdschInfo->transmissionScheme;
2809        dlTtiReqPdu->u.pdsch_pdu.refPoint = pdschInfo->refPoint;
2810        dlTtiReqPdu->u.pdsch_pdu.dlDmrsSymbPos = pdschInfo->dmrs.dlDmrsSymbPos;
2811        dlTtiReqPdu->u.pdsch_pdu.dmrsConfigType = pdschInfo->dmrs.dmrsConfigType;
2812        dlTtiReqPdu->u.pdsch_pdu.dlDmrsScramblingId = pdschInfo->dmrs.dlDmrsScramblingId;
2813        dlTtiReqPdu->u.pdsch_pdu.scid = pdschInfo->dmrs.scid;
2814        dlTtiReqPdu->u.pdsch_pdu.numDmrsCdmGrpsNoData = pdschInfo->dmrs.numDmrsCdmGrpsNoData;
2815        dlTtiReqPdu->u.pdsch_pdu.dmrsPorts = pdschInfo->dmrs.dmrsPorts;
2816        dlTtiReqPdu->u.pdsch_pdu.resourceAlloc = pdschInfo->pdschFreqAlloc.resourceAllocType;
2817        /* since we are using type-1, hence rbBitmap excluded */
2818        dlTtiReqPdu->u.pdsch_pdu.rbStart = pdschInfo->pdschFreqAlloc.freqAlloc.startPrb;
2819        dlTtiReqPdu->u.pdsch_pdu.rbSize = pdschInfo->pdschFreqAlloc.freqAlloc.numPrb;
2820        dlTtiReqPdu->u.pdsch_pdu.vrbToPrbMapping = pdschInfo->pdschFreqAlloc.vrbPrbMapping;
2821        dlTtiReqPdu->u.pdsch_pdu.startSymbIndex = pdschInfo->pdschTimeAlloc.timeAlloc.startSymb;
2822        dlTtiReqPdu->u.pdsch_pdu.nrOfSymbols = pdschInfo->pdschTimeAlloc.timeAlloc.numSymb;
2823        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.numPrgs = pdschInfo->beamPdschInfo.numPrgs;
2824        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.prgSize = pdschInfo->beamPdschInfo.prgSize;
2825        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.digBfInterfaces = pdschInfo->beamPdschInfo.digBfInterfaces;
2826        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2827           pmIdx = pdschInfo->beamPdschInfo.prg[0].pmIdx;
2828        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2829           beamIdx[0].beamidx = pdschInfo->beamPdschInfo.prg[0].beamIdx[0];
2830        dlTtiReqPdu->u.pdsch_pdu.powerControlOffset = pdschInfo->txPdschPower.powerControlOffset;  
2831        dlTtiReqPdu->u.pdsch_pdu.powerControlOffsetSS = pdschInfo->txPdschPower.powerControlOffsetSS;
2832        dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdsch_pdu_t);
2833
2834        SET_MSG_LEN(*msgLen, (sizeof(dlTtiReqPdu->pduType) + \
2835           sizeof(dlTtiReqPdu->pduSize) + sizeof(fapi_dl_pdsch_pdu_t)));
2836
2837     }
2838
2839 }
2840
2841 /***********************************************************************
2842  *
2843  * @brief calculates the total size to be allocated for DL TTI Req
2844  *
2845  * @details
2846  *
2847  *    Function : calcDlTtiReqPduCount
2848  *
2849  *    Functionality:
2850  *         -calculates the total pdu count to be allocated for DL TTI Req
2851  *
2852  * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
2853  * @return count
2854  *
2855  * ********************************************************************/
2856 uint8_t calcDlTtiReqPduCount(DlSchedInfo *dlInfo)
2857 {
2858    uint8_t count = 0;
2859    uint8_t idx = 0;
2860
2861    if(dlInfo->isBroadcastPres)
2862    {
2863       if(dlInfo->brdcstAlloc.ssbTrans)
2864       {
2865          for(idx = 0; idx < dlInfo->brdcstAlloc.ssbIdxSupported; idx++)
2866          {
2867             /* SSB PDU is filled */
2868             count++;
2869          }
2870       }
2871       if(dlInfo->brdcstAlloc.sib1Trans)
2872       {
2873          /* PDCCH and PDSCH PDU is filled */
2874          count += 2;
2875       }
2876    }
2877    if(dlInfo->rarAlloc != NULLP)
2878    {
2879       /* PDCCH and PDSCH PDU is filled */
2880       count += 2;
2881    }
2882    if(dlInfo->msg4Alloc != NULLP)
2883    {
2884       /* PDCCH and PDSCH PDU is filled */
2885       count += 2;
2886    }
2887
2888    return count;
2889 }
2890
2891 /***********************************************************************
2892  *
2893  * @brief calculates the total size to be allocated for DL TTI Req
2894  *
2895  * @details
2896  *
2897  *    Function : calcTxDataReqPduCount
2898  *
2899  *    Functionality:
2900  *         -calculates the total pdu count to be allocated for DL TTI Req
2901  *
2902  * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
2903  * @return count
2904  *
2905  * ********************************************************************/
2906 uint8_t calcTxDataReqPduCount(DlSchedInfo *dlInfo)
2907 {
2908    uint8_t count = 0;
2909
2910    if(dlInfo->isBroadcastPres && dlInfo->brdcstAlloc.sib1Trans)
2911    {
2912       count++;
2913    }
2914    if(dlInfo->rarAlloc != NULLP)
2915    {
2916       count++;
2917    }
2918    if(dlInfo->msg4Alloc != NULLP)
2919    {
2920       count++;
2921    }
2922
2923    return count;
2924 }
2925 /***********************************************************************
2926  *
2927  * @brief fills the SIB1 TX-DATA request message
2928  *
2929  * @details
2930  *
2931  *    Function : fillSib1TxDataReq
2932  *
2933  *    Functionality:
2934  *         - fills the SIB1 TX-DATA request message
2935  *
2936  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
2937  * @params[in]    macCellCfg consist of SIB1 pdu
2938  * @params[in]    uint32_t *msgLen
2939  * @params[in]    uint16_t pduIndex
2940  * @return ROK
2941  *
2942  * ********************************************************************/
2943 uint8_t fillSib1TxDataReq(fapi_tx_pdu_desc_t *pduDesc,MacCellCfg *macCellCfg,
2944    uint32_t *msgLen, uint16_t pduIndex)
2945 {
2946    uint32_t pduLen = 0;
2947    uint32_t *sib1TxdataValue = NULLP;
2948
2949    pduDesc[pduIndex].pduIndex = pduIndex;
2950    pduDesc[pduIndex].numTlvs = 1;
2951
2952    /* fill the TLV */
2953    /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
2954    pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
2955    pduDesc[pduIndex].tlvs[0].tl.length = macCellCfg->sib1Cfg.sib1PduLen;
2956    LWR_MAC_ALLOC(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2957    if(sib1TxdataValue == NULLP)
2958    {
2959       return RFAILED;
2960    }
2961    memcpy(sib1TxdataValue,macCellCfg->sib1Cfg.sib1Pdu,
2962       macCellCfg->sib1Cfg.sib1PduLen);
2963    pduDesc[pduIndex].tlvs[0].value = sib1TxdataValue;
2964
2965    /* The total length of the PDU description and   PDU data */
2966    pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
2967    pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
2968    pduDesc[pduIndex].pduLength = pduLen; 
2969    msgLen += pduLen;
2970
2971 #ifndef INTEL_WLS   
2972    MAC_FREE(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2973 #endif
2974
2975    return ROK;
2976 }
2977
2978 /***********************************************************************
2979  *
2980  * @brief fills the RAR TX-DATA request message
2981  *
2982  * @details
2983  *
2984  *    Function : fillRarTxDataReq
2985  *
2986  *    Functionality:
2987  *         - fills the RAR TX-DATA request message
2988  *
2989  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
2990  * @params[in]    RarInfo *rarInfo
2991  * @params[in]    uint32_t *msgLen
2992  * @params[in]    uint16_t pduIndex
2993  * @return ROK
2994  *
2995  * ********************************************************************/
2996 uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
2997    uint32_t *msgLen, uint16_t pduIndex)
2998 {
2999    uint32_t pduLen = 0;
3000    uint32_t *rarTxdataValue = NULLP;
3001
3002    pduDesc[pduIndex].pduIndex = pduIndex;
3003    pduDesc[pduIndex].numTlvs = 1;
3004
3005    /* fill the TLV */
3006    /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
3007    pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
3008    pduDesc[pduIndex].tlvs[0].tl.length = rarInfo->rarPduLen;
3009    LWR_MAC_ALLOC(rarTxdataValue,rarInfo->rarPduLen);
3010    if(rarTxdataValue == NULLP)
3011    {
3012       return RFAILED;
3013    }
3014    memcpy(rarTxdataValue,rarInfo->rarPdu,rarInfo->rarPduLen);
3015    pduDesc[pduIndex].tlvs[0].value = (uint32_t)rarTxdataValue;
3016
3017    /* The total length of the PDU description and   PDU data */
3018    pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
3019    pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
3020    pduDesc[pduIndex].pduLength = pduLen; 
3021    msgLen += pduLen;
3022
3023 /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
3024  * But since we did not implement WLS, this has to be done here
3025  */
3026 #ifndef INTEL_WLS   
3027    MAC_FREE(rarTxdataValue,rarInfo->rarPduLen);
3028 #endif
3029
3030    return ROK;
3031 }
3032
3033 /***********************************************************************
3034  *
3035  * @brief fills the Msg4 TX-DATA request message
3036  *
3037  * @details
3038  *
3039  *    Function : fillMsg4TxDataReq
3040  *
3041  *    Functionality:
3042  *         - fills the Msg4 TX-DATA request message
3043  *
3044  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
3045  * @params[in]    Msg4Info *msg4Info
3046  * @params[in]    uint32_t *msgLen
3047  * @params[in]    uint16_t pduIndex
3048  * @return ROK
3049  *
3050  * ********************************************************************/
3051 uint8_t fillMsg4TxDataReq(fapi_tx_pdu_desc_t *pduDesc, Msg4Info *msg4Info,
3052    uint32_t *msgLen, uint16_t pduIndex)
3053 {
3054    uint32_t pduLen = 0;
3055    uint32_t *msg4TxDataValue = NULLP;
3056
3057    pduDesc[pduIndex].pduIndex = pduIndex;
3058    pduDesc[pduIndex].numTlvs = 1;
3059    
3060    /* fill the TLV */
3061    /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
3062    pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
3063    pduDesc[pduIndex].tlvs[0].tl.length = msg4Info->msg4PduLen;
3064    LWR_MAC_ALLOC(msg4TxDataValue, msg4Info->msg4PduLen);
3065    if(msg4TxDataValue == NULLP)
3066    {
3067       return RFAILED;
3068    }
3069    memcpy(msg4TxDataValue, msg4Info->msg4Pdu, msg4Info->msg4PduLen);
3070    pduDesc[pduIndex].tlvs[0].value = (uint32_t)msg4TxDataValue;
3071
3072    /* The total length of the PDU description and PDU data */
3073    pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
3074    pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
3075    pduDesc[pduIndex].pduLength = pduLen; 
3076    msgLen += pduLen;
3077
3078    /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
3079     * But since we did not implement WLS, this has to be done here
3080     */
3081    #ifndef INTEL_WLS   
3082       MAC_FREE(msg4TxDataValue, msg4Info->msg4PduLen);
3083    #endif
3084
3085    return ROK;
3086 }
3087
3088 #endif /* FAPI */
3089 /*******************************************************************
3090  *
3091  * @brief Sends DL TTI Request to PHY
3092  *
3093  * @details
3094  *
3095  *    Function : handleDlTtiReq
3096  *
3097  *    Functionality:
3098  *         -Sends FAPI DL TTI req to PHY
3099  *
3100  * @params[in]    timing info
3101  * @return ROK     - success
3102  *         RFAILED - failure
3103  *
3104  * ****************************************************************/
3105 uint16_t handleDlTtiReq(SlotIndInfo currTimingInfo)
3106 {
3107 #ifdef INTEL_FAPI
3108    uint8_t idx;
3109    uint8_t nPdu = 0;
3110    uint8_t numPduEncoded = 0;
3111    uint16_t pduIndex = 0;
3112    uint32_t msgLen = 0;
3113    uint32_t dlTtiReqMsgSize = 0;
3114
3115    fapi_dl_tti_req_t *dlTtiReq = NULLP;
3116    SlotIndInfo dlTtiReqTimingInfo;
3117
3118    RgCellCb  *cellCbParams = NULLP;
3119    MacDlSlot *currDlSlot = NULLP;
3120    MacCellCfg macCellCfg;
3121    memset(&macCellCfg, 0, sizeof(MacCellCfg));
3122    Inst inst = 0;
3123    RntiType rntiType;
3124    
3125    if(clGlobalCp.phyState == PHY_STATE_RUNNING)
3126    {
3127       /* consider phy delay */
3128       ADD_DELTA_TO_TIME(currTimingInfo,dlTtiReqTimingInfo,PHY_DELTA);
3129
3130       cellCbParams = rgCb[inst].cell;
3131                 macCellCfg = cellCbParams->macCellCfg;
3132
3133                 currDlSlot = &macCb.macCell->dlSlot[dlTtiReqTimingInfo.slot]; 
3134                 nPdu = calcDlTtiReqPduCount(&currDlSlot->dlInfo);
3135                 dlTtiReqMsgSize = sizeof(fapi_dl_tti_req_t) + (nPdu * \
3136                                 sizeof(fapi_dl_tti_req_pdu_t));
3137                 if(nPdu > 0)
3138                 {
3139                         if(currDlSlot->dlInfo.isBroadcastPres)
3140                         {
3141                                 if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
3142                                 {
3143                                         dlTtiReqMsgSize += sizeof(fapi_dl_dci_t);
3144                                 }
3145                         }
3146                         if(currDlSlot->dlInfo.rarAlloc != NULLP)
3147                         {
3148                                 dlTtiReqMsgSize += sizeof(fapi_dl_dci_t);
3149                         }
3150                         if(currDlSlot->dlInfo.msg4Alloc != NULLP)
3151                         {
3152                                 dlTtiReqMsgSize += sizeof(fapi_dl_dci_t);
3153                         }
3154                 }
3155                 LWR_MAC_ALLOC(dlTtiReq, dlTtiReqMsgSize);
3156                 if(dlTtiReq != NULLP)
3157                 {
3158                         memset(dlTtiReq, 0, dlTtiReqMsgSize);
3159                         dlTtiReq->sfn  = dlTtiReqTimingInfo.sfn;
3160                         dlTtiReq->slot = dlTtiReqTimingInfo.slot;
3161                         dlTtiReq->nPdus = calcDlTtiReqPduCount(&currDlSlot->dlInfo);  /* get total Pdus */
3162                         nPdu = dlTtiReq->nPdus;
3163                         dlTtiReq->nGroup = 0;
3164
3165                         if(dlTtiReq->nPdus > 0)
3166                         {
3167                                 dlTtiReq->pdus = (fapi_dl_tti_req_pdu_t*)(dlTtiReq + \
3168                                                 (sizeof(fapi_dl_tti_req_t) - sizeof(fapi_dl_tti_req_pdu_t*)));
3169                                 if(!dlTtiReq->pdus)
3170                                 {
3171                                         DU_LOG("\nLWR_MAC: Memory allocation failed");
3172                                         return RFAILED;
3173                                 }
3174
3175                                 if(currDlSlot->dlInfo.isBroadcastPres)
3176                                 {
3177                                         if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
3178                                         {
3179                                                 if(dlTtiReq->pdus != NULLP)
3180                                                 {
3181                                                         for(idx = 0; idx < currDlSlot->dlInfo.brdcstAlloc.ssbIdxSupported; idx++)
3182                                                         {
3183                                                                 fillSsbPdu(&dlTtiReq->pdus[numPduEncoded], &macCellCfg,\
3184                                                                                 currDlSlot, &msgLen, idx, dlTtiReq->sfn);
3185                                                                 numPduEncoded++;
3186                                                         }
3187                                                 }
3188                                                 printf("\033[1;31m");
3189                                                 DU_LOG("\nLWR_MAC: MIB sent..");
3190                                                 printf("\033[0m");
3191                                         }
3192                                         if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
3193                                         {
3194                                                 /* Filling SIB1 param */
3195                                                 if(numPduEncoded != nPdu)
3196                                                 {
3197                                                         rntiType = SI_RNTI_TYPE;
3198                                                         fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo,\
3199                                                                         &msgLen, rntiType);
3200                                                         numPduEncoded++;
3201                                                         fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3202                                                                         &currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg,
3203                                                                         currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.bwp,
3204                                                                         &msgLen, pduIndex);
3205                                                         pduIndex++;
3206                                                         numPduEncoded++;
3207                                                 }
3208                                                 printf("\033[1;34m");
3209                                                 DU_LOG("\nLWR_MAC: SIB1 sent...");
3210                                                 printf("\033[0m");
3211                                         }
3212                                 }
3213                                 if(currDlSlot->dlInfo.rarAlloc != NULLP)
3214                                 {
3215                                         /* Filling RAR param */
3216                                         rntiType = RA_RNTI_TYPE;
3217                                         fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3218                                                         &currDlSlot->dlInfo, &msgLen, rntiType);
3219                                         numPduEncoded++;
3220                                         fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3221                                                         &currDlSlot->dlInfo.rarAlloc->rarPdschCfg,
3222                                                         currDlSlot->dlInfo.rarAlloc->bwp,
3223                                                         &msgLen, pduIndex);
3224                                         numPduEncoded++;
3225                                         pduIndex++;
3226
3227                                         printf("\033[1;32m");
3228                                         DU_LOG("\nLWR_MAC: RAR sent...");
3229                                         printf("\033[0m");
3230                                 }
3231                                 if(currDlSlot->dlInfo.msg4Alloc != NULLP)
3232                                 {
3233                                         /* Filling Msg4 param */
3234                                         rntiType = TC_RNTI_TYPE;
3235                                         fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3236                                                         &currDlSlot->dlInfo, &msgLen, rntiType);
3237                                         numPduEncoded++;
3238                                         fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3239                                                         &currDlSlot->dlInfo.msg4Alloc->msg4PdschCfg,
3240                                                         currDlSlot->dlInfo.msg4Alloc->bwp,
3241                                                         &msgLen, pduIndex);
3242                                         numPduEncoded++;
3243                                         pduIndex++;
3244
3245                                         printf("\033[1;32m");
3246                                         DU_LOG("\nLWR_MAC: MSG4 sent...");
3247                                         printf("\033[0m");
3248                                 }
3249                                 msgLen += sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
3250                                 fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
3251                                 LwrMacSendToPhy(dlTtiReq->header.message_type_id, dlTtiReqMsgSize, \
3252                                                 (void *)dlTtiReq);
3253
3254                                 /* send Tx-DATA req message */
3255                                 sendTxDataReq(currTimingInfo, &currDlSlot->dlInfo);
3256                         }
3257                         else
3258                         {
3259                                 msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
3260                                 fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
3261                                 LwrMacSendToPhy(dlTtiReq->header.message_type_id, dlTtiReqMsgSize, (void *)dlTtiReq);
3262                         }
3263                         memset(currDlSlot, 0, sizeof(MacDlSlot));
3264                         return ROK;
3265                 }
3266                 else
3267                 {
3268                         DU_LOG("\nLWR_MAC: Failed to allocate memory for DL TTI Request");
3269                         memset(currDlSlot, 0, sizeof(MacDlSlot));
3270                         return RFAILED;
3271                 }
3272         }
3273    else
3274    {
3275        lwr_mac_handleInvalidEvt(&currTimingInfo);
3276        return RFAILED;
3277    }
3278 #endif
3279    return ROK;
3280 }
3281
3282 /*******************************************************************
3283  *
3284  * @brief Sends TX data Request to PHY
3285  *
3286  * @details
3287  *
3288  *    Function : sendTxDataReq
3289  *
3290  *    Functionality:
3291  *         -Sends FAPI TX data req to PHY
3292  *
3293  * @params[in]    timing info
3294  * @return ROK     - success
3295  *         RFAILED - failure
3296  *
3297  * ****************************************************************/
3298 uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo)
3299 {
3300 #ifdef INTEL_FAPI
3301    uint8_t nPdu = 0;
3302    uint32_t msgLen = 0;
3303    uint16_t pduIndex = 0;
3304    uint32_t txDataReqMsgSize = 0;
3305    fapi_tx_data_req_t *txDataReq = NULLP;
3306    Inst inst = 0;
3307
3308    /* send TX_Data request message */
3309    nPdu = calcTxDataReqPduCount(dlInfo);
3310    if(nPdu > 0)
3311    {
3312       txDataReqMsgSize = sizeof(fapi_tx_data_req_t) + \
3313          (nPdu * sizeof(fapi_tx_pdu_desc_t));
3314       if(dlInfo->brdcstAlloc.sib1Trans)
3315       {
3316          txDataReqMsgSize += rgCb[inst].cell->macCellCfg.sib1Cfg.sib1PduLen;
3317       }
3318       if(dlInfo->rarAlloc != NULLP)
3319       {
3320          txDataReqMsgSize += dlInfo->rarAlloc->rarInfo.rarPduLen;
3321       }
3322       if(dlInfo->msg4Alloc != NULLP)
3323       {
3324          txDataReqMsgSize += dlInfo->msg4Alloc->msg4Info.msg4PduLen;
3325       }
3326
3327       LWR_MAC_ALLOC(txDataReq, txDataReqMsgSize);
3328       if(txDataReq == NULLP)
3329       {
3330          DU_LOG("\nLWR_MAC: Failed to allocate memory for TX data Request");
3331          return RFAILED;
3332       }
3333
3334       memset(txDataReq, 0, txDataReqMsgSize);
3335                 txDataReq->sfn  = currTimingInfo.sfn;
3336                 txDataReq->slot = currTimingInfo.slot;
3337       txDataReq->pduDesc = (fapi_tx_pdu_desc_t *)(txDataReq + \
3338          (sizeof(fapi_tx_data_req_t) - sizeof(fapi_tx_pdu_desc_t *)));
3339
3340       if(dlInfo->brdcstAlloc.sib1Trans)
3341       {
3342          fillSib1TxDataReq(txDataReq->pduDesc,
3343                &rgCb[inst].cell->macCellCfg, &msgLen, pduIndex);
3344          pduIndex++;
3345          txDataReq->numPdus++;
3346       }
3347       if(dlInfo->rarAlloc != NULLP)
3348       {
3349          fillRarTxDataReq(txDataReq->pduDesc, &dlInfo->rarAlloc->rarInfo, &msgLen, pduIndex);
3350          pduIndex++;
3351          txDataReq->numPdus++;
3352
3353          MAC_FREE(dlInfo->rarAlloc,sizeof(RarAlloc));
3354          dlInfo->rarAlloc = NULLP;
3355       }
3356       if(dlInfo->msg4Alloc != NULLP)
3357       {
3358          fillMsg4TxDataReq(txDataReq->pduDesc, &dlInfo->msg4Alloc->\
3359              msg4Info, &msgLen, pduIndex);
3360          pduIndex++;
3361          txDataReq->numPdus++;
3362
3363          MAC_FREE(dlInfo->msg4Alloc,sizeof(Msg4Alloc));
3364          dlInfo->msg4Alloc = NULLP;
3365       }
3366       msgLen += sizeof(fapi_tx_data_req_t) - sizeof(fapi_msg_t);
3367       fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
3368       LwrMacSendToPhy(txDataReq->header.message_type_id, txDataReqMsgSize, \
3369          (void *)txDataReq);
3370    }
3371 #endif
3372    return ROK;
3373 }
3374
3375 /***********************************************************************
3376  *
3377  * @brief calculates the total size to be allocated for UL TTI Req
3378  *
3379  * @details
3380  *
3381  *    Function : getnPdus
3382  *
3383  *    Functionality:
3384  *         -calculates the total pdu count to be allocated for UL TTI Req
3385  *
3386  * @params[in] Pointer to fapi Ul TTI Req
3387  *             Pointer to CurrUlSlot
3388  * @return count
3389  * ********************************************************************/
3390 #ifdef INTEL_FAPI
3391 uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
3392 {
3393    uint8_t pduCount = 0;
3394
3395    if(ulTtiReq && currUlSlot)
3396         {
3397                 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH)
3398                 {
3399                         pduCount++;
3400                         ulTtiReq->rachPresent = PDU_PRESENT;
3401                 }
3402                 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)
3403                 {
3404                         pduCount++;
3405                         ulTtiReq->nUlsch++;
3406                 }
3407                 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
3408                 {
3409                    pduCount++;
3410          ulTtiReq->nUlsch = PDU_PRESENT;
3411       }
3412       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
3413       {
3414          pduCount++;
3415          ulTtiReq->nUlcch = PDU_PRESENT;
3416       }
3417       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_SRS)
3418       {
3419          pduCount++;
3420       }
3421    }
3422    return pduCount;
3423 }
3424 #endif
3425
3426 /***********************************************************************
3427  *
3428  * @brief Set the value of zero correlation config in PRACH PDU
3429  *
3430  * @details
3431  *
3432  *    Function : setNumCs
3433  *
3434  *    Functionality:
3435  *         -Set the value of zero correlation config in PRACH PDU
3436  *
3437  * @params[in] Pointer to zero correlation config
3438  *             Pointer to MacCellCfg
3439  * ********************************************************************/
3440
3441 void setNumCs(uint8_t *numCs, MacCellCfg *macCellCfg)
3442 {
3443 #ifdef INTEL_FAPI
3444    uint8_t idx;
3445    if(macCellCfg != NULLP)
3446    {
3447       idx = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
3448       *numCs = UnrestrictedSetNcsTable[idx];
3449    }
3450 #endif
3451 }
3452
3453 /***********************************************************************
3454  *
3455  * @brief Fills the PRACH PDU in UL TTI Request
3456  *
3457  * @details
3458  *
3459  *    Function : fillPrachPdu
3460  *
3461  *    Functionality:
3462  *         -Fills the PRACH PDU in UL TTI Request
3463  *
3464  * @params[in] Pointer to Prach Pdu
3465  *             Pointer to CurrUlSlot
3466  *             Pointer to macCellCfg
3467  *             Pointer to msgLen
3468  * ********************************************************************/
3469
3470 #ifdef INTEL_FAPI
3471 void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot, uint32_t *msgLen)
3472 {
3473    if(ulTtiReqPdu != NULLP)
3474    {
3475       ulTtiReqPdu->pduType = PRACH_PDU_TYPE; 
3476       ulTtiReqPdu->u.prach_pdu.physCellId = macCellCfg->phyCellId;
3477       ulTtiReqPdu->u.prach_pdu.numPrachOcas = currUlSlot->ulInfo.prachSchInfo.numPrachOcas;
3478       ulTtiReqPdu->u.prach_pdu.prachFormat = \
3479       currUlSlot->ulInfo.prachSchInfo.prachFormat;
3480       ulTtiReqPdu->u.prach_pdu.numRa = currUlSlot->ulInfo.prachSchInfo.numRa;
3481       ulTtiReqPdu->u.prach_pdu.prachStartSymbol = \
3482       currUlSlot->ulInfo.prachSchInfo.prachStartSymb;
3483       setNumCs(&ulTtiReqPdu->u.prach_pdu.numCs, macCellCfg);
3484       ulTtiReqPdu->u.prach_pdu.beamforming.numPrgs = 0;
3485       ulTtiReqPdu->u.prach_pdu.beamforming.prgSize = 0;
3486       ulTtiReqPdu->u.prach_pdu.beamforming.digBfInterfaces = 0;
3487       ulTtiReqPdu->u.prach_pdu.beamforming.pmi_bfi[0].pmIdx = 0;
3488       ulTtiReqPdu->u.prach_pdu.beamforming.pmi_bfi[0].beamIdx[0].beamidx = 0;
3489       ulTtiReqPdu->pduSize = sizeof(fapi_ul_prach_pdu_t); 
3490
3491       SET_MSG_LEN(*msgLen, (sizeof(ulTtiReqPdu->pduType) + \
3492          sizeof(ulTtiReqPdu->pduSize) + sizeof(fapi_ul_prach_pdu_t)));
3493    }
3494 }
3495
3496 void fillPuschPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot, uint32_t *msgLen)
3497 {
3498    if(ulTtiReqPdu != NULLP)
3499    {
3500       ulTtiReqPdu->pduType = PUSCH_PDU_TYPE;
3501       ulTtiReqPdu->u.pusch_pdu.pduBitMap = 1;
3502       ulTtiReqPdu->u.pusch_pdu.rnti = currUlSlot->ulInfo.crnti;
3503                 /* TODO : Fill handle in raCb when scheduling pusch and access here */
3504       ulTtiReqPdu->u.pusch_pdu.handle = 100;
3505       ulTtiReqPdu->u.pusch_pdu.bwpSize = macCellCfg->initialUlBwp.bwp.numPrb;
3506       ulTtiReqPdu->u.pusch_pdu.bwpStart = macCellCfg->initialUlBwp.bwp.firstPrb;
3507       ulTtiReqPdu->u.pusch_pdu.subCarrierSpacing = \
3508                    macCellCfg->initialUlBwp.bwp.scs;
3509       ulTtiReqPdu->u.pusch_pdu.cyclicPrefix = \
3510                    macCellCfg->initialUlBwp.bwp.cyclicPrefix;
3511       ulTtiReqPdu->u.pusch_pdu.targetCodeRate = 308;
3512       ulTtiReqPdu->u.pusch_pdu.qamModOrder = 2;
3513       ulTtiReqPdu->u.pusch_pdu.mcsIndex = \
3514                    currUlSlot->ulInfo.schPuschInfo.tbInfo.mcs;
3515       ulTtiReqPdu->u.pusch_pdu.mcsTable = 0;
3516       ulTtiReqPdu->u.pusch_pdu.transformPrecoding = 1;
3517       ulTtiReqPdu->u.pusch_pdu.dataScramblingId = currUlSlot->ulInfo.cellId;
3518       ulTtiReqPdu->u.pusch_pdu.nrOfLayers = 1;
3519       ulTtiReqPdu->u.pusch_pdu.ulDmrsSymbPos = 4;
3520       ulTtiReqPdu->u.pusch_pdu.dmrsConfigType = 0;
3521       ulTtiReqPdu->u.pusch_pdu.ulDmrsScramblingId = currUlSlot->ulInfo.cellId;
3522       ulTtiReqPdu->u.pusch_pdu.scid = 0;
3523       ulTtiReqPdu->u.pusch_pdu.numDmrsCdmGrpsNoData = 1;
3524       ulTtiReqPdu->u.pusch_pdu.dmrsPorts = 0;
3525       ulTtiReqPdu->u.pusch_pdu.resourceAlloc = \
3526                    currUlSlot->ulInfo.schPuschInfo.resAllocType;
3527       ulTtiReqPdu->u.pusch_pdu.rbStart = \
3528                    currUlSlot->ulInfo.schPuschInfo.fdAlloc.startPrb;
3529       ulTtiReqPdu->u.pusch_pdu.rbSize = \
3530                    currUlSlot->ulInfo.schPuschInfo.fdAlloc.numPrb;
3531       ulTtiReqPdu->u.pusch_pdu.vrbToPrbMapping = 0;
3532       ulTtiReqPdu->u.pusch_pdu.frequencyHopping = 0;
3533       ulTtiReqPdu->u.pusch_pdu.txDirectCurrentLocation = 0;
3534       ulTtiReqPdu->u.pusch_pdu.uplinkFrequencyShift7p5khz = 0;
3535       ulTtiReqPdu->u.pusch_pdu.startSymbIndex = \
3536                    currUlSlot->ulInfo.schPuschInfo.tdAlloc.startSymb;
3537       ulTtiReqPdu->u.pusch_pdu.nrOfSymbols = \
3538                    currUlSlot->ulInfo.schPuschInfo.tdAlloc.numSymb;
3539       ulTtiReqPdu->u.pusch_pdu.puschData.rvIndex = \
3540                    currUlSlot->ulInfo.schPuschInfo.tbInfo.rv;
3541       ulTtiReqPdu->u.pusch_pdu.puschData.harqProcessId = \
3542                    currUlSlot->ulInfo.schPuschInfo.harqProcId;
3543       ulTtiReqPdu->u.pusch_pdu.puschData.newDataIndicator = \
3544                    currUlSlot->ulInfo.schPuschInfo.tbInfo.ndi;
3545       ulTtiReqPdu->u.pusch_pdu.puschData.tbSize = \
3546                    currUlSlot->ulInfo.schPuschInfo.tbInfo.tbSize;
3547                 /* numCb is 0 for new transmission */
3548       ulTtiReqPdu->u.pusch_pdu.puschData.numCb = 0;
3549
3550       ulTtiReqPdu->pduSize = sizeof(fapi_ul_pusch_pdu_t);
3551        
3552       SET_MSG_LEN(*msgLen, (sizeof(ulTtiReqPdu->pduType) + \
3553          sizeof(ulTtiReqPdu->pduSize) + sizeof(fapi_ul_pusch_pdu_t)));
3554    }
3555 }
3556
3557 void fillPucchPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg,\
3558   MacUlSlot *currUlSlot, uint32_t *msgLen)
3559 {
3560    if(ulTtiReqPdu != NULLP)
3561    {
3562            ulTtiReqPdu->pduType                  = PUCCH_PDU_TYPE;
3563            ulTtiReqPdu->u.pucch_pdu.rnti         = currUlSlot->ulInfo.schPucchInfo.rnti;
3564                 /* TODO : Fill handle in raCb when scheduling pucch and access here */
3565            ulTtiReqPdu->u.pucch_pdu.handle       = 100;
3566            ulTtiReqPdu->u.pucch_pdu.bwpSize      = macCellCfg->initialUlBwp.bwp.numPrb;
3567            ulTtiReqPdu->u.pucch_pdu.bwpStart     = macCellCfg->initialUlBwp.bwp.firstPrb;
3568            ulTtiReqPdu->u.pucch_pdu.subCarrierSpacing = macCellCfg->initialUlBwp.bwp.scs;
3569            ulTtiReqPdu->u.pucch_pdu.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
3570            ulTtiReqPdu->u.pucch_pdu.formatType   = currUlSlot->ulInfo.schPucchInfo.pucchFormat; /* Supporting PUCCH Format 0 */
3571            ulTtiReqPdu->u.pucch_pdu.multiSlotTxIndicator = 0; /* No Multi Slot transmission */
3572            ulTtiReqPdu->u.pucch_pdu.pi2Bpsk              = 0; /* Disabled */
3573            ulTtiReqPdu->u.pucch_pdu.prbStart     = currUlSlot->ulInfo.schPucchInfo.fdAlloc.startPrb;
3574            ulTtiReqPdu->u.pucch_pdu.prbSize      = currUlSlot->ulInfo.schPucchInfo.fdAlloc.numPrb;
3575            ulTtiReqPdu->u.pucch_pdu.startSymbolIndex = currUlSlot->ulInfo.schPucchInfo.tdAlloc.startSymb;
3576            ulTtiReqPdu->u.pucch_pdu.nrOfSymbols  = currUlSlot->ulInfo.schPucchInfo.tdAlloc.numSymb;
3577            ulTtiReqPdu->u.pucch_pdu.freqHopFlag  = 0; /* Disabled */
3578            ulTtiReqPdu->u.pucch_pdu.secondHopPrb = 0;
3579            ulTtiReqPdu->u.pucch_pdu.groupHopFlag = 0;     
3580            ulTtiReqPdu->u.pucch_pdu.sequenceHopFlag = 0;
3581            ulTtiReqPdu->u.pucch_pdu.hoppingId    = 0;
3582            ulTtiReqPdu->u.pucch_pdu.initialCyclicShift = 0;
3583            ulTtiReqPdu->u.pucch_pdu.dataScramblingId = 0; /* Valid for Format 2, 3, 4 */
3584            ulTtiReqPdu->u.pucch_pdu.timeDomainOccIdx = 0; /* Valid for Format 1 */
3585            ulTtiReqPdu->u.pucch_pdu.preDftOccIdx     = 0; /* Valid for Format 4 */
3586            ulTtiReqPdu->u.pucch_pdu.preDftOccLen     = 0; /* Valid for Format 4 */
3587            ulTtiReqPdu->u.pucch_pdu.addDmrsFlag      = 0; /* Valid for Format 3, 4 */
3588            ulTtiReqPdu->u.pucch_pdu.dmrsScramblingId = 0; /* Valid for Format 2 */
3589            ulTtiReqPdu->u.pucch_pdu.dmrsCyclicShift  = 0; /* Valid for Format 4 */
3590            ulTtiReqPdu->u.pucch_pdu.srFlag           = currUlSlot->ulInfo.schPucchInfo.srFlag;
3591            ulTtiReqPdu->u.pucch_pdu.bitLenHarq       = currUlSlot->ulInfo.schPucchInfo.numHarqBits;
3592            ulTtiReqPdu->u.pucch_pdu.bitLenCsiPart1   = 0; /* Valid for Format 2, 3, 4 */
3593            ulTtiReqPdu->u.pucch_pdu.bitLenCsiPart2   = 0; /* Valid for Format 2, 3, 4 */
3594       ulTtiReqPdu->u.pucch_pdu.beamforming.numPrgs = 0; /* Not Supported */
3595       ulTtiReqPdu->u.pucch_pdu.beamforming.prgSize = 0;
3596       ulTtiReqPdu->u.pucch_pdu.beamforming.digBfInterfaces = 0;
3597       ulTtiReqPdu->u.pucch_pdu.beamforming.pmi_bfi[0].pmIdx = 0;
3598       ulTtiReqPdu->u.pucch_pdu.beamforming.pmi_bfi[0].beamIdx[0].beamidx = 0;
3599
3600       ulTtiReqPdu->pduSize = sizeof(fapi_ul_pucch_pdu_t);
3601       SET_MSG_LEN(*msgLen, (sizeof(ulTtiReqPdu->pduType) + \
3602          sizeof(ulTtiReqPdu->pduSize) + sizeof(fapi_ul_pucch_pdu_t)));
3603         }
3604 }
3605
3606 #endif
3607
3608 /*******************************************************************
3609  *
3610  * @brief Sends UL TTI Request to PHY
3611  *
3612  * @details
3613  *
3614  *    Function : handleUlTtiReq
3615  *
3616  *    Functionality:
3617  *         -Sends FAPI Param req to PHY
3618  *
3619  * @params[in]  Pointer to CmLteTimingInfo
3620  * @return ROK     - success
3621  *         RFAILED - failure
3622  *
3623  ******************************************************************/
3624 uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo)
3625 {
3626 #ifdef INTEL_FAPI
3627    uint8_t    pduIdx = -1;
3628    uint8_t    numPdu = 0;
3629    uint32_t   msgLen = 0;
3630    uint32_t   msgSize = 0;
3631
3632    fapi_ul_tti_req_t *ulTtiReq = NULLP;
3633    SlotIndInfo ulTtiReqTimingInfo;
3634
3635    RgCellCb  *cellCbParams = NULLP;
3636    MacUlSlot *currUlSlot = NULLP;
3637    MacCellCfg macCellCfg;
3638    Inst inst = 0;
3639
3640    if(clGlobalCp.phyState == PHY_STATE_RUNNING)
3641         {
3642                 cellCbParams = rgCb[inst].cell;
3643                 macCellCfg = cellCbParams->macCellCfg;
3644
3645                 /* add PHY delta */
3646                 ADD_DELTA_TO_TIME(currTimingInfo,ulTtiReqTimingInfo,PHY_DELTA);
3647
3648                 currUlSlot = &macCb.macCell->ulSlot[ulTtiReqTimingInfo.slot % MAX_SLOT_SUPPORTED];
3649                 numPdu = getnPdus(NULL, currUlSlot);
3650                 msgSize = sizeof(fapi_ul_tti_req_t) + (numPdu*sizeof(fapi_ul_tti_req_pdu_t));
3651                 LWR_MAC_ALLOC(ulTtiReq, msgSize);
3652
3653                 if(ulTtiReq != NULLP)
3654                 {
3655                         memset(ulTtiReq, 0, msgSize);
3656                         ulTtiReq->sfn  = ulTtiReqTimingInfo.sfn;
3657                         ulTtiReq->slot = ulTtiReqTimingInfo.slot;
3658                         ulTtiReq->nPdus = getnPdus(ulTtiReq, currUlSlot);
3659                         ulTtiReq->nGroup = 0;
3660                         if(ulTtiReq->nPdus > 0)
3661                         {
3662                                 ulTtiReq->pdus = (fapi_ul_tti_req_pdu_t *)(ulTtiReq + \
3663                                                 (sizeof(fapi_ul_tti_req_t) - sizeof(fapi_ul_tti_req_pdu_t*)));
3664                                 /* Fill Prach Pdu */
3665                                 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH)
3666                                 {
3667                                         pduIdx++;
3668                                         fillPrachPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot, &msgLen);
3669                                 }
3670
3671                                 /* Fill PUSCH PDU */
3672                                 if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)
3673                                 {
3674                                         pduIdx++;
3675                                         fillPuschPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot, &msgLen);
3676                                 }
3677                                 /* Fill PUCCH PDU */
3678             if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
3679                                 {
3680                                         pduIdx++;
3681                                         fillPucchPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot, &msgLen);
3682                                 }
3683                                 if((currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH) || \
3684                                                 (currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)|| \
3685                                                 (currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI))
3686                                 {
3687                                         msgLen += (sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t));
3688                                         fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
3689
3690                                         DU_LOG("\nLWR_MAC: Sending UL TTI Request");
3691                                         LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgSize, (void *)ulTtiReq);
3692                                 }   
3693                         } 
3694                         else
3695                         {
3696                                 msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
3697                                 fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
3698
3699                                 DU_LOG("\nLWR_MAC: Sending UL TTI Request");
3700                                 LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgSize, (void *)ulTtiReq);
3701                         }
3702                         memset(currUlSlot, 0, sizeof(MacUlSlot));
3703                         return ROK;
3704                 }
3705                 else
3706                 {
3707                         DU_LOG("\nLWR_MAC: Failed to allocate memory for UL TTI Request");
3708                         memset(currUlSlot, 0, sizeof(MacUlSlot));
3709                         return RFAILED;
3710                 }
3711         }
3712    else
3713    {
3714        lwr_mac_handleInvalidEvt(&currTimingInfo);
3715    }
3716 #endif
3717    return ROK;
3718 }
3719
3720 lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
3721 {
3722    {
3723       /* PHY_STATE_IDLE */
3724        lwr_mac_handleParamReqEvt,
3725        lwr_mac_handleParamRspEvt,
3726        lwr_mac_handleConfigReqEvt,
3727        lwr_mac_handleConfigRspEvt,
3728        lwr_mac_handleInvalidEvt,
3729        lwr_mac_handleInvalidEvt,
3730    },
3731    {
3732        /* PHY_STATE_CONFIGURED */
3733        lwr_mac_handleParamReqEvt,
3734        lwr_mac_handleParamRspEvt,
3735        lwr_mac_handleConfigReqEvt,
3736        lwr_mac_handleConfigRspEvt,
3737        lwr_mac_handleStartReqEvt,
3738        lwr_mac_handleInvalidEvt,
3739    },
3740    {
3741        /* PHY_STATE_RUNNING */
3742        lwr_mac_handleInvalidEvt,
3743        lwr_mac_handleInvalidEvt,
3744        lwr_mac_handleConfigReqEvt,
3745        lwr_mac_handleConfigRspEvt,
3746        lwr_mac_handleInvalidEvt,
3747        lwr_mac_handleStopReqEvt,
3748    }
3749 };
3750
3751 /*******************************************************************
3752  *
3753  * @brief Sends message to LWR_MAC Fsm Event Handler
3754  *
3755  * @details
3756  *
3757  *    Function : sendToLowerMac
3758  *
3759  *    Functionality:
3760  *         -Sends message to LowerMac
3761  *
3762  * @params[in] Message Type
3763  *             Message Length
3764  *             Messaga Pointer
3765  *
3766  * @return void
3767  *
3768 ******************************************************************/
3769 void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg)
3770 {
3771    clGlobalCp.event = msgType;
3772    fapiEvtHdlr[clGlobalCp.phyState][clGlobalCp.event](msg);
3773 }
3774 /**********************************************************************
3775          End of file
3776 **********************************************************************/