RLC BO, BO response and DL Data handling. [Issue-ID: ODUHIGH-181]
[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->coresetCfg.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->coresetCfg.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 DL DCI PDU required for DL TTI info in MAC
2512  *
2513  * @details
2514  *
2515  *    Function : fillDlMsgDlDciPdu
2516  *
2517  *    Functionality:
2518  *         -Fills the Dl DCI PDU  
2519  *
2520  * @params[in] Pointer to fapi_dl_dci_t
2521  *             Pointer to PdcchCfg
2522  * @return ROK
2523  *
2524  ******************************************************************/
2525 void fillDlMsgDlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *pdcchInfo,\
2526       DlMsgInfo *dlMsgInfo)
2527 {
2528    if(dlDciPtr != NULLP)
2529    {
2530       uint8_t numBytes;
2531       uint8_t bytePos;
2532       uint8_t bitPos;
2533
2534       uint16_t coresetSize = 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 = 0;
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 = pdcchInfo->dci.rnti;
2565       dlDciPtr->scramblingId = pdcchInfo->dci.scramblingId;
2566       dlDciPtr->scramblingRnti = pdcchInfo->dci.scramblingRnti;
2567       dlDciPtr->cceIndex = pdcchInfo->dci.cceIndex;
2568       dlDciPtr->aggregationLevel = pdcchInfo->dci.aggregLevel;
2569       dlDciPtr->pc_and_bform.numPrgs = pdcchInfo->dci.beamPdcchInfo.numPrgs;
2570       dlDciPtr->pc_and_bform.prgSize = pdcchInfo->dci.beamPdcchInfo.prgSize;
2571       dlDciPtr->pc_and_bform.digBfInterfaces = pdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2572       dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = pdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2573       dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = pdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2574       dlDciPtr->beta_pdcch_1_0 = pdcchInfo->dci.txPdcchPower.powerValue;
2575       dlDciPtr->powerControlOfssetSS = pdcchInfo->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       coresetSize = pdcchInfo->coresetCfg.coreSetSize;
2584       rbStart = pdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.startPrb;
2585       rbLen = pdcchInfo->dci.pdschCfg->pdschFreqAlloc.freqAlloc.numPrb;
2586
2587       if((rbLen >=1) && (rbLen <= coresetSize - rbStart))
2588       {
2589          if((rbLen - 1) <= floor(coresetSize / 2))
2590             freqDomResAssign = (coresetSize * (rbLen-1)) + rbStart;
2591          else
2592             freqDomResAssign = (coresetSize * (coresetSize - rbLen + 1)) \
2593                                + (coresetSize - 1 - rbStart);
2594
2595          freqDomResAssignSize = ceil(log2(coresetSize * (coresetSize + 1) / 2));
2596       }
2597
2598       /* Fetching DCI field values */
2599       dciFormatId      = dlMsgInfo->dciFormatId;;     /* Always set to 1 for DL */
2600       timeDomResAssign = pdcchInfo->dci.pdschCfg->pdschTimeAlloc.rowIndex -1;
2601       VRB2PRBMap       = pdcchInfo->dci.pdschCfg->pdschFreqAlloc.vrbPrbMapping;
2602       modNCodScheme    = pdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2603       ndi              = dlMsgInfo->ndi;
2604       redundancyVer    = pdcchInfo->dci.pdschCfg->codeword[0].rvIndex;
2605       harqProcessNum   = dlMsgInfo->harqProcNum;
2606       dlAssignmentIdx  = dlMsgInfo->dlAssignIdx;
2607       pucchTpc         = dlMsgInfo->pucchTpc;
2608       pucchResoInd     = dlMsgInfo->pucchResInd;
2609       harqFeedbackInd  = dlMsgInfo->harqFeedbackInd;
2610
2611       /* Reversing bits in each DCI field */
2612       dciFormatId      = reverseBits(dciFormatId, dciFormatIdSize);
2613       freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2614       timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2615       VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2616       modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2617       ndi              = reverseBits(ndi, ndiSize);
2618       redundancyVer    = reverseBits(redundancyVer, redundancyVerSize);
2619       harqProcessNum   = reverseBits(harqProcessNum, harqProcessNumSize);
2620       dlAssignmentIdx  = reverseBits(dlAssignmentIdx , dlAssignmentIdxSize);
2621       pucchTpc         = reverseBits(pucchTpc, pucchTpcSize);
2622       pucchResoInd     = reverseBits(pucchResoInd, pucchResoIndSize);
2623       harqFeedbackInd  = reverseBits(harqFeedbackInd, harqFeedbackIndSize);
2624
2625
2626       /* Calulating total number of bytes in buffer */
2627       dlDciPtr->payloadSizeBits = (dciFormatIdSize + freqDomResAssignSize\
2628             + timeDomResAssignSize + VRB2PRBMapSize + modNCodSchemeSize\
2629             + ndiSize + redundancyVerSize + harqProcessNumSize + dlAssignmentIdxSize\
2630             + pucchTpcSize + pucchResoIndSize + harqFeedbackIndSize);
2631
2632       numBytes = dlDciPtr->payloadSizeBits / 8;
2633       if(dlDciPtr->payloadSizeBits % 8)
2634          numBytes += 1;
2635
2636       if(numBytes > FAPI_DCI_PAYLOAD_BYTE_LEN)
2637       {
2638          DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
2639          return;
2640       }
2641
2642       /* Initialize buffer */
2643       for(bytePos = 0; bytePos < numBytes; bytePos++)
2644          dlDciPtr->payload[bytePos] = 0;
2645
2646       bytePos = numBytes - 1;
2647       bitPos = 0;
2648
2649       /* Packing DCI format fields */
2650       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2651             dciFormatId, dciFormatIdSize);
2652       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2653             freqDomResAssign, freqDomResAssignSize);
2654       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2655             timeDomResAssign, timeDomResAssignSize);
2656       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2657             VRB2PRBMap, VRB2PRBMapSize);
2658       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2659             modNCodScheme, modNCodSchemeSize);
2660       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2661             ndi, ndiSize);
2662       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2663             redundancyVer, redundancyVerSize);
2664       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2665             redundancyVer, redundancyVerSize);
2666       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2667             harqProcessNum, harqProcessNumSize);
2668       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2669             dlAssignmentIdx, dlAssignmentIdxSize);
2670       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2671             pucchTpc, pucchTpcSize);
2672       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2673             pucchResoInd, pucchResoIndSize);
2674       fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2675             harqFeedbackInd, harqFeedbackIndSize);
2676    }
2677 }
2678
2679 /*******************************************************************
2680  *
2681  * @brief fills PDCCH PDU required for DL TTI info in MAC
2682  *
2683  * @details
2684  *
2685  *    Function : fillPdcchPdu
2686  *
2687  *    Functionality:
2688  *         -Fills the Pdcch PDU info
2689  *          stored in MAC
2690  *
2691  * @params[in] Pointer to FAPI DL TTI Req
2692  *             Pointer to PdcchCfg
2693  * @return ROK
2694  *
2695  ******************************************************************/
2696 uint8_t fillPdcchPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, DlSchedInfo *dlInfo, \
2697       RntiType rntiType, uint8_t coreSetType)
2698 {
2699    if(dlTtiReqPdu != NULLP)
2700    {
2701       PdcchCfg *pdcchInfo = NULLP;
2702       BwpCfg *bwp = NULLP;
2703
2704       memset(&dlTtiReqPdu->pdu.pdcch_pdu, 0, sizeof(fapi_dl_pdcch_pdu_t));
2705       if(rntiType == SI_RNTI_TYPE)
2706       {
2707          pdcchInfo = &dlInfo->brdcstAlloc.sib1Alloc.sib1PdcchCfg;
2708          bwp = &dlInfo->brdcstAlloc.sib1Alloc.bwp;
2709          fillSib1DlDciPdu(dlTtiReqPdu->pdu.pdcch_pdu.dlDci, pdcchInfo);
2710       }
2711       else if(rntiType == RA_RNTI_TYPE)
2712       {
2713          pdcchInfo = &dlInfo->rarAlloc->rarPdcchCfg;
2714          bwp = &dlInfo->rarAlloc->bwp;
2715          fillRarDlDciPdu(dlTtiReqPdu->pdu.pdcch_pdu.dlDci, pdcchInfo);
2716       }
2717       else if(rntiType == TC_RNTI_TYPE || rntiType == C_RNTI_TYPE)
2718       {
2719          pdcchInfo = &dlInfo->dlMsgAlloc->dlMsgPdcchCfg;
2720          bwp = &dlInfo->dlMsgAlloc->bwp;
2721          fillDlMsgDlDciPdu(dlTtiReqPdu->pdu.pdcch_pdu.dlDci, pdcchInfo,\
2722             &dlInfo->dlMsgAlloc->dlMsgInfo);
2723       }
2724       else
2725       {
2726          DU_LOG("\nLWR_MAC: Failed filling PDCCH Pdu");
2727          return RFAILED;;
2728       }
2729       dlTtiReqPdu->pduType = PDCCH_PDU_TYPE;
2730       dlTtiReqPdu->pdu.pdcch_pdu.bwpSize = bwp->freqAlloc.numPrb;
2731       dlTtiReqPdu->pdu.pdcch_pdu.bwpStart = bwp->freqAlloc.startPrb;
2732       dlTtiReqPdu->pdu.pdcch_pdu.subCarrierSpacing = bwp->subcarrierSpacing; 
2733       dlTtiReqPdu->pdu.pdcch_pdu.cyclicPrefix = bwp->cyclicPrefix; 
2734       dlTtiReqPdu->pdu.pdcch_pdu.startSymbolIndex = pdcchInfo->coresetCfg.startSymbolIndex;
2735       dlTtiReqPdu->pdu.pdcch_pdu.durationSymbols = pdcchInfo->coresetCfg.durationSymbols;
2736       memcpy(dlTtiReqPdu->pdu.pdcch_pdu.freqDomainResource, pdcchInfo->coresetCfg.freqDomainResource, 6);
2737       dlTtiReqPdu->pdu.pdcch_pdu.cceRegMappingType = pdcchInfo->coresetCfg.cceRegMappingType;
2738       dlTtiReqPdu->pdu.pdcch_pdu.regBundleSize = pdcchInfo->coresetCfg.regBundleSize;
2739       dlTtiReqPdu->pdu.pdcch_pdu.interleaverSize = pdcchInfo->coresetCfg.interleaverSize;
2740       dlTtiReqPdu->pdu.pdcch_pdu.coreSetSize = pdcchInfo->coresetCfg.coreSetType;
2741       dlTtiReqPdu->pdu.pdcch_pdu.shiftIndex =  pdcchInfo->coresetCfg.shiftIndex;
2742       dlTtiReqPdu->pdu.pdcch_pdu.precoderGranularity = pdcchInfo->coresetCfg.precoderGranularity;
2743       dlTtiReqPdu->pdu.pdcch_pdu.numDlDci = pdcchInfo->numDlDci;
2744       dlTtiReqPdu->pdu.pdcch_pdu.coreSetType = coreSetType;
2745
2746       /* Calculating PDU length. Considering only one dl dci pdu for now */
2747       dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdcch_pdu_t);
2748    }
2749
2750    return ROK;
2751 }
2752
2753 /*******************************************************************
2754  *
2755  * @brief fills PDSCH PDU required for DL TTI info in MAC
2756  *
2757  * @details
2758  *
2759  *    Function : fillPdschPdu
2760  *
2761  *    Functionality:
2762  *         -Fills the Pdsch PDU info
2763  *          stored in MAC
2764  *
2765  * @params[in] Pointer to FAPI DL TTI Req
2766  *             Pointer to PdschCfg
2767  *             Pointer to msgLen of DL TTI Info
2768  * @return ROK
2769  *
2770  ******************************************************************/
2771
2772 void fillPdschPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, PdschCfg *pdschInfo,
2773       BwpCfg bwp, uint16_t pduIndex)
2774 {
2775    uint8_t idx;
2776
2777    if(dlTtiReqPdu != NULLP)
2778    {
2779       dlTtiReqPdu->pduType = PDSCH_PDU_TYPE;
2780       memset(&dlTtiReqPdu->pdu.pdsch_pdu, 0, sizeof(fapi_dl_pdsch_pdu_t));
2781       dlTtiReqPdu->pdu.pdsch_pdu.pduBitMap = pdschInfo->pduBitmap;
2782       dlTtiReqPdu->pdu.pdsch_pdu.rnti = pdschInfo->rnti;         
2783       dlTtiReqPdu->pdu.pdsch_pdu.pdu_index = pduIndex;
2784       dlTtiReqPdu->pdu.pdsch_pdu.bwpSize = bwp.freqAlloc.numPrb;       
2785       dlTtiReqPdu->pdu.pdsch_pdu.bwpStart = bwp.freqAlloc.startPrb;
2786       dlTtiReqPdu->pdu.pdsch_pdu.subCarrierSpacing = bwp.subcarrierSpacing;
2787       dlTtiReqPdu->pdu.pdsch_pdu.cyclicPrefix = bwp.cyclicPrefix;
2788       dlTtiReqPdu->pdu.pdsch_pdu.nrOfCodeWords = pdschInfo->numCodewords;
2789       for(idx = 0; idx < MAX_CODEWORDS ; idx++)
2790       { 
2791          dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].targetCodeRate = pdschInfo->codeword[idx].targetCodeRate;
2792          dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].qamModOrder = pdschInfo->codeword[idx].qamModOrder;
2793          dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].mcsIndex = pdschInfo->codeword[idx].mcsIndex;
2794          dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].mcsTable = pdschInfo->codeword[idx].mcsTable;
2795          dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].rvIndex = pdschInfo->codeword[idx].rvIndex;
2796          dlTtiReqPdu->pdu.pdsch_pdu.cwInfo[idx].tbSize = pdschInfo->codeword[idx].tbSize;
2797       }
2798       dlTtiReqPdu->pdu.pdsch_pdu.dataScramblingId = pdschInfo->dataScramblingId;       
2799       dlTtiReqPdu->pdu.pdsch_pdu.nrOfLayers = pdschInfo->numLayers;
2800       dlTtiReqPdu->pdu.pdsch_pdu.transmissionScheme = pdschInfo->transmissionScheme;
2801       dlTtiReqPdu->pdu.pdsch_pdu.refPoint = pdschInfo->refPoint;
2802       dlTtiReqPdu->pdu.pdsch_pdu.dlDmrsSymbPos = pdschInfo->dmrs.dlDmrsSymbPos;
2803       dlTtiReqPdu->pdu.pdsch_pdu.dmrsConfigType = pdschInfo->dmrs.dmrsConfigType;
2804       dlTtiReqPdu->pdu.pdsch_pdu.dlDmrsScramblingId = pdschInfo->dmrs.dlDmrsScramblingId;
2805       dlTtiReqPdu->pdu.pdsch_pdu.scid = pdschInfo->dmrs.scid;
2806       dlTtiReqPdu->pdu.pdsch_pdu.numDmrsCdmGrpsNoData = pdschInfo->dmrs.numDmrsCdmGrpsNoData;
2807       dlTtiReqPdu->pdu.pdsch_pdu.dmrsPorts = pdschInfo->dmrs.dmrsPorts;
2808       dlTtiReqPdu->pdu.pdsch_pdu.resourceAlloc = pdschInfo->pdschFreqAlloc.resourceAllocType;
2809       /* since we are using type-1, hence rbBitmap excluded */
2810       dlTtiReqPdu->pdu.pdsch_pdu.rbStart = pdschInfo->pdschFreqAlloc.freqAlloc.startPrb;
2811       dlTtiReqPdu->pdu.pdsch_pdu.rbSize = pdschInfo->pdschFreqAlloc.freqAlloc.numPrb;
2812       dlTtiReqPdu->pdu.pdsch_pdu.vrbToPrbMapping = pdschInfo->pdschFreqAlloc.vrbPrbMapping;
2813       dlTtiReqPdu->pdu.pdsch_pdu.startSymbIndex = pdschInfo->pdschTimeAlloc.timeAlloc.startSymb;
2814       dlTtiReqPdu->pdu.pdsch_pdu.nrOfSymbols = pdschInfo->pdschTimeAlloc.timeAlloc.numSymb;
2815       dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.numPrgs = pdschInfo->beamPdschInfo.numPrgs;
2816       dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.prgSize = pdschInfo->beamPdschInfo.prgSize;
2817       dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.digBfInterfaces = pdschInfo->beamPdschInfo.digBfInterfaces;
2818       dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2819          pmIdx = pdschInfo->beamPdschInfo.prg[0].pmIdx;
2820       dlTtiReqPdu->pdu.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2821          beamIdx[0].beamidx = pdschInfo->beamPdschInfo.prg[0].beamIdx[0];
2822       dlTtiReqPdu->pdu.pdsch_pdu.powerControlOffset = pdschInfo->txPdschPower.powerControlOffset;  
2823       dlTtiReqPdu->pdu.pdsch_pdu.powerControlOffsetSS = pdschInfo->txPdschPower.powerControlOffsetSS;
2824       dlTtiReqPdu->pdu.pdsch_pdu.mappingType =   pdschInfo->dmrs.mappingType;
2825       dlTtiReqPdu->pdu.pdsch_pdu.nrOfDmrsSymbols = pdschInfo->dmrs.nrOfDmrsSymbols;
2826       dlTtiReqPdu->pdu.pdsch_pdu.dmrsAddPos = pdschInfo->dmrs.dmrsAddPos;
2827
2828       dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdsch_pdu_t);
2829    }
2830 }
2831
2832 /***********************************************************************
2833  *
2834  * @brief calculates the total size to be allocated for DL TTI Req
2835  *
2836  * @details
2837  *
2838  *    Function : calcDlTtiReqPduCount
2839  *
2840  *    Functionality:
2841  *         -calculates the total pdu count to be allocated for DL TTI Req
2842  *
2843  * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
2844  * @return count
2845  *
2846  * ********************************************************************/
2847 uint8_t calcDlTtiReqPduCount(DlSchedInfo *dlInfo)
2848 {
2849    uint8_t count = 0;
2850    uint8_t idx = 0;
2851
2852    if(dlInfo->isBroadcastPres)
2853    {
2854       if(dlInfo->brdcstAlloc.ssbTrans)
2855       {
2856          for(idx = 0; idx < dlInfo->brdcstAlloc.ssbIdxSupported; idx++)
2857          {
2858             /* SSB PDU is filled */
2859             count++;
2860          }
2861       }
2862       if(dlInfo->brdcstAlloc.sib1Trans)
2863       {
2864          /* PDCCH and PDSCH PDU is filled */
2865          count += 2;
2866       }
2867    }
2868    if(dlInfo->rarAlloc != NULLP)
2869    {
2870       /* PDCCH and PDSCH PDU is filled */
2871       count += 2;
2872    }
2873    if(dlInfo->dlMsgAlloc != NULLP)
2874    {
2875       /* PDCCH and PDSCH PDU is filled */
2876       count += 2;
2877    }
2878    return count;
2879 }
2880
2881 /***********************************************************************
2882  *
2883  * @brief calculates the total size to be allocated for DL TTI Req
2884  *
2885  * @details
2886  *
2887  *    Function : calcTxDataReqPduCount
2888  *
2889  *    Functionality:
2890  *         -calculates the total pdu count to be allocated for DL TTI Req
2891  *
2892  * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
2893  * @return count
2894  *
2895  * ********************************************************************/
2896 uint8_t calcTxDataReqPduCount(DlSchedInfo *dlInfo)
2897 {
2898    uint8_t count = 0;
2899
2900    if(dlInfo->isBroadcastPres && dlInfo->brdcstAlloc.sib1Trans)
2901    {
2902       count++;
2903    }
2904    if(dlInfo->rarAlloc != NULLP)
2905    {
2906       count++;
2907    }
2908    if(dlInfo->dlMsgAlloc != NULLP)
2909    {
2910       count++;
2911    }
2912    return count;
2913 }
2914 /***********************************************************************
2915  *
2916  * @brief fills the SIB1 TX-DATA request message
2917  *
2918  * @details
2919  *
2920  *    Function : fillSib1TxDataReq
2921  *
2922  *    Functionality:
2923  *         - fills the SIB1 TX-DATA request message
2924  *
2925  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
2926  * @params[in]    macCellCfg consist of SIB1 pdu
2927  * @params[in]    uint32_t *msgLen
2928  * @params[in]    uint16_t pduIndex
2929  * @return ROK
2930  *
2931  * ********************************************************************/
2932 uint8_t fillSib1TxDataReq(fapi_tx_pdu_desc_t *pduDesc,MacCellCfg *macCellCfg,
2933       uint16_t pduIndex)
2934 {
2935    uint32_t pduLen = 0;
2936    uint8_t *sib1TxdataValue = NULLP;
2937
2938    pduDesc[pduIndex].pdu_index = pduIndex;
2939    pduDesc[pduIndex].num_tlvs = 1;
2940
2941    /* fill the TLV */
2942    /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
2943    pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
2944    pduDesc[pduIndex].tlvs[0].tl.length = macCellCfg->sib1Cfg.sib1PduLen;
2945    LWR_MAC_ALLOC(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2946    if(sib1TxdataValue == NULLP)
2947    {
2948       return RFAILED;
2949    }
2950    memcpy(sib1TxdataValue,macCellCfg->sib1Cfg.sib1Pdu,
2951          macCellCfg->sib1Cfg.sib1PduLen);
2952    pduDesc[pduIndex].tlvs[0].value = sib1TxdataValue;
2953
2954    /* The total length of the PDU description and   PDU data */
2955    pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
2956    pduLen += sizeof(fapi_uint8_ptr_tlv_t); /* only 1 TLV is present */
2957    pduDesc[pduIndex].pdu_length = pduLen; 
2958
2959 #ifndef INTEL_WLS   
2960    MAC_FREE(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2961 #endif
2962
2963    return ROK;
2964 }
2965
2966 /***********************************************************************
2967  *
2968  * @brief fills the RAR TX-DATA request message
2969  *
2970  * @details
2971  *
2972  *    Function : fillRarTxDataReq
2973  *
2974  *    Functionality:
2975  *         - fills the RAR TX-DATA request message
2976  *
2977  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
2978  * @params[in]    RarInfo *rarInfo
2979  * @params[in]    uint32_t *msgLen
2980  * @params[in]    uint16_t pduIndex
2981  * @return ROK
2982  *
2983  * ********************************************************************/
2984 uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
2985       uint16_t pduIndex)
2986 {
2987    uint32_t pduLen = 0;
2988    uint8_t *rarTxdataValue = NULLP;
2989
2990    pduDesc[pduIndex].pdu_index = pduIndex;
2991    pduDesc[pduIndex].num_tlvs = 1;
2992
2993    /* fill the TLV */
2994    /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
2995    pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
2996    pduDesc[pduIndex].tlvs[0].tl.length = rarInfo->rarPduLen;
2997    LWR_MAC_ALLOC(rarTxdataValue,rarInfo->rarPduLen);
2998    if(rarTxdataValue == NULLP)
2999    {
3000       return RFAILED;
3001    }
3002    memcpy(rarTxdataValue,rarInfo->rarPdu,rarInfo->rarPduLen);
3003    pduDesc[pduIndex].tlvs[0].value = rarTxdataValue;
3004
3005    /* The total length of the PDU description and   PDU data */
3006    pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
3007    pduLen += sizeof(fapi_uint8_ptr_tlv_t); /* only 1 TLV is present */
3008    pduDesc[pduIndex].pdu_length = pduLen; 
3009
3010    /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
3011     * But since we did not implement WLS, this has to be done here
3012     */
3013 #ifndef INTEL_WLS   
3014    MAC_FREE(rarTxdataValue,rarInfo->rarPduLen);
3015 #endif
3016
3017    return ROK;
3018 }
3019
3020 /***********************************************************************
3021  *
3022  * @brief fills the DL dedicated Msg TX-DATA request message
3023  *
3024  * @details
3025  *
3026  *    Function : fillDlMsgTxDataReq
3027  *
3028  *    Functionality:
3029  *         - fills the Dl Dedicated Msg TX-DATA request message
3030  *
3031  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
3032  * @params[in]    DlMsgInfo *dlMsgInfo
3033  * @params[in]    uint32_t *msgLen
3034  * @params[in]    uint16_t pduIndex
3035  * @return ROK
3036  *
3037  * ********************************************************************/
3038 uint8_t fillDlMsgTxDataReq(fapi_tx_pdu_desc_t *pduDesc, DlMsgInfo *dlMsgInfo,
3039       uint16_t pduIndex)
3040 {
3041    uint32_t pduLen = 0;
3042    uint8_t *dedMsgTxDataValue = NULLP;
3043
3044    pduDesc[pduIndex].pdu_index = pduIndex;
3045    pduDesc[pduIndex].num_tlvs = 1;
3046
3047    /* fill the TLV */
3048    /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
3049    pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
3050    pduDesc[pduIndex].tlvs[0].tl.length = dlMsgInfo->dlMsgPduLen;
3051    LWR_MAC_ALLOC(dedMsgTxDataValue, dlMsgInfo->dlMsgPduLen);
3052    if(dedMsgTxDataValue == NULLP)
3053    {
3054       return RFAILED;
3055    }
3056    memcpy(dedMsgTxDataValue, dlMsgInfo->dlMsgPdu, dlMsgInfo->dlMsgPduLen);
3057    pduDesc[pduIndex].tlvs[0].value = dedMsgTxDataValue;
3058
3059    /* The total length of the PDU description and PDU data */
3060    pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
3061    pduLen += sizeof(fapi_uint8_ptr_tlv_t); /* only 1 TLV is present */
3062    pduDesc[pduIndex].pdu_length = pduLen;
3063
3064    /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
3065     * But since we did not implement WLS, this has to be done here
3066     */
3067 #ifndef INTEL_WLS
3068    MAC_FREE(dedMsgTxDataValue, dlMsgInfo->dlMsgPduLen);
3069 #endif
3070
3071    return ROK;
3072 }
3073
3074
3075 #endif /* FAPI */
3076 /*******************************************************************
3077  *
3078  * @brief Sends DL TTI Request to PHY
3079  *
3080  * @details
3081  *
3082  *    Function : fillDlTtiReq
3083  *
3084  *    Functionality:
3085  *         -Sends FAPI DL TTI req to PHY
3086  *
3087  * @params[in]    timing info
3088  * @return ROK     - success
3089  *         RFAILED - failure
3090  *
3091  * ****************************************************************/
3092 uint16_t fillDlTtiReq(SlotIndInfo currTimingInfo)
3093 {
3094 #ifdef INTEL_FAPI
3095    uint8_t idx;
3096    uint8_t nPdu = 0;
3097    uint8_t numPduEncoded = 0;
3098    uint16_t cellIdx;
3099    uint16_t pduIndex = 0;
3100    uint32_t msgLen = 0;
3101
3102    fapi_dl_tti_req_t *dlTtiReq = NULLP;
3103    SlotIndInfo dlTtiReqTimingInfo;
3104
3105    MacDlSlot *currDlSlot = NULLP;
3106    MacCellCfg macCellCfg;
3107    memset(&macCellCfg, 0, sizeof(MacCellCfg));
3108    RntiType rntiType;
3109
3110    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
3111    {
3112       GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
3113       /* consider phy delay */
3114       ADD_DELTA_TO_TIME(currTimingInfo,dlTtiReqTimingInfo,PHY_DELTA);
3115
3116       macCellCfg = macCb.macCell[cellIdx]->macCellCfg;
3117
3118       currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlTtiReqTimingInfo.slot]; 
3119       nPdu = calcDlTtiReqPduCount(&currDlSlot->dlInfo);
3120       LWR_MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
3121       if(dlTtiReq != NULLP)
3122       {
3123          memset(dlTtiReq, 0, sizeof(fapi_dl_tti_req_t));
3124          dlTtiReq->sfn  = dlTtiReqTimingInfo.sfn;
3125          dlTtiReq->slot = dlTtiReqTimingInfo.slot;
3126          dlTtiReq->nPdus = calcDlTtiReqPduCount(&currDlSlot->dlInfo);  /* get total Pdus */
3127          nPdu = dlTtiReq->nPdus;
3128          dlTtiReq->nGroup = 0;
3129
3130          if(dlTtiReq->nPdus > 0)
3131          {
3132             if(currDlSlot->dlInfo.isBroadcastPres)
3133             {
3134                if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
3135                {
3136                   if(dlTtiReq->pdus != NULLP)
3137                   {
3138                      for(idx = 0; idx < currDlSlot->dlInfo.brdcstAlloc.ssbIdxSupported; idx++)
3139                      {
3140                         fillSsbPdu(&dlTtiReq->pdus[numPduEncoded], &macCellCfg,\
3141                               currDlSlot, idx, dlTtiReq->sfn);
3142                         numPduEncoded++;
3143                      }
3144                   }
3145                   printf("\033[1;31m");
3146                   DU_LOG("\nLWR_MAC: MIB sent..");
3147                   printf("\033[0m");
3148                }
3149                if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
3150                {
3151                   /* Filling SIB1 param */
3152                   if(numPduEncoded != nPdu)
3153                   {
3154                      rntiType = SI_RNTI_TYPE;
3155                      fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo,\
3156                            rntiType, CORESET_TYPE0);
3157                      numPduEncoded++;
3158                      fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3159                            &currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg,
3160                            currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.bwp,
3161                            pduIndex);
3162                      pduIndex++;
3163                      numPduEncoded++;
3164                   }
3165                   printf("\033[1;34m");
3166                   DU_LOG("\nLWR_MAC: SIB1 sent...");
3167                   printf("\033[0m");
3168                }
3169             }
3170             if(currDlSlot->dlInfo.rarAlloc != NULLP)
3171             {
3172                /* Filling RAR param */
3173                rntiType = RA_RNTI_TYPE;
3174                fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3175                      &currDlSlot->dlInfo, rntiType, CORESET_TYPE0);
3176                numPduEncoded++;
3177                fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3178                      &currDlSlot->dlInfo.rarAlloc->rarPdschCfg,
3179                      currDlSlot->dlInfo.rarAlloc->bwp,
3180                      pduIndex);
3181                numPduEncoded++;
3182                pduIndex++;
3183
3184                printf("\033[1;32m");
3185                DU_LOG("\nLWR_MAC: RAR sent...");
3186                printf("\033[0m");
3187             }
3188             if(currDlSlot->dlInfo.dlMsgAlloc != NULLP)
3189             {
3190                if(currDlSlot->dlInfo.dlMsgAlloc->dlMsgInfo.dlMsgPdu != NULLP)
3191                {
3192                   /* Filling Msg4 param */
3193                   printf("\033[1;32m");
3194                   if(currDlSlot->dlInfo.dlMsgAlloc->dlMsgInfo.isMsg4Pdu)
3195                   {
3196                      rntiType = TC_RNTI_TYPE;
3197                      fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3198                            &currDlSlot->dlInfo, rntiType, CORESET_TYPE0);
3199                      DU_LOG("\nLWR_MAC: MSG4 sent...");
3200                   }
3201                   else
3202                   { 
3203                      /* Filling other DL msg params */
3204                      rntiType = C_RNTI_TYPE;
3205                      fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], \
3206                            &currDlSlot->dlInfo, rntiType, CORESET_TYPE1);
3207                      DU_LOG("\nLWR_MAC: DL MSG sent...");
3208                   }
3209                   printf("\033[0m");
3210
3211                   numPduEncoded++;
3212                   fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],
3213                         &currDlSlot->dlInfo.dlMsgAlloc->dlMsgPdschCfg,
3214                         currDlSlot->dlInfo.dlMsgAlloc->bwp,
3215                         pduIndex);
3216                   numPduEncoded++;
3217                   pduIndex++;
3218                }
3219                else
3220                {
3221                   MAC_FREE(currDlSlot->dlInfo.dlMsgAlloc, sizeof(DlMsgAlloc));
3222                   currDlSlot->dlInfo.dlMsgAlloc = NULLP;
3223                }
3224             }
3225
3226             msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
3227             fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
3228             LwrMacSendToPhy(dlTtiReq->header.msg_id, sizeof(fapi_dl_tti_req_t), \
3229                   (void *)dlTtiReq);
3230
3231             /* send Tx-DATA req message */
3232             sendTxDataReq(currTimingInfo, &currDlSlot->dlInfo);
3233          }
3234          else
3235          {
3236             msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
3237             fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
3238             LwrMacSendToPhy(dlTtiReq->header.msg_id, sizeof(fapi_dl_tti_req_t), (void *)dlTtiReq);
3239          }
3240          memset(currDlSlot, 0, sizeof(MacDlSlot));
3241          return ROK;
3242       }
3243       else
3244       {
3245          DU_LOG("\nLWR_MAC: Failed to allocate memory for DL TTI Request");
3246          memset(currDlSlot, 0, sizeof(MacDlSlot));
3247          return RFAILED;
3248       }
3249    }
3250    else
3251    {
3252       lwr_mac_procInvalidEvt(&currTimingInfo);
3253       return RFAILED;
3254    }
3255 #endif
3256    return ROK;
3257 }
3258
3259 /*******************************************************************
3260  *
3261  * @brief Sends TX data Request to PHY
3262  *
3263  * @details
3264  *
3265  *    Function : sendTxDataReq
3266  *
3267  *    Functionality:
3268  *         -Sends FAPI TX data req to PHY
3269  *
3270  * @params[in]    timing info
3271  * @return ROK     - success
3272  *         RFAILED - failure
3273  *
3274  * ****************************************************************/
3275 uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo)
3276 {
3277 #ifdef INTEL_FAPI
3278    uint8_t nPdu = 0;
3279    uint16_t cellIdx;
3280    uint32_t msgLen = 0;
3281    uint16_t pduIndex = 0;
3282    uint32_t txDataReqMsgSize = 0;
3283    fapi_tx_data_req_t *txDataReq = NULLP;
3284
3285    GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
3286
3287    /* send TX_Data request message */
3288    nPdu = calcTxDataReqPduCount(dlInfo);
3289    if(nPdu > 0)
3290    {
3291       txDataReqMsgSize = sizeof(fapi_tx_data_req_t);
3292       if(dlInfo->brdcstAlloc.sib1Trans)
3293       {
3294          txDataReqMsgSize += macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen;
3295       }
3296       if(dlInfo->rarAlloc != NULLP)
3297       {
3298          txDataReqMsgSize += dlInfo->rarAlloc->rarInfo.rarPduLen;
3299       }
3300       if(dlInfo->dlMsgAlloc != NULLP)
3301       {
3302          txDataReqMsgSize += dlInfo->dlMsgAlloc->dlMsgInfo.dlMsgPduLen;
3303       }
3304
3305       LWR_MAC_ALLOC(txDataReq, txDataReqMsgSize);
3306       if(txDataReq == NULLP)
3307       {
3308          DU_LOG("\nLWR_MAC: Failed to allocate memory for TX data Request");
3309          return RFAILED;
3310       }
3311
3312       memset(txDataReq, 0, txDataReqMsgSize);
3313       txDataReq->sfn  = currTimingInfo.sfn;
3314       txDataReq->slot = currTimingInfo.slot;
3315       if(dlInfo->brdcstAlloc.sib1Trans)
3316       {
3317          fillSib1TxDataReq(txDataReq->pdu_desc,
3318                &macCb.macCell[cellIdx]->macCellCfg, pduIndex);
3319          pduIndex++;
3320          txDataReq->num_pdus++;
3321       }
3322       if(dlInfo->rarAlloc != NULLP)
3323       {
3324          fillRarTxDataReq(txDataReq->pdu_desc, &dlInfo->rarAlloc->rarInfo, pduIndex);
3325          pduIndex++;
3326          txDataReq->num_pdus++;
3327
3328          MAC_FREE(dlInfo->rarAlloc,sizeof(RarAlloc));
3329          dlInfo->rarAlloc = NULLP;
3330       }
3331       if(dlInfo->dlMsgAlloc != NULLP)
3332       {
3333          fillDlMsgTxDataReq(txDataReq->pdu_desc, \
3334             &dlInfo->dlMsgAlloc->dlMsgInfo, pduIndex);
3335          pduIndex++;
3336          txDataReq->num_pdus++;
3337
3338          MAC_FREE(dlInfo->dlMsgAlloc->dlMsgInfo.dlMsgPdu,\
3339             dlInfo->dlMsgAlloc->dlMsgInfo.dlMsgPduLen);
3340          dlInfo->dlMsgAlloc->dlMsgInfo.dlMsgPdu = NULLP;
3341          MAC_FREE(dlInfo->dlMsgAlloc, sizeof(DlMsgAlloc));
3342          dlInfo->dlMsgAlloc = NULLP;
3343       }
3344
3345       msgLen = txDataReqMsgSize - sizeof(fapi_msg_t);
3346       fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
3347       LwrMacSendToPhy(txDataReq->header.msg_id, txDataReqMsgSize, \
3348             (void *)txDataReq);
3349    }
3350 #endif
3351    return ROK;
3352 }
3353
3354 /***********************************************************************
3355  *
3356  * @brief calculates the total size to be allocated for UL TTI Req
3357  *
3358  * @details
3359  *
3360  *    Function : getnPdus
3361  *
3362  *    Functionality:
3363  *         -calculates the total pdu count to be allocated for UL TTI Req
3364  *
3365  * @params[in] Pointer to fapi Ul TTI Req
3366  *             Pointer to CurrUlSlot
3367  * @return count
3368  * ********************************************************************/
3369 #ifdef INTEL_FAPI
3370 uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
3371 {
3372    uint8_t pduCount = 0;
3373
3374    if(ulTtiReq && currUlSlot)
3375    {
3376       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH)
3377       {
3378          pduCount++;
3379          ulTtiReq->rachPresent++;
3380       }
3381       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)
3382       {
3383          pduCount++;
3384          ulTtiReq->nUlsch++;
3385       }
3386       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
3387       {
3388          pduCount++;
3389          ulTtiReq->nUlsch++;
3390       }
3391       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
3392       {
3393          pduCount++;
3394          ulTtiReq->nUlcch++;
3395       }
3396       if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_SRS)
3397       {
3398          pduCount++;
3399       }
3400    }
3401    return pduCount;
3402 }
3403 #endif
3404
3405 /***********************************************************************
3406  *
3407  * @brief Set the value of zero correlation config in PRACH PDU
3408  *
3409  * @details
3410  *
3411  *    Function : setNumCs
3412  *
3413  *    Functionality:
3414  *         -Set the value of zero correlation config in PRACH PDU
3415  *
3416  * @params[in] Pointer to zero correlation config
3417  *             Pointer to MacCellCfg
3418  * ********************************************************************/
3419
3420 void setNumCs(uint16_t *numCs, MacCellCfg *macCellCfg)
3421 {
3422 #ifdef INTEL_FAPI
3423    uint8_t idx;
3424    if(macCellCfg != NULLP)
3425    {
3426       idx = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
3427       *numCs = UnrestrictedSetNcsTable[idx];
3428    }
3429 #endif
3430 }
3431
3432 /***********************************************************************
3433  *
3434  * @brief Fills the PRACH PDU in UL TTI Request
3435  *
3436  * @details
3437  *
3438  *    Function : fillPrachPdu
3439  *
3440  *    Functionality:
3441  *         -Fills the PRACH PDU in UL TTI Request
3442  *
3443  * @params[in] Pointer to Prach Pdu
3444  *             Pointer to CurrUlSlot
3445  *             Pointer to macCellCfg
3446  *             Pointer to msgLen
3447  * ********************************************************************/
3448
3449 #ifdef INTEL_FAPI
3450 void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot)
3451 {
3452    if(ulTtiReqPdu != NULLP)
3453    {
3454       ulTtiReqPdu->pduType = PRACH_PDU_TYPE; 
3455       ulTtiReqPdu->pdu.prach_pdu.physCellId = macCellCfg->phyCellId;
3456       ulTtiReqPdu->pdu.prach_pdu.numPrachOcas = \
3457          currUlSlot->ulInfo.prachSchInfo.numPrachOcas;
3458       ulTtiReqPdu->pdu.prach_pdu.prachFormat = \
3459          currUlSlot->ulInfo.prachSchInfo.prachFormat;
3460       ulTtiReqPdu->pdu.prach_pdu.numRa = currUlSlot->ulInfo.prachSchInfo.numRa;
3461       ulTtiReqPdu->pdu.prach_pdu.prachStartSymbol = \
3462          currUlSlot->ulInfo.prachSchInfo.prachStartSymb;
3463       setNumCs(&ulTtiReqPdu->pdu.prach_pdu.numCs, macCellCfg);
3464       ulTtiReqPdu->pdu.prach_pdu.beamforming.numPrgs = 0;
3465       ulTtiReqPdu->pdu.prach_pdu.beamforming.prgSize = 0;
3466       ulTtiReqPdu->pdu.prach_pdu.beamforming.digBfInterface = 0;
3467       ulTtiReqPdu->pdu.prach_pdu.beamforming.rx_bfi[0].beamIdx[0].beamidx = 0;
3468       ulTtiReqPdu->pduSize = sizeof(fapi_ul_prach_pdu_t); 
3469    }
3470 }
3471
3472 void fillPuschPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot)
3473 {
3474    if(ulTtiReqPdu != NULLP)
3475    {
3476       ulTtiReqPdu->pduType = PUSCH_PDU_TYPE;
3477       memset(&ulTtiReqPdu->pdu.pusch_pdu, 0, sizeof(fapi_ul_pusch_pdu_t));
3478       ulTtiReqPdu->pdu.pusch_pdu.pduBitMap = 1;
3479       ulTtiReqPdu->pdu.pusch_pdu.rnti = currUlSlot->ulInfo.crnti;
3480       /* TODO : Fill handle in raCb when scheduling pusch and access here */
3481       ulTtiReqPdu->pdu.pusch_pdu.handle = 100;
3482       ulTtiReqPdu->pdu.pusch_pdu.bwpSize = macCellCfg->initialUlBwp.bwp.numPrb;
3483       ulTtiReqPdu->pdu.pusch_pdu.bwpStart = macCellCfg->initialUlBwp.bwp.firstPrb;
3484       ulTtiReqPdu->pdu.pusch_pdu.subCarrierSpacing = \
3485          macCellCfg->initialUlBwp.bwp.scs;
3486       ulTtiReqPdu->pdu.pusch_pdu.cyclicPrefix = \
3487          macCellCfg->initialUlBwp.bwp.cyclicPrefix;
3488       ulTtiReqPdu->pdu.pusch_pdu.targetCodeRate = 308;
3489       ulTtiReqPdu->pdu.pusch_pdu.qamModOrder = 2;
3490       ulTtiReqPdu->pdu.pusch_pdu.mcsIndex = \
3491          currUlSlot->ulInfo.schPuschInfo.tbInfo.mcs;
3492       ulTtiReqPdu->pdu.pusch_pdu.mcsTable = 0;
3493       ulTtiReqPdu->pdu.pusch_pdu.transformPrecoding = 1;
3494       ulTtiReqPdu->pdu.pusch_pdu.dataScramblingId = currUlSlot->ulInfo.cellId;
3495       ulTtiReqPdu->pdu.pusch_pdu.nrOfLayers = 1;
3496       ulTtiReqPdu->pdu.pusch_pdu.ulDmrsSymbPos = 4;
3497       ulTtiReqPdu->pdu.pusch_pdu.dmrsConfigType = 0;
3498       ulTtiReqPdu->pdu.pusch_pdu.ulDmrsScramblingId = currUlSlot->ulInfo.cellId;
3499       ulTtiReqPdu->pdu.pusch_pdu.scid = 0;
3500       ulTtiReqPdu->pdu.pusch_pdu.numDmrsCdmGrpsNoData = 1;
3501       ulTtiReqPdu->pdu.pusch_pdu.dmrsPorts = 0;
3502       ulTtiReqPdu->pdu.pusch_pdu.resourceAlloc = \
3503          currUlSlot->ulInfo.schPuschInfo.resAllocType;
3504       ulTtiReqPdu->pdu.pusch_pdu.rbStart = \
3505          currUlSlot->ulInfo.schPuschInfo.fdAlloc.startPrb;
3506       ulTtiReqPdu->pdu.pusch_pdu.rbSize = \
3507          currUlSlot->ulInfo.schPuschInfo.fdAlloc.numPrb;
3508       ulTtiReqPdu->pdu.pusch_pdu.vrbToPrbMapping = 0;
3509       ulTtiReqPdu->pdu.pusch_pdu.frequencyHopping = 0;
3510       ulTtiReqPdu->pdu.pusch_pdu.txDirectCurrentLocation = 0;
3511       ulTtiReqPdu->pdu.pusch_pdu.uplinkFrequencyShift7p5khz = 0;
3512       ulTtiReqPdu->pdu.pusch_pdu.startSymbIndex = \
3513          currUlSlot->ulInfo.schPuschInfo.tdAlloc.startSymb;
3514       ulTtiReqPdu->pdu.pusch_pdu.nrOfSymbols = \
3515          currUlSlot->ulInfo.schPuschInfo.tdAlloc.numSymb;
3516       ulTtiReqPdu->pdu.pusch_pdu.mappingType = \
3517          currUlSlot->ulInfo.schPuschInfo.dmrsMappingType;
3518       ulTtiReqPdu->pdu.pusch_pdu.nrOfDmrsSymbols = \
3519          currUlSlot->ulInfo.schPuschInfo.nrOfDmrsSymbols;
3520       ulTtiReqPdu->pdu.pusch_pdu.dmrsAddPos = \
3521          currUlSlot->ulInfo.schPuschInfo.dmrsAddPos;
3522       ulTtiReqPdu->pdu.pusch_pdu.puschData.rvIndex = \
3523          currUlSlot->ulInfo.schPuschInfo.tbInfo.rv;
3524       ulTtiReqPdu->pdu.pusch_pdu.puschData.harqProcessId = \
3525          currUlSlot->ulInfo.schPuschInfo.harqProcId;
3526       ulTtiReqPdu->pdu.pusch_pdu.puschData.newDataIndicator = \
3527          currUlSlot->ulInfo.schPuschInfo.tbInfo.ndi;
3528       ulTtiReqPdu->pdu.pusch_pdu.puschData.tbSize = \
3529          currUlSlot->ulInfo.schPuschInfo.tbInfo.tbSize;
3530       /* numCb is 0 for new transmission */
3531       ulTtiReqPdu->pdu.pusch_pdu.puschData.numCb = 0;
3532
3533       ulTtiReqPdu->pduSize = sizeof(fapi_ul_pusch_pdu_t);
3534    }
3535 }
3536
3537 void fillPucchPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg,\
3538       MacUlSlot *currUlSlot)
3539 {
3540    if(ulTtiReqPdu != NULLP)
3541    {
3542       ulTtiReqPdu->pduType                  = PUCCH_PDU_TYPE;
3543       memset(&ulTtiReqPdu->pdu.pucch_pdu, 0, sizeof(fapi_ul_pucch_pdu_t));
3544       ulTtiReqPdu->pdu.pucch_pdu.rnti         = currUlSlot->ulInfo.schPucchInfo.rnti;
3545       /* TODO : Fill handle in raCb when scheduling pucch and access here */
3546       ulTtiReqPdu->pdu.pucch_pdu.handle       = 100;
3547       ulTtiReqPdu->pdu.pucch_pdu.bwpSize      = macCellCfg->initialUlBwp.bwp.numPrb;
3548       ulTtiReqPdu->pdu.pucch_pdu.bwpStart     = macCellCfg->initialUlBwp.bwp.firstPrb;
3549       ulTtiReqPdu->pdu.pucch_pdu.subCarrierSpacing = macCellCfg->initialUlBwp.bwp.scs;
3550       ulTtiReqPdu->pdu.pucch_pdu.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
3551       ulTtiReqPdu->pdu.pucch_pdu.formatType   = currUlSlot->ulInfo.schPucchInfo.pucchFormat; /* Supporting PUCCH Format 0 */
3552       ulTtiReqPdu->pdu.pucch_pdu.multiSlotTxIndicator = 0; /* No Multi Slot transmission */
3553       ulTtiReqPdu->pdu.pucch_pdu.pi2Bpsk              = 0; /* Disabled */
3554       ulTtiReqPdu->pdu.pucch_pdu.prbStart     = currUlSlot->ulInfo.schPucchInfo.fdAlloc.startPrb;
3555       ulTtiReqPdu->pdu.pucch_pdu.prbSize      = currUlSlot->ulInfo.schPucchInfo.fdAlloc.numPrb;
3556       ulTtiReqPdu->pdu.pucch_pdu.startSymbolIndex = currUlSlot->ulInfo.schPucchInfo.tdAlloc.startSymb;
3557       ulTtiReqPdu->pdu.pucch_pdu.nrOfSymbols  = currUlSlot->ulInfo.schPucchInfo.tdAlloc.numSymb;
3558       ulTtiReqPdu->pdu.pucch_pdu.freqHopFlag  = 0; /* Disabled */
3559       ulTtiReqPdu->pdu.pucch_pdu.secondHopPrb = 0;
3560       ulTtiReqPdu->pdu.pucch_pdu.groupHopFlag = 0;     
3561       ulTtiReqPdu->pdu.pucch_pdu.sequenceHopFlag = 0;
3562       ulTtiReqPdu->pdu.pucch_pdu.hoppingId    = 0;
3563       ulTtiReqPdu->pdu.pucch_pdu.initialCyclicShift = 0;
3564       ulTtiReqPdu->pdu.pucch_pdu.dataScramblingId = 0; /* Valid for Format 2, 3, 4 */
3565       ulTtiReqPdu->pdu.pucch_pdu.timeDomainOccIdx = 0; /* Valid for Format 1 */
3566       ulTtiReqPdu->pdu.pucch_pdu.preDftOccIdx     = 0; /* Valid for Format 4 */
3567       ulTtiReqPdu->pdu.pucch_pdu.preDftOccLen     = 0; /* Valid for Format 4 */
3568       ulTtiReqPdu->pdu.pucch_pdu.addDmrsFlag      = 0; /* Valid for Format 3, 4 */
3569       ulTtiReqPdu->pdu.pucch_pdu.dmrsScramblingId = 0; /* Valid for Format 2 */
3570       ulTtiReqPdu->pdu.pucch_pdu.dmrsCyclicShift  = 0; /* Valid for Format 4 */
3571       ulTtiReqPdu->pdu.pucch_pdu.srFlag           = currUlSlot->ulInfo.schPucchInfo.srFlag;
3572       ulTtiReqPdu->pdu.pucch_pdu.bitLenHarq       = currUlSlot->ulInfo.schPucchInfo.numHarqBits;
3573       ulTtiReqPdu->pdu.pucch_pdu.bitLenCsiPart1   = 0; /* Valid for Format 2, 3, 4 */
3574       ulTtiReqPdu->pdu.pucch_pdu.bitLenCsiPart2   = 0; /* Valid for Format 2, 3, 4 */
3575       ulTtiReqPdu->pdu.pucch_pdu.beamforming.numPrgs = 0; /* Not Supported */
3576       ulTtiReqPdu->pdu.pucch_pdu.beamforming.prgSize = 0;
3577       ulTtiReqPdu->pdu.pucch_pdu.beamforming.digBfInterface = 0;
3578       ulTtiReqPdu->pdu.pucch_pdu.beamforming.rx_bfi[0].beamIdx[0].beamidx = 0;
3579
3580       ulTtiReqPdu->pduSize = sizeof(fapi_ul_pucch_pdu_t);
3581    }
3582 }
3583
3584 #endif
3585
3586 /*******************************************************************
3587  *
3588  * @brief Sends UL TTI Request to PHY
3589  *
3590  * @details
3591  *
3592  *    Function : fillUlTtiReq
3593  *
3594  *    Functionality:
3595  *         -Sends FAPI Param req to PHY
3596  *
3597  * @params[in]  Pointer to CmLteTimingInfo
3598  * @return ROK     - success
3599  *         RFAILED - failure
3600  *
3601  ******************************************************************/
3602 uint16_t fillUlTtiReq(SlotIndInfo currTimingInfo)
3603 {
3604 #ifdef INTEL_FAPI
3605    uint16_t   cellIdx;
3606    uint8_t    pduIdx = -1;
3607    uint32_t   msgLen = 0;
3608    uint32_t   msgSize = 0;
3609
3610    fapi_ul_tti_req_t *ulTtiReq = NULLP;
3611    SlotIndInfo ulTtiReqTimingInfo;
3612
3613    MacUlSlot *currUlSlot = NULLP;
3614    MacCellCfg macCellCfg;
3615
3616    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
3617    {
3618       GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
3619       macCellCfg = macCb.macCell[cellIdx]->macCellCfg;
3620
3621       /* add PHY delta */
3622       ADD_DELTA_TO_TIME(currTimingInfo,ulTtiReqTimingInfo,PHY_DELTA);
3623
3624       currUlSlot = &macCb.macCell[cellIdx]->ulSlot[ulTtiReqTimingInfo.slot % MAX_SLOT_SUPPORTED];
3625       msgSize = sizeof(fapi_ul_tti_req_t);
3626       LWR_MAC_ALLOC(ulTtiReq, msgSize);
3627
3628       if(ulTtiReq != NULLP)
3629       {
3630          memset(ulTtiReq, 0, msgSize);
3631          ulTtiReq->sfn  = ulTtiReqTimingInfo.sfn;
3632          ulTtiReq->slot = ulTtiReqTimingInfo.slot;
3633          ulTtiReq->nPdus = getnPdus(ulTtiReq, currUlSlot);
3634          ulTtiReq->nGroup = 0;
3635          if(ulTtiReq->nPdus > 0)
3636          {
3637             /* Fill Prach Pdu */
3638             if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH)
3639             {
3640                pduIdx++;
3641                fillPrachPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot);
3642             }
3643
3644             /* Fill PUSCH PDU */
3645             if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)
3646             {
3647                pduIdx++;
3648                fillPuschPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot);
3649             }
3650             /* Fill PUCCH PDU */
3651             if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
3652             {
3653                pduIdx++;
3654                fillPucchPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot);
3655             }
3656          } 
3657          msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
3658          fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
3659
3660          DU_LOG("\nLWR_MAC: Sending UL TTI Request");
3661          LwrMacSendToPhy(ulTtiReq->header.msg_id, msgSize, (void *)ulTtiReq);
3662
3663          memset(currUlSlot, 0, sizeof(MacUlSlot));
3664          return ROK;
3665       }
3666       else
3667       {
3668          DU_LOG("\nLWR_MAC: Failed to allocate memory for UL TTI Request");
3669          memset(currUlSlot, 0, sizeof(MacUlSlot));
3670          return RFAILED;
3671       }
3672    }
3673    else
3674    {
3675       lwr_mac_procInvalidEvt(&currTimingInfo);
3676    }
3677 #endif
3678    return ROK;
3679 }
3680
3681 #ifdef INTEL_FAPI
3682 /*******************************************************************
3683  *
3684  * @brief fills bsr Ul DCI PDU required for UL DCI Request to PHY
3685  *
3686  * @details
3687  *
3688  *    Function : fillUlDciPdu
3689  *
3690  *    Functionality:
3691  *         -Fills the Ul DCI PDU, spec Ref:38.212, Table 7.3.1-1
3692  *
3693  * @params[in] Pointer to fapi_dl_dci_t
3694  *             Pointer to DciInfo
3695  * @return ROK
3696  *
3697  ******************************************************************/
3698 void fillUlDciPdu(fapi_dl_dci_t *ulDciPtr, DciInfo *schDciInfo)
3699 {
3700    if(ulDciPtr != NULLP)
3701    {
3702       uint8_t numBytes;
3703       uint8_t bytePos;
3704       uint8_t bitPos;
3705
3706       uint8_t coreset1Size = 0;
3707       uint16_t rbStart = 0;
3708       uint16_t rbLen = 0;
3709       uint8_t  dciFormatId = 0;
3710       uint32_t freqDomResAssign;
3711       uint8_t  timeDomResAssign;
3712       uint8_t  freqHopFlag;
3713       uint8_t  modNCodScheme;
3714       uint8_t  ndi;
3715       uint8_t  redundancyVer = 0;
3716       uint8_t  harqProcessNum = 0;
3717       uint8_t  puschTpc = 0;
3718       uint8_t  ul_SlInd = 0;
3719
3720       /* Size(in bits) of each field in DCI format 0_0 */
3721       uint8_t dciFormatIdSize      = 1;
3722       uint8_t freqDomResAssignSize = 0;
3723       uint8_t timeDomResAssignSize = 4;
3724       uint8_t freqHopFlagSize      = 1;
3725       uint8_t modNCodSchemeSize    = 5;
3726       uint8_t ndiSize              = 1;
3727       uint8_t redundancyVerSize    = 2;
3728       uint8_t harqProcessNumSize   = 4;
3729       uint8_t puschTpcSize         = 2;
3730       uint8_t ul_SlIndSize         = 1;
3731
3732       ulDciPtr->rnti                          = schDciInfo->dciInfo.rnti;
3733       ulDciPtr->scramblingId                  = schDciInfo->dciInfo.scramblingId;    
3734       ulDciPtr->scramblingRnti                = schDciInfo->dciInfo.scramblingRnti;
3735       ulDciPtr->cceIndex                      = schDciInfo->dciInfo.cceIndex;
3736       ulDciPtr->aggregationLevel              = schDciInfo->dciInfo.aggregLevel;
3737       ulDciPtr->pc_and_bform.numPrgs          = schDciInfo->dciInfo.beamPdcchInfo.numPrgs;
3738       ulDciPtr->pc_and_bform.prgSize          = schDciInfo->dciInfo.beamPdcchInfo.prgSize;
3739       ulDciPtr->pc_and_bform.digBfInterfaces  = schDciInfo->dciInfo.beamPdcchInfo.digBfInterfaces;
3740       ulDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = schDciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx;
3741       ulDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = schDciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0];
3742       ulDciPtr->beta_pdcch_1_0                = schDciInfo->dciInfo.txPdcchPower.powerValue;           
3743       ulDciPtr->powerControlOfssetSS          = schDciInfo->dciInfo.txPdcchPower.powerControlOffsetSS;
3744
3745       /* Calculating freq domain resource allocation field value and size
3746        * coreset1Size = Size of coreset 1
3747        * RBStart = Starting Virtual Rsource block
3748        * RBLen = length of contiguously allocted RBs
3749        * Spec 38.214 Sec 5.1.2.2.2
3750        */
3751       if(schDciInfo->formatType == FORMAT0_0)
3752       {
3753          coreset1Size = schDciInfo->coresetCfg.coreSetSize;
3754          rbLen = schDciInfo->format.format0_0.freqAlloc.numPrb;
3755          rbStart = schDciInfo->format.format0_0.freqAlloc.startPrb;
3756
3757          if((rbLen >=1) && (rbLen <= coreset1Size - rbStart))
3758          {
3759             if((rbLen - 1) <= floor(coreset1Size / 2))
3760                freqDomResAssign = (coreset1Size * (rbLen-1)) + rbStart;
3761             else
3762                freqDomResAssign = (coreset1Size * (coreset1Size - rbLen + 1)) \
3763                                   + (coreset1Size - 1 - rbStart);
3764
3765             freqDomResAssignSize = ceil(log2(coreset1Size * (coreset1Size + 1) / 2));
3766          }
3767          /* Fetching DCI field values */
3768          dciFormatId      = schDciInfo->formatType; /* DCI indentifier for UL DCI */
3769          timeDomResAssign = schDciInfo->format.format0_0.rowIndex;
3770          freqHopFlag      = schDciInfo->format.format0_0.freqHopFlag; 
3771          modNCodScheme    = schDciInfo->format.format0_0.mcs;
3772          ndi              = schDciInfo->format.format0_0.ndi; 
3773          redundancyVer    = schDciInfo->format.format0_0.rv;
3774          harqProcessNum   = schDciInfo->format.format0_0.harqProcId; 
3775          puschTpc         = schDciInfo->format.format0_0.tpcCmd;
3776          ul_SlInd         = schDciInfo->format.format0_0.sUlCfgd;
3777
3778          /* Reversing bits in each DCI field */
3779          dciFormatId      = reverseBits(dciFormatId, dciFormatIdSize);
3780          freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
3781          timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
3782          modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
3783          redundancyVer    = reverseBits(redundancyVer, redundancyVerSize);
3784          harqProcessNum   = reverseBits(harqProcessNum, harqProcessNumSize);
3785          puschTpc         = reverseBits(puschTpc, puschTpcSize);
3786          ul_SlInd         = reverseBits(ul_SlInd, ul_SlIndSize);
3787       }
3788       /* Calulating total number of bytes in buffer */
3789       ulDciPtr->payloadSizeBits = (dciFormatIdSize + freqDomResAssignSize\
3790       + timeDomResAssignSize + freqHopFlagSize + modNCodSchemeSize + ndi \
3791       + redundancyVerSize + harqProcessNumSize + puschTpcSize + ul_SlIndSize);
3792
3793       numBytes = ulDciPtr->payloadSizeBits / 8;
3794       if(ulDciPtr->payloadSizeBits % 8)
3795          numBytes += 1;
3796
3797       if(numBytes > FAPI_DCI_PAYLOAD_BYTE_LEN)
3798       {
3799          DU_LOG("\nLWR_MAC : Total bytes for DCI is more than expected");
3800          return;
3801       }
3802
3803       /* Initialize buffer */
3804       for(bytePos = 0; bytePos < numBytes; bytePos++)
3805          ulDciPtr->payload[bytePos] = 0;
3806
3807       bytePos = numBytes - 1;
3808       bitPos = 0;
3809
3810       /* Packing DCI format fields */
3811       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3812             dciFormatId, dciFormatIdSize);
3813       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3814             freqDomResAssign, freqDomResAssignSize);
3815       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3816             timeDomResAssign, timeDomResAssignSize);
3817       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3818             freqHopFlag, freqHopFlagSize);
3819       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3820             modNCodScheme, modNCodSchemeSize);
3821       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3822             ndi, ndiSize);
3823       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3824             redundancyVer, redundancyVerSize);
3825       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3826             harqProcessNum, harqProcessNumSize);
3827       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3828             puschTpc, puschTpcSize);
3829       fillDlDciPayload(ulDciPtr->payload, &bytePos, &bitPos,\
3830             ul_SlInd, ul_SlIndSize);
3831    }
3832 } /* fillUlDciPdu */
3833
3834 /*******************************************************************
3835  *
3836  * @brief fills PDCCH PDU required for UL DCI REQ to PHY
3837  *
3838  * @details
3839  *
3840  *    Function : fillUlDciPdcchPdu
3841  *
3842  *    Functionality:
3843  *         -Fills the Pdcch PDU info
3844  *
3845  * @params[in] Pointer to FAPI DL TTI Req
3846  *             Pointer to PdcchCfg
3847  * @return ROK
3848  *
3849  ******************************************************************/
3850 uint8_t fillUlDciPdcchPdu(fapi_dci_pdu_t *ulDciReqPdu, DlSchedInfo *dlInfo, uint8_t coreSetType)
3851 {
3852    if(ulDciReqPdu != NULLP)
3853    {
3854       memset(&ulDciReqPdu->pdcchPduConfig, 0, sizeof(fapi_dl_pdcch_pdu_t));
3855       fillUlDciPdu(ulDciReqPdu->pdcchPduConfig.dlDci, dlInfo->ulGrant);
3856       ulDciReqPdu->pduType                          = PDCCH_PDU_TYPE;
3857       ulDciReqPdu->pdcchPduConfig.bwpSize           = dlInfo->ulGrant->bwpCfg.freqAlloc.numPrb;
3858       ulDciReqPdu->pdcchPduConfig.bwpStart          = dlInfo->ulGrant->bwpCfg.freqAlloc.startPrb;
3859       ulDciReqPdu->pdcchPduConfig.subCarrierSpacing = dlInfo->ulGrant->bwpCfg.subcarrierSpacing; 
3860       ulDciReqPdu->pdcchPduConfig.cyclicPrefix      = dlInfo->ulGrant->bwpCfg.cyclicPrefix; 
3861       ulDciReqPdu->pdcchPduConfig.startSymbolIndex  = dlInfo->ulGrant->coresetCfg.startSymbolIndex;
3862       ulDciReqPdu->pdcchPduConfig.durationSymbols   = dlInfo->ulGrant->coresetCfg.durationSymbols;
3863       memcpy(ulDciReqPdu->pdcchPduConfig.freqDomainResource, dlInfo->ulGrant->coresetCfg.freqDomainResource, 6);
3864       ulDciReqPdu->pdcchPduConfig.cceRegMappingType = dlInfo->ulGrant->coresetCfg.cceRegMappingType;
3865       ulDciReqPdu->pdcchPduConfig.regBundleSize     = dlInfo->ulGrant->coresetCfg.regBundleSize;
3866       ulDciReqPdu->pdcchPduConfig.interleaverSize   = dlInfo->ulGrant->coresetCfg.interleaverSize;
3867       ulDciReqPdu->pdcchPduConfig.coreSetSize       = dlInfo->ulGrant->coresetCfg.coreSetType;
3868       ulDciReqPdu->pdcchPduConfig.shiftIndex        = dlInfo->ulGrant->coresetCfg.shiftIndex;
3869       ulDciReqPdu->pdcchPduConfig.precoderGranularity = dlInfo->ulGrant->coresetCfg.precoderGranularity;
3870       ulDciReqPdu->pdcchPduConfig.numDlDci          = 1;
3871       ulDciReqPdu->pdcchPduConfig.coreSetType       = coreSetType;
3872
3873       /* Calculating PDU length. Considering only one Ul dci pdu for now */
3874       ulDciReqPdu->pduSize = sizeof(fapi_dl_pdcch_pdu_t);
3875    }
3876    return ROK;
3877 }
3878 #endif
3879 /*******************************************************************
3880  *
3881  * @brief Sends UL DCI Request to PHY
3882  *
3883  * @details
3884  *
3885  *    Function : fillUlDciReq
3886  *
3887  *    Functionality:
3888  *         -Sends FAPI Ul Dci req to PHY
3889  *
3890  * @params[in]  Pointer to CmLteTimingInfo
3891  * @return ROK     - success
3892  *         RFAILED - failure
3893  *
3894  ******************************************************************/
3895 uint16_t fillUlDciReq(SlotIndInfo currTimingInfo)
3896 {
3897 #ifdef INTEL_FAPI
3898    uint8_t cellIdx;
3899    uint8_t  numPduEncoded = 0;
3900    uint32_t msgLen  = 0;
3901    uint32_t msgSize = 0;
3902
3903    fapi_ul_dci_req_t *ulDciReq = NULLP;
3904    SlotIndInfo ulDciReqTimingInfo;
3905
3906    MacDlSlot *currDlSlot = NULLP;
3907
3908    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
3909    {
3910       GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
3911       memcpy(&ulDciReqTimingInfo, &currTimingInfo, sizeof(SlotIndInfo));
3912       currDlSlot = &macCb.macCell[cellIdx]->dlSlot[ulDciReqTimingInfo.slot % MAX_SLOT_SUPPORTED];
3913
3914       if(currDlSlot->dlInfo.ulGrant != NULLP)
3915       {
3916          msgSize = sizeof(fapi_ul_dci_req_t);
3917          LWR_MAC_ALLOC(ulDciReq, msgSize);
3918          if(ulDciReq != NULLP)
3919          {
3920             memset(ulDciReq, 0, msgSize);
3921             ulDciReq->sfn  = ulDciReqTimingInfo.sfn;
3922             ulDciReq->slot = ulDciReqTimingInfo.slot;
3923             ulDciReq->numPdus = 1;  // No. of PDCCH PDUs
3924             if(ulDciReq->numPdus > 0)
3925             {
3926                /* Fill PDCCH configuration Pdu */
3927                fillUlDciPdcchPdu(&ulDciReq->pdus[numPduEncoded], &currDlSlot->dlInfo, CORESET_TYPE1);
3928                numPduEncoded++;
3929                /* free UL GRANT at SCH */
3930                MAC_FREE(currDlSlot->dlInfo.ulGrant, sizeof(DciInfo));
3931                currDlSlot->dlInfo.ulGrant = NULLP;
3932                /* send UL DCI to PHY */
3933                msgLen = sizeof(fapi_ul_dci_req_t) - sizeof(fapi_msg_t);
3934                fillMsgHeader(&ulDciReq->header, FAPI_UL_DCI_REQUEST, msgLen);
3935                LwrMacSendToPhy(ulDciReq->header.msg_id, sizeof(fapi_ul_dci_req_t), (void *)ulDciReq);
3936             }
3937
3938          }
3939          else
3940          {
3941             DU_LOG("\nLWR_MAC: Failed to allocate memory for UL DCI Request");
3942             memset(currDlSlot, 0, sizeof(MacDlSlot));
3943             return RFAILED;
3944          }
3945       }
3946    }
3947    else
3948    {
3949        lwr_mac_procInvalidEvt(&currTimingInfo);
3950    }
3951 #endif
3952    return ROK;
3953 }
3954
3955 lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
3956 {
3957    {
3958       /* PHY_STATE_IDLE */
3959       lwr_mac_procParamReqEvt,
3960       lwr_mac_procParamRspEvt,
3961       lwr_mac_procConfigReqEvt,
3962       lwr_mac_procConfigRspEvt,
3963       lwr_mac_procInvalidEvt,
3964       lwr_mac_procInvalidEvt,
3965    },
3966    {
3967       /* PHY_STATE_CONFIGURED */
3968       lwr_mac_procParamReqEvt,
3969       lwr_mac_procParamRspEvt,
3970       lwr_mac_procConfigReqEvt,
3971       lwr_mac_procConfigRspEvt,
3972       lwr_mac_procStartReqEvt,
3973       lwr_mac_procInvalidEvt,
3974    },
3975    {
3976       /* PHY_STATE_RUNNING */
3977       lwr_mac_procInvalidEvt,
3978       lwr_mac_procInvalidEvt,
3979       lwr_mac_procConfigReqEvt,
3980       lwr_mac_procConfigRspEvt,
3981       lwr_mac_procInvalidEvt,
3982       lwr_mac_procStopReqEvt,
3983    }
3984 };
3985
3986 /*******************************************************************
3987  *
3988  * @brief Sends message to LWR_MAC Fsm Event Handler
3989  *
3990  * @details
3991  *
3992  *    Function : sendToLowerMac
3993  *
3994  *    Functionality:
3995  *         -Sends message to LowerMac
3996  *
3997  * @params[in] Message Type
3998  *             Message Length
3999  *             Messaga Pointer
4000  *
4001  * @return void
4002  *
4003  ******************************************************************/
4004 void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg)
4005 {
4006    lwrMacCb.event = msgType;
4007    fapiEvtHdlr[lwrMacCb.phyState][lwrMacCb.event](msg);
4008 }
4009 /**********************************************************************
4010   End of file
4011  **********************************************************************/