Rach Indication
[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
22 /* header include files -- defines (.h) */
23 #include "envopt.h"        /* environment options */
24 #include "envdep.h"        /* environment dependent */
25 #include "envind.h"        /* environment independent */
26 #include "gen.h"           /* general layer */
27 #include "ssi.h"           /* system service interface */
28 #include "cm_hash.h"       /* common hash list */
29 #include "cm_mblk.h"       /* common memory link list library */
30 #include "cm_llist.h"      /* common linked list library */
31 #include "cm_err.h"        /* common error */
32 #include "cm_lte.h"        /* common LTE */
33 #include "lrg.h"           /* Layer manager interface includes*/
34 #include "crg.h"           /* CRG interface includes*/
35 #include "rgu.h"           /* RGU interface includes*/
36 #include "tfu.h"           /* TFU interface includes */
37 #include "rg_sch_inf.h"    /* SCH interface includes */
38 #include "rg_prg.h"       /* PRG (MAC-MAC) interface includes*/
39 #include "rg_env.h"       /* MAC environmental includes*/
40 #include "rg.h"           /* MAC includes*/
41 #include "rg_err.h"       /* MAC error includes*/
42 #include "du_log.h"
43 #include "lwr_mac_fsm.h"
44
45 /* header/extern include files (.x) */
46 #include "gen.x"           /* general layer typedefs */
47 #include "ssi.x"           /* system services typedefs */
48 #include "cm5.x"           /* common timers */
49 #include "cm_hash.x"       /* common hash list */
50 #include "cm_lib.x"        /* common library */
51 #include "cm_llist.x"      /* common linked list */
52 #include "cm_mblk.x"       /* memory management */
53 #include "cm_tkns.x"       /* common tokens */
54 #include "cm_lte.x"       /* common tokens */
55 #include "rgu.x"           /* RGU types */
56 #include "tfu.x"           /* RGU types */
57 #include "lrg.x"           /* layer management typedefs for MAC */
58 #include "crg.x"           /* CRG interface includes */
59 #include "rg_sch_inf.x"    /* SCH interface typedefs */
60 #include "rg_prg.x"        /* PRG (MAC-MAC) Interface typedefs */
61 #include "du_app_mac_inf.h"
62 #include "mac.h"
63 #include "rg.x"            /* typedefs for MAC */
64 #include "lwr_mac_phy.h"
65 #include "math.h"
66
67 #define MIB_SFN_BITMASK 0xFC
68 #define PDCCH_PDU_TYPE 0
69 #define PDSCH_PDU_TYPE 1
70 #define SSB_PDU_TYPE 3
71 #define PRACH_PDU_TYPE 0
72 #define PDU_PRESENT 1
73 #define SETLENGTH(x, size) x += size
74
75 extern void fapiMacConfigRsp();
76 extern uint8_t UnrestrictedSetNcsTable[MAX_ZERO_CORR_CFG_IDX];
77
78 /* Global variables */
79 SlotIndInfo slotIndInfo;
80 uint8_t slotIndIdx;
81
82 void lwrMacInit()
83 {
84 #ifdef INTEL_WLS
85    uint8_t  idx;
86
87    /* Initializing WLS free mem list */
88    slotIndIdx = 1;
89    for(idx = 0; idx < WLS_MEM_FREE_PRD; idx++)
90    {
91       cmLListInit(&wlsBlockToFreeList[idx]);
92    }
93 #endif
94 }
95
96  /*******************************************************************
97   *
98   * @brief Handles Invalid Request Event
99   *
100   * @details
101   *
102   *    Function : lwr_mac_handleInvalidEvt
103   *
104   *    Functionality:
105   *         - Displays the PHY state when the invalid event occurs
106   *
107   * @params[in]
108   * @return ROK     - success
109   *         RFAILED - failure
110   *
111   * ****************************************************************/
112 S16 lwr_mac_handleInvalidEvt(void *msg)
113 {
114   printf("\nLOWER MAC: Error Indication Event[%d] received in state [%d]", clGlobalCp.event, clGlobalCp.phyState);
115   RETVALUE(ROK);
116 }
117
118 #ifdef FAPI
119 /*******************************************************************
120   *
121   * @brief Fills FAPI message header
122   *
123   * @details
124   *
125   *    Function : fillMsgHeader
126   *
127   *    Functionality:
128   *         -Fills FAPI message header
129   *
130   * @params[in] Pointer to header
131   *             Number of messages
132   *             Messae Type
133   *             Length of message
134   * @return void
135   *
136   * ****************************************************************/
137 PUBLIC void fillMsgHeader(fapi_msg_t *hdr, uint16_t msgType, uint16_t msgLen)
138 {
139    hdr->message_type_id = msgType;
140    hdr->length = msgLen;
141 }
142
143 /*******************************************************************
144   *
145   * @brief Fills FAPI Config Request message header
146   *
147   * @details
148   *
149   *    Function : fillTlvs
150   *
151   *    Functionality:
152   *         -Fills FAPI Config Request message header
153   *
154   * @params[in] Pointer to TLV
155   *             Tag
156   *             Length
157   *             Value
158   *             MsgLen
159   * @return void
160   *
161   * ****************************************************************/
162 PUBLIC void fillTlvs(fapi_uint16_tlv_t *tlv, uint16_t tag, uint16_t length,
163 uint16_t value, uint32_t *msgLen)
164 {
165    tlv->tl.tag    = tag;
166    tlv->tl.length = length;
167    tlv->value     = value;
168    *msgLen        = *msgLen + sizeof(tag) + sizeof(length) + length;
169 }
170  /*******************************************************************
171   *
172   * @brief fills the cyclic prefix by comparing the bitmask
173   *
174   * @details
175   *
176   *    Function : fillCyclicPrefix
177   *
178   *    Functionality:
179   *         -checks the value with the bitmask and
180   *          fills the cellPtr's cyclic prefix.
181   *
182   * @params[in] Pointer to ClCellParam
183   *             Value to be compared
184   * @return void
185   *
186   ********************************************************************/
187 PUBLIC void fillCyclicPrefix(uint8_t value, ClCellParam **cellPtr)
188 {
189    if((value & FAPI_NORMAL_CYCLIC_PREFIX_MASK) == FAPI_NORMAL_CYCLIC_PREFIX_MASK)
190    {
191       (*cellPtr)->cyclicPrefix   = NORMAL_CYCLIC_PREFIX_MASK;
192    }
193    else if((value & FAPI_EXTENDED_CYCLIC_PREFIX_MASK) == FAPI_EXTENDED_CYCLIC_PREFIX_MASK)
194    {
195       (*cellPtr)->cyclicPrefix   = EXTENDED_CYCLIC_PREFIX_MASK;
196    }
197    else
198    {
199       (*cellPtr)->cyclicPrefix = INVALID_VALUE;
200    }
201 }
202
203  /*******************************************************************
204   *
205   * @brief fills the subcarrier spacing of Downlink by comparing the bitmask
206   *
207   * @details
208   *
209   *    Function : fillSubcarrierSpaceDl
210   *
211   *    Functionality:
212   *         -checks the value with the bitmask and
213   *          fills the cellPtr's subcarrier spacing in DL
214   *
215   * @params[in] Pointer to ClCellParam
216   *             Value to be compared
217   * @return void
218   *
219   * ****************************************************************/
220
221 PUBLIC void fillSubcarrierSpaceDl(uint8_t value, ClCellParam **cellPtr)
222 {
223    if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
224    {
225       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_15_KHZ;
226    }
227    else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
228    {
229       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_30_KHZ;
230    }
231    else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
232    {
233       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_60_KHZ;
234    }
235    else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
236    {
237       (*cellPtr)->supportedSubcarrierSpacingDl = SPACING_120_KHZ;
238    }
239    else
240    {
241       (*cellPtr)->supportedSubcarrierSpacingDl = INVALID_VALUE;
242    }
243 }
244
245  /*******************************************************************
246   *
247   * @brief fills the downlink bandwidth by comparing the bitmask
248   *
249   * @details
250   *
251   *    Function : fillBandwidthDl
252   *
253   *    Functionality:
254   *         -checks the value with the bitmask and
255   *         -fills the cellPtr's DL Bandwidth
256   *
257   * @params[in] Pointer to ClCellParam
258   *             Value to be compared
259   * @return void
260   *
261   * ****************************************************************/
262
263 PUBLIC void fillBandwidthDl(uint16_t value, ClCellParam **cellPtr)
264 {
265    if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
266    {
267       (*cellPtr)->supportedBandwidthDl = BW_5MHZ;
268    }
269    else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
270    {
271       (*cellPtr)->supportedBandwidthDl = BW_10MHZ;
272    }
273    else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
274    {
275       (*cellPtr)->supportedBandwidthDl = BW_15MHZ;
276    }
277    else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
278    {
279       (*cellPtr)->supportedBandwidthDl = BW_20MHZ;
280    }
281    else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
282    {
283       (*cellPtr)->supportedBandwidthDl = BW_40MHZ;
284    }
285    else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
286    {
287       (*cellPtr)->supportedBandwidthDl = BW_50MHZ;
288    }
289    else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
290    {
291       (*cellPtr)->supportedBandwidthDl = BW_60MHZ;
292    }
293    else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
294    {
295       (*cellPtr)->supportedBandwidthDl = BW_70MHZ;
296    }
297    else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
298    {
299       (*cellPtr)->supportedBandwidthDl = BW_80MHZ;
300    }
301    else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
302    {
303       (*cellPtr)->supportedBandwidthDl = BW_90MHZ;
304    }
305    else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
306    {
307       (*cellPtr)->supportedBandwidthDl = BW_100MHZ;
308    }
309    else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
310    {
311       (*cellPtr)->supportedBandwidthDl = BW_200MHZ;
312    }
313    else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
314    {
315       (*cellPtr)->supportedBandwidthDl = BW_400MHZ;
316    }
317    else
318    {
319       (*cellPtr)->supportedBandwidthDl = INVALID_VALUE;
320    }
321 }
322
323  /*******************************************************************
324   *
325   * @brief fills the subcarrier spacing of Uplink by comparing the bitmask
326   *
327   * @details
328   *
329   *    Function : fillSubcarrierSpaceUl
330   *
331   *    Functionality:
332   *         -checks the value with the bitmask and
333   *         -fills cellPtr's subcarrier spacing in UL
334   *
335   * @params[in] Pointer to ClCellParam
336   *             Value to be compared
337   * @return void
338   *
339   * ****************************************************************/
340
341 PUBLIC void fillSubcarrierSpaceUl(uint8_t value, ClCellParam **cellPtr)
342 {
343    if((value & FAPI_15KHZ_MASK) == FAPI_15KHZ_MASK)
344    {
345       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_15_KHZ;
346    }
347    else if((value & FAPI_30KHZ_MASK) == FAPI_30KHZ_MASK)
348    {
349       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_30_KHZ;
350    }
351    else if((value & FAPI_60KHZ_MASK) == FAPI_60KHZ_MASK)
352    {
353       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_60_KHZ;
354    }
355    else if((value & FAPI_120KHZ_MASK) == FAPI_120KHZ_MASK)
356    {
357       (*cellPtr)->supportedSubcarrierSpacingsUl = SPACING_120_KHZ;
358    }
359    else
360    {
361       (*cellPtr)->supportedSubcarrierSpacingsUl = INVALID_VALUE;
362    }
363 }
364
365  /*******************************************************************
366   *
367   * @brief fills the uplink bandwidth by comparing the bitmask
368   *
369   * @details
370   *
371   *    Function : fillBandwidthUl
372   *
373   *    Functionality:
374   *         -checks the value with the bitmask and
375   *          fills the cellPtr's UL Bandwidth
376   *
377   *
378   *
379   * @params[in] Pointer to ClCellParam
380   *             Value to be compared
381   * @return void
382   *
383   *
384   * ****************************************************************/
385
386 PUBLIC void fillBandwidthUl(uint16_t value, ClCellParam **cellPtr)
387 {
388    if((value & FAPI_5MHZ_BW_MASK) == FAPI_5MHZ_BW_MASK)
389    {
390       (*cellPtr)->supportedBandwidthUl = BW_5MHZ;
391    }
392    else if((value & FAPI_10MHZ_BW_MASK) == FAPI_10MHZ_BW_MASK)
393    {
394       (*cellPtr)->supportedBandwidthUl = BW_10MHZ;
395    }
396    else if((value & FAPI_15MHZ_BW_MASK) == FAPI_15MHZ_BW_MASK)
397    {
398       (*cellPtr)->supportedBandwidthUl = BW_15MHZ;
399    }
400    else if((value & FAPI_20MHZ_BW_MASK) == FAPI_20MHZ_BW_MASK)
401    {
402       (*cellPtr)->supportedBandwidthUl = BW_20MHZ;
403    }
404    else if((value & FAPI_40MHZ_BW_MASK) == FAPI_40MHZ_BW_MASK)
405    {
406       (*cellPtr)->supportedBandwidthUl = BW_40MHZ;
407    }
408    else if((value & FAPI_50MHZ_BW_MASK) == FAPI_50MHZ_BW_MASK)
409    {
410       (*cellPtr)->supportedBandwidthUl = BW_50MHZ;
411    }
412    else if((value & FAPI_60MHZ_BW_MASK) == FAPI_60MHZ_BW_MASK)
413    {
414       (*cellPtr)->supportedBandwidthUl = BW_60MHZ;
415    }
416    else if((value & FAPI_70MHZ_BW_MASK) == FAPI_70MHZ_BW_MASK)
417    {
418       (*cellPtr)->supportedBandwidthUl = BW_70MHZ;
419    }
420    else if((value & FAPI_80MHZ_BW_MASK) == FAPI_80MHZ_BW_MASK)
421    {
422       (*cellPtr)->supportedBandwidthUl = BW_80MHZ;
423    }
424    else if((value & FAPI_90MHZ_BW_MASK) == FAPI_90MHZ_BW_MASK)
425    {
426       (*cellPtr)->supportedBandwidthUl = BW_90MHZ;
427    }
428    else if((value & FAPI_100MHZ_BW_MASK) == FAPI_100MHZ_BW_MASK)
429    {
430       (*cellPtr)->supportedBandwidthUl = BW_100MHZ;
431    }
432    else if((value & FAPI_200MHZ_BW_MASK) == FAPI_200MHZ_BW_MASK)
433    {
434       (*cellPtr)->supportedBandwidthUl = BW_200MHZ;
435    }
436    else if((value & FAPI_400MHZ_BW_MASK) == FAPI_400MHZ_BW_MASK)
437    {
438       (*cellPtr)->supportedBandwidthUl = BW_400MHZ;
439    }
440    else
441    {
442       (*cellPtr)->supportedBandwidthUl = INVALID_VALUE;
443    }
444 }
445  /*******************************************************************
446   *
447   * @brief fills the CCE maping by comparing the bitmask
448   *
449   * @details
450   *
451   *    Function : fillCCEmaping
452   *
453   *    Functionality:
454   *         -checks the value with the bitmask and
455   *          fills the cellPtr's CCE Mapping Type
456   *
457   *
458   * @params[in] Pointer to ClCellParam
459   *             Value to be compared
460   * @return void
461   *
462   * ****************************************************************/
463
464 PUBLIC void fillCCEmaping(uint8_t value,  ClCellParam **cellPtr)
465 {
466    if ((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_INTERLEAVED_MASK)
467    {
468       (*cellPtr)->cceMappingType = CCE_MAPPING_INTERLEAVED_MASK;
469    }
470    else if((value & FAPI_CCE_MAPPING_INTERLEAVED_MASK) == FAPI_CCE_MAPPING_NONINTERLVD_MASK)
471    {
472       (*cellPtr)->cceMappingType = CCE_MAPPING_NONINTERLVD_MASK;
473    }
474    else
475    {
476       (*cellPtr)->cceMappingType = INVALID_VALUE;
477    }
478 }
479
480  /*******************************************************************
481   *
482   * @brief fills the PUCCH format by comparing the bitmask
483   *
484   * @details
485   *
486   *    Function : fillPucchFormat
487   *
488   *    Functionality:
489   *         -checks the value with the bitmask and
490   *          fills the cellPtr's pucch format
491   *
492   *
493   * @params[in] Pointer to ClCellParam
494   *             Value to be compared
495   * @return void
496   *
497   * ****************************************************************/
498
499 PUBLIC void fillPucchFormat(uint8_t value, ClCellParam **cellPtr)
500 {
501    if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
502    {
503       (*cellPtr)->pucchFormats    = FORMAT_0;
504    }
505    else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
506    {
507       (*cellPtr)->pucchFormats    = FORMAT_1;
508    }
509    else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
510    {
511       (*cellPtr)->pucchFormats    = FORMAT_2;
512    }
513    else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
514    {
515       (*cellPtr)->pucchFormats    = FORMAT_3;
516    }
517    else if((value & FAPI_FORMAT_4_MASK) == FAPI_FORMAT_4_MASK)
518    {
519       (*cellPtr)->pucchFormats    = FORMAT_4;
520    }
521    else
522    {
523       (*cellPtr)->pucchFormats    = INVALID_VALUE;
524    }
525 }
526
527  /*******************************************************************
528   *
529   * @brief fills the PDSCH Mapping Type by comparing the bitmask
530   *
531   * @details
532   *
533   *    Function : fillPdschMappingType
534   *
535   *    Functionality:
536   *         -checks the value with the bitmask and
537   *          fills the cellPtr's PDSCH MappingType
538   *
539   * @params[in] Pointer to ClCellParam
540   *             Value to be compared
541   * @return void
542   *
543   * ****************************************************************/
544
545 PUBLIC void fillPdschMappingType(uint8_t value, ClCellParam **cellPtr)
546 {
547    if((value & FAPI_PDSCH_MAPPING_TYPE_A_MASK) == FAPI_PDSCH_MAPPING_TYPE_A_MASK)
548    {
549       (*cellPtr)->pdschMappingType = MAPPING_TYPE_A;
550    }
551    else if((value & FAPI_PDSCH_MAPPING_TYPE_B_MASK) == FAPI_PDSCH_MAPPING_TYPE_B_MASK)
552    {
553       (*cellPtr)->pdschMappingType = MAPPING_TYPE_B;
554    }
555    else
556    {
557       (*cellPtr)->pdschMappingType = INVALID_VALUE;
558    }
559 }
560
561 /*******************************************************************
562   *
563   * @brief fills the PDSCH Allocation Type by comparing the bitmask
564   *
565   * @details
566   *
567   *    Function : fillPdschAllocationType
568   *
569   *    Functionality:
570   *         -checks the value with the bitmask and
571   *          fills the cellPtr's PDSCH AllocationType
572   *
573   * @params[in] Pointer to ClCellParam
574   *             Value to be compared
575   * @return void
576   *
577   * ****************************************************************/
578
579 PUBLIC void fillPdschAllocationType(uint8_t value, ClCellParam **cellPtr)
580 {
581    if((value & FAPI_PDSCH_ALLOC_TYPE_0_MASK) == FAPI_PDSCH_ALLOC_TYPE_0_MASK)
582    {
583       (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_0;
584    }
585    else if((value & FAPI_PDSCH_ALLOC_TYPE_1_MASK) == FAPI_PDSCH_ALLOC_TYPE_1_MASK)
586    {
587       (*cellPtr)->pdschAllocationTypes = ALLOCATION_TYPE_1;
588    }
589    else
590    {
591       (*cellPtr)->pdschAllocationTypes = INVALID_VALUE;
592    }
593 }
594
595 /*******************************************************************
596   *
597   * @brief fills the PDSCH PRB Mapping Type by comparing the bitmask
598   *
599   * @details
600   *
601   *    Function : fillPrbMappingType
602   *
603   *    Functionality:
604   *         -checks the value with the bitmask and
605   *          fills the cellPtr's PRB Mapping Type
606   *
607   * @params[in] Pointer to ClCellParam
608   *             Value to be compared
609   * @return void
610   *
611   ******************************************************************/
612 PUBLIC void fillPrbMappingType(uint8_t value, ClCellParam **cellPtr)
613 {
614    if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
615    {
616       (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
617    }
618    else if((value & FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PDSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
619    {
620       (*cellPtr)->pdschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
621    }
622    else
623    {
624       (*cellPtr)->pdschVrbToPrbMapping = INVALID_VALUE;
625    }
626 }
627
628 /*******************************************************************
629   *
630   * @brief fills the PDSCH DmrsConfig Type by comparing the bitmask
631   *
632   * @details
633   *
634   *    Function : fillPdschDmrsConfigType
635   *
636   *    Functionality:
637   *         -checks the value with the bitmask and
638   *          fills the cellPtr's DmrsConfig Type
639   *
640   * @params[in] Pointer to ClCellParam
641   *             Value to be compared
642   * @return void
643   *
644   ******************************************************************/
645
646 PUBLIC void fillPdschDmrsConfigType(uint8_t value, ClCellParam **cellPtr)
647 {
648   if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_1_MASK)
649   {
650      (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
651   }
652   else if((value & FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PDSCH_DMRS_CONFIG_TYPE_2_MASK)
653   {
654      (*cellPtr)->pdschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
655   }
656   else
657   {
658      (*cellPtr)->pdschDmrsConfigTypes = INVALID_VALUE;
659   }
660 }
661
662 /*******************************************************************
663   *
664   * @brief fills the PDSCH DmrsLength by comparing the bitmask
665   *
666   * @details
667   *
668   *    Function : fillPdschDmrsLength
669   *
670   *    Functionality:
671   *         -checks the value with the bitmask and
672   *          fills the cellPtr's PdschDmrsLength
673   *
674   * @params[in] Pointer to ClCellParam
675   *             Value to be compared
676   * @return void
677   *
678   ******************************************************************/
679 PUBLIC void fillPdschDmrsLength(uint8_t value, ClCellParam **cellPtr)
680 {
681    if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_1)
682    {
683       (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_1;
684    }
685    else if(value == FAPI_PDSCH_DMRS_MAX_LENGTH_2)
686    {
687       (*cellPtr)->pdschDmrsMaxLength = DMRS_MAX_LENGTH_2;
688    }
689    else
690    {
691       (*cellPtr)->pdschDmrsMaxLength = INVALID_VALUE;
692    }
693 }
694
695 /*******************************************************************
696   *
697   * @brief fills the PDSCH Dmrs Additional Pos by comparing the bitmask
698   *
699   * @details
700   *
701   *    Function : fillPdschDmrsAddPos
702   *
703   *    Functionality:
704   *         -checks the value with the bitmask and
705   *          fills the cellPtr's Pdsch DmrsAddPos
706   *
707   * @params[in] Pointer to ClCellParam
708   *             Value to be compared
709   * @return void
710   *
711   ******************************************************************/
712
713 PUBLIC void fillPdschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
714 {
715    if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
716    {
717       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
718    }
719    else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
720    {
721       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
722    }
723    else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
724    {
725       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
726    }
727    else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
728    {
729       (*cellPtr)->pdschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
730    }
731    else
732    {
733       (*cellPtr)->pdschDmrsAdditionalPos = INVALID_VALUE;
734    }
735 }
736
737 /*******************************************************************
738   *
739   * @brief fills the Modulation Order in DL by comparing the bitmask
740   *
741   * @details
742   *
743   *    Function : fillModulationOrderDl
744   *
745   *    Functionality:
746   *         -checks the value with the bitmask and
747   *          fills the cellPtr's ModulationOrder in DL.
748   *
749   * @params[in] Pointer to ClCellParam
750   *             Value to be compared
751   * @return void
752   *
753   ******************************************************************/
754 PUBLIC void fillModulationOrderDl(uint8_t value, ClCellParam **cellPtr)
755 {
756    if(value == 0 )
757    {
758       (*cellPtr)->supportedMaxModulationOrderDl = MOD_QPSK;
759    }
760    else if(value == 1)
761    {
762       (*cellPtr)->supportedMaxModulationOrderDl = MOD_16QAM;
763    }
764    else if(value == 2)
765    {
766       (*cellPtr)->supportedMaxModulationOrderDl = MOD_64QAM;
767    }
768    else if(value == 3)
769    {
770       (*cellPtr)->supportedMaxModulationOrderDl = MOD_256QAM;
771    }
772    else
773    {
774       (*cellPtr)->supportedMaxModulationOrderDl = INVALID_VALUE;
775    }
776 }
777
778 /*******************************************************************
779   *
780   * @brief fills the PUSCH DmrsConfig Type by comparing the bitmask
781   *
782   * @details
783   *
784   *    Function : fillPuschDmrsConfigType
785   *
786   *    Functionality:
787   *         -checks the value with the bitmask and
788   *          fills the cellPtr's PUSCH DmrsConfigType
789   *
790   * @params[in] Pointer to ClCellParam
791   *             Value to be compared
792   * @return void
793   *
794   ******************************************************************/
795
796 PUBLIC void fillPuschDmrsConfig(uint8_t value, ClCellParam **cellPtr)
797 {
798    if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_1_MASK)
799    {
800       (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_1;
801    }
802    else if((value & FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK) == FAPI_PUSCH_DMRS_CONFIG_TYPE_2_MASK)
803    {
804       (*cellPtr)->puschDmrsConfigTypes = DMRS_CONFIG_TYPE_2;
805    }
806    else
807    {
808       (*cellPtr)->puschDmrsConfigTypes = INVALID_VALUE;
809    }
810 }
811
812 /*******************************************************************
813   *
814   * @brief fills the PUSCH DmrsLength by comparing the bitmask
815   *
816   * @details
817   *
818   *    Function : fillPuschDmrsLength
819   *
820   *    Functionality:
821   *         -checks the value with the bitmask and
822   *          fills the cellPtr's PUSCH DmrsLength
823   *
824   * @params[in] Pointer to ClCellParam
825   *             Value to be compared
826   * @return void
827   *
828   ******************************************************************/
829
830 PUBLIC void fillPuschDmrsLength(uint8_t value, ClCellParam **cellPtr)
831 {
832    if(value  == FAPI_PUSCH_DMRS_MAX_LENGTH_1)
833    {
834       (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_1;
835    }
836    else if(value  == FAPI_PUSCH_DMRS_MAX_LENGTH_2)
837    {
838       (*cellPtr)->puschDmrsMaxLength = DMRS_MAX_LENGTH_2;
839    }
840    else
841    {
842       (*cellPtr)->puschDmrsMaxLength = INVALID_VALUE;
843    }
844 }
845
846 /*******************************************************************
847   *
848   * @brief fills the PUSCH Dmrs Additional position by comparing the bitmask
849   *
850   * @details
851   *
852   *    Function : fillPuschDmrsAddPos
853   *
854   *    Functionality:
855   *         -checks the value with the bitmask and
856   *          fills the cellPtr's PUSCH DmrsAddPos
857   *
858   * @params[in] Pointer to ClCellParam
859   *             Value to be compared
860   * @return void
861   *
862   ******************************************************************/
863
864 PUBLIC void fillPuschDmrsAddPos(uint8_t value, ClCellParam **cellPtr)
865 {
866    if((value & FAPI_DMRS_ADDITIONAL_POS_0_MASK) == FAPI_DMRS_ADDITIONAL_POS_0_MASK)
867    {
868       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_0;
869    }
870    else if((value & FAPI_DMRS_ADDITIONAL_POS_1_MASK) == FAPI_DMRS_ADDITIONAL_POS_1_MASK)
871    {
872       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_1;
873    }
874    else if((value & FAPI_DMRS_ADDITIONAL_POS_2_MASK) == FAPI_DMRS_ADDITIONAL_POS_2_MASK)
875    {
876       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_2;
877    }
878    else if((value & FAPI_DMRS_ADDITIONAL_POS_3_MASK) == FAPI_DMRS_ADDITIONAL_POS_3_MASK)
879    {
880       (*cellPtr)->puschDmrsAdditionalPos = DMRS_ADDITIONAL_POS_3;
881    }
882    else
883    {
884       (*cellPtr)->puschDmrsAdditionalPos = INVALID_VALUE;
885    }
886 }
887
888 /*******************************************************************
889   *
890   * @brief fills the PUSCH Mapping Type by comparing the bitmask
891   *
892   * @details
893   *
894   *    Function : fillPuschMappingType
895   *
896   *    Functionality:
897   *         -checks the value with the bitmask and
898   *          fills the cellPtr's PUSCH MappingType
899   *
900   * @params[in] Pointer to ClCellParam
901   *             Value to be compared
902   * @return void
903   *
904   ******************************************************************/
905
906 PUBLIC void fillPuschMappingType(uint8_t value, ClCellParam **cellPtr)
907 {
908    if((value & FAPI_PUSCH_MAPPING_TYPE_A_MASK) == FAPI_PUSCH_MAPPING_TYPE_A_MASK)
909    {
910       (*cellPtr)->puschMappingType = MAPPING_TYPE_A;
911    }
912    else if((value & FAPI_PUSCH_MAPPING_TYPE_B_MASK) == FAPI_PUSCH_MAPPING_TYPE_B_MASK)
913    {
914       (*cellPtr)->puschMappingType = MAPPING_TYPE_B;
915    }
916    else
917    {
918       (*cellPtr)->puschMappingType = INVALID_VALUE;
919    }
920 }
921
922 /*******************************************************************
923   *
924   * @brief fills the PUSCH Allocation Type by comparing the bitmask
925   *
926   * @details
927   *
928   *    Function : fillPuschAllocationType
929   *
930   *    Functionality:
931   *         -checks the value with the bitmask and
932   *          fills the cellPtr's PUSCH AllocationType
933   *
934   * @params[in] Pointer to ClCellParam
935   *             Value to be compared
936   * @return void
937   *
938   ******************************************************************/
939
940 PUBLIC void fillPuschAllocationType(uint8_t value, ClCellParam **cellPtr)
941 {
942    if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
943    {
944       (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_0;
945    }
946    else if((value & FAPI_PUSCH_ALLOC_TYPE_0_MASK) == FAPI_PUSCH_ALLOC_TYPE_0_MASK)
947    {
948       (*cellPtr)->puschAllocationTypes = ALLOCATION_TYPE_1;
949    }
950    else
951    {
952       (*cellPtr)->puschAllocationTypes = INVALID_VALUE;
953    }
954 }
955
956 /*******************************************************************
957   *
958   * @brief fills the PUSCH PRB Mapping Type by comparing the bitmask
959   *
960   * @details
961   *
962   *    Function : fillPuschPrbMappingType
963   *
964   *    Functionality:
965   *         -checks the value with the bitmask and
966   *          fills the cellPtr's PUSCH PRB MApping Type
967   *
968   * @params[in] Pointer to ClCellParam
969   *             Value to be compared
970   * @return void
971   *
972   ******************************************************************/
973
974 PUBLIC void fillPuschPrbMappingType(uint8_t value, ClCellParam **cellPtr)
975 {
976    if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_NON_INTLV_MASK)
977    {
978       (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_NON_INTLV;
979    }
980    else if((value & FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK) == FAPI_PUSCH_VRB_TO_PRB_MAP_INTLVD_MASK)
981    {
982       (*cellPtr)->puschVrbToPrbMapping = VRB_TO_PRB_MAP_INTLVD;
983    }
984    else
985    {
986       (*cellPtr)->puschVrbToPrbMapping = INVALID_VALUE;
987    }
988 }
989
990 /*******************************************************************
991   *
992   * @brief fills the Modulation Order in Ul by comparing the bitmask
993   *
994   * @details
995   *
996   *    Function : fillModulationOrderUl
997   *
998   *    Functionality:
999   *         -checks the value with the bitmask and
1000   *          fills the cellPtr's Modualtsion Order in UL.
1001   *
1002   * @params[in] Pointer to ClCellParam
1003   *             Value to be compared
1004   * @return void
1005   *
1006   ******************************************************************/
1007
1008 PUBLIC void fillModulationOrderUl(uint8_t value, ClCellParam **cellPtr)
1009 {
1010    if(value == 0)
1011    {
1012       (*cellPtr)->supportedModulationOrderUl = MOD_QPSK;
1013    }
1014    else if(value == 1)
1015    {
1016       (*cellPtr)->supportedModulationOrderUl = MOD_16QAM;
1017    }
1018    else if(value == 2)
1019    {
1020       (*cellPtr)->supportedModulationOrderUl = MOD_64QAM;
1021    }
1022    else if(value == 3)
1023    {
1024       (*cellPtr)->supportedModulationOrderUl = MOD_256QAM;
1025    }
1026    else
1027    {
1028       (*cellPtr)->supportedModulationOrderUl = INVALID_VALUE;
1029    }
1030 }
1031
1032 /*******************************************************************
1033   *
1034   * @brief fills the PUSCH Aggregation Factor by comparing the bitmask
1035   *
1036   * @details
1037   *
1038   *    Function : fillPuschAggregationFactor
1039   *
1040   *    Functionality:
1041   *         -checks the value with the bitmask and
1042   *          fills the cellPtr's PUSCH Aggregation Factor
1043   *
1044   * @params[in] Pointer to ClCellParam
1045   *             Value to be compared
1046   * @return void
1047   *
1048   ******************************************************************/
1049
1050 PUBLIC void fillPuschAggregationFactor(uint8_t value, ClCellParam **cellPtr)
1051 {
1052    if((value & FAPI_FORMAT_0_MASK) == FAPI_FORMAT_0_MASK)
1053    {
1054       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_1;
1055    }
1056    else if((value & FAPI_FORMAT_1_MASK) == FAPI_FORMAT_1_MASK)
1057    {
1058       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_2;
1059    }
1060    else if((value & FAPI_FORMAT_2_MASK) == FAPI_FORMAT_2_MASK)
1061    {
1062       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_4;
1063    }
1064    else if((value & FAPI_FORMAT_3_MASK) == FAPI_FORMAT_3_MASK)
1065    {
1066       (*cellPtr)->puschAggregationFactor    = AGG_FACTOR_8;
1067    }
1068    else
1069    {
1070       (*cellPtr)->puschAggregationFactor    = INVALID_VALUE;
1071    }
1072 }
1073
1074 /*******************************************************************
1075   *
1076   * @brief fills the PRACH Long Format by comparing the bitmask
1077   *
1078   * @details
1079   *
1080   *    Function : fillPrachLongFormat
1081   *
1082   *    Functionality:
1083   *         -checks the value with the bitmask and
1084   *          fills the cellPtr's PRACH Long Format
1085   *
1086   * @params[in] Pointer to ClCellParam
1087   *             Value to be compared
1088   * @return void
1089   *
1090   ******************************************************************/
1091
1092 PUBLIC void fillPrachLongFormat(uint8_t value, ClCellParam **cellPtr)
1093 {
1094    if((value & FAPI_PRACH_LF_FORMAT_0_MASK) == FAPI_PRACH_LF_FORMAT_0_MASK)
1095    {
1096       (*cellPtr)->prachLongFormats    = FORMAT_0;
1097    }
1098    else if((value & FAPI_PRACH_LF_FORMAT_1_MASK) == FAPI_PRACH_LF_FORMAT_1_MASK)
1099    {
1100       (*cellPtr)->prachLongFormats    = FORMAT_1;
1101    }
1102    else if((value & FAPI_PRACH_LF_FORMAT_2_MASK) == FAPI_PRACH_LF_FORMAT_2_MASK)
1103    {
1104       (*cellPtr)->prachLongFormats    = FORMAT_2;
1105    }
1106    else if((value & FAPI_PRACH_LF_FORMAT_3_MASK) == FAPI_PRACH_LF_FORMAT_3_MASK)
1107    {
1108       (*cellPtr)->prachLongFormats    = FORMAT_3;
1109    }
1110    else
1111    {
1112       (*cellPtr)->prachLongFormats    = INVALID_VALUE;
1113    }
1114 }
1115
1116 /*******************************************************************
1117   *
1118   * @brief fills the PRACH Short Format by comparing the bitmask
1119   *
1120   * @details
1121   *
1122   *    Function : fillPrachShortFormat
1123   *
1124   *    Functionality:
1125   *         -checks the value with the bitmask and
1126   *          fills the cellPtr's PRACH ShortFormat
1127   *
1128   * @params[in] Pointer to ClCellParam
1129   *             Value to be compared
1130   * @return void
1131   *
1132   ******************************************************************/
1133
1134 PUBLIC void fillPrachShortFormat(uint8_t value, ClCellParam **cellPtr)
1135 {
1136    if((value & FAPI_PRACH_SF_FORMAT_A1_MASK) == FAPI_PRACH_SF_FORMAT_A1_MASK)
1137    {
1138       (*cellPtr)->prachShortFormats    = SF_FORMAT_A1;
1139    }
1140    else if((value & FAPI_PRACH_SF_FORMAT_A2_MASK) == FAPI_PRACH_SF_FORMAT_A2_MASK)
1141    {
1142       (*cellPtr)->prachShortFormats    = SF_FORMAT_A2;
1143    }
1144    else if((value & FAPI_PRACH_SF_FORMAT_A3_MASK) == FAPI_PRACH_SF_FORMAT_A3_MASK)
1145    {
1146       (*cellPtr)->prachShortFormats    = SF_FORMAT_A3;
1147    }
1148    else if((value & FAPI_PRACH_SF_FORMAT_B1_MASK) == FAPI_PRACH_SF_FORMAT_B1_MASK)
1149    {
1150       (*cellPtr)->prachShortFormats    = SF_FORMAT_B1;
1151    }
1152    else if((value & FAPI_PRACH_SF_FORMAT_B2_MASK) == FAPI_PRACH_SF_FORMAT_B2_MASK)
1153    {
1154       (*cellPtr)->prachShortFormats    = SF_FORMAT_B2;
1155    }
1156    else if((value & FAPI_PRACH_SF_FORMAT_B3_MASK) == FAPI_PRACH_SF_FORMAT_B3_MASK)
1157    {
1158       (*cellPtr)->prachShortFormats    = SF_FORMAT_B3;
1159    }
1160    else if((value & FAPI_PRACH_SF_FORMAT_B4_MASK) == FAPI_PRACH_SF_FORMAT_B4_MASK)
1161    {
1162       (*cellPtr)->prachShortFormats    = SF_FORMAT_B4;
1163    }
1164    else if((value & FAPI_PRACH_SF_FORMAT_C0_MASK) == FAPI_PRACH_SF_FORMAT_C0_MASK)
1165    {
1166       (*cellPtr)->prachShortFormats    = SF_FORMAT_C0;
1167    }
1168    else if((value & FAPI_PRACH_SF_FORMAT_C2_MASK) == FAPI_PRACH_SF_FORMAT_C2_MASK)
1169    {
1170       (*cellPtr)->prachShortFormats    = SF_FORMAT_C2;
1171    }
1172    else
1173    {
1174       (*cellPtr)->prachShortFormats    = INVALID_VALUE;
1175    }
1176 }
1177
1178 /*******************************************************************
1179   *
1180   * @brief fills the Fd Occasions Type by comparing the bitmask
1181   *
1182   * @details
1183   *
1184   *    Function : fillFdOccasions
1185   *
1186   *    Functionality:
1187   *         -checks the value with the bitmask and
1188   *          fills the cellPtr's Fd Occasions
1189   *
1190   * @params[in] Pointer to ClCellParam
1191   *             Value to be compared
1192   * @return void
1193   *
1194   ******************************************************************/
1195
1196 PUBLIC void fillFdOccasions(uint8_t value, ClCellParam **cellPtr)
1197 {
1198    if(value == 0)
1199    {
1200       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_1;
1201    }
1202    else if(value == 1)
1203    {
1204       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_2;
1205    }
1206    else if(value == 3)
1207    {
1208       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_4;
1209    }
1210    else if(value == 4)
1211    {
1212       (*cellPtr)->maxPrachFdOccasionsInASlot = PRACH_FD_OCC_IN_A_SLOT_8;
1213    }
1214    else
1215    {
1216       (*cellPtr)->maxPrachFdOccasionsInASlot = INVALID_VALUE;
1217    }
1218 }
1219
1220 /*******************************************************************
1221   *
1222   * @brief fills the RSSI Measurement by comparing the bitmask
1223   *
1224   * @details
1225   *
1226   *    Function : fillRssiMeas
1227   *
1228   *    Functionality:
1229   *         -checks the value with the bitmask and
1230   *          fills the cellPtr's RSSI Measurement report
1231   *
1232   * @params[in] Pointer to ClCellParam
1233   *             Value to be compared
1234   * @return void
1235   *
1236   ******************************************************************/
1237
1238 PUBLIC void fillRssiMeas(uint8_t value, ClCellParam **cellPtr)
1239 {
1240    if((value & FAPI_RSSI_REPORT_IN_DBM_MASK) == FAPI_RSSI_REPORT_IN_DBM_MASK)
1241    {
1242       (*cellPtr)->rssiMeasurementSupport    = RSSI_REPORT_DBM;
1243    }
1244    else if((value & FAPI_RSSI_REPORT_IN_DBFS_MASK) == FAPI_RSSI_REPORT_IN_DBFS_MASK)
1245    {
1246       (*cellPtr)->rssiMeasurementSupport    = RSSI_REPORT_DBFS;
1247    }
1248    else
1249    {
1250       (*cellPtr)->rssiMeasurementSupport    = INVALID_VALUE;
1251    }
1252 }
1253
1254  /*******************************************************************
1255   *
1256   * @brief Returns the TLVs value
1257   *
1258   * @details
1259   *
1260   *    Function : getParamValue
1261   *
1262   *    Functionality:
1263   *         -return TLVs value
1264   *
1265   * @params[in]
1266   * @return ROK     - temp
1267   *         RFAILED - failure
1268   *
1269   * ****************************************************************/
1270
1271 uint32_t getParamValue(fapi_uint16_tlv_t *tlv, uint16_t type)
1272 {
1273     //uint16_t valueLen;
1274     void *posPtr;
1275     //valueLen = tlv->tl.length;
1276     posPtr   = &tlv->tl.tag;
1277     posPtr   += sizeof(tlv->tl.tag);
1278     posPtr   += sizeof(tlv->tl.length);
1279     /*TO DO: malloc to SSI memory */
1280     if(type == FAPI_UINT_8)
1281     {
1282        //temp = (uint8_t *)malloc(valueLen * sizeof(U8));
1283        //memcpy(temp, posPtr, valueLen);
1284        return(*(uint8_t *)posPtr);
1285     }
1286     else if(type == FAPI_UINT_16)
1287     {
1288        return(*(uint16_t *)posPtr);
1289     }
1290     else if(type == FAPI_UINT_32)
1291     {
1292        return(*(uint32_t *)posPtr);
1293     }
1294     else
1295     {
1296       DU_LOG("\nLOWER MAC: Value Extraction failed" );
1297       return RFAILED;
1298     }
1299 }
1300 #endif /* FAPI */
1301  /*******************************************************************
1302   *
1303   * @brief Sends FAPI Param req to PHY
1304   *
1305   * @details
1306   *
1307   *    Function : lwr_mac_handleParamReqEvt
1308   *
1309   *    Functionality:
1310   *         -Sends FAPI Param req to PHY
1311   *
1312   * @params[in]
1313   * @return ROK     - success
1314   *         RFAILED - failure
1315   *
1316   * ****************************************************************/
1317
1318 S16 lwr_mac_handleParamReqEvt(void *msg)
1319 {
1320 #ifdef FAPI
1321    /* startGuardTimer(); */
1322    uint32_t msgLen;      //Length of message Body
1323    msgLen = 0;
1324    fapi_param_req_t *paramReq;
1325 #ifdef INTEL_WLS
1326    WLS_MEM_ALLOC(paramReq, sizeof(fapi_param_req_t));
1327 #else
1328    MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
1329 #endif
1330  
1331    if(paramReq != NULLP)
1332    {
1333       fillMsgHeader(&paramReq->header, FAPI_PARAM_REQUEST, msgLen);
1334       DU_LOG("\nLOWER MAC: Sending Param Request to Phy");
1335       LwrMacSendToPhy(paramReq->header.message_type_id, sizeof(fapi_param_req_t), (void *)paramReq);
1336       MAC_FREE(paramReq, sizeof(fapi_param_req_t));
1337       return ROK;
1338    }
1339    else
1340    {
1341       DU_LOG("\nLOWER MAC: Failed to allocate memory for Param Request");
1342       return RFAILED;
1343    }
1344 #else
1345    return ROK;
1346 #endif
1347 }
1348
1349  /*******************************************************************
1350   *
1351   * @brief Sends FAPI Param Response to MAC via PHY
1352   *
1353   * @details
1354   *
1355   *    Function : lwr_mac_handleParamRspEvt
1356   *
1357   *    Functionality:
1358   *         -Sends FAPI Param rsp to MAC via PHY
1359   *
1360   * @params[in]
1361   * @return ROK     - success
1362   *         RFAILED - failure
1363   *
1364   * ****************************************************************/
1365
1366 S16 lwr_mac_handleParamRspEvt(void *msg)
1367 {
1368 #ifdef FAPI
1369   /* stopGuardTimer(); */
1370    uint8_t index;
1371    uint32_t encodedVal;
1372         fapi_param_resp_t *paramRsp;
1373    ClCellParam *cellParam = NULLP;
1374
1375    paramRsp = (fapi_param_resp_t *)msg;
1376    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1377
1378    if(paramRsp != NULLP)
1379    {
1380       MAC_ALLOC(cellParam, sizeof(ClCellParam));
1381       if(cellParam != NULLP)
1382       {
1383          DU_LOG("\n LOWER MAC: Filling TLVS into MAC API");
1384          if(paramRsp->error_code == MSG_OK)
1385          {
1386             for(index = 0; index < paramRsp->number_of_tlvs; index++)
1387             {
1388                switch(paramRsp->tlvs[index].tl.tag)
1389                {
1390                   case FAPI_RELEASE_CAPABILITY_TAG:
1391                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1392                      if(encodedVal != RFAILED && (encodedVal & RELEASE_15) == RELEASE_15)
1393                      {
1394                         cellParam->releaseCapability = RELEASE_15;
1395                      }
1396                      break;
1397
1398                   case FAPI_PHY_STATE_TAG:
1399                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1400                      if(encodedVal != RFAILED && encodedVal != clGlobalCp.phyState)
1401                      {
1402                         printf("\n PhyState mismatch [%d][%d]", clGlobalCp.phyState, clGlobalCp.event);
1403                         RETVALUE(RFAILED);
1404                      }
1405                      break;
1406
1407                   case FAPI_SKIP_BLANK_DL_CONFIG_TAG:
1408                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1409                      if(encodedVal != RFAILED && encodedVal != 0)
1410                      {
1411                        cellParam->skipBlankDlConfig = SUPPORTED;
1412                      }
1413                      else
1414                      {
1415                        cellParam->skipBlankDlConfig = NOT_SUPPORTED;
1416                      }
1417                      break;
1418
1419                   case FAPI_SKIP_BLANK_UL_CONFIG_TAG:
1420                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1421                      if(encodedVal != RFAILED && encodedVal != 0)
1422                      {
1423                        cellParam->skipBlankUlConfig = SUPPORTED;
1424                      }
1425                      else
1426                      {
1427                        cellParam->skipBlankUlConfig = NOT_SUPPORTED;
1428                      }
1429                      break;
1430
1431                   case FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG:
1432                      cellParam->numTlvsToReport = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1433                      break;
1434
1435                   case FAPI_CYCLIC_PREFIX_TAG:
1436                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1437                      if(encodedVal != RFAILED)
1438                      {
1439                         fillCyclicPrefix(encodedVal, &cellParam);
1440                      }
1441                      break;
1442
1443                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG:
1444                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1445                      if(encodedVal != RFAILED)
1446                      {
1447                         fillSubcarrierSpaceDl(encodedVal, &cellParam);
1448                      }
1449                      break;
1450
1451                   case FAPI_SUPPORTED_BANDWIDTH_DL_TAG:
1452                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1453                      if(encodedVal != RFAILED)
1454                      {
1455                         fillBandwidthDl(encodedVal, &cellParam);
1456                      }
1457                      break;
1458
1459                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG:
1460                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1461                      if(encodedVal != RFAILED)
1462                      {
1463                         fillSubcarrierSpaceUl(encodedVal, &cellParam);
1464                      }
1465                      break;
1466
1467                   case FAPI_SUPPORTED_BANDWIDTH_UL_TAG:
1468                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1469                      if(encodedVal != RFAILED)
1470                      {
1471                         fillBandwidthUl(encodedVal, &cellParam);
1472                      }
1473                      break;
1474
1475                   case FAPI_CCE_MAPPING_TYPE_TAG:
1476                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1477                      if(encodedVal != RFAILED)
1478                      {
1479                         fillCCEmaping(encodedVal, &cellParam);
1480                      }
1481                      break;
1482
1483                   case FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG:
1484                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1485                      if(encodedVal != RFAILED && encodedVal != 0)
1486                      {
1487                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = SUPPORTED;
1488                      }
1489                      else
1490                      {
1491                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = NOT_SUPPORTED;
1492                      }
1493                      break;
1494
1495                   case FAPI_PRECODER_GRANULARITY_CORESET_TAG:
1496                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1497                      if(encodedVal != RFAILED && encodedVal != 0)
1498                      {
1499                         cellParam->precoderGranularityCoreset = SUPPORTED;
1500                      }
1501                      else
1502                      {
1503                         cellParam->precoderGranularityCoreset = NOT_SUPPORTED;
1504                      }
1505                      break;
1506
1507                   case FAPI_PDCCH_MU_MIMO_TAG:
1508                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1509                      if(encodedVal != RFAILED && encodedVal != 0)
1510                      {
1511                         cellParam->pdcchMuMimo = SUPPORTED;
1512                      }
1513                      else
1514                      {
1515                         cellParam->pdcchMuMimo = NOT_SUPPORTED;
1516                      }
1517                      break;
1518
1519                   case FAPI_PDCCH_PRECODER_CYCLING_TAG:
1520                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1521                      if(encodedVal != RFAILED && encodedVal != 0)
1522                      {
1523                         cellParam->pdcchPrecoderCycling = SUPPORTED;
1524                      }
1525                      else
1526                      {
1527                         cellParam->pdcchPrecoderCycling = NOT_SUPPORTED;
1528                      }
1529                      break;
1530
1531                   case FAPI_MAX_PDCCHS_PER_SLOT_TAG:
1532                      cellParam->maxPdcchsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1533                      break;
1534
1535                   case FAPI_PUCCH_FORMATS_TAG:
1536                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1537                      if(encodedVal != RFAILED)
1538                      {
1539                         fillPucchFormat(encodedVal, &cellParam);
1540                      }
1541                      break;
1542
1543                   case FAPI_MAX_PUCCHS_PER_SLOT_TAG:
1544                        cellParam->maxPucchsPerSlot   = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1545                      break;
1546
1547                   case FAPI_PDSCH_MAPPING_TYPE_TAG:
1548                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1549                      if(encodedVal != RFAILED)
1550                      {
1551                         fillPdschMappingType(encodedVal, &cellParam);
1552                      }
1553                      break;
1554
1555                   case FAPI_PDSCH_ALLOCATION_TYPES_TAG:
1556                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1557                      if(encodedVal != RFAILED)
1558                      {
1559                         fillPdschAllocationType(encodedVal, &cellParam);
1560                      }
1561                      break;
1562
1563                   case FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG:
1564                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1565                      if(encodedVal != RFAILED)
1566                      {
1567                         fillPrbMappingType(encodedVal, &cellParam);
1568                      }
1569                      break;
1570
1571                   case FAPI_PDSCH_CBG_TAG:
1572                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1573                      if(encodedVal != RFAILED && encodedVal != 0)
1574                      {
1575                         cellParam->pdschCbg = SUPPORTED;
1576                      }
1577                      else
1578                      {
1579                         cellParam->pdschCbg = NOT_SUPPORTED;
1580                      }
1581                      break;
1582
1583                   case FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG:
1584                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1585                      if(encodedVal != RFAILED)
1586                      {
1587                         fillPdschDmrsConfigType(encodedVal, &cellParam);
1588                      }
1589                      break;
1590
1591                   case FAPI_PDSCH_DMRS_MAX_LENGTH_TAG:
1592                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1593                      if(encodedVal != RFAILED)
1594                      {
1595                         fillPdschDmrsLength(encodedVal, &cellParam);
1596                      }
1597                      break;
1598
1599                   case FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG:
1600                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1601                      if(encodedVal != RFAILED)
1602                      {
1603                         fillPdschDmrsAddPos(encodedVal, &cellParam);
1604                      }
1605                      break;
1606
1607                   case FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG:
1608                      cellParam->maxPdschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1609                      break;
1610
1611                   case FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG:
1612                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1613                      if(encodedVal != RFAILED && encodedVal < FAPI_MAX_NUMBERMIMO_LAYERS_PDSCH)
1614                      {
1615                         cellParam->maxNumberMimoLayersPdsch   = encodedVal;
1616                      }
1617                      break;
1618
1619                   case FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG:
1620                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1621                      if(encodedVal != RFAILED)
1622                      {
1623                         fillModulationOrderDl(encodedVal, &cellParam);
1624                      }
1625                      break;
1626
1627                   case FAPI_MAX_MU_MIMO_USERS_DL_TAG:
1628                      cellParam->maxMuMimoUsersDl         = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1629                      break;
1630
1631                   case FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG:
1632                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1633                      if(encodedVal != RFAILED && encodedVal != 0)
1634                      {
1635                         cellParam->pdschDataInDmrsSymbols = SUPPORTED;
1636                      }
1637                      else
1638                      {
1639                         cellParam->pdschDataInDmrsSymbols = NOT_SUPPORTED;
1640                      }
1641                      break;
1642
1643                   case FAPI_PREMPTIONSUPPORT_TAG:
1644                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1645                      if(encodedVal != RFAILED && encodedVal != 0)
1646                      {
1647                         cellParam->premptionSupport = SUPPORTED;
1648                      }
1649                      else
1650                      {
1651                         cellParam->premptionSupport = NOT_SUPPORTED;
1652                      }
1653                      break;
1654
1655                   case FAPI_PDSCH_NON_SLOT_SUPPORT_TAG:
1656                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1657                      if(encodedVal != RFAILED && encodedVal != 0)
1658                      {
1659                         cellParam->pdschNonSlotSupport = SUPPORTED;
1660                      }
1661                      else
1662                      {
1663                         cellParam->pdschNonSlotSupport = NOT_SUPPORTED;
1664                      }
1665                      break;
1666
1667                   case FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG:
1668                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1669                      if(encodedVal != RFAILED && encodedVal != 0)
1670                      {
1671                         cellParam->uciMuxUlschInPusch = SUPPORTED;
1672                      }
1673                      else
1674                      {
1675                         cellParam->uciMuxUlschInPusch = NOT_SUPPORTED;
1676                      }
1677                      break;
1678
1679                   case FAPI_UCI_ONLY_PUSCH_TAG:
1680                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1681                      if(encodedVal != RFAILED && encodedVal != 0)
1682                      {
1683                         cellParam->uciOnlyPusch = SUPPORTED;
1684                      }
1685                      else
1686                      {
1687                         cellParam->uciOnlyPusch = NOT_SUPPORTED;
1688                      }
1689                      break;
1690
1691                   case FAPI_PUSCH_FREQUENCY_HOPPING_TAG:
1692                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1693                      if(encodedVal != RFAILED && encodedVal != 0)
1694                      {
1695                         cellParam->puschFrequencyHopping = SUPPORTED;
1696                      }
1697                      else
1698                      {
1699                         cellParam->puschFrequencyHopping = NOT_SUPPORTED;
1700                      }
1701                      break;
1702
1703                  case FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG:
1704                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1705                     if(encodedVal != RFAILED)
1706                     {
1707                        fillPuschDmrsConfig(encodedVal, &cellParam);
1708                     }
1709                     break;
1710
1711                  case FAPI_PUSCH_DMRS_MAX_LEN_TAG:
1712                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1713                     if(encodedVal != RFAILED)
1714                     {
1715                        fillPuschDmrsLength(encodedVal, &cellParam);
1716                     }
1717                     break;
1718
1719                  case FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG:
1720                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1721                     if(encodedVal != RFAILED)
1722                     {
1723                        fillPuschDmrsAddPos(encodedVal, &cellParam);
1724                     }
1725                     break;
1726
1727                  case FAPI_PUSCH_CBG_TAG:
1728                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1729                     if(encodedVal != RFAILED && encodedVal != 0)
1730                     {
1731                        cellParam->puschCbg = SUPPORTED;
1732                     }
1733                     else
1734                     {
1735                        cellParam->puschCbg = NOT_SUPPORTED;
1736                     }
1737                     break;
1738
1739                 case FAPI_PUSCH_MAPPING_TYPE_TAG:
1740                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1741                    if(encodedVal != RFAILED)
1742                    {
1743                       fillPuschMappingType(encodedVal, &cellParam);
1744                    }
1745                    break;
1746
1747                 case FAPI_PUSCH_ALLOCATION_TYPES_TAG:
1748                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1749                    if(encodedVal != RFAILED)
1750                    {
1751                       fillPuschAllocationType(encodedVal, &cellParam);
1752                    }
1753                    break;
1754
1755                 case FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG:
1756                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1757                    if(encodedVal != RFAILED)
1758                    {
1759                       fillPuschPrbMappingType(encodedVal, &cellParam);
1760                    }
1761                    break;
1762
1763                 case FAPI_PUSCH_MAX_PTRS_PORTS_TAG:
1764                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1765                    if(encodedVal != RFAILED && encodedVal < FAPI_PUSCH_MAX_PTRS_PORTS_UB)
1766                    {
1767                 cellParam->puschMaxPtrsPorts = encodedVal;
1768                    }
1769                    break;
1770
1771                 case FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG:
1772                    cellParam->maxPduschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1773                    break;
1774
1775                 case FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG:
1776                    cellParam->maxNumberMimoLayersNonCbPusch = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1777                    break;
1778
1779                 case FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG:
1780                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1781                    if(encodedVal != RFAILED)
1782                    {
1783                       fillModulationOrderUl(encodedVal, &cellParam);
1784                    }
1785                    break;
1786
1787                 case FAPI_MAX_MU_MIMO_USERS_UL_TAG:
1788                    cellParam->maxMuMimoUsersUl = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1789                    break;
1790
1791                 case FAPI_DFTS_OFDM_SUPPORT_TAG:
1792                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1793                    if(encodedVal != RFAILED && encodedVal != 0)
1794                    {
1795                       cellParam->dftsOfdmSupport = SUPPORTED;
1796                    }
1797                    else
1798                    {
1799                       cellParam->dftsOfdmSupport = NOT_SUPPORTED;
1800                    }
1801                    break;
1802
1803                 case FAPI_PUSCH_AGGREGATION_FACTOR_TAG:
1804                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1805                    if(encodedVal != RFAILED)
1806                    {
1807                       fillPuschAggregationFactor(encodedVal, &cellParam);
1808                    }
1809                    break;
1810
1811                 case FAPI_PRACH_LONG_FORMATS_TAG:
1812                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1813                    if(encodedVal != RFAILED)
1814                    {
1815                       fillPrachLongFormat(encodedVal, &cellParam);
1816                    }
1817                    break;
1818
1819                 case FAPI_PRACH_SHORT_FORMATS_TAG:
1820                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1821                    if(encodedVal != RFAILED)
1822                    {
1823                       fillPrachShortFormat(encodedVal, &cellParam);
1824                    }
1825                    break;
1826
1827                 case FAPI_PRACH_RESTRICTED_SETS_TAG:
1828                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1829                    if(encodedVal != RFAILED && encodedVal != 0)
1830                    {
1831                       cellParam->prachRestrictedSets = SUPPORTED;
1832                    }
1833                    else
1834                    {
1835                       cellParam->prachRestrictedSets = NOT_SUPPORTED;
1836                    }
1837                    break;
1838
1839                case FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG:
1840                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1841                   if(encodedVal != RFAILED)
1842                   {
1843                      fillFdOccasions(encodedVal, &cellParam);
1844                   }
1845                   break;
1846
1847                case FAPI_RSSI_MEASUREMENT_SUPPORT_TAG:
1848                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1849                   if(encodedVal != RFAILED)
1850                   {
1851                      fillRssiMeas(encodedVal, &cellParam);
1852                   }
1853                   break;
1854                default:
1855                //printf("\n Invalid value for TLV[%x] at index[%d]", paramRsp->tlvs[index].tl.tag, index);
1856                                         break;
1857               }
1858            }
1859            MAC_FREE(cellParam, sizeof(ClCellParam));
1860            MAC_FREE(paramRsp, sizeof(fapi_param_resp_t));
1861              
1862            sendToLowerMac(FAPI_CONFIG_REQUEST, 0, (void *)NULL);
1863            return ROK;
1864          }
1865          else
1866          {
1867             DU_LOG("\n LOWER MAC: Invalid error code %d", paramRsp->error_code);
1868             return RFAILED;
1869          }
1870      }
1871      else
1872      {
1873         DU_LOG("\nLOWER MAC: Failed to allocate memory for cell param");
1874         return RFAILED;
1875      }
1876    }
1877    else
1878    {
1879        DU_LOG("\nLOWER MAC:  Param Response received from PHY is NULL");
1880        return RFAILED;
1881    }
1882 #else
1883    return ROK;
1884 #endif
1885 }
1886
1887  /*******************************************************************
1888   *
1889   * @brief Sends FAPI Config req to PHY
1890   *
1891   * @details
1892   *
1893   *    Function : lwr_mac_handleConfigReqEvt
1894   *
1895   *    Functionality:
1896   *         -Sends FAPI Config Req to PHY
1897   *
1898   * @params[in]
1899   * @return ROK     - success
1900   *         RFAILED - failure
1901   *
1902   * ****************************************************************/
1903
1904 S16 lwr_mac_handleConfigReqEvt(void *msg)
1905 {
1906 #ifdef FAPI
1907    uint8_t index = 0;
1908    uint32_t msgLen = 0;
1909    uint32_t configReqSize;
1910    RgCellCb  *cellParams;
1911    MacCellCfg macCfgParams;
1912    Inst inst = 0;
1913
1914    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1915
1916    fapi_config_req_t *configReq;
1917    cellParams = rgCb[inst].cell;
1918    macCfgParams = cellParams->macCellCfg;
1919    configReqSize = sizeof(fapi_config_req_t) + (macCfgParams.numTlv * sizeof(fapi_uint16_tlv_t));
1920 #ifdef INTEL_WLS
1921    WLS_MEM_ALLOC(configReq, configReqSize);
1922 #else
1923    MAC_ALLOC(configReq, configReqSize);
1924 #endif
1925
1926    if(configReq != NULL)
1927    {
1928       configReq->number_of_tlvs = macCfgParams.numTlv;
1929
1930       if(macCfgParams.dlCarrCfg.pres)
1931       {
1932          fillTlvs(&configReq->tlvs[index++], FAPI_DL_BANDWIDTH_TAG,            sizeof(uint16_t), macCfgParams.dlCarrCfg.bw, &msgLen);
1933          fillTlvs(&configReq->tlvs[index++], FAPI_DL_FREQUENCY_TAG,            sizeof(uint32_t), macCfgParams.dlCarrCfg.freq, &msgLen);
1934          fillTlvs(&configReq->tlvs[index++], FAPI_DL_K0_TAG,                   sizeof(uint16_t), macCfgParams.dlCarrCfg.k0[0], &msgLen);
1935          fillTlvs(&configReq->tlvs[index++], FAPI_DL_GRIDSIZE_TAG,             sizeof(uint16_t), macCfgParams.dlCarrCfg.gridSize[0], &msgLen);
1936          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_TX_ANT_TAG,              sizeof(uint16_t), macCfgParams.dlCarrCfg.numAnt, &msgLen);
1937       }
1938       if(macCfgParams.ulCarrCfg.pres)
1939       {
1940          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_BANDWIDTH_TAG,        sizeof(uint16_t), macCfgParams.ulCarrCfg.bw, &msgLen);
1941          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_FREQUENCY_TAG,        sizeof(uint32_t), macCfgParams.ulCarrCfg.freq, &msgLen);
1942          fillTlvs(&configReq->tlvs[index++], FAPI_UL_K0_TAG,                   sizeof(uint16_t), macCfgParams.ulCarrCfg.k0[0], &msgLen);
1943          fillTlvs(&configReq->tlvs[index++], FAPI_UL_GRID_SIZE_TAG,            sizeof(uint16_t), macCfgParams.ulCarrCfg.gridSize[0], &msgLen);
1944          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_RX_ANT_TAG,              sizeof(uint16_t), macCfgParams.ulCarrCfg.numAnt, &msgLen);
1945       }
1946       fillTlvs(&configReq->tlvs[index++], FAPI_FREQUENCY_SHIFT_7P5_KHZ_TAG,    sizeof(uint8_t), macCfgParams.freqShft, &msgLen);
1947
1948       /* fill cell config */
1949       fillTlvs(&configReq->tlvs[index++], FAPI_PHY_CELL_ID_TAG,                sizeof(uint8_t), macCfgParams.phyCellId, &msgLen);
1950       fillTlvs(&configReq->tlvs[index++], FAPI_FRAME_DUPLEX_TYPE_TAG,          sizeof(uint8_t), macCfgParams.dupType, &msgLen);
1951
1952       /* fill SSB configuration */
1953       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_POWER_TAG,              sizeof(uint32_t), macCfgParams.ssbCfg.ssbPbchPwr, &msgLen);
1954       fillTlvs(&configReq->tlvs[index++], FAPI_BCH_PAYLOAD_TAG,                sizeof(uint8_t), macCfgParams.ssbCfg.bchPayloadFlag, &msgLen);
1955       fillTlvs(&configReq->tlvs[index++], FAPI_SCS_COMMON_TAG,                 sizeof(uint8_t), macCfgParams.ssbCfg.scsCmn, &msgLen);
1956
1957       /* fill PRACH configuration */
1958       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SEQUENCE_LENGTH_TAG,      sizeof(uint8_t), macCfgParams.prachCfg.prachSeqLen, &msgLen);
1959       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SUBC_SPACING_TAG,         sizeof(uint8_t), macCfgParams.prachCfg.prachSubcSpacing, &msgLen);
1960       fillTlvs(&configReq->tlvs[index++], FAPI_RESTRICTED_SET_CONFIG_TAG,      sizeof(uint8_t), macCfgParams.prachCfg.prachRstSetCfg, &msgLen);
1961       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_PRACH_FD_OCCASIONS_TAG,
1962                                 sizeof(uint8_t), macCfgParams.prachCfg.msg1Fdm, &msgLen);
1963       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ROOT_SEQUENCE_INDEX_TAG,  sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].rootSeqIdx, &msgLen);
1964       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_ROOT_SEQUENCES_TAG,         sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numRootSeq, &msgLen);
1965       fillTlvs(&configReq->tlvs[index++], FAPI_K1_TAG,                         sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].k1, &msgLen);
1966       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ZERO_CORR_CONF_TAG ,      sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].zeroCorrZoneCfg, &msgLen);
1967       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_UNUSED_ROOT_SEQUENCES_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numUnusedRootSeq, &msgLen);
1968       //MAC_ALLOC(macCfgParams.prachCfg.fdm[0].unsuedRootSeq, \
1969          sizeof(uint8_t)*macCfgParams.prachCfg.fdm[0].numUnusedRootSeq);
1970       macCfgParams.prachCfg.fdm[0].unsuedRootSeq = (uint8_t *)malloc(sizeof(uint8_t)*macCfgParams.prachCfg.fdm[0].numUnusedRootSeq);
1971       fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG,
1972                    sizeof(uint8_t), *(macCfgParams.prachCfg.fdm[0].unsuedRootSeq), &msgLen);
1973       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PER_RACH_TAG,               sizeof(uint8_t), macCfgParams.prachCfg.ssbPerRach, &msgLen);
1974       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_MULTIPLE_CARRIERS_IN_A_BAND_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.prachMultCarrBand, &msgLen);
1975
1976       /* fill SSB table */
1977       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_OFFSET_POINT_A_TAG,         sizeof(uint16_t), macCfgParams.ssbCfg.ssbOffsetPointA, &msgLen);
1978       fillTlvs(&configReq->tlvs[index++], FAPI_BETA_PSS_TAG,                   sizeof(uint8_t),  macCfgParams.ssbCfg.betaPss, &msgLen);
1979       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PERIOD_TAG,                 sizeof(uint8_t),  macCfgParams.ssbCfg.ssbPeriod, &msgLen);
1980       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_SUBCARRIER_OFFSET_TAG,      sizeof(uint8_t),  macCfgParams.ssbCfg.ssbScOffset, &msgLen);
1981       fillTlvs(&configReq->tlvs[index++], FAPI_MIB_TAG ,                       sizeof(uint32_t), macCfgParams.ssbCfg.mibPdu[0], &msgLen);
1982       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_MASK_TAG,                   sizeof(uint32_t), macCfgParams.ssbCfg.ssbMask[0], &msgLen);
1983       fillTlvs(&configReq->tlvs[index++], FAPI_BEAM_ID_TAG,                    sizeof(uint8_t),  macCfgParams.ssbCfg.beamId[0], &msgLen);
1984       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_MULTIPLE_CARRIERS_IN_A_BAND_TAG, sizeof(uint8_t), macCfgParams.ssbCfg.multCarrBand, &msgLen);
1985       fillTlvs(&configReq->tlvs[index++], FAPI_MULTIPLE_CELLS_SS_PBCH_IN_A_CARRIER_TAG, sizeof(uint8_t), macCfgParams.ssbCfg.multCellCarr, &msgLen);
1986
1987       /* fill TDD table */
1988       fillTlvs(&configReq->tlvs[index++], FAPI_TDD_PERIOD_TAG,                 sizeof(uint8_t), macCfgParams.tddCfg.tddPeriod, &msgLen);
1989       fillTlvs(&configReq->tlvs[index++], FAPI_SLOT_CONFIG_TAG,                sizeof(uint8_t), macCfgParams.tddCfg.slotCfg[0][0], &msgLen);
1990
1991       /* fill measurement config */
1992       fillTlvs(&configReq->tlvs[index++], FAPI_RSSI_MESUREMENT_TAG,            sizeof(uint8_t), macCfgParams.rssiUnit, &msgLen);
1993
1994       fillMsgHeader(&configReq->header, FAPI_CONFIG_REQUEST, msgLen);
1995       DU_LOG("\nLOWER_MAC: Sending Config Request to Phy");
1996       /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
1997       LwrMacSendToPhy(configReq->header.message_type_id, msgLen, (void *)configReq);
1998       MAC_FREE(configReq, configReqSize);
1999       return ROK;
2000    }
2001    else
2002    {
2003       DU_LOG("\nLOWER_MAC: Failed to allocate memory for config Request");
2004       return RFAILED;
2005    }
2006 #else
2007    return ROK;
2008 #endif
2009 }
2010
2011 S16 lwr_mac_handleConfigRspEvt(void *msg)
2012 {
2013 #ifdef FAPI
2014    fapi_config_resp_t *configRsp;
2015         configRsp = (fapi_config_resp_t *)msg;
2016    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
2017
2018    if(configRsp != NULL)
2019    {
2020       if(configRsp->error_code == MSG_OK)
2021       {
2022          DU_LOG("\nLOWER MAC: PHY has moved to Conigured state \n");
2023          clGlobalCp.phyState = PHY_STATE_CONFIGURED;
2024          /* TODO : 
2025           * Store config response into an intermediate struture and send to MAC
2026           * Support LC and LWLC for sending config rsp to MAC 
2027           */
2028          fapiMacConfigRsp();
2029          MAC_FREE(configRsp, sizeof(fapi_config_resp_t));
2030          return ROK;
2031       }
2032       else
2033       {
2034
2035          DU_LOG("\n LOWER MAC: Invalid error code %d", configRsp->error_code);
2036          return RFAILED;
2037       }
2038    }
2039    else
2040    {
2041       DU_LOG("\nLOWER_MAC: Config Response received from PHY is NULL");
2042       return RFAILED;
2043    }
2044 #else
2045    return ROK;
2046 #endif
2047 }
2048
2049 S16 lwr_mac_handleStartReqEvt(void *msg)
2050 {
2051 #ifdef FAPI
2052    uint32_t msgLen = 0;
2053    fapi_start_req_t *startReq;
2054 #ifdef INTEL_WLS
2055    WLS_MEM_ALLOC(startReq, sizeof(fapi_start_req_t));
2056 #else
2057    MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
2058 #endif
2059
2060    if(startReq != NULL)
2061    {
2062       fillMsgHeader(&startReq->header, FAPI_START_REQUEST, msgLen);
2063       DU_LOG("\nLOWER MAC: Sending Start Request to PHY");
2064       LwrMacSendToPhy(startReq->header.message_type_id, sizeof(fapi_start_req_t), (void *)startReq);
2065       MAC_FREE(startReq, sizeof(fapi_start_req_t));
2066       return ROK;
2067    }
2068    else
2069    {
2070       DU_LOG("\nLOWER MAC: Failed to allocate memory for Start Request");
2071       return RFAILED;
2072    }
2073 #else
2074    return ROK;
2075 #endif
2076 }
2077
2078 S16 lwr_mac_handleStopReqEvt(void *msg)
2079 {
2080 #ifdef FAPI
2081    /* stop TX and RX operation return PHy to configured State
2082       send stop.indication to l2/l3 */
2083 #endif
2084    return ROK;
2085 }
2086
2087 /*******************************************************************
2088  *
2089  * @brief Modifes the received mibPdu to uint32 bit
2090  *        and stores it in MacCellCfg
2091  *
2092  * @details
2093  *
2094  *    Function : setMibPdu
2095  *
2096  *    Functionality:
2097  *         -Sets the MibPdu
2098  *
2099  * @params[in] Pointer to mibPdu
2100  *             pointer to modified value
2101  ******************************************************************/
2102
2103 PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val)
2104 {
2105    *mibPdu |= (((uint8_t)(slotIndInfo.sfn >> 2)) & MIB_SFN_BITMASK);
2106    *val = (mibPdu[0] << 24 | mibPdu[1] << 16 | mibPdu[2] << 8);
2107     DU_LOG("\nLOWER MAC: value filled %x", *val);
2108 }
2109
2110 #ifdef FAPI
2111 /*******************************************************************
2112  *
2113  * @brief fills SSB PDU required for DL TTI info in MAC
2114  *
2115  * @details
2116  *
2117  *    Function : fillSsbPdu
2118  *
2119  *    Functionality:
2120  *         -Fills the SSB PDU info
2121  *          stored in MAC
2122  *
2123  * @params[in] Pointer to FAPI DL TTI Req
2124  *             Pointer to RgCellCb
2125  *             Pointer to msgLen of DL TTI Info
2126  * @return ROK
2127  *
2128  ******************************************************************/
2129
2130 S16 fillSsbPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, MacCellCfg *macCellCfg,
2131         MacDlSlot *currDlSlot,
2132         uint32_t *msgLen, uint8_t ssbIdxCount) 
2133 {
2134    uint32_t mibPayload = 0;
2135    if(dlTtiReqPdu != NULL)
2136    {
2137       dlTtiReqPdu->pduType = SSB_PDU_TYPE;     /* SSB PDU */
2138       dlTtiReqPdu->u.ssb_pdu.physCellId = macCellCfg->phyCellId;
2139       dlTtiReqPdu->u.ssb_pdu.betaPss = macCellCfg->ssbCfg.betaPss;
2140       dlTtiReqPdu->u.ssb_pdu.ssbBlockIndex = currDlSlot->cellBroadcastInfo.ssbInfo[ssbIdxCount].ssbIdx;
2141       dlTtiReqPdu->u.ssb_pdu.ssbSubCarrierOffset = macCellCfg->ssbCfg.ssbScOffset;
2142       /* ssbOfPdufstA to be filled in ssbCfg */
2143       dlTtiReqPdu->u.ssb_pdu.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2144       dlTtiReqPdu->u.ssb_pdu.bchPayloadFlag = macCellCfg->ssbCfg.bchPayloadFlag;
2145       /* Bit manipulation for SFN */
2146       setMibPdu(macCellCfg->ssbCfg.mibPdu, &mibPayload);
2147       dlTtiReqPdu->u.ssb_pdu.bchPayload.v.bchPayload = mibPayload;
2148       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.numPrgs = 0;
2149       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.prgSize = 0;
2150       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.digBfInterfaces = 0;
2151       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.pmi_bfi[0].pmIdx = 0;
2152       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming. \
2153          pmi_bfi[0].beamIdx[0].beamidx = macCellCfg->ssbCfg.beamId[0];
2154       dlTtiReqPdu->pduSize = sizeof(fapi_dl_ssb_pdu_t);  /* Size of SSB PDU */
2155       SETLENGTH(*msgLen, sizeof(fapi_dl_ssb_pdu_t));
2156       return ROK;
2157     }
2158     else
2159     {
2160        return RFAILED;
2161     }
2162 }
2163
2164 /*******************************************************************
2165  *
2166  * @brief fills Dl DCI PDU required for DL TTI info in MAC
2167  *
2168  * @details
2169  *
2170  *    Function : fillDlDciPdu
2171  *
2172  *    Functionality:
2173  *         -Fills the Dl DCI PDU
2174  *
2175  * @params[in] Pointer to fapi_dl_dci_t
2176  *             Pointer to Sib1PdcchCfg
2177  * @return ROK
2178  *
2179  ******************************************************************/
2180
2181 void fillDlDciPdu(fapi_dl_dci_t *dlDciPtr, Sib1PdcchCfg *sib1PdcchInfo)
2182 {
2183    if(dlDciPtr != NULLP)
2184    {
2185       uint8_t numBytes;
2186       uint8_t bytePos;
2187       uint8_t bitPos;
2188       
2189       uint16_t coreset0Size;
2190       uint16_t rbStart;
2191       uint16_t rbLen;
2192       uint32_t freqDomResAssign;
2193       uint32_t timeDomResAssign;
2194       uint8_t  VRB2PRBMap;
2195       uint32_t modNCodScheme;
2196       uint8_t  redundancyVer;
2197       uint32_t sysInfoInd;
2198       uint32_t reserved;
2199
2200       /* Size(in bits) of each field in DCI format 0_1 
2201                  * as mentioned in spec 38.214 */
2202       uint8_t freqDomResAssignSize;
2203       uint8_t timeDomResAssignSize = 4;
2204       uint8_t VRB2PRBMapSize       = 1;
2205       uint8_t modNCodSchemeSize    = 5;
2206       uint8_t redundancyVerSize    = 2;
2207       uint8_t sysInfoIndSize       = 1;
2208       uint8_t reservedSize         = 15;
2209
2210       dlDciPtr->rnti = sib1PdcchInfo->sib1DlDci.rnti;
2211       dlDciPtr->scramblingId = sib1PdcchInfo->sib1DlDci.scramblingId;    
2212       dlDciPtr->scramblingRnti = sib1PdcchInfo->sib1DlDci.scramblingRnti;
2213       dlDciPtr->cceIndex = sib1PdcchInfo->sib1DlDci.cceIndex;
2214       dlDciPtr->aggregationLevel = sib1PdcchInfo->sib1DlDci.aggregLevel;
2215       dlDciPtr->pc_and_bform.numPrgs = sib1PdcchInfo->sib1DlDci.beamPdcchInfo.numPrgs;
2216       dlDciPtr->pc_and_bform.prgSize = sib1PdcchInfo->sib1DlDci.beamPdcchInfo.prgSize;
2217       dlDciPtr->pc_and_bform.digBfInterfaces = sib1PdcchInfo->sib1DlDci.beamPdcchInfo.digBfInterfaces;
2218       dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = sib1PdcchInfo->sib1DlDci.beamPdcchInfo.prg[0].pmIdx;
2219       dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = sib1PdcchInfo->sib1DlDci.beamPdcchInfo.prg[0].beamIdx[0];
2220       dlDciPtr->beta_pdcch_1_0 = sib1PdcchInfo->sib1DlDci.txPdcchPower.powerValue;           
2221       dlDciPtr->powerControlOfssetSS = sib1PdcchInfo->sib1DlDci.txPdcchPower.powerControlOffsetSS;
2222
2223       /* Calculating freq domain resource allocation field value and size
2224        * coreset0Size = Size of coreset 0
2225        * RBStart = Starting Virtual Rsource block
2226        * RBLen = length of contiguously allocted RBs
2227        * Spec 38.214 Sec 5.1.2.2.2
2228        */
2229       coreset0Size= sib1PdcchInfo->sib1Coreset0Cfg.coreSet0Size;
2230                 rbStart = 0;              /* For SIB1 */
2231       //rbStart = sib1PdcchInfo->sib1DlDci.pdschCfg->sib1FreqAlloc.rbStart;
2232       rbLen = sib1PdcchInfo->sib1DlDci.pdschCfg->sib1FreqAlloc.rbSize;
2233
2234       if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2235       {
2236          if((rbLen - 1) <= floor(coreset0Size / 2))
2237             freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2238          else
2239             freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2240                + (coreset0Size - 1 - rbStart);
2241
2242          freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2243       }
2244
2245       /* Fetching DCI field values */
2246       timeDomResAssign = sib1PdcchInfo->sib1DlDci.pdschCfg->sib1TimeAlloc.
2247                          rowIndex -1;
2248       VRB2PRBMap       = sib1PdcchInfo->sib1DlDci.pdschCfg->sib1FreqAlloc.\
2249                          vrbPrbMapping;
2250       modNCodScheme    = sib1PdcchInfo->sib1DlDci.pdschCfg->codeword[0].mcsIndex;
2251       redundancyVer    = sib1PdcchInfo->sib1DlDci.pdschCfg->codeword[0].rvIndex;
2252       sysInfoInd       = 0;           /* 0 for SIB1; 1 for SI messages */
2253       reserved         = 0;
2254
2255       /* Reversing bits in each DCI field */
2256       freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2257       timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2258       VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2259       modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2260       redundancyVer    = reverseBits(redundancyVer, redundancyVerSize);
2261       sysInfoInd       = reverseBits(sysInfoInd, sysInfoIndSize);
2262       reserved         = reverseBits(reserved, reservedSize);
2263
2264      /* Calulating total number of bytes in buffer */
2265      dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2266               + VRB2PRBMapSize + modNCodSchemeSize + redundancyVerSize\
2267               + sysInfoIndSize + reservedSize;
2268
2269      numBytes = dlDciPtr->payloadSizeBits / 8;
2270      if(dlDciPtr->payloadSizeBits % 8)
2271         numBytes += 1;
2272
2273      if(numBytes > DCI_PAYLOAD_BYTE_LEN)
2274      {
2275         DU_LOG("\nLOWER MAC : Total bytes for DCI is more than expected");
2276         return;
2277      }
2278
2279      /* Initialize buffer */
2280      for(bytePos = 0; bytePos < numBytes; bytePos++)
2281         dlDciPtr->payload[bytePos] = 0;
2282
2283      bytePos = numBytes - 1;
2284      bitPos = 0;
2285
2286      /* Packing DCI format fields */
2287      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2288         freqDomResAssign, freqDomResAssignSize);
2289      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2290         timeDomResAssign, timeDomResAssignSize);
2291      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2292         VRB2PRBMap, VRB2PRBMapSize);
2293      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2294         modNCodScheme, modNCodSchemeSize);
2295      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2296         redundancyVer, redundancyVerSize);
2297      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2298         sysInfoInd, sysInfoIndSize);
2299      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2300         reserved, reservedSize);
2301
2302    }
2303 } /* fillDlDciPdu */
2304
2305 /*******************************************************************
2306  *
2307  * @brief fills PDCCH PDU required for DL TTI info in MAC
2308  *
2309  * @details
2310  *
2311  *    Function : fillPdcchPdu
2312  *
2313  *    Functionality:
2314  *         -Fills the Pdcch PDU info
2315  *          stored in MAC
2316  *
2317  * @params[in] Pointer to FAPI DL TTI Req
2318  *             Pointer to Sib1PdcchCfg
2319  *             Pointer to msgLen of DL TTI Info
2320  * @return ROK
2321  *
2322  ******************************************************************/
2323
2324 S16 fillPdcchPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, Sib1PdcchCfg *sib1PdcchInfo,
2325 uint32_t *msgLen)
2326 {
2327     if(dlTtiReqPdu != NULLP)
2328     {
2329        dlTtiReqPdu->pduType = PDCCH_PDU_TYPE;
2330        dlTtiReqPdu->u.pdcch_pdu.bwpSize = sib1PdcchInfo->sib1PdcchBwpCfg.BWPSize;
2331        dlTtiReqPdu->u.pdcch_pdu.bwpPart = sib1PdcchInfo->sib1PdcchBwpCfg.BWPStart;
2332        dlTtiReqPdu->u.pdcch_pdu.subCarrierSpacing = sib1PdcchInfo->sib1PdcchBwpCfg.subcarrierSpacing; 
2333        dlTtiReqPdu->u.pdcch_pdu.cyclicPrefix = sib1PdcchInfo->sib1PdcchBwpCfg.cyclicPrefix; 
2334        dlTtiReqPdu->u.pdcch_pdu.startSymbolIndex = sib1PdcchInfo->sib1Coreset0Cfg.startSymbolIndex;
2335        dlTtiReqPdu->u.pdcch_pdu.durationSymbols = sib1PdcchInfo->sib1Coreset0Cfg.durationSymbols;
2336        memcpy(dlTtiReqPdu->u.pdcch_pdu.freqDomainResource, sib1PdcchInfo->sib1Coreset0Cfg.freqDomainResource, 6);
2337        dlTtiReqPdu->u.pdcch_pdu.cceRegMappingType = sib1PdcchInfo->sib1Coreset0Cfg.cceRegMappingType;
2338        dlTtiReqPdu->u.pdcch_pdu.regBundleSize = sib1PdcchInfo->sib1Coreset0Cfg.regBundleSize;
2339        dlTtiReqPdu->u.pdcch_pdu.interleaverSize = sib1PdcchInfo->sib1Coreset0Cfg.interleaverSize;
2340        dlTtiReqPdu->u.pdcch_pdu.coreSetSize = sib1PdcchInfo->sib1Coreset0Cfg.coreSetType;
2341        dlTtiReqPdu->u.pdcch_pdu.shiftIndex =  sib1PdcchInfo->sib1Coreset0Cfg.shiftIndex;
2342        dlTtiReqPdu->u.pdcch_pdu.precoderGranularity = sib1PdcchInfo->sib1Coreset0Cfg.precoderGranularity;
2343        dlTtiReqPdu->u.pdcch_pdu.numDlDci = sib1PdcchInfo->numDlDci;
2344 #ifdef INTEL_WLS       
2345        WLS_MEM_ALLOC(dlTtiReqPdu->u.pdcch_pdu.dlDci, sizeof(fapi_dl_dci_t));
2346 #else
2347        MAC_ALLOC(dlTtiReqPdu->u.pdcch_pdu.dlDci, sizeof(fapi_dl_dci_t));
2348 #endif
2349        fillDlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, sib1PdcchInfo);
2350        dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdcch_pdu_t);
2351        SETLENGTH(*msgLen, sizeof(fapi_dl_pdcch_pdu_t));
2352
2353     }
2354     return ROK;
2355
2356 }
2357
2358 /*******************************************************************
2359  *
2360  * @brief fills PDSCH PDU required for DL TTI info in MAC
2361  *
2362  * @details
2363  *
2364  *    Function : fillPdschPdu
2365  *
2366  *    Functionality:
2367  *         -Fills the Pdsch PDU info
2368  *          stored in MAC
2369  *
2370  * @params[in] Pointer to FAPI DL TTI Req
2371  *             Pointer to Sib1PdschCfg
2372  *             Pointer to msgLen of DL TTI Info
2373  * @return ROK
2374  *
2375  ******************************************************************/
2376
2377 void fillPdschPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, Sib1PdschCfg *sib1PdschInfo,
2378 uint32_t *msgLen)
2379 {
2380     uint8_t idx;
2381
2382     if(dlTtiReqPdu != NULLP)
2383     {
2384        dlTtiReqPdu->pduType = PDSCH_PDU_TYPE;
2385        dlTtiReqPdu->u.pdsch_pdu.pduBitMap = sib1PdschInfo->pduBitmap;
2386        dlTtiReqPdu->u.pdsch_pdu.rnti = sib1PdschInfo->rnti;         
2387        dlTtiReqPdu->u.pdsch_pdu.pduIndex = sib1PdschInfo->pduIndex;
2388        dlTtiReqPdu->u.pdsch_pdu.bwpSize = sib1PdschInfo->sib1PdschBwpCfg.BWPSize;       
2389        dlTtiReqPdu->u.pdsch_pdu.bwpStart = sib1PdschInfo->sib1PdschBwpCfg.BWPStart;
2390        dlTtiReqPdu->u.pdsch_pdu.subCarrierSpacing = sib1PdschInfo->sib1PdschBwpCfg.subcarrierSpacing;
2391        dlTtiReqPdu->u.pdsch_pdu.cyclicPrefix = sib1PdschInfo->sib1PdschBwpCfg.cyclicPrefix;
2392        dlTtiReqPdu->u.pdsch_pdu.nrOfCodeWords = sib1PdschInfo->numCodewords;
2393        for(idx = 0; idx < MAX_CODEWORDS ; idx++)
2394        { 
2395           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].targetCodeRate = sib1PdschInfo->codeword[idx].targetCodeRate;
2396           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].qamModOrder = sib1PdschInfo->codeword[idx].qamModOrder;
2397           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].mcsIndex = sib1PdschInfo->codeword[idx].mcsIndex;
2398           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].mcsTable = sib1PdschInfo->codeword[idx].mcsTable;
2399           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].rvIndex = sib1PdschInfo->codeword[idx].rvIndex;
2400           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].tbSize = sib1PdschInfo->codeword[idx].tbSize;
2401        }
2402        dlTtiReqPdu->u.pdsch_pdu.dataScramblingId = sib1PdschInfo->dataScramblingId;       
2403        dlTtiReqPdu->u.pdsch_pdu.nrOfLayers = sib1PdschInfo->numLayers;
2404        dlTtiReqPdu->u.pdsch_pdu.transmissionScheme = sib1PdschInfo->transmissionScheme;
2405        dlTtiReqPdu->u.pdsch_pdu.refPoint = sib1PdschInfo->refPoint;
2406        dlTtiReqPdu->u.pdsch_pdu.dlDmrsSymbPos = sib1PdschInfo->dmrs.dlDmrsSymbPos;
2407        dlTtiReqPdu->u.pdsch_pdu.dmrsConfigType = sib1PdschInfo->dmrs.dmrsConfigType;
2408        dlTtiReqPdu->u.pdsch_pdu.dlDmrsScramblingId = sib1PdschInfo->dmrs.dlDmrsScramblingId;
2409        dlTtiReqPdu->u.pdsch_pdu.scid = sib1PdschInfo->dmrs.scid;
2410        dlTtiReqPdu->u.pdsch_pdu.numDmrsCdmGrpsNoData = sib1PdschInfo->dmrs.numDmrsCdmGrpsNoData;
2411        dlTtiReqPdu->u.pdsch_pdu.dmrsPorts = sib1PdschInfo->dmrs.dmrsPorts;
2412        dlTtiReqPdu->u.pdsch_pdu.resourceAlloc = sib1PdschInfo->sib1FreqAlloc.resourceAlloc;
2413        /* since we are using type-1, hence rbBitmap excluded */
2414        dlTtiReqPdu->u.pdsch_pdu.rbStart = sib1PdschInfo->sib1FreqAlloc.rbStart;
2415        dlTtiReqPdu->u.pdsch_pdu.rbSize = sib1PdschInfo->sib1FreqAlloc.rbSize;
2416        dlTtiReqPdu->u.pdsch_pdu.vrbToPrbMapping = sib1PdschInfo->sib1FreqAlloc.vrbPrbMapping;
2417        dlTtiReqPdu->u.pdsch_pdu.startSymbIndex = sib1PdschInfo->sib1TimeAlloc.startSymbolIndex;
2418        dlTtiReqPdu->u.pdsch_pdu.nrOfSymbols = sib1PdschInfo->sib1TimeAlloc.numSymbols;
2419        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.numPrgs = sib1PdschInfo->beamPdschInfo.numPrgs;
2420        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.prgSize = sib1PdschInfo->beamPdschInfo.prgSize;
2421        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.digBfInterfaces = sib1PdschInfo->beamPdschInfo.digBfInterfaces;
2422        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2423           pmIdx = sib1PdschInfo->beamPdschInfo.prg[0].pmIdx;
2424        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2425           beamIdx[0].beamidx = sib1PdschInfo->beamPdschInfo.prg[0].beamIdx[0];
2426        dlTtiReqPdu->u.pdsch_pdu.powerControlOffset = sib1PdschInfo->txPdschPower.powerControlOffset;  
2427        dlTtiReqPdu->u.pdsch_pdu.powerControlOffsetSS = sib1PdschInfo->txPdschPower.powerControlOffsetSS;
2428        dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdsch_pdu_t);
2429        SETLENGTH(*msgLen, sizeof(fapi_dl_pdsch_pdu_t));
2430
2431     }
2432
2433 }
2434
2435 /***********************************************************************
2436  *
2437  * @brief calculates the total size to be allocated for DL TTI Req
2438  *
2439  * @details
2440  *
2441  *    Function : calculatePduCount
2442  *
2443  *    Functionality:
2444  *         -calculates the total pdu count to be allocated for DL TTI Req
2445  *
2446  * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
2447  * @return count
2448  *
2449  * ********************************************************************/
2450 uint8_t calculatePduCount(DlBrdcstAlloc *cellBroadcastInfo)
2451 {
2452    uint8_t count = 0;
2453    uint8_t idx = 0;
2454    if(cellBroadcastInfo->ssbTrans)
2455    {
2456       for(idx = 0; idx < cellBroadcastInfo->ssbIdxSupported; idx++)
2457       {
2458          count++;
2459       }
2460    }
2461    if(cellBroadcastInfo->sib1Trans)
2462    {
2463       count += 2;
2464    }
2465    return count;
2466 }
2467
2468 #endif
2469
2470 /*******************************************************************
2471  *
2472  * @brief Sends DL TTI Request to PHY
2473  *
2474  * @details
2475  *
2476  *    Function : handleDlTtiReq
2477  *
2478  *    Functionality:
2479  *         -Sends FAPI Param req to PHY
2480  *
2481  * @params[in]    RgDlSf *dlTtiReqSlot
2482  * @return ROK     - success
2483  *         RFAILED - failure
2484  *
2485  * ****************************************************************/
2486 S16 handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
2487 {
2488 #ifdef FAPI
2489         uint8_t idx;
2490         uint8_t nPdu = 0;
2491         uint8_t numPduEncoded = 0;
2492         uint32_t msgLen = 0;
2493         fapi_dl_tti_req_t *dlTtiReq = NULLP;
2494         fapi_dl_tti_req_pdu_t *dlTtiReqPdu = NULLP;
2495         RgCellCb  *cellCbParams = NULLP;
2496         MacDlSlot *currDlSlot = NULLP;
2497         MacCellCfg macCellCfg;
2498         memset(&macCellCfg, 0, sizeof(MacCellCfg));
2499         Inst inst = 0;
2500
2501         if(clGlobalCp.phyState == PHY_STATE_RUNNING)
2502         {
2503                 cellCbParams = rgCb[inst].cell;
2504                 macCellCfg = cellCbParams->macCellCfg;
2505
2506                 if(dlTtiReqtimingInfo != NULLP)
2507                 {
2508 #ifdef INTEL_WLS
2509                         WLS_MEM_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
2510 #else
2511                         MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
2512 #endif
2513                         if(dlTtiReq != NULLP)
2514                         {
2515                                 dlTtiReq->sfn = dlTtiReqtimingInfo->sfn;
2516                                 dlTtiReq->slot = dlTtiReqtimingInfo->slot;
2517                                 currDlSlot = &macCb.macCell->dlSlot[dlTtiReq->slot % MAX_SLOT_SUPPORTED];
2518                                 dlTtiReq->nPdus = calculatePduCount(&currDlSlot->cellBroadcastInfo);  /* get total Pdus */
2519                                 nPdu = dlTtiReq->nPdus;
2520                                 dlTtiReq->nGroup = 0;
2521                                 if(dlTtiReq->nPdus > 0)
2522                                 {
2523 #ifdef INTEL_WLS
2524                                         WLS_MEM_ALLOC(dlTtiReqPdu, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
2525 #else
2526                                         MAC_ALLOC(dlTtiReqPdu, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
2527 #endif
2528                                         if(currDlSlot->cellBroadcastInfo.ssbTrans)
2529                                         {
2530                                                 if(dlTtiReqPdu != NULLP)
2531                                                 {
2532                                                         for(idx = 0; idx < currDlSlot->cellBroadcastInfo.ssbIdxSupported; idx++)
2533                                                         {
2534                                                                 if(idx > 0)
2535                                                                         dlTtiReq->pdus++;
2536                                                                 fillSsbPdu(dlTtiReqPdu, &macCellCfg, currDlSlot, &msgLen, idx);
2537                                                                 dlTtiReq->pdus = dlTtiReqPdu;
2538                                                                 numPduEncoded++;
2539                                                         }
2540                                                 }
2541                                         }
2542                                         if(currDlSlot->cellBroadcastInfo.sib1Trans)
2543                                         {
2544                                                 /* Filling SIB1 param */
2545                                                 if(dlTtiReqPdu != NULLP)
2546                                                 {
2547                                                         if(numPduEncoded != nPdu)
2548                                                         {
2549                                                                 dlTtiReq->pdus++;
2550                                                                 dlTtiReqPdu = dlTtiReq->pdus;
2551                                                                 fillPdcchPdu(dlTtiReqPdu, &currDlSlot->cellBroadcastInfo.\
2552                                                                                 sib1Alloc.sib1PdcchCfg, &msgLen);
2553                                                                 dlTtiReq->pdus = dlTtiReqPdu;
2554                                                                 numPduEncoded++;
2555                                                                 dlTtiReq->pdus++;
2556                                                                 dlTtiReqPdu = dlTtiReq->pdus;
2557                                                                 fillPdschPdu(dlTtiReqPdu,&currDlSlot->cellBroadcastInfo.\
2558                                                                                 sib1Alloc.sib1PdschCfg, &msgLen);
2559                                                                 dlTtiReq->pdus = dlTtiReqPdu;
2560                                                                 numPduEncoded++;
2561                                                         }
2562                                                 }
2563                                         }
2564                                         msgLen += sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
2565                                         fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
2566                                         /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
2567                                         LwrMacSendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
2568                                         if(currDlSlot->cellBroadcastInfo.sib1Trans)
2569                                         {
2570                                                 if(currDlSlot->cellBroadcastInfo.ssbTrans)
2571                                                 {
2572
2573                                                         MAC_FREE(dlTtiReq->pdus[1].u.pdcch_pdu.dlDci, 
2574                                                                         sizeof(fapi_dl_dci_t));
2575                                                 }
2576                                                 else
2577                                                 {
2578
2579                                                         MAC_FREE(dlTtiReq->pdus[0].u.pdcch_pdu.dlDci, 
2580                                                                         sizeof(fapi_dl_dci_t));
2581                                                 }
2582                                         }
2583
2584                                         MAC_FREE(dlTtiReqPdu, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
2585                                 }
2586                                 else
2587                                 {
2588                                         msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
2589                                         fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
2590                                         /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
2591                                         LwrMacSendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
2592                                 }
2593                                 MAC_FREE(dlTtiReq, sizeof(fapi_dl_tti_req_t));
2594                                 return ROK;
2595                         }
2596                         else
2597                         {
2598                                 DU_LOG("\nLOWER MAC: Failed to allocate memory for DL TTI Request");
2599                                 return RFAILED;
2600                         }
2601                 }
2602       else
2603       {
2604          DU_LOG("\nLOWER MAC: Current TTI Info is NULL");
2605          return RFAILED;
2606       }
2607    }
2608    else
2609    {
2610        lwr_mac_handleInvalidEvt(dlTtiReqtimingInfo);
2611    }
2612 #endif
2613    return ROK;
2614 }
2615
2616 /***********************************************************************
2617  *
2618  * @brief calculates the total size to be allocated for UL TTI Req
2619  *
2620  * @details
2621  *
2622  *    Function : getnPdus
2623  *
2624  *    Functionality:
2625  *         -calculates the total pdu count to be allocated for UL TTI Req
2626  *
2627  * @params[in] Pointer to fapi Ul TTI Req
2628  *             Pointer to CurrUlSlot
2629  * @return count
2630  * ********************************************************************/
2631 #ifdef FAPI
2632 uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
2633 {
2634         uint8_t pduCount = 0;
2635
2636         if(currUlSlot != NULLP)
2637    {
2638            if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_PRACH)
2639            {
2640               pduCount++;
2641               ulTtiReq->rachPresent = PDU_PRESENT;
2642                 }
2643                 if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
2644                 {
2645                    pduCount++;
2646                         ulTtiReq->nUlsch = PDU_PRESENT;
2647                 }
2648                 if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_UCI)
2649                 {
2650                    pduCount++;
2651                         ulTtiReq->nUlcch = PDU_PRESENT;
2652                 }
2653                 if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_SRS)
2654                 {
2655                    pduCount++;
2656                 }
2657    }
2658         return pduCount;
2659
2660 #endif  
2661
2662 /***********************************************************************
2663  *
2664  * @brief Set the value of zero correlation config in PRACH PDU
2665  *
2666  * @details
2667  *
2668  *    Function : setNumCs
2669  *
2670  *    Functionality:
2671  *         -Set the value of zero correlation config in PRACH PDU
2672  *
2673  * @params[in] Pointer to zero correlation config
2674  *             Pointer to MacCellCfg
2675  * ********************************************************************/
2676
2677 void setNumCs(uint8_t *numCs, MacCellCfg *macCellCfg)
2678 {
2679 #ifdef FAPI
2680    uint8_t idx;
2681         if(macCellCfg != NULLP)
2682         {
2683            idx = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
2684            *numCs = UnrestrictedSetNcsTable[idx];
2685         }
2686 #endif
2687 }
2688
2689 /***********************************************************************
2690  *
2691  * @brief Fills the PRACH PDU in UL TTI Request
2692  *
2693  * @details
2694  *
2695  *    Function : fillPrachPdu
2696  *
2697  *    Functionality:
2698  *         -Fills the PRACH PDU in UL TTI Request
2699  *
2700  * @params[in] Pointer to Prach Pdu
2701  *             Pointer to CurrUlSlot
2702  *             Pointer to macCellCfg
2703  *             Pointer to msgLen
2704  * ********************************************************************/
2705
2706 #ifdef FAPI
2707 void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot, uint32_t *msgLen)
2708 {
2709    if(ulTtiReqPdu != NULLP)
2710    {
2711       ulTtiReqPdu->pduType = PRACH_PDU_TYPE; 
2712       ulTtiReqPdu->u.prach_pdu.physCellId = macCellCfg->phyCellId;
2713       ulTtiReqPdu->u.prach_pdu.numPrachOcas = currUlSlot->ulCellInfo.prachSchInfo.numPrachOcas;
2714       ulTtiReqPdu->u.prach_pdu.prachFormat = \
2715                 currUlSlot->ulCellInfo.prachSchInfo.prachFormat;
2716       ulTtiReqPdu->u.prach_pdu.numRa = currUlSlot->ulCellInfo.prachSchInfo.numRa;
2717       ulTtiReqPdu->u.prach_pdu.prachStartSymbol = \
2718                 currUlSlot->ulCellInfo.prachSchInfo.prachStartSymb;
2719       setNumCs(&ulTtiReqPdu->u.prach_pdu.numCs, macCellCfg);
2720       ulTtiReqPdu->u.prach_pdu.beamforming.numPrgs = 0;
2721       ulTtiReqPdu->u.prach_pdu.beamforming.prgSize = 0;
2722       ulTtiReqPdu->u.prach_pdu.beamforming.digBfInterfaces = 0;
2723       ulTtiReqPdu->u.prach_pdu.beamforming.pmi_bfi[0].pmIdx = 0;
2724       ulTtiReqPdu->u.prach_pdu.beamforming.pmi_bfi[0].beamIdx[0].beamidx = 0;
2725       ulTtiReqPdu->pduSize = sizeof(fapi_ul_prach_pdu_t); 
2726       SETLENGTH(*msgLen, sizeof(fapi_dl_pdsch_pdu_t));
2727    }
2728 }
2729 #endif
2730
2731 /*******************************************************************
2732  *
2733  * @brief Sends UL TTI Request to PHY
2734  *
2735  * @details
2736  *
2737  *    Function : handleUlTtiReq
2738  *
2739  *    Functionality:
2740  *         -Sends FAPI Param req to PHY
2741  *
2742  * @params[in]  Pointer to CmLteTimingInfo
2743  * @return ROK     - success
2744  *         RFAILED - failure
2745  *
2746  ******************************************************************/
2747 S16 handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
2748 {
2749 #ifdef FAPI
2750    uint32_t msgLen = 0;
2751    fapi_ul_tti_req_t *ulTtiReq = NULLP;
2752    fapi_ul_tti_req_pdu_t *ulTtiReqPdu = NULLP;
2753    RgCellCb  *cellCbParams = NULLP;
2754    MacUlSlot *currUlSlot = NULLP;
2755    MacCellCfg macCellCfg;
2756         memset(&macCellCfg, 0, sizeof(MacCellCfg));
2757    Inst inst = 0;
2758
2759    if(clGlobalCp.phyState == PHY_STATE_RUNNING)
2760    {
2761       cellCbParams = rgCb[inst].cell;
2762       macCellCfg = cellCbParams->macCellCfg;
2763
2764       if(currTimingInfo != NULLP)
2765       {
2766 #ifdef INTEL_WLS
2767          WLS_MEM_ALLOC(ulTtiReq, sizeof(fapi_ul_tti_req_t));
2768 #else
2769          MAC_ALLOC(ulTtiReq, sizeof(fapi_ul_tti_req_t));
2770 #endif
2771          if(ulTtiReq != NULLP)
2772          {
2773             ulTtiReq->sfn = currTimingInfo->sfn;
2774             ulTtiReq->slot = currTimingInfo->slot;
2775             currUlSlot = &macCb.macCell->ulSlot[ulTtiReq->slot % MAX_SLOT_SUPPORTED];
2776                  ulTtiReq->nPdus = getnPdus(ulTtiReq, currUlSlot);
2777             ulTtiReq->nGroup = 0;
2778             if(ulTtiReq->nPdus > 0)
2779             {
2780 #ifdef INTEL_WLS
2781                WLS_MEM_ALLOC(ulTtiReqPdu, (ulTtiReq->nPdus * sizeof(fapi_ul_tti_req_pdu_t)));
2782 #else
2783                MAC_ALLOC(ulTtiReqPdu, (ulTtiReq->nPdus * sizeof(fapi_ul_tti_req_pdu_t)));
2784 #endif
2785                /* Fill Prach Pdu */
2786                if(ulTtiReq->rachPresent)
2787                {
2788                  if(ulTtiReqPdu != NULLP)
2789                  {
2790                     fillPrachPdu(ulTtiReqPdu, &macCellCfg, currUlSlot, &msgLen);
2791                     ulTtiReq->pdus = ulTtiReqPdu;
2792                  }
2793                  msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
2794                  fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
2795                  DU_LOG("\nLOWER MAC: Sending UL TTI Request");
2796                  LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgLen, (void *)ulTtiReq);
2797                                           MAC_FREE(ulTtiReqPdu, (ulTtiReq->nPdus * sizeof(fapi_ul_tti_req_pdu_t)));
2798                }
2799             } 
2800             else
2801             {
2802                 msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
2803                 fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
2804                 DU_LOG("\nLOWER MAC: Sending UL TTI Request");
2805                 LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgLen, (void *)ulTtiReq);
2806             }
2807                                 MAC_FREE(ulTtiReq, sizeof(fapi_ul_tti_req_t));
2808                                 return ROK;
2809          }
2810               else
2811               {
2812                  DU_LOG("\nLOWER MAC: Failed to allocate memory for UL TTI Request");
2813             return RFAILED;
2814          }
2815       }
2816       else
2817       {
2818          DU_LOG("\nLOWER MAC: Current TTI Info in UL is NULL");
2819          return RFAILED;
2820       }
2821    }
2822    else
2823    {
2824        lwr_mac_handleInvalidEvt(currTimingInfo);
2825    }
2826 #endif
2827    return ROK;
2828 }
2829
2830 lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
2831 {
2832    {
2833       /* PHY_STATE_IDLE */
2834        lwr_mac_handleParamReqEvt,
2835        lwr_mac_handleParamRspEvt,
2836        lwr_mac_handleConfigReqEvt,
2837        lwr_mac_handleConfigRspEvt,
2838        lwr_mac_handleInvalidEvt,
2839    },
2840    {
2841        /* PHY_STATE_CONFIGURED */
2842        lwr_mac_handleParamReqEvt,
2843        lwr_mac_handleParamRspEvt,
2844        lwr_mac_handleConfigReqEvt,
2845        lwr_mac_handleConfigRspEvt,
2846        lwr_mac_handleStartReqEvt,
2847    },
2848    {
2849        /* PHY_STATE_RUNNING */
2850        lwr_mac_handleInvalidEvt,
2851        lwr_mac_handleInvalidEvt,
2852        lwr_mac_handleConfigReqEvt,
2853        lwr_mac_handleConfigRspEvt,
2854        lwr_mac_handleInvalidEvt,
2855    }
2856 };
2857
2858 /*******************************************************************
2859  *
2860  * @brief Sends message to Lower Mac Fsm Event Handler
2861  *
2862  * @details
2863  *
2864  *    Function : sendToLowerMac
2865  *
2866  *    Functionality:
2867  *         -Sends message to LowerMac
2868  *
2869  * @params[in] Message Type
2870  *             Message Length
2871  *             Messaga Pointer
2872  *
2873  * @return void
2874  *
2875 ******************************************************************/
2876 void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg)
2877 {
2878    clGlobalCp.event = msgType;
2879    fapiEvtHdlr[clGlobalCp.phyState][clGlobalCp.event](msg);
2880 }
2881 /**********************************************************************
2882          End of file
2883 **********************************************************************/