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