Nanosleep for slot Ind, warning fixes, WLS changes, memory leak fixes
[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         LWR_MAC_ALLOC(paramReq, sizeof(fapi_param_req_t));
1326    if(paramReq != NULLP)
1327    {
1328       fillMsgHeader(&paramReq->header, FAPI_PARAM_REQUEST, msgLen);
1329       DU_LOG("\nLOWER MAC: Sending Param Request to Phy");
1330       LwrMacSendToPhy(paramReq->header.message_type_id, sizeof(fapi_param_req_t), (void *)paramReq);
1331       return ROK;
1332    }
1333    else
1334    {
1335       DU_LOG("\nLOWER MAC: Failed to allocate memory for Param Request");
1336       return RFAILED;
1337    }
1338 #else
1339    return ROK;
1340 #endif
1341 }
1342
1343  /*******************************************************************
1344   *
1345   * @brief Sends FAPI Param Response to MAC via PHY
1346   *
1347   * @details
1348   *
1349   *    Function : lwr_mac_handleParamRspEvt
1350   *
1351   *    Functionality:
1352   *         -Sends FAPI Param rsp to MAC via PHY
1353   *
1354   * @params[in]
1355   * @return ROK     - success
1356   *         RFAILED - failure
1357   *
1358   * ****************************************************************/
1359
1360 S16 lwr_mac_handleParamRspEvt(void *msg)
1361 {
1362 #ifdef FAPI
1363   /* stopGuardTimer(); */
1364    uint8_t index;
1365    uint32_t encodedVal;
1366         fapi_param_resp_t *paramRsp;
1367    ClCellParam *cellParam = NULLP;
1368
1369    paramRsp = (fapi_param_resp_t *)msg;
1370    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1371
1372    if(paramRsp != NULLP)
1373    {
1374       MAC_ALLOC(cellParam, sizeof(ClCellParam));
1375       if(cellParam != NULLP)
1376       {
1377          DU_LOG("\n LOWER MAC: Filling TLVS into MAC API");
1378          if(paramRsp->error_code == MSG_OK)
1379          {
1380             for(index = 0; index < paramRsp->number_of_tlvs; index++)
1381             {
1382                switch(paramRsp->tlvs[index].tl.tag)
1383                {
1384                   case FAPI_RELEASE_CAPABILITY_TAG:
1385                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1386                      if(encodedVal != RFAILED && (encodedVal & RELEASE_15) == RELEASE_15)
1387                      {
1388                         cellParam->releaseCapability = RELEASE_15;
1389                      }
1390                      break;
1391
1392                   case FAPI_PHY_STATE_TAG:
1393                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1394                      if(encodedVal != RFAILED && encodedVal != clGlobalCp.phyState)
1395                      {
1396                         printf("\n PhyState mismatch [%d][%d]", clGlobalCp.phyState, clGlobalCp.event);
1397                         RETVALUE(RFAILED);
1398                      }
1399                      break;
1400
1401                   case FAPI_SKIP_BLANK_DL_CONFIG_TAG:
1402                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1403                      if(encodedVal != RFAILED && encodedVal != 0)
1404                      {
1405                        cellParam->skipBlankDlConfig = SUPPORTED;
1406                      }
1407                      else
1408                      {
1409                        cellParam->skipBlankDlConfig = NOT_SUPPORTED;
1410                      }
1411                      break;
1412
1413                   case FAPI_SKIP_BLANK_UL_CONFIG_TAG:
1414                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1415                      if(encodedVal != RFAILED && encodedVal != 0)
1416                      {
1417                        cellParam->skipBlankUlConfig = SUPPORTED;
1418                      }
1419                      else
1420                      {
1421                        cellParam->skipBlankUlConfig = NOT_SUPPORTED;
1422                      }
1423                      break;
1424
1425                   case FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG:
1426                      cellParam->numTlvsToReport = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1427                      break;
1428
1429                   case FAPI_CYCLIC_PREFIX_TAG:
1430                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1431                      if(encodedVal != RFAILED)
1432                      {
1433                         fillCyclicPrefix(encodedVal, &cellParam);
1434                      }
1435                      break;
1436
1437                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG:
1438                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1439                      if(encodedVal != RFAILED)
1440                      {
1441                         fillSubcarrierSpaceDl(encodedVal, &cellParam);
1442                      }
1443                      break;
1444
1445                   case FAPI_SUPPORTED_BANDWIDTH_DL_TAG:
1446                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1447                      if(encodedVal != RFAILED)
1448                      {
1449                         fillBandwidthDl(encodedVal, &cellParam);
1450                      }
1451                      break;
1452
1453                   case FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG:
1454                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1455                      if(encodedVal != RFAILED)
1456                      {
1457                         fillSubcarrierSpaceUl(encodedVal, &cellParam);
1458                      }
1459                      break;
1460
1461                   case FAPI_SUPPORTED_BANDWIDTH_UL_TAG:
1462                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_16);
1463                      if(encodedVal != RFAILED)
1464                      {
1465                         fillBandwidthUl(encodedVal, &cellParam);
1466                      }
1467                      break;
1468
1469                   case FAPI_CCE_MAPPING_TYPE_TAG:
1470                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1471                      if(encodedVal != RFAILED)
1472                      {
1473                         fillCCEmaping(encodedVal, &cellParam);
1474                      }
1475                      break;
1476
1477                   case FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG:
1478                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1479                      if(encodedVal != RFAILED && encodedVal != 0)
1480                      {
1481                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = SUPPORTED;
1482                      }
1483                      else
1484                      {
1485                         cellParam->coresetOutsideFirst3OfdmSymsOfSlot = NOT_SUPPORTED;
1486                      }
1487                      break;
1488
1489                   case FAPI_PRECODER_GRANULARITY_CORESET_TAG:
1490                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1491                      if(encodedVal != RFAILED && encodedVal != 0)
1492                      {
1493                         cellParam->precoderGranularityCoreset = SUPPORTED;
1494                      }
1495                      else
1496                      {
1497                         cellParam->precoderGranularityCoreset = NOT_SUPPORTED;
1498                      }
1499                      break;
1500
1501                   case FAPI_PDCCH_MU_MIMO_TAG:
1502                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1503                      if(encodedVal != RFAILED && encodedVal != 0)
1504                      {
1505                         cellParam->pdcchMuMimo = SUPPORTED;
1506                      }
1507                      else
1508                      {
1509                         cellParam->pdcchMuMimo = NOT_SUPPORTED;
1510                      }
1511                      break;
1512
1513                   case FAPI_PDCCH_PRECODER_CYCLING_TAG:
1514                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1515                      if(encodedVal != RFAILED && encodedVal != 0)
1516                      {
1517                         cellParam->pdcchPrecoderCycling = SUPPORTED;
1518                      }
1519                      else
1520                      {
1521                         cellParam->pdcchPrecoderCycling = NOT_SUPPORTED;
1522                      }
1523                      break;
1524
1525                   case FAPI_MAX_PDCCHS_PER_SLOT_TAG:
1526                      cellParam->maxPdcchsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1527                      break;
1528
1529                   case FAPI_PUCCH_FORMATS_TAG:
1530                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1531                      if(encodedVal != RFAILED)
1532                      {
1533                         fillPucchFormat(encodedVal, &cellParam);
1534                      }
1535                      break;
1536
1537                   case FAPI_MAX_PUCCHS_PER_SLOT_TAG:
1538                        cellParam->maxPucchsPerSlot   = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1539                      break;
1540
1541                   case FAPI_PDSCH_MAPPING_TYPE_TAG:
1542                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1543                      if(encodedVal != RFAILED)
1544                      {
1545                         fillPdschMappingType(encodedVal, &cellParam);
1546                      }
1547                      break;
1548
1549                   case FAPI_PDSCH_ALLOCATION_TYPES_TAG:
1550                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1551                      if(encodedVal != RFAILED)
1552                      {
1553                         fillPdschAllocationType(encodedVal, &cellParam);
1554                      }
1555                      break;
1556
1557                   case FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG:
1558                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1559                      if(encodedVal != RFAILED)
1560                      {
1561                         fillPrbMappingType(encodedVal, &cellParam);
1562                      }
1563                      break;
1564
1565                   case FAPI_PDSCH_CBG_TAG:
1566                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1567                      if(encodedVal != RFAILED && encodedVal != 0)
1568                      {
1569                         cellParam->pdschCbg = SUPPORTED;
1570                      }
1571                      else
1572                      {
1573                         cellParam->pdschCbg = NOT_SUPPORTED;
1574                      }
1575                      break;
1576
1577                   case FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG:
1578                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1579                      if(encodedVal != RFAILED)
1580                      {
1581                         fillPdschDmrsConfigType(encodedVal, &cellParam);
1582                      }
1583                      break;
1584
1585                   case FAPI_PDSCH_DMRS_MAX_LENGTH_TAG:
1586                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1587                      if(encodedVal != RFAILED)
1588                      {
1589                         fillPdschDmrsLength(encodedVal, &cellParam);
1590                      }
1591                      break;
1592
1593                   case FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG:
1594                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1595                      if(encodedVal != RFAILED)
1596                      {
1597                         fillPdschDmrsAddPos(encodedVal, &cellParam);
1598                      }
1599                      break;
1600
1601                   case FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG:
1602                      cellParam->maxPdschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1603                      break;
1604
1605                   case FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG:
1606                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1607                      if(encodedVal != RFAILED && encodedVal < FAPI_MAX_NUMBERMIMO_LAYERS_PDSCH)
1608                      {
1609                         cellParam->maxNumberMimoLayersPdsch   = encodedVal;
1610                      }
1611                      break;
1612
1613                   case FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG:
1614                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1615                      if(encodedVal != RFAILED)
1616                      {
1617                         fillModulationOrderDl(encodedVal, &cellParam);
1618                      }
1619                      break;
1620
1621                   case FAPI_MAX_MU_MIMO_USERS_DL_TAG:
1622                      cellParam->maxMuMimoUsersDl         = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1623                      break;
1624
1625                   case FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG:
1626                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1627                      if(encodedVal != RFAILED && encodedVal != 0)
1628                      {
1629                         cellParam->pdschDataInDmrsSymbols = SUPPORTED;
1630                      }
1631                      else
1632                      {
1633                         cellParam->pdschDataInDmrsSymbols = NOT_SUPPORTED;
1634                      }
1635                      break;
1636
1637                   case FAPI_PREMPTIONSUPPORT_TAG:
1638                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1639                      if(encodedVal != RFAILED && encodedVal != 0)
1640                      {
1641                         cellParam->premptionSupport = SUPPORTED;
1642                      }
1643                      else
1644                      {
1645                         cellParam->premptionSupport = NOT_SUPPORTED;
1646                      }
1647                      break;
1648
1649                   case FAPI_PDSCH_NON_SLOT_SUPPORT_TAG:
1650                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1651                      if(encodedVal != RFAILED && encodedVal != 0)
1652                      {
1653                         cellParam->pdschNonSlotSupport = SUPPORTED;
1654                      }
1655                      else
1656                      {
1657                         cellParam->pdschNonSlotSupport = NOT_SUPPORTED;
1658                      }
1659                      break;
1660
1661                   case FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG:
1662                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1663                      if(encodedVal != RFAILED && encodedVal != 0)
1664                      {
1665                         cellParam->uciMuxUlschInPusch = SUPPORTED;
1666                      }
1667                      else
1668                      {
1669                         cellParam->uciMuxUlschInPusch = NOT_SUPPORTED;
1670                      }
1671                      break;
1672
1673                   case FAPI_UCI_ONLY_PUSCH_TAG:
1674                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1675                      if(encodedVal != RFAILED && encodedVal != 0)
1676                      {
1677                         cellParam->uciOnlyPusch = SUPPORTED;
1678                      }
1679                      else
1680                      {
1681                         cellParam->uciOnlyPusch = NOT_SUPPORTED;
1682                      }
1683                      break;
1684
1685                   case FAPI_PUSCH_FREQUENCY_HOPPING_TAG:
1686                      encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1687                      if(encodedVal != RFAILED && encodedVal != 0)
1688                      {
1689                         cellParam->puschFrequencyHopping = SUPPORTED;
1690                      }
1691                      else
1692                      {
1693                         cellParam->puschFrequencyHopping = NOT_SUPPORTED;
1694                      }
1695                      break;
1696
1697                  case FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG:
1698                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1699                     if(encodedVal != RFAILED)
1700                     {
1701                        fillPuschDmrsConfig(encodedVal, &cellParam);
1702                     }
1703                     break;
1704
1705                  case FAPI_PUSCH_DMRS_MAX_LEN_TAG:
1706                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1707                     if(encodedVal != RFAILED)
1708                     {
1709                        fillPuschDmrsLength(encodedVal, &cellParam);
1710                     }
1711                     break;
1712
1713                  case FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG:
1714                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1715                     if(encodedVal != RFAILED)
1716                     {
1717                        fillPuschDmrsAddPos(encodedVal, &cellParam);
1718                     }
1719                     break;
1720
1721                  case FAPI_PUSCH_CBG_TAG:
1722                     encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1723                     if(encodedVal != RFAILED && encodedVal != 0)
1724                     {
1725                        cellParam->puschCbg = SUPPORTED;
1726                     }
1727                     else
1728                     {
1729                        cellParam->puschCbg = NOT_SUPPORTED;
1730                     }
1731                     break;
1732
1733                 case FAPI_PUSCH_MAPPING_TYPE_TAG:
1734                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1735                    if(encodedVal != RFAILED)
1736                    {
1737                       fillPuschMappingType(encodedVal, &cellParam);
1738                    }
1739                    break;
1740
1741                 case FAPI_PUSCH_ALLOCATION_TYPES_TAG:
1742                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1743                    if(encodedVal != RFAILED)
1744                    {
1745                       fillPuschAllocationType(encodedVal, &cellParam);
1746                    }
1747                    break;
1748
1749                 case FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG:
1750                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1751                    if(encodedVal != RFAILED)
1752                    {
1753                       fillPuschPrbMappingType(encodedVal, &cellParam);
1754                    }
1755                    break;
1756
1757                 case FAPI_PUSCH_MAX_PTRS_PORTS_TAG:
1758                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1759                    if(encodedVal != RFAILED && encodedVal < FAPI_PUSCH_MAX_PTRS_PORTS_UB)
1760                    {
1761                 cellParam->puschMaxPtrsPorts = encodedVal;
1762                    }
1763                    break;
1764
1765                 case FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG:
1766                    cellParam->maxPduschsTBsPerSlot = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1767                    break;
1768
1769                 case FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG:
1770                    cellParam->maxNumberMimoLayersNonCbPusch = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1771                    break;
1772
1773                 case FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG:
1774                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1775                    if(encodedVal != RFAILED)
1776                    {
1777                       fillModulationOrderUl(encodedVal, &cellParam);
1778                    }
1779                    break;
1780
1781                 case FAPI_MAX_MU_MIMO_USERS_UL_TAG:
1782                    cellParam->maxMuMimoUsersUl = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1783                    break;
1784
1785                 case FAPI_DFTS_OFDM_SUPPORT_TAG:
1786                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1787                    if(encodedVal != RFAILED && encodedVal != 0)
1788                    {
1789                       cellParam->dftsOfdmSupport = SUPPORTED;
1790                    }
1791                    else
1792                    {
1793                       cellParam->dftsOfdmSupport = NOT_SUPPORTED;
1794                    }
1795                    break;
1796
1797                 case FAPI_PUSCH_AGGREGATION_FACTOR_TAG:
1798                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1799                    if(encodedVal != RFAILED)
1800                    {
1801                       fillPuschAggregationFactor(encodedVal, &cellParam);
1802                    }
1803                    break;
1804
1805                 case FAPI_PRACH_LONG_FORMATS_TAG:
1806                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1807                    if(encodedVal != RFAILED)
1808                    {
1809                       fillPrachLongFormat(encodedVal, &cellParam);
1810                    }
1811                    break;
1812
1813                 case FAPI_PRACH_SHORT_FORMATS_TAG:
1814                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1815                    if(encodedVal != RFAILED)
1816                    {
1817                       fillPrachShortFormat(encodedVal, &cellParam);
1818                    }
1819                    break;
1820
1821                 case FAPI_PRACH_RESTRICTED_SETS_TAG:
1822                    encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1823                    if(encodedVal != RFAILED && encodedVal != 0)
1824                    {
1825                       cellParam->prachRestrictedSets = SUPPORTED;
1826                    }
1827                    else
1828                    {
1829                       cellParam->prachRestrictedSets = NOT_SUPPORTED;
1830                    }
1831                    break;
1832
1833                case FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG:
1834                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1835                   if(encodedVal != RFAILED)
1836                   {
1837                      fillFdOccasions(encodedVal, &cellParam);
1838                   }
1839                   break;
1840
1841                case FAPI_RSSI_MEASUREMENT_SUPPORT_TAG:
1842                   encodedVal = getParamValue(&paramRsp->tlvs[index], FAPI_UINT_8);
1843                   if(encodedVal != RFAILED)
1844                   {
1845                      fillRssiMeas(encodedVal, &cellParam);
1846                   }
1847                   break;
1848                default:
1849                //printf("\n Invalid value for TLV[%x] at index[%d]", paramRsp->tlvs[index].tl.tag, index);
1850                                         break;
1851               }
1852            }
1853            MAC_FREE(cellParam, sizeof(ClCellParam));
1854            sendToLowerMac(FAPI_CONFIG_REQUEST, 0, (void *)NULL);
1855            return ROK;
1856          }
1857          else
1858          {
1859             DU_LOG("\n LOWER MAC: Invalid error code %d", paramRsp->error_code);
1860             return RFAILED;
1861          }
1862      }
1863      else
1864      {
1865         DU_LOG("\nLOWER MAC: Failed to allocate memory for cell param");
1866         return RFAILED;
1867      }
1868    }
1869    else
1870    {
1871        DU_LOG("\nLOWER MAC:  Param Response received from PHY is NULL");
1872        return RFAILED;
1873    }
1874 #else
1875    return ROK;
1876 #endif
1877 }
1878
1879  /*******************************************************************
1880   *
1881   * @brief Sends FAPI Config req to PHY
1882   *
1883   * @details
1884   *
1885   *    Function : lwr_mac_handleConfigReqEvt
1886   *
1887   *    Functionality:
1888   *         -Sends FAPI Config Req to PHY
1889   *
1890   * @params[in]
1891   * @return ROK     - success
1892   *         RFAILED - failure
1893   *
1894   * ****************************************************************/
1895
1896 S16 lwr_mac_handleConfigReqEvt(void *msg)
1897 {
1898 #ifdef FAPI
1899    uint8_t index = 0;
1900    uint32_t msgLen = 0;
1901    uint32_t configReqSize;
1902    RgCellCb  *cellParams;
1903    MacCellCfg macCfgParams;
1904    Inst inst = 0;
1905
1906    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
1907
1908    fapi_config_req_t *configReq;
1909    cellParams = rgCb[inst].cell;
1910    macCfgParams = cellParams->macCellCfg;
1911    configReqSize = sizeof(fapi_config_req_t) + (macCfgParams.numTlv * sizeof(fapi_uint16_tlv_t));
1912         LWR_MAC_ALLOC(configReq, configReqSize);
1913    if(configReq != NULL)
1914    {
1915       configReq->number_of_tlvs = macCfgParams.numTlv;
1916
1917       if(macCfgParams.dlCarrCfg.pres)
1918       {
1919          fillTlvs(&configReq->tlvs[index++], FAPI_DL_BANDWIDTH_TAG,            sizeof(uint16_t), macCfgParams.dlCarrCfg.bw, &msgLen);
1920          fillTlvs(&configReq->tlvs[index++], FAPI_DL_FREQUENCY_TAG,            sizeof(uint32_t), macCfgParams.dlCarrCfg.freq, &msgLen);
1921          fillTlvs(&configReq->tlvs[index++], FAPI_DL_K0_TAG,                   sizeof(uint16_t), macCfgParams.dlCarrCfg.k0[0], &msgLen);
1922          fillTlvs(&configReq->tlvs[index++], FAPI_DL_GRIDSIZE_TAG,             sizeof(uint16_t), macCfgParams.dlCarrCfg.gridSize[0], &msgLen);
1923          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_TX_ANT_TAG,              sizeof(uint16_t), macCfgParams.dlCarrCfg.numAnt, &msgLen);
1924       }
1925       if(macCfgParams.ulCarrCfg.pres)
1926       {
1927          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_BANDWIDTH_TAG,        sizeof(uint16_t), macCfgParams.ulCarrCfg.bw, &msgLen);
1928          fillTlvs(&configReq->tlvs[index++], FAPI_UPLINK_FREQUENCY_TAG,        sizeof(uint32_t), macCfgParams.ulCarrCfg.freq, &msgLen);
1929          fillTlvs(&configReq->tlvs[index++], FAPI_UL_K0_TAG,                   sizeof(uint16_t), macCfgParams.ulCarrCfg.k0[0], &msgLen);
1930          fillTlvs(&configReq->tlvs[index++], FAPI_UL_GRID_SIZE_TAG,            sizeof(uint16_t), macCfgParams.ulCarrCfg.gridSize[0], &msgLen);
1931          fillTlvs(&configReq->tlvs[index++], FAPI_NUM_RX_ANT_TAG,              sizeof(uint16_t), macCfgParams.ulCarrCfg.numAnt, &msgLen);
1932       }
1933       fillTlvs(&configReq->tlvs[index++], FAPI_FREQUENCY_SHIFT_7P5_KHZ_TAG,    sizeof(uint8_t), macCfgParams.freqShft, &msgLen);
1934
1935       /* fill cell config */
1936       fillTlvs(&configReq->tlvs[index++], FAPI_PHY_CELL_ID_TAG,                sizeof(uint8_t), macCfgParams.phyCellId, &msgLen);
1937       fillTlvs(&configReq->tlvs[index++], FAPI_FRAME_DUPLEX_TYPE_TAG,          sizeof(uint8_t), macCfgParams.dupType, &msgLen);
1938
1939       /* fill SSB configuration */
1940       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_POWER_TAG,              sizeof(uint32_t), macCfgParams.ssbCfg.ssbPbchPwr, &msgLen);
1941       fillTlvs(&configReq->tlvs[index++], FAPI_BCH_PAYLOAD_TAG,                sizeof(uint8_t), macCfgParams.ssbCfg.bchPayloadFlag, &msgLen);
1942       fillTlvs(&configReq->tlvs[index++], FAPI_SCS_COMMON_TAG,                 sizeof(uint8_t), macCfgParams.ssbCfg.scsCmn, &msgLen);
1943
1944       /* fill PRACH configuration */
1945       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SEQUENCE_LENGTH_TAG,      sizeof(uint8_t), macCfgParams.prachCfg.prachSeqLen, &msgLen);
1946       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_SUBC_SPACING_TAG,         sizeof(uint8_t), macCfgParams.prachCfg.prachSubcSpacing, &msgLen);
1947       fillTlvs(&configReq->tlvs[index++], FAPI_RESTRICTED_SET_CONFIG_TAG,      sizeof(uint8_t), macCfgParams.prachCfg.prachRstSetCfg, &msgLen);
1948       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_PRACH_FD_OCCASIONS_TAG,
1949                                 sizeof(uint8_t), macCfgParams.prachCfg.msg1Fdm, &msgLen);
1950       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ROOT_SEQUENCE_INDEX_TAG,  sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].rootSeqIdx, &msgLen);
1951       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_ROOT_SEQUENCES_TAG,         sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numRootSeq, &msgLen);
1952       fillTlvs(&configReq->tlvs[index++], FAPI_K1_TAG,                         sizeof(uint16_t), macCfgParams.prachCfg.fdm[0].k1, &msgLen);
1953       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_ZERO_CORR_CONF_TAG ,      sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].zeroCorrZoneCfg, &msgLen);
1954       fillTlvs(&configReq->tlvs[index++], FAPI_NUM_UNUSED_ROOT_SEQUENCES_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.fdm[0].numUnusedRootSeq, &msgLen);
1955                 if(macCfgParams.prachCfg.fdm[0].numUnusedRootSeq)
1956                 {
1957                    LWR_MAC_ALLOC(macCfgParams.prachCfg.fdm[0].unsuedRootSeq ,
1958                       sizeof(uint8_t)*macCfgParams.prachCfg.fdm[0].numUnusedRootSeq);
1959                    fillTlvs(&configReq->tlvs[index++], FAPI_UNUSED_ROOT_SEQUENCES_TAG,\
1960                       sizeof(uint8_t), *(macCfgParams.prachCfg.fdm[0].unsuedRootSeq), &msgLen);
1961                 }
1962                 else
1963                 {
1964                    macCfgParams.prachCfg.fdm[0].unsuedRootSeq = NULL;
1965                 }
1966
1967       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PER_RACH_TAG,               sizeof(uint8_t), macCfgParams.prachCfg.ssbPerRach, &msgLen);
1968       fillTlvs(&configReq->tlvs[index++], FAPI_PRACH_MULTIPLE_CARRIERS_IN_A_BAND_TAG,  sizeof(uint8_t), macCfgParams.prachCfg.prachMultCarrBand, &msgLen);
1969
1970       /* fill SSB table */
1971       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_OFFSET_POINT_A_TAG,         sizeof(uint16_t), macCfgParams.ssbCfg.ssbOffsetPointA, &msgLen);
1972       fillTlvs(&configReq->tlvs[index++], FAPI_BETA_PSS_TAG,                   sizeof(uint8_t),  macCfgParams.ssbCfg.betaPss, &msgLen);
1973       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_PERIOD_TAG,                 sizeof(uint8_t),  macCfgParams.ssbCfg.ssbPeriod, &msgLen);
1974       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_SUBCARRIER_OFFSET_TAG,      sizeof(uint8_t),  macCfgParams.ssbCfg.ssbScOffset, &msgLen);
1975       fillTlvs(&configReq->tlvs[index++], FAPI_MIB_TAG ,                       sizeof(uint32_t), macCfgParams.ssbCfg.mibPdu[0], &msgLen);
1976       fillTlvs(&configReq->tlvs[index++], FAPI_SSB_MASK_TAG,                   sizeof(uint32_t), macCfgParams.ssbCfg.ssbMask[0], &msgLen);
1977       fillTlvs(&configReq->tlvs[index++], FAPI_BEAM_ID_TAG,                    sizeof(uint8_t),  macCfgParams.ssbCfg.beamId[0], &msgLen);
1978       fillTlvs(&configReq->tlvs[index++], FAPI_SS_PBCH_MULTIPLE_CARRIERS_IN_A_BAND_TAG, sizeof(uint8_t), macCfgParams.ssbCfg.multCarrBand, &msgLen);
1979       fillTlvs(&configReq->tlvs[index++], FAPI_MULTIPLE_CELLS_SS_PBCH_IN_A_CARRIER_TAG, sizeof(uint8_t), macCfgParams.ssbCfg.multCellCarr, &msgLen);
1980
1981       /* fill TDD table */
1982       fillTlvs(&configReq->tlvs[index++], FAPI_TDD_PERIOD_TAG,                 sizeof(uint8_t), macCfgParams.tddCfg.tddPeriod, &msgLen);
1983       fillTlvs(&configReq->tlvs[index++], FAPI_SLOT_CONFIG_TAG,                sizeof(uint8_t), macCfgParams.tddCfg.slotCfg[0][0], &msgLen);
1984
1985       /* fill measurement config */
1986       fillTlvs(&configReq->tlvs[index++], FAPI_RSSI_MESUREMENT_TAG,            sizeof(uint8_t), macCfgParams.rssiUnit, &msgLen);
1987
1988       fillMsgHeader(&configReq->header, FAPI_CONFIG_REQUEST, msgLen);
1989       DU_LOG("\nLOWER_MAC: Sending Config Request to Phy");
1990       /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
1991       LwrMacSendToPhy(configReq->header.message_type_id, msgLen, (void *)configReq);
1992       return ROK;
1993    }
1994    else
1995    {
1996       DU_LOG("\nLOWER_MAC: Failed to allocate memory for config Request");
1997       return RFAILED;
1998    }
1999 #else
2000    return ROK;
2001 #endif
2002 }
2003
2004 S16 lwr_mac_handleConfigRspEvt(void *msg)
2005 {
2006 #ifdef FAPI
2007    fapi_config_resp_t *configRsp;
2008         configRsp = (fapi_config_resp_t *)msg;
2009    DU_LOG("\nLOWER MAC: Received EVENT[%d] at STATE[%d]", clGlobalCp.event, clGlobalCp.phyState);
2010
2011    if(configRsp != NULL)
2012    {
2013       if(configRsp->error_code == MSG_OK)
2014       {
2015          DU_LOG("\nLOWER MAC: PHY has moved to Configured state \n");
2016          clGlobalCp.phyState = PHY_STATE_CONFIGURED;
2017          /* TODO : 
2018           * Store config response into an intermediate struture and send to MAC
2019           * Support LC and LWLC for sending config rsp to MAC 
2020           */
2021          fapiMacConfigRsp();
2022          return ROK;
2023       }
2024       else
2025       {
2026
2027          DU_LOG("\n LOWER MAC: Invalid error code %d", configRsp->error_code);
2028          return RFAILED;
2029       }
2030    }
2031    else
2032    {
2033       DU_LOG("\nLOWER_MAC: Config Response received from PHY is NULL");
2034       return RFAILED;
2035    }
2036 #else
2037    return ROK;
2038 #endif
2039 }
2040
2041 S16 lwr_mac_handleStartReqEvt(void *msg)
2042 {
2043 #ifdef FAPI
2044    uint32_t msgLen = 0;
2045    fapi_start_req_t *startReq;
2046
2047         LWR_MAC_ALLOC(startReq, sizeof(fapi_start_req_t));
2048    if(startReq != NULL)
2049    {
2050       fillMsgHeader(&startReq->header, FAPI_START_REQUEST, msgLen);
2051       DU_LOG("\nLOWER MAC: Sending Start Request to PHY");
2052       LwrMacSendToPhy(startReq->header.message_type_id, sizeof(fapi_start_req_t), (void *)startReq);
2053       return ROK;
2054    }
2055    else
2056    {
2057       DU_LOG("\nLOWER MAC: Failed to allocate memory for Start Request");
2058       return RFAILED;
2059    }
2060 #else
2061    return ROK;
2062 #endif
2063 }
2064
2065 S16 lwr_mac_handleStopReqEvt(void *msg)
2066 {
2067 #ifdef FAPI
2068    /* stop TX and RX operation return PHy to configured State
2069       send stop.indication to l2/l3 */
2070 #endif
2071    return ROK;
2072 }
2073
2074 /*******************************************************************
2075  *
2076  * @brief Modifes the received mibPdu to uint32 bit
2077  *        and stores it in MacCellCfg
2078  *
2079  * @details
2080  *
2081  *    Function : setMibPdu
2082  *
2083  *    Functionality:
2084  *         -Sets the MibPdu
2085  *
2086  * @params[in] Pointer to mibPdu
2087  *             pointer to modified value
2088  ******************************************************************/
2089
2090 PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val)
2091 {
2092    *mibPdu |= (((uint8_t)(slotIndInfo.sfn >> 2)) & MIB_SFN_BITMASK);
2093    *val = (mibPdu[0] << 24 | mibPdu[1] << 16 | mibPdu[2] << 8);
2094     DU_LOG("\nLOWER MAC: value filled %x", *val);
2095 }
2096
2097 #ifdef FAPI
2098 /*******************************************************************
2099  *
2100  * @brief fills SSB PDU required for DL TTI info in MAC
2101  *
2102  * @details
2103  *
2104  *    Function : fillSsbPdu
2105  *
2106  *    Functionality:
2107  *         -Fills the SSB PDU info
2108  *          stored in MAC
2109  *
2110  * @params[in] Pointer to FAPI DL TTI Req
2111  *             Pointer to RgCellCb
2112  *             Pointer to msgLen of DL TTI Info
2113  * @return ROK
2114  *
2115  ******************************************************************/
2116
2117 S16 fillSsbPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, MacCellCfg *macCellCfg,
2118         MacDlSlot *currDlSlot,
2119         uint32_t *msgLen, uint8_t ssbIdxCount) 
2120 {
2121    uint32_t mibPayload = 0;
2122    if(dlTtiReqPdu != NULL)
2123    {
2124       dlTtiReqPdu->pduType = SSB_PDU_TYPE;     /* SSB PDU */
2125       dlTtiReqPdu->u.ssb_pdu.physCellId = macCellCfg->phyCellId;
2126       dlTtiReqPdu->u.ssb_pdu.betaPss = macCellCfg->ssbCfg.betaPss;
2127       dlTtiReqPdu->u.ssb_pdu.ssbBlockIndex = currDlSlot->dlInfo.brdcstAlloc.ssbInfo[ssbIdxCount].ssbIdx;
2128       dlTtiReqPdu->u.ssb_pdu.ssbSubCarrierOffset = macCellCfg->ssbCfg.ssbScOffset;
2129       /* ssbOfPdufstA to be filled in ssbCfg */
2130       dlTtiReqPdu->u.ssb_pdu.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2131       dlTtiReqPdu->u.ssb_pdu.bchPayloadFlag = macCellCfg->ssbCfg.bchPayloadFlag;
2132       /* Bit manipulation for SFN */
2133       setMibPdu(macCellCfg->ssbCfg.mibPdu, &mibPayload);
2134       dlTtiReqPdu->u.ssb_pdu.bchPayload.v.bchPayload = mibPayload;
2135       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.numPrgs = 0;
2136       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.prgSize = 0;
2137       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.digBfInterfaces = 0;
2138       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming.pmi_bfi[0].pmIdx = 0;
2139       dlTtiReqPdu->u.ssb_pdu.preCodingAndBeamforming. \
2140          pmi_bfi[0].beamIdx[0].beamidx = macCellCfg->ssbCfg.beamId[0];
2141       dlTtiReqPdu->pduSize = sizeof(fapi_dl_ssb_pdu_t);  /* Size of SSB PDU */
2142       SETLENGTH(*msgLen, sizeof(fapi_dl_ssb_pdu_t));
2143       return ROK;
2144     }
2145     else
2146     {
2147        return RFAILED;
2148     }
2149 }
2150
2151 /*******************************************************************
2152  *
2153  * @brief fills Dl DCI PDU required for DL TTI info in MAC
2154  *
2155  * @details
2156  *
2157  *    Function : fillSib1DlDciPdu
2158  *
2159  *    Functionality:
2160  *         -Fills the Dl DCI PDU
2161  *
2162  * @params[in] Pointer to fapi_dl_dci_t
2163  *             Pointer to PdcchCfg
2164  * @return ROK
2165  *
2166  ******************************************************************/
2167
2168 void fillSib1DlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *sib1PdcchInfo)
2169 {
2170    if(dlDciPtr != NULLP)
2171    {
2172       uint8_t numBytes;
2173       uint8_t bytePos;
2174       uint8_t bitPos;
2175       
2176       uint16_t coreset0Size;
2177       uint16_t rbStart;
2178       uint16_t rbLen;
2179       uint32_t freqDomResAssign;
2180       uint32_t timeDomResAssign;
2181       uint8_t  VRB2PRBMap;
2182       uint32_t modNCodScheme;
2183       uint8_t  redundancyVer;
2184       uint32_t sysInfoInd;
2185       uint32_t reserved;
2186
2187       /* Size(in bits) of each field in DCI format 0_1 
2188                  * as mentioned in spec 38.214 */
2189       uint8_t freqDomResAssignSize;
2190       uint8_t timeDomResAssignSize = 4;
2191       uint8_t VRB2PRBMapSize       = 1;
2192       uint8_t modNCodSchemeSize    = 5;
2193       uint8_t redundancyVerSize    = 2;
2194       uint8_t sysInfoIndSize       = 1;
2195       uint8_t reservedSize         = 15;
2196
2197       dlDciPtr->rnti = sib1PdcchInfo->dci.rnti;
2198       dlDciPtr->scramblingId = sib1PdcchInfo->dci.scramblingId;    
2199       dlDciPtr->scramblingRnti = sib1PdcchInfo->dci.scramblingRnti;
2200       dlDciPtr->cceIndex = sib1PdcchInfo->dci.cceIndex;
2201       dlDciPtr->aggregationLevel = sib1PdcchInfo->dci.aggregLevel;
2202       dlDciPtr->pc_and_bform.numPrgs = sib1PdcchInfo->dci.beamPdcchInfo.numPrgs;
2203       dlDciPtr->pc_and_bform.prgSize = sib1PdcchInfo->dci.beamPdcchInfo.prgSize;
2204       dlDciPtr->pc_and_bform.digBfInterfaces = sib1PdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2205       dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = sib1PdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2206       dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = sib1PdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2207       dlDciPtr->beta_pdcch_1_0 = sib1PdcchInfo->dci.txPdcchPower.powerValue;           
2208       dlDciPtr->powerControlOfssetSS = sib1PdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2209
2210       /* Calculating freq domain resource allocation field value and size
2211        * coreset0Size = Size of coreset 0
2212        * RBStart = Starting Virtual Rsource block
2213        * RBLen = length of contiguously allocted RBs
2214        * Spec 38.214 Sec 5.1.2.2.2
2215        */
2216       coreset0Size= sib1PdcchInfo->coreset0Cfg.coreSet0Size;
2217                 rbStart = 0;              /* For SIB1 */
2218       //rbStart = sib1PdcchInfo->dci.pdschCfg->freqAlloc.rbStart;
2219       rbLen = sib1PdcchInfo->dci.pdschCfg->freqAlloc.rbSize;
2220
2221       if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2222       {
2223          if((rbLen - 1) <= floor(coreset0Size / 2))
2224             freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2225          else
2226             freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2227                + (coreset0Size - 1 - rbStart);
2228
2229          freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2230       }
2231
2232       /* Fetching DCI field values */
2233       timeDomResAssign = sib1PdcchInfo->dci.pdschCfg->timeAlloc.
2234                          rowIndex -1;
2235       VRB2PRBMap       = sib1PdcchInfo->dci.pdschCfg->freqAlloc.\
2236                          vrbPrbMapping;
2237       modNCodScheme    = sib1PdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2238       redundancyVer    = sib1PdcchInfo->dci.pdschCfg->codeword[0].rvIndex;
2239       sysInfoInd       = 0;           /* 0 for SIB1; 1 for SI messages */
2240       reserved         = 0;
2241
2242       /* Reversing bits in each DCI field */
2243       freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2244       timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2245       VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2246       modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2247       redundancyVer    = reverseBits(redundancyVer, redundancyVerSize);
2248       sysInfoInd       = reverseBits(sysInfoInd, sysInfoIndSize);
2249
2250      /* Calulating total number of bytes in buffer */
2251      dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2252               + VRB2PRBMapSize + modNCodSchemeSize + redundancyVerSize\
2253               + sysInfoIndSize + reservedSize;
2254
2255      numBytes = dlDciPtr->payloadSizeBits / 8;
2256      if(dlDciPtr->payloadSizeBits % 8)
2257         numBytes += 1;
2258
2259      if(numBytes > DCI_PAYLOAD_BYTE_LEN)
2260      {
2261         DU_LOG("\nLOWER MAC : Total bytes for DCI is more than expected");
2262         return;
2263      }
2264
2265      /* Initialize buffer */
2266      for(bytePos = 0; bytePos < numBytes; bytePos++)
2267         dlDciPtr->payload[bytePos] = 0;
2268
2269      bytePos = numBytes - 1;
2270      bitPos = 0;
2271
2272      /* Packing DCI format fields */
2273      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2274         freqDomResAssign, freqDomResAssignSize);
2275      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2276         timeDomResAssign, timeDomResAssignSize);
2277      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2278         VRB2PRBMap, VRB2PRBMapSize);
2279      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2280         modNCodScheme, modNCodSchemeSize);
2281      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2282         redundancyVer, redundancyVerSize);
2283      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2284         sysInfoInd, sysInfoIndSize);
2285      fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2286         reserved, reservedSize);
2287
2288    }
2289 } /* fillSib1DlDciPdu */
2290
2291 /*******************************************************************
2292  *
2293  * @brief fills Dl DCI PDU required for DL TTI info in MAC
2294  *
2295  * @details
2296  *
2297  *    Function : fillRarDlDciPdu
2298  *
2299  *    Functionality:
2300  *         -Fills the Dl DCI PDU
2301  *
2302  * @params[in] Pointer to fapi_dl_dci_t
2303  *             Pointer to PdcchCfg
2304  * @return ROK
2305  *
2306  ******************************************************************/
2307
2308 void fillRarDlDciPdu(fapi_dl_dci_t *dlDciPtr, PdcchCfg *rarPdcchInfo)
2309 {
2310         if(dlDciPtr != NULLP)
2311         {
2312                 uint8_t numBytes;
2313                 uint8_t bytePos;
2314                 uint8_t bitPos;
2315
2316                 uint16_t coreset0Size;
2317                 uint16_t rbStart;
2318                 uint16_t rbLen;
2319                 uint32_t freqDomResAssign;
2320                 uint8_t timeDomResAssign;
2321                 uint8_t  VRB2PRBMap;
2322                 uint8_t modNCodScheme;
2323                 uint8_t tbScaling;
2324                 uint32_t reserved;
2325
2326                 /* Size(in bits) of each field in DCI format 1_0 */
2327                 uint8_t freqDomResAssignSize;
2328                 uint8_t timeDomResAssignSize = 4;
2329                 uint8_t VRB2PRBMapSize       = 1;
2330                 uint8_t modNCodSchemeSize    = 5;
2331                 uint8_t tbScalingSize        = 2;
2332                 uint8_t reservedSize         = 16;
2333
2334                 dlDciPtr->rnti = rarPdcchInfo->dci.rnti;
2335                 dlDciPtr->scramblingId = rarPdcchInfo->dci.scramblingId;    
2336                 dlDciPtr->scramblingRnti = rarPdcchInfo->dci.scramblingRnti;
2337                 dlDciPtr->cceIndex = rarPdcchInfo->dci.cceIndex;
2338                 dlDciPtr->aggregationLevel = rarPdcchInfo->dci.aggregLevel;
2339                 dlDciPtr->pc_and_bform.numPrgs = rarPdcchInfo->dci.beamPdcchInfo.numPrgs;
2340                 dlDciPtr->pc_and_bform.prgSize = rarPdcchInfo->dci.beamPdcchInfo.prgSize;
2341                 dlDciPtr->pc_and_bform.digBfInterfaces = rarPdcchInfo->dci.beamPdcchInfo.digBfInterfaces;
2342                 dlDciPtr->pc_and_bform.pmi_bfi[0].pmIdx = rarPdcchInfo->dci.beamPdcchInfo.prg[0].pmIdx;
2343                 dlDciPtr->pc_and_bform.pmi_bfi[0].beamIdx[0].beamidx = rarPdcchInfo->dci.beamPdcchInfo.prg[0].beamIdx[0];
2344                 dlDciPtr->beta_pdcch_1_0 = rarPdcchInfo->dci.txPdcchPower.powerValue;           
2345                 dlDciPtr->powerControlOfssetSS = rarPdcchInfo->dci.txPdcchPower.powerControlOffsetSS;
2346
2347                 /* Calculating freq domain resource allocation field value and size
2348                  * coreset0Size = Size of coreset 0
2349                  * RBStart = Starting Virtual Rsource block
2350                  * RBLen = length of contiguously allocted RBs
2351                  * Spec 38.214 Sec 5.1.2.2.2
2352                  */
2353
2354                 /* TODO: Fill values of coreset0Size, rbStart and rbLen */
2355                 coreset0Size= rarPdcchInfo->coreset0Cfg.coreSet0Size;
2356                 rbStart = 0;              /* For SIB1 */
2357                 //rbStart = rarPdcchInfo->dci.pdschCfg->freqAlloc.rbStart;
2358                 rbLen = rarPdcchInfo->dci.pdschCfg->freqAlloc.rbSize;
2359
2360                 if((rbLen >=1) && (rbLen <= coreset0Size - rbStart))
2361                 {
2362                         if((rbLen - 1) <= floor(coreset0Size / 2))
2363                                 freqDomResAssign = (coreset0Size * (rbLen-1)) + rbStart;
2364                         else
2365                                 freqDomResAssign = (coreset0Size * (coreset0Size - rbLen + 1)) \
2366                                                                                  + (coreset0Size - 1 - rbStart);
2367
2368                         freqDomResAssignSize = ceil(log2(coreset0Size * (coreset0Size + 1) / 2));
2369                 }
2370
2371                 /* Fetching DCI field values */
2372                 timeDomResAssign = rarPdcchInfo->dci.pdschCfg->timeAlloc.rowIndex -1;
2373                 VRB2PRBMap       = rarPdcchInfo->dci.pdschCfg->freqAlloc.vrbPrbMapping;
2374                 modNCodScheme    = rarPdcchInfo->dci.pdschCfg->codeword[0].mcsIndex;
2375                 tbScaling        = 0; /* configured to 0 scaling */
2376                 reserved         = 0;
2377
2378                 /* Reversing bits in each DCI field */
2379                 freqDomResAssign = reverseBits(freqDomResAssign, freqDomResAssignSize);
2380                 timeDomResAssign = reverseBits(timeDomResAssign, timeDomResAssignSize);
2381                 VRB2PRBMap       = reverseBits(VRB2PRBMap, VRB2PRBMapSize);
2382                 modNCodScheme    = reverseBits(modNCodScheme, modNCodSchemeSize);
2383                 tbScaling        = reverseBits(tbScaling, tbScalingSize); 
2384
2385                 /* Calulating total number of bytes in buffer */
2386                 dlDciPtr->payloadSizeBits = freqDomResAssignSize + timeDomResAssignSize\
2387                                                                                          + VRB2PRBMapSize + modNCodSchemeSize + tbScalingSize + reservedSize;
2388
2389                 numBytes = dlDciPtr->payloadSizeBits / 8;
2390                 if(dlDciPtr->payloadSizeBits % 8)
2391                         numBytes += 1;
2392
2393                 if(numBytes > DCI_PAYLOAD_BYTE_LEN)
2394                 {
2395                         DU_LOG("\nLOWER MAC : Total bytes for DCI is more than expected");
2396                         return;
2397                 }
2398
2399                 /* Initialize buffer */
2400                 for(bytePos = 0; bytePos < numBytes; bytePos++)
2401                         dlDciPtr->payload[bytePos] = 0;
2402
2403                 bytePos = numBytes - 1;
2404                 bitPos = 0;
2405
2406                 /* Packing DCI format fields */
2407                 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2408                                 freqDomResAssign, freqDomResAssignSize);
2409                 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2410                                 timeDomResAssign, timeDomResAssignSize);
2411                 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2412                                 VRB2PRBMap, VRB2PRBMapSize);
2413                 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2414                                 modNCodScheme, modNCodSchemeSize);
2415                 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2416                                 tbScaling, tbScalingSize);
2417                 fillDlDciPayload(dlDciPtr->payload, &bytePos, &bitPos,\
2418                                 reserved, reservedSize);
2419         }
2420 } /* fillRarDlDciPdu */
2421
2422 /*******************************************************************
2423  *
2424  * @brief fills PDCCH PDU required for DL TTI info in MAC
2425  *
2426  * @details
2427  *
2428  *    Function : fillPdcchPdu
2429  *
2430  *    Functionality:
2431  *         -Fills the Pdcch PDU info
2432  *          stored in MAC
2433  *
2434  * @params[in] Pointer to FAPI DL TTI Req
2435  *             Pointer to PdcchCfg
2436  *             Pointer to msgLen of DL TTI Info
2437  * @return ROK
2438  *
2439  ******************************************************************/
2440
2441 S16 fillPdcchPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, PdcchCfg *pdcchInfo,
2442 uint32_t *msgLen)
2443 {
2444     if(dlTtiReqPdu != NULLP)
2445     {
2446        dlTtiReqPdu->pduType = PDCCH_PDU_TYPE;
2447        dlTtiReqPdu->u.pdcch_pdu.bwpSize = pdcchInfo->pdcchBwpCfg.BWPSize;
2448        dlTtiReqPdu->u.pdcch_pdu.bwpPart = pdcchInfo->pdcchBwpCfg.BWPStart;
2449        dlTtiReqPdu->u.pdcch_pdu.subCarrierSpacing = pdcchInfo->pdcchBwpCfg.subcarrierSpacing; 
2450        dlTtiReqPdu->u.pdcch_pdu.cyclicPrefix = pdcchInfo->pdcchBwpCfg.cyclicPrefix; 
2451        dlTtiReqPdu->u.pdcch_pdu.startSymbolIndex = pdcchInfo->coreset0Cfg.startSymbolIndex;
2452        dlTtiReqPdu->u.pdcch_pdu.durationSymbols = pdcchInfo->coreset0Cfg.durationSymbols;
2453        memcpy(dlTtiReqPdu->u.pdcch_pdu.freqDomainResource, pdcchInfo->coreset0Cfg.freqDomainResource, 6);
2454        dlTtiReqPdu->u.pdcch_pdu.cceRegMappingType = pdcchInfo->coreset0Cfg.cceRegMappingType;
2455        dlTtiReqPdu->u.pdcch_pdu.regBundleSize = pdcchInfo->coreset0Cfg.regBundleSize;
2456        dlTtiReqPdu->u.pdcch_pdu.interleaverSize = pdcchInfo->coreset0Cfg.interleaverSize;
2457        dlTtiReqPdu->u.pdcch_pdu.coreSetSize = pdcchInfo->coreset0Cfg.coreSetType;
2458        dlTtiReqPdu->u.pdcch_pdu.shiftIndex =  pdcchInfo->coreset0Cfg.shiftIndex;
2459        dlTtiReqPdu->u.pdcch_pdu.precoderGranularity = pdcchInfo->coreset0Cfg.precoderGranularity;
2460        dlTtiReqPdu->u.pdcch_pdu.numDlDci = pdcchInfo->numDlDci;
2461                  LWR_MAC_ALLOC(dlTtiReqPdu->u.pdcch_pdu.dlDci, sizeof(fapi_dl_dci_t));
2462        if(pdcchInfo->dci.rnti == SI_RNTI)
2463                  {
2464           fillSib1DlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, pdcchInfo);
2465        }
2466                  else
2467                  {
2468           fillRarDlDciPdu(dlTtiReqPdu->u.pdcch_pdu.dlDci, pdcchInfo);
2469                  }
2470
2471        dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdcch_pdu_t);
2472        SETLENGTH(*msgLen, sizeof(fapi_dl_pdcch_pdu_t));
2473
2474     }
2475     return ROK;
2476
2477 }
2478
2479 /*******************************************************************
2480  *
2481  * @brief fills PDSCH PDU required for DL TTI info in MAC
2482  *
2483  * @details
2484  *
2485  *    Function : fillPdschPdu
2486  *
2487  *    Functionality:
2488  *         -Fills the Pdsch PDU info
2489  *          stored in MAC
2490  *
2491  * @params[in] Pointer to FAPI DL TTI Req
2492  *             Pointer to PdschCfg
2493  *             Pointer to msgLen of DL TTI Info
2494  * @return ROK
2495  *
2496  ******************************************************************/
2497
2498 void fillPdschPdu(fapi_dl_tti_req_pdu_t *dlTtiReqPdu, PdschCfg *pdschInfo,
2499 uint32_t *msgLen)
2500 {
2501     uint8_t idx;
2502
2503     if(dlTtiReqPdu != NULLP)
2504     {
2505        dlTtiReqPdu->pduType = PDSCH_PDU_TYPE;
2506        dlTtiReqPdu->u.pdsch_pdu.pduBitMap = pdschInfo->pduBitmap;
2507        dlTtiReqPdu->u.pdsch_pdu.rnti = pdschInfo->rnti;         
2508        dlTtiReqPdu->u.pdsch_pdu.pduIndex = pdschInfo->pduIndex;
2509        dlTtiReqPdu->u.pdsch_pdu.bwpSize = pdschInfo->pdschBwpCfg.BWPSize;       
2510        dlTtiReqPdu->u.pdsch_pdu.bwpStart = pdschInfo->pdschBwpCfg.BWPStart;
2511        dlTtiReqPdu->u.pdsch_pdu.subCarrierSpacing = pdschInfo->pdschBwpCfg.subcarrierSpacing;
2512        dlTtiReqPdu->u.pdsch_pdu.cyclicPrefix = pdschInfo->pdschBwpCfg.cyclicPrefix;
2513        dlTtiReqPdu->u.pdsch_pdu.nrOfCodeWords = pdschInfo->numCodewords;
2514        for(idx = 0; idx < MAX_CODEWORDS ; idx++)
2515        { 
2516           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].targetCodeRate = pdschInfo->codeword[idx].targetCodeRate;
2517           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].qamModOrder = pdschInfo->codeword[idx].qamModOrder;
2518           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].mcsIndex = pdschInfo->codeword[idx].mcsIndex;
2519           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].mcsTable = pdschInfo->codeword[idx].mcsTable;
2520           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].rvIndex = pdschInfo->codeword[idx].rvIndex;
2521           dlTtiReqPdu->u.pdsch_pdu.cwInfo[idx].tbSize = pdschInfo->codeword[idx].tbSize;
2522        }
2523        dlTtiReqPdu->u.pdsch_pdu.dataScramblingId = pdschInfo->dataScramblingId;       
2524        dlTtiReqPdu->u.pdsch_pdu.nrOfLayers = pdschInfo->numLayers;
2525        dlTtiReqPdu->u.pdsch_pdu.transmissionScheme = pdschInfo->transmissionScheme;
2526        dlTtiReqPdu->u.pdsch_pdu.refPoint = pdschInfo->refPoint;
2527        dlTtiReqPdu->u.pdsch_pdu.dlDmrsSymbPos = pdschInfo->dmrs.dlDmrsSymbPos;
2528        dlTtiReqPdu->u.pdsch_pdu.dmrsConfigType = pdschInfo->dmrs.dmrsConfigType;
2529        dlTtiReqPdu->u.pdsch_pdu.dlDmrsScramblingId = pdschInfo->dmrs.dlDmrsScramblingId;
2530        dlTtiReqPdu->u.pdsch_pdu.scid = pdschInfo->dmrs.scid;
2531        dlTtiReqPdu->u.pdsch_pdu.numDmrsCdmGrpsNoData = pdschInfo->dmrs.numDmrsCdmGrpsNoData;
2532        dlTtiReqPdu->u.pdsch_pdu.dmrsPorts = pdschInfo->dmrs.dmrsPorts;
2533        dlTtiReqPdu->u.pdsch_pdu.resourceAlloc = pdschInfo->freqAlloc.resourceAlloc;
2534        /* since we are using type-1, hence rbBitmap excluded */
2535        dlTtiReqPdu->u.pdsch_pdu.rbStart = pdschInfo->freqAlloc.rbStart;
2536        dlTtiReqPdu->u.pdsch_pdu.rbSize = pdschInfo->freqAlloc.rbSize;
2537        dlTtiReqPdu->u.pdsch_pdu.vrbToPrbMapping = pdschInfo->freqAlloc.vrbPrbMapping;
2538        dlTtiReqPdu->u.pdsch_pdu.startSymbIndex = pdschInfo->timeAlloc.startSymbolIndex;
2539        dlTtiReqPdu->u.pdsch_pdu.nrOfSymbols = pdschInfo->timeAlloc.numSymbols;
2540        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.numPrgs = pdschInfo->beamPdschInfo.numPrgs;
2541        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.prgSize = pdschInfo->beamPdschInfo.prgSize;
2542        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.digBfInterfaces = pdschInfo->beamPdschInfo.digBfInterfaces;
2543        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2544           pmIdx = pdschInfo->beamPdschInfo.prg[0].pmIdx;
2545        dlTtiReqPdu->u.pdsch_pdu.preCodingAndBeamforming.pmi_bfi[0]. \
2546           beamIdx[0].beamidx = pdschInfo->beamPdschInfo.prg[0].beamIdx[0];
2547        dlTtiReqPdu->u.pdsch_pdu.powerControlOffset = pdschInfo->txPdschPower.powerControlOffset;  
2548        dlTtiReqPdu->u.pdsch_pdu.powerControlOffsetSS = pdschInfo->txPdschPower.powerControlOffsetSS;
2549        dlTtiReqPdu->pduSize = sizeof(fapi_dl_pdsch_pdu_t);
2550        SETLENGTH(*msgLen, sizeof(fapi_dl_pdsch_pdu_t));
2551
2552     }
2553
2554 }
2555
2556 /***********************************************************************
2557  *
2558  * @brief calculates the total size to be allocated for DL TTI Req
2559  *
2560  * @details
2561  *
2562  *    Function : calculatePduCount
2563  *
2564  *    Functionality:
2565  *         -calculates the total pdu count to be allocated for DL TTI Req
2566  *
2567  * @params[in]    DlBrdcstAlloc *cellBroadcastInfo
2568  * @return count
2569  *
2570  * ********************************************************************/
2571 uint8_t calculatePduCount(DlAlloc *dlInfo)
2572 {
2573    uint8_t count = 0;
2574    uint8_t idx = 0;
2575         if(dlInfo->isBroadcastPres)
2576         {
2577       if(dlInfo->brdcstAlloc.ssbTrans)
2578       {
2579          for(idx = 0; idx < dlInfo->brdcstAlloc.ssbIdxSupported; idx++)
2580          {
2581             count++;
2582          }
2583       }
2584       if(dlInfo->brdcstAlloc.sib1Trans)
2585       {
2586          count += 2;
2587       }
2588    }
2589         if(dlInfo->isRarPres)
2590         {
2591            count += 2;
2592         }
2593    return count;
2594 }
2595
2596 /***********************************************************************
2597  *
2598  * @brief fills the SIB1 TX-DATA request message
2599  *
2600  * @details
2601  *
2602  *    Function : fillSib1TxDataReq
2603  *
2604  *    Functionality:
2605  *         - fills the SIB1 TX-DATA request message
2606  *
2607  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
2608  * @params[in]    MacCellCfg *macCellCfg
2609  * @params[in]    uint16_t pduIndex
2610  * @params[in]    uint32_t *msgLen
2611  * @return ROK
2612  *
2613  * ********************************************************************/
2614 uint8_t fillSib1TxDataReq(fapi_tx_pdu_desc_t *pduDesc,MacCellCfg *macCellCfg,
2615    uint16_t pduIndex, uint32_t *msgLen)
2616 {
2617    uint32_t pduLen = 0;
2618         uint32_t *sib1TxdataValue = NULLP;
2619
2620         pduDesc->pduIndex = pduIndex;
2621         pduDesc->numTlvs = 1;
2622
2623         /* fill the TLV */
2624         /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
2625         pduDesc->tlvs[0].tl.tag = 1; /* pointer to be sent */
2626         pduDesc->tlvs[0].tl.length = macCellCfg->sib1Cfg.sib1PduLen;
2627         LWR_MAC_ALLOC(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2628         if(sib1TxdataValue == NULLP)
2629         {
2630            return RFAILED;
2631         }
2632         memcpy(sib1TxdataValue,macCellCfg->sib1Cfg.sib1Pdu,
2633            macCellCfg->sib1Cfg.sib1PduLen);
2634         pduDesc->tlvs[0].value = sib1TxdataValue;
2635
2636    /* The total length of the PDU description and       PDU data */
2637         pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
2638         pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
2639    pduDesc->pduLength = pduLen; 
2640         msgLen += pduLen;
2641
2642 #ifndef INTEL_WLS   
2643    MAC_FREE(sib1TxdataValue,macCellCfg->sib1Cfg.sib1PduLen);
2644 #endif
2645
2646
2647         return ROK;
2648 }
2649
2650 /***********************************************************************
2651  *
2652  * @brief fills the RAR TX-DATA request message
2653  *
2654  * @details
2655  *
2656  *    Function : fillRarTxDataReq
2657  *
2658  *    Functionality:
2659  *         - fills the RAR TX-DATA request message
2660  *
2661  * @params[in]    fapi_tx_pdu_desc_t *pduDesc
2662  * @params[in]    RarInfo *rarInfo
2663  * @params[in]    uint16_t pduIndex
2664  * @params[in]    uint32_t *msgLen
2665  * @return ROK
2666  *
2667  * ********************************************************************/
2668 uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
2669    uint16_t pduIndex, uint32_t *msgLen)
2670 {
2671    uint32_t pduLen = 0;
2672         uint32_t *rarTxdataValue = NULLP;
2673
2674         pduDesc[pduIndex].pduIndex = pduIndex;
2675         pduDesc[pduIndex].numTlvs = 1;
2676
2677         /* fill the TLV */
2678         /* as of now, memory is allocated from SSI, later WLS memory needs to be taken */
2679         pduDesc[pduIndex].tlvs[0].tl.tag = 1; /* pointer to be sent */
2680         pduDesc[pduIndex].tlvs[0].tl.length = rarInfo->rarPduLen;
2681         LWR_MAC_ALLOC(rarTxdataValue,rarInfo->rarPduLen);
2682         if(rarTxdataValue == NULLP)
2683         {
2684            return RFAILED;
2685         }
2686         memcpy(rarTxdataValue,rarInfo->rarPdu,rarInfo->rarPduLen);
2687         pduDesc[pduIndex].tlvs[0].value = (uint32_t)rarTxdataValue;
2688
2689    /* The total length of the PDU description and       PDU data */
2690         pduLen += 8; /* size of PDU length 2 bytes, PDU index 2 bytes, numTLV 4 bytes */
2691         pduLen += sizeof(fapi_uint32_tlv_t); /* only 1 TLV is present */
2692    pduDesc[pduIndex].pduLength = pduLen; 
2693         msgLen += pduLen;
2694
2695 /* TODO: The pointer value which was stored, needs to be free-ed at PHY *
2696  * But since we did not implement WLS, this has to be done here
2697  */
2698 #ifndef INTEL_WLS   
2699    MAC_FREE(rarTxdataValue,rarInfo->rarPduLen);
2700 #endif
2701
2702         return ROK;
2703 }
2704
2705 #endif
2706
2707 /*******************************************************************
2708  *
2709  * @brief Sends DL TTI Request to PHY
2710  *
2711  * @details
2712  *
2713  *    Function : handleDlTtiReq
2714  *
2715  *    Functionality:
2716  *         -Sends FAPI Param req to PHY
2717  *
2718  * @params[in]    RgDlSf *dlTtiReqSlot
2719  * @return ROK     - success
2720  *         RFAILED - failure
2721  *
2722  * ****************************************************************/
2723 uint16_t handleDlTtiReq(CmLteTimingInfo *dlTtiReqtimingInfo)
2724 {
2725 #ifdef FAPI
2726         uint8_t idx;
2727         uint8_t nPdu = 0;
2728         uint8_t numPduEncoded = 0;
2729         uint32_t msgLen = 0;
2730         fapi_dl_tti_req_t *dlTtiReq = NULLP;
2731         fapi_tx_data_req_t *txDataReq = NULLP;
2732         RgCellCb  *cellCbParams = NULLP;
2733         MacDlSlot *currDlSlot = NULLP;
2734         MacCellCfg macCellCfg;
2735         memset(&macCellCfg, 0, sizeof(MacCellCfg));
2736         Inst inst = 0;
2737
2738         if(clGlobalCp.phyState == PHY_STATE_RUNNING)
2739         {
2740                 cellCbParams = rgCb[inst].cell;
2741                 macCellCfg = cellCbParams->macCellCfg;
2742
2743                 if(dlTtiReqtimingInfo != NULLP)
2744                 {
2745                    LWR_MAC_ALLOC(dlTtiReq, sizeof(fapi_dl_tti_req_t));
2746                         if(dlTtiReq != NULLP)
2747                         {
2748                                 dlTtiReq->sfn = dlTtiReqtimingInfo->sfn;
2749                                 dlTtiReq->slot = dlTtiReqtimingInfo->slot;
2750                                 currDlSlot = &macCb.macCell->dlSlot[dlTtiReq->slot % MAX_SLOT_SUPPORTED];
2751                                 dlTtiReq->nPdus = calculatePduCount(&currDlSlot->dlInfo);  /* get total Pdus */
2752                                 nPdu = dlTtiReq->nPdus;
2753                                 dlTtiReq->nGroup = 0;
2754                                 if(dlTtiReq->nPdus > 0)
2755                                 {
2756                                    LWR_MAC_ALLOC(dlTtiReq->pdus, (nPdu * sizeof(fapi_dl_tti_req_pdu_t)));
2757                if(!dlTtiReq->pdus)
2758                {
2759                   DU_LOG("\nLOWER MAC: Memory allocation failed");
2760                   return RFAILED;
2761                }
2762           
2763                                         if(currDlSlot->dlInfo.isBroadcastPres)
2764                                         {
2765                                                 if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
2766                                                 {
2767                                                         if(dlTtiReq->pdus != NULLP)
2768                                                         {
2769                                                                 for(idx = 0; idx < currDlSlot->dlInfo.brdcstAlloc.ssbIdxSupported; idx++)
2770                                                                 {
2771                                                                         if(idx > 0)
2772                                                                                 dlTtiReq->pdus++;
2773                                                                         fillSsbPdu(&dlTtiReq->pdus[numPduEncoded], &macCellCfg, currDlSlot, &msgLen, idx);
2774                                                                         numPduEncoded++;
2775                                                                 }
2776                                                         }
2777                                                         DU_LOG("\nLOWER MAC: MIB sent..");
2778                                                 }
2779                                                 if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
2780                                                 {
2781                                                         /* Filling SIB1 param */
2782                                                         if(numPduEncoded != nPdu)
2783                                                         {
2784                                                                 fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo.brdcstAlloc.\
2785                                                                                 sib1Alloc.sib1PdcchCfg, &msgLen);
2786                                                                 numPduEncoded++;
2787                                                                 fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo.brdcstAlloc.\
2788                                                                                 sib1Alloc.sib1PdschCfg, &msgLen);
2789                                                                 numPduEncoded++;
2790                                                         }
2791                                                         DU_LOG("\nLOWER MAC: SIB1 sent...");
2792                                                 }
2793                                         }
2794                                         if(currDlSlot->dlInfo.isRarPres)
2795                                         {
2796                                                 /* Filling RAR param */
2797                                                 fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdcchCfg, &msgLen);
2798                                                 numPduEncoded++;
2799                                                 fillPdschPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdschCfg, &msgLen);
2800                                                 numPduEncoded++;
2801                                                 DU_LOG("\nLOWER MAC: RAR sent...");
2802                                         }
2803
2804                                         msgLen += sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
2805                                         fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
2806                                         /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
2807                                         LwrMacSendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
2808
2809                /* send TX_Data request message */
2810                if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
2811                {
2812                   msgLen = 0;
2813                   LWR_MAC_ALLOC(txDataReq,sizeof(fapi_tx_data_req_t));
2814                   txDataReq->sfn = dlTtiReqtimingInfo->sfn;
2815                   txDataReq->slot = dlTtiReqtimingInfo->slot;
2816                   txDataReq->numPdus = 1;
2817                                                 LWR_MAC_ALLOC(txDataReq->pduDesc, (txDataReq->numPdus * \
2818                                                 sizeof(fapi_tx_pdu_desc_t)));
2819                   fillSib1TxDataReq(
2820                         txDataReq->pduDesc,
2821                         &rgCb[inst].cell->macCellCfg,
2822                         currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg.pduIndex,
2823                         &msgLen);
2824                   msgLen += sizeof(fapi_tx_data_req_t) - sizeof(fapi_msg_t);
2825                   fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
2826                   LwrMacSendToPhy(txDataReq->header.message_type_id, msgLen,(void *)txDataReq);
2827                }
2828                if(currDlSlot->dlInfo.isRarPres)
2829                {
2830                   msgLen = 0;
2831                                                 /* mux and form RAR pdu */
2832                                                 fillRarPdu(&currDlSlot->dlInfo.rarAlloc.rarInfo);
2833                   LWR_MAC_ALLOC(txDataReq,sizeof(fapi_tx_data_req_t));
2834                   txDataReq->sfn = dlTtiReqtimingInfo->sfn;
2835                   txDataReq->slot = dlTtiReqtimingInfo->slot;
2836                   txDataReq->numPdus = 1;
2837                                                 LWR_MAC_ALLOC(txDataReq->pduDesc, (txDataReq->numPdus * \
2838                                                    sizeof(fapi_tx_pdu_desc_t)));
2839                   fillRarTxDataReq(
2840                         txDataReq->pduDesc,
2841                         &currDlSlot->dlInfo.rarAlloc.rarInfo,
2842                         currDlSlot->dlInfo.rarAlloc.rarPdschCfg.pduIndex,
2843                         &msgLen);
2844                   fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
2845                   LwrMacSendToPhy(txDataReq->header.message_type_id, msgLen,(void *)txDataReq);
2846                }
2847                                 }
2848                                 else
2849                                 {
2850                                         msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
2851                                         fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
2852                                         /* TODO : Recheck the size / msglen to be sent to WLS_Put*/
2853                                         LwrMacSendToPhy(dlTtiReq->header.message_type_id, msgLen, (void *)dlTtiReq);
2854                                 }
2855                                 return ROK;
2856                         }
2857                         else
2858                         {
2859                                 DU_LOG("\nLOWER MAC: Failed to allocate memory for DL TTI Request");
2860                                 return RFAILED;
2861                         }
2862                 }
2863       else
2864       {
2865          DU_LOG("\nLOWER MAC: Current TTI Info is NULL");
2866          return RFAILED;
2867       }
2868    }
2869    else
2870    {
2871        lwr_mac_handleInvalidEvt(dlTtiReqtimingInfo);
2872    }
2873 #endif
2874    return ROK;
2875 }
2876
2877 /***********************************************************************
2878  *
2879  * @brief calculates the total size to be allocated for UL TTI Req
2880  *
2881  * @details
2882  *
2883  *    Function : getnPdus
2884  *
2885  *    Functionality:
2886  *         -calculates the total pdu count to be allocated for UL TTI Req
2887  *
2888  * @params[in] Pointer to fapi Ul TTI Req
2889  *             Pointer to CurrUlSlot
2890  * @return count
2891  * ********************************************************************/
2892 #ifdef FAPI
2893 uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
2894 {
2895         uint8_t pduCount = 0;
2896
2897         if(currUlSlot != NULLP)
2898    {
2899            if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_PRACH)
2900            {
2901               pduCount++;
2902               ulTtiReq->rachPresent = PDU_PRESENT;
2903                 }
2904                 if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
2905                 {
2906                    pduCount++;
2907                         ulTtiReq->nUlsch = PDU_PRESENT;
2908                 }
2909                 if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_UCI)
2910                 {
2911                    pduCount++;
2912                         ulTtiReq->nUlcch = PDU_PRESENT;
2913                 }
2914                 if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_SRS)
2915                 {
2916                    pduCount++;
2917                 }
2918    }
2919         return pduCount;
2920
2921 #endif  
2922
2923 /***********************************************************************
2924  *
2925  * @brief Set the value of zero correlation config in PRACH PDU
2926  *
2927  * @details
2928  *
2929  *    Function : setNumCs
2930  *
2931  *    Functionality:
2932  *         -Set the value of zero correlation config in PRACH PDU
2933  *
2934  * @params[in] Pointer to zero correlation config
2935  *             Pointer to MacCellCfg
2936  * ********************************************************************/
2937
2938 void setNumCs(uint8_t *numCs, MacCellCfg *macCellCfg)
2939 {
2940 #ifdef FAPI
2941    uint8_t idx;
2942         if(macCellCfg != NULLP)
2943         {
2944            idx = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
2945            *numCs = UnrestrictedSetNcsTable[idx];
2946         }
2947 #endif
2948 }
2949
2950 /***********************************************************************
2951  *
2952  * @brief Fills the PRACH PDU in UL TTI Request
2953  *
2954  * @details
2955  *
2956  *    Function : fillPrachPdu
2957  *
2958  *    Functionality:
2959  *         -Fills the PRACH PDU in UL TTI Request
2960  *
2961  * @params[in] Pointer to Prach Pdu
2962  *             Pointer to CurrUlSlot
2963  *             Pointer to macCellCfg
2964  *             Pointer to msgLen
2965  * ********************************************************************/
2966
2967 #ifdef FAPI
2968 void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot, uint32_t *msgLen)
2969 {
2970    if(ulTtiReqPdu != NULLP)
2971    {
2972       ulTtiReqPdu->pduType = PRACH_PDU_TYPE; 
2973       ulTtiReqPdu->u.prach_pdu.physCellId = macCellCfg->phyCellId;
2974       ulTtiReqPdu->u.prach_pdu.numPrachOcas = currUlSlot->ulCellInfo.prachSchInfo.numPrachOcas;
2975       ulTtiReqPdu->u.prach_pdu.prachFormat = \
2976                 currUlSlot->ulCellInfo.prachSchInfo.prachFormat;
2977       ulTtiReqPdu->u.prach_pdu.numRa = currUlSlot->ulCellInfo.prachSchInfo.numRa;
2978       ulTtiReqPdu->u.prach_pdu.prachStartSymbol = \
2979                 currUlSlot->ulCellInfo.prachSchInfo.prachStartSymb;
2980       setNumCs(&ulTtiReqPdu->u.prach_pdu.numCs, macCellCfg);
2981       ulTtiReqPdu->u.prach_pdu.beamforming.numPrgs = 0;
2982       ulTtiReqPdu->u.prach_pdu.beamforming.prgSize = 0;
2983       ulTtiReqPdu->u.prach_pdu.beamforming.digBfInterfaces = 0;
2984       ulTtiReqPdu->u.prach_pdu.beamforming.pmi_bfi[0].pmIdx = 0;
2985       ulTtiReqPdu->u.prach_pdu.beamforming.pmi_bfi[0].beamIdx[0].beamidx = 0;
2986       ulTtiReqPdu->pduSize = sizeof(fapi_ul_prach_pdu_t); 
2987       SETLENGTH(*msgLen, sizeof(fapi_dl_pdsch_pdu_t));
2988    }
2989 }
2990 #endif
2991
2992 /*******************************************************************
2993  *
2994  * @brief Sends UL TTI Request to PHY
2995  *
2996  * @details
2997  *
2998  *    Function : handleUlTtiReq
2999  *
3000  *    Functionality:
3001  *         -Sends FAPI Param req to PHY
3002  *
3003  * @params[in]  Pointer to CmLteTimingInfo
3004  * @return ROK     - success
3005  *         RFAILED - failure
3006  *
3007  ******************************************************************/
3008 S16 handleUlTtiReq(CmLteTimingInfo *currTimingInfo)
3009 {
3010 #ifdef FAPI
3011    uint32_t msgLen = 0;
3012    fapi_ul_tti_req_t *ulTtiReq = NULLP;
3013    fapi_ul_tti_req_pdu_t *ulTtiReqPdu = NULLP;
3014    RgCellCb  *cellCbParams = NULLP;
3015    MacUlSlot *currUlSlot = NULLP;
3016    MacCellCfg macCellCfg;
3017         memset(&macCellCfg, 0, sizeof(MacCellCfg));
3018    Inst inst = 0;
3019
3020    if(clGlobalCp.phyState == PHY_STATE_RUNNING)
3021    {
3022       cellCbParams = rgCb[inst].cell;
3023       macCellCfg = cellCbParams->macCellCfg;
3024
3025       if(currTimingInfo != NULLP)
3026       {
3027          LWR_MAC_ALLOC(ulTtiReq, sizeof(fapi_ul_tti_req_t));
3028          if(ulTtiReq != NULLP)
3029          {
3030             ulTtiReq->sfn = currTimingInfo->sfn;
3031             ulTtiReq->slot = currTimingInfo->slot;
3032             currUlSlot = &macCb.macCell->ulSlot[ulTtiReq->slot % MAX_SLOT_SUPPORTED];
3033                  ulTtiReq->nPdus = getnPdus(ulTtiReq, currUlSlot);
3034             ulTtiReq->nGroup = 0;
3035             if(ulTtiReq->nPdus > 0)
3036             {
3037                                    LWR_MAC_ALLOC(ulTtiReqPdu, (ulTtiReq->nPdus *
3038                                         sizeof(fapi_ul_tti_req_pdu_t)));
3039                /* Fill Prach Pdu */
3040                if(ulTtiReq->rachPresent)
3041                {
3042                  if(ulTtiReqPdu != NULLP)
3043                  {
3044                     fillPrachPdu(ulTtiReqPdu, &macCellCfg, currUlSlot, &msgLen);
3045                     ulTtiReq->pdus = ulTtiReqPdu;
3046                  }
3047                  msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
3048                  fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
3049                  DU_LOG("\nLOWER MAC: Sending UL TTI Request");
3050                  LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgLen, (void *)ulTtiReq);
3051                }
3052             } 
3053             else
3054             {
3055                 msgLen = sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t);
3056                 fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
3057                 DU_LOG("\nLOWER MAC: Sending UL TTI Request");
3058                 LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgLen, (void *)ulTtiReq);
3059             }
3060                                 return ROK;
3061          }
3062               else
3063               {
3064                  DU_LOG("\nLOWER MAC: Failed to allocate memory for UL TTI Request");
3065             return RFAILED;
3066          }
3067       }
3068       else
3069       {
3070          DU_LOG("\nLOWER MAC: Current TTI Info in UL is NULL");
3071          return RFAILED;
3072       }
3073    }
3074    else
3075    {
3076        lwr_mac_handleInvalidEvt(currTimingInfo);
3077    }
3078 #endif
3079    return ROK;
3080 }
3081
3082 lwrMacFsmHdlr fapiEvtHdlr[MAX_STATE][MAX_EVENT] =
3083 {
3084    {
3085       /* PHY_STATE_IDLE */
3086        lwr_mac_handleParamReqEvt,
3087        lwr_mac_handleParamRspEvt,
3088        lwr_mac_handleConfigReqEvt,
3089        lwr_mac_handleConfigRspEvt,
3090        lwr_mac_handleInvalidEvt,
3091    },
3092    {
3093        /* PHY_STATE_CONFIGURED */
3094        lwr_mac_handleParamReqEvt,
3095        lwr_mac_handleParamRspEvt,
3096        lwr_mac_handleConfigReqEvt,
3097        lwr_mac_handleConfigRspEvt,
3098        lwr_mac_handleStartReqEvt,
3099    },
3100    {
3101        /* PHY_STATE_RUNNING */
3102        lwr_mac_handleInvalidEvt,
3103        lwr_mac_handleInvalidEvt,
3104        lwr_mac_handleConfigReqEvt,
3105        lwr_mac_handleConfigRspEvt,
3106        lwr_mac_handleInvalidEvt,
3107    }
3108 };
3109
3110 /*******************************************************************
3111  *
3112  * @brief Sends message to Lower Mac Fsm Event Handler
3113  *
3114  * @details
3115  *
3116  *    Function : sendToLowerMac
3117  *
3118  *    Functionality:
3119  *         -Sends message to LowerMac
3120  *
3121  * @params[in] Message Type
3122  *             Message Length
3123  *             Messaga Pointer
3124  *
3125  * @return void
3126  *
3127 ******************************************************************/
3128 void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg)
3129 {
3130    clGlobalCp.event = msgType;
3131    fapiEvtHdlr[clGlobalCp.phyState][clGlobalCp.event](msg);
3132 }
3133 /**********************************************************************
3134          End of file
3135 **********************************************************************/