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