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