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