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