[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-449] Fixes releate to Cell Id
[o-du/l2.git] / src / du_app / du_sys_info_hdl.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 /* This file contains ASN codec for MIB and SIB1 msgs */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "lkw.x"
23 #include "lrg.x"
24 #include "legtp.h"
25 #include "du_app_mac_inf.h"
26 #include "du_cfg.h"
27 #include "du_app_rlc_inf.h"
28 #include "du_mgr.h"
29 #include "du_utils.h"
30 #include "BCCH-BCH-Message.h"
31 #include "MIB.h"
32 #include "PLMN-IdentityInfo.h"
33 #include "PLMN-IdentitY.h"
34 #include "SIB-TypeInfo.h"
35 #include "SchedulingInfo.h"
36 #include "SI-SchedulingInfo.h"
37 #include "ConnEstFailureControl.h"
38 #include "FrequencyInfoDL-SIB.h"
39 #include "SearchSpace.h"
40 #include "SCS-SpecificCarrier.h"
41 #include "NR-MultiBandInfo.h"
42 #include "PDCCH-ConfigCommon.h"
43 #include "PDSCH-TimeDomainResourceAllocation.h"
44 #include "PDSCH-TimeDomainResourceAllocationList.h"
45 #include "PDSCH-ConfigCommon.h"
46 #include "BWP-DownlinkCommon.h"
47 #include "DownlinkConfigCommonSIB.h"
48 #include "RACH-ConfigCommon.h"
49 #include "PUSCH-TimeDomainResourceAllocation.h"
50 #include "PUSCH-TimeDomainResourceAllocationList.h"
51 #include "PUSCH-ConfigCommon.h"
52 #include "PUCCH-ConfigCommon.h"
53 #include "UplinkConfigCommonSIB.h"
54 #include "TDD-UL-DL-ConfigCommon.h"
55 #include "ServingCellConfigCommonSIB.h"
56 #include "MCC.h"
57 #include "SIB1.h"
58 #include "odu_common_codec.h"
59 #include "du_sys_info_hdl.h"
60 #include "du_f1ap_conversions.h"
61
62 void FreeSib1Msg(SIB1_t *sib1Msg);
63 uint8_t FreqInfoUlret = RFAILED;
64 uint8_t RachCfgCommonret = RFAILED;
65 uint8_t PuschCfgCommonret = RFAILED;
66 uint8_t UlCfgCommSibret = RFAILED;
67 uint8_t FreqInfoDlret = RFAILED;
68 uint8_t DlCfgCommSibret = RFAILED;
69 uint8_t CommonSerachSpaceListret = RFAILED;
70
71 /*******************************************************************
72  *
73  * @brief Builds MIB
74  *
75  * @details
76  *
77  *    Function : BuildMib
78  *
79  *    Functionality: Building MIB
80  *
81  * @return ROK     - success
82  *         RFAILED - failure
83  *
84  * ****************************************************************/
85 uint8_t BuildMib(MIB_t *mib)
86 {
87    mib->systemFrameNumber.size = sizeof(uint8_t);
88    DU_ALLOC(mib->systemFrameNumber.buf, mib->systemFrameNumber.size);
89    if(!(mib->systemFrameNumber.buf))
90    {
91       DU_LOG("\nERROR  -->  DU APP: MIB msg memory allocation failure");
92       return RFAILED;
93    }
94
95    *(mib->systemFrameNumber.buf) =  duCfgParam.mibParams.sysFrmNum;
96    mib->systemFrameNumber.bits_unused = ODU_VALUE_TWO;
97
98    mib->subCarrierSpacingCommon = duCfgParam.mibParams.subCarrierSpacingCommon;
99    mib->ssb_SubcarrierOffset = duCfgParam.mibParams.ssb_SubcarrierOffset;
100    mib->dmrs_TypeA_Position = duCfgParam.mibParams.dmrs_TypeA_Position;
101    mib->pdcch_ConfigSIB1.controlResourceSetZero = duCfgParam.mibParams.controlResourceSetZero;
102    mib->pdcch_ConfigSIB1.searchSpaceZero = duCfgParam.mibParams.searchSpaceZero;
103    mib->cellBarred = duCfgParam.mibParams.cellBarred;
104    mib->intraFreqReselection = duCfgParam.mibParams.intraFreqReselection;
105    mib->spare.size = sizeof(uint8_t);
106    DU_ALLOC(mib->spare.buf, mib->spare.size);
107    if(!mib->spare.buf)
108    {
109       DU_LOG("\nERROR  -->  DU APP: MIB msg memory allocation failure");
110       return RFAILED;
111    }
112    *(mib->spare.buf) = SPARE;
113    mib->spare.bits_unused = ODU_VALUE_SEVEN;
114    return ROK;
115 }
116 /*******************************************************************
117  *
118  * @brief Free MIB PDU for broadcast
119  *
120  * @details
121  *
122  *    Function : FreeMibPdu
123  *
124  *    Functionality: Deallocating MIB PDU for system broadcast
125  *
126  * @param[in]: BCCH_BCH_Message_t *bcchMsg
127  *
128  * @return void         
129  *
130  * ****************************************************************/
131 void FreeMibPdu(BCCH_BCH_Message_t *bcchMsg)
132 {
133    if(bcchMsg)
134    {
135       if(bcchMsg->message.choice.mib)
136       {
137          if((bcchMsg->message.choice.mib->systemFrameNumber.buf))
138          {
139             if(bcchMsg->message.choice.mib->spare.buf)
140             {
141                DU_FREE(bcchMsg->message.choice.mib->spare.buf,\
142                      bcchMsg->message.choice.mib->spare.size);
143             }
144             DU_FREE(bcchMsg->message.choice.mib->systemFrameNumber.buf,
145                   bcchMsg->message.choice.mib->systemFrameNumber.size);
146          }
147          DU_FREE(bcchMsg->message.choice.mib, sizeof(MIB_t));
148       }
149       DU_FREE(bcchMsg, sizeof(BCCH_BCH_Message_t));
150    }
151 }
152 /*******************************************************************
153  *
154  * @brief Builds MIB PDU for broadcast
155  *
156  * @details
157  *
158  *    Function : BuildMibPdu
159  *
160  *    Functionality: Building MIB PDU for system broadcast
161  *
162  * @return ROK     - success
163  *         RFAILED - failure
164  *
165  * ****************************************************************/
166 uint8_t BuildMibPdu()
167 {
168    uint8_t ret = RFAILED;
169    BCCH_BCH_Message_t *bcchMsg;
170    asn_enc_rval_t encRetVal;        /* Encoder return value */
171    while(true)
172    {
173       DU_ALLOC(bcchMsg, sizeof(BCCH_BCH_Message_t));
174       if(!bcchMsg)
175       {
176          DU_LOG("\nERROR  -->  Memory allocation failure in BuildMibPdu");
177          break;
178       }
179
180       bcchMsg->message.present = BCCH_BCH_MessageType_PR_mib;
181       DU_ALLOC(bcchMsg->message.choice.mib, sizeof(MIB_t));
182       if(!bcchMsg->message.choice.mib)
183       {
184          DU_LOG("\nERROR  -->  Memory allocation failure in BuildMibPdu");
185          break;
186       }
187       if(BuildMib(bcchMsg->message.choice.mib) != ROK)
188       {
189          break;
190       }
191       xer_fprint(stdout, &asn_DEF_BCCH_BCH_Message, bcchMsg);
192       memset(encBuf, 0, ENC_BUF_MAX_LEN);
193       encBufSize = 0;
194       encRetVal = aper_encode(&asn_DEF_BCCH_BCH_Message, 0,
195             bcchMsg, PrepFinalEncBuf, encBuf);
196       printf("\nencbufSize:%d\n", encBufSize);
197       if(encRetVal.encoded == -1) 
198       {   
199          DU_LOG("\nERROR  -->  DU APP: Could not encode BCCH BCH Message Type structure(at %s)\n", 
200                encRetVal.failed_type?\
201                encRetVal.failed_type->name
202                :"unknown");
203          break;
204       }    
205
206       /* Print encoded buffer */
207       for(int i=0; i< encBufSize; i++)
208       {
209          printf("%x\t",encBuf[i]);
210       } 
211       printf("\n");
212
213       ret = ROK;
214       break;
215    }
216    /* Free allocated memory */
217    FreeMibPdu(bcchMsg);
218
219    return ret;
220
221 }
222 /*******************************************************************
223  *
224  * @brief free MIB message in Served Cell Info
225  *
226  * @details
227  *
228  *    Function : FreeMibMsg
229  *
230  *    Functionality: deallocating MIB message in Served Cell Info
231  *
232  * @param[in]   MIB_t *mibMsg
233  *
234  * @return void
235  *        
236  *
237  * ****************************************************************/
238 void FreeMibMsg( MIB_t *mibMsg)
239 {
240    if(mibMsg)
241    {
242       if((mibMsg->systemFrameNumber.buf))
243       {   
244          if(mibMsg->spare.buf)
245          {
246             DU_FREE(mibMsg->spare.buf, mibMsg->spare.size);
247          }
248          DU_FREE(mibMsg->systemFrameNumber.buf,
249                mibMsg->systemFrameNumber.size);
250       }
251       DU_FREE(mibMsg, sizeof(MIB_t));
252    }
253 }
254 /*******************************************************************
255  *
256  * @brief Builds MIB message in Served Cell Info
257  *
258  * @details
259  *
260  *    Function : BuildMibMsg
261  *
262  *    Functionality: Building MIB message in Served Cell Info
263  *
264  * @return ROK     - success
265  *         RFAILED - failure
266  *
267  * ****************************************************************/
268 uint8_t BuildMibMsg()
269 {
270    MIB_t          *mibMsg;
271    asn_enc_rval_t encRetVal;        /* Encoder return value */
272    uint8_t ret = RFAILED;
273    while(true)
274    {
275       DU_ALLOC(mibMsg, sizeof(MIB_t));
276       if(!mibMsg)
277       {
278          DU_LOG("\nERROR  -->  DU APP: MIB msg memory allocation failure");
279          return RFAILED;
280       }
281       if(BuildMib(mibMsg) != ROK)
282       {
283          break;
284       }
285       xer_fprint(stdout, &asn_DEF_MIB, mibMsg);
286       memset(encBuf, 0, ENC_BUF_MAX_LEN);
287       encBufSize = 0;
288       encRetVal = aper_encode(&asn_DEF_MIB, 0,
289             mibMsg, PrepFinalEncBuf, encBuf);
290       printf("\nencbufSize:%d\n", encBufSize);
291       if(encRetVal.encoded      == -1) 
292       {   
293          DU_LOG("\nERROR  -->  DU APP: Could not encode MIB structure(at %s)\n", 
294                encRetVal.failed_type?\
295                encRetVal.failed_type->name
296                :"unknown");
297          break;
298       }  
299
300       /* Print encoded buffer */
301       for(int i=0; i< encBufSize; i++)
302       {
303          printf("%x\t",encBuf[i]);
304       } 
305       printf("\n");
306
307       /* Free allocated memory */
308       ret = ROK;
309       break;
310    }
311
312    FreeMibMsg(mibMsg);
313
314    return ret;
315
316 }
317
318 /*******************************************************************
319  *
320  * @brief Builds CellIdentity  within SIB1 message
321  *
322  * @details
323  *
324  *    Function : BuildCellIdentity
325  *
326  *    Functionality: Building RAN area code in SIB1 message 
327  *
328  * @params[in] RAN_AreaCode_t **ranAreaCode 
329  * @return ROK     - success
330  *         RFAILED - failure
331  *
332  * ****************************************************************/
333 uint8_t BuildCellIdentity(CellIdentity_t  *cellIdentity)
334 {
335    cellIdentity->size = ODU_VALUE_FIVE*sizeof(uint8_t);
336
337    DU_ALLOC(cellIdentity->buf, cellIdentity->size);
338    if(!cellIdentity->buf)
339    {   
340       DU_LOG("\nERROR  -->  DU APP: CellIdentity memory allocation failure");
341       return RFAILED;
342    }
343    fillBitString(cellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity); 
344
345    return ROK;
346 }
347 /*******************************************************************
348  *
349  * @brief Builds RANAC within SIB1 message
350  *
351  * @details
352  *
353  *    Function : BuildRanac
354  *
355  *    Functionality: Building RAN area code in SIB1 message 
356  *
357  * @params[in] RAN_AreaCode_t **ranAreaCode 
358  * @return ROK     - success
359  *         RFAILED - failure
360  *
361  * ****************************************************************/
362 uint8_t BuildRanac(RAN_AreaCode_t **ranAreaCode)
363 {
364    RAN_AreaCode_t *ranac;
365    DU_ALLOC(ranac, sizeof(RAN_AreaCode_t));
366    if(!ranac)
367    {   
368       DU_LOG("\nERROR  -->  DU APP: RANAC memory allocation failure");
369       return RFAILED;
370    }   
371    *ranac = duCfgParam.sib1Params.ranac;
372    *ranAreaCode = ranac;
373    return ROK;
374 }
375 /*******************************************************************
376  *
377  * @brief Builds TAC within SIB1 message
378  *
379  * @details
380  *
381  *    Function : BuildTac
382  *
383  *    Functionality: Building Tracking area code in SIB1 message 
384  *
385  * @params[in] TrackingAreaCode_t **tac 
386  * @return ROK     - success
387  *         RFAILED - failure
388  *
389  * ****************************************************************/
390 uint8_t BuildTac(TrackingAreaCode_t **trackAreaCode)
391 {
392    TrackingAreaCode_t *tac;
393
394
395    DU_ALLOC(tac, sizeof(TrackingAreaCode_t));
396    if(!tac)
397    {   
398       DU_LOG("\nERROR  -->  DU APP: TAC memory allocation failure");
399       return RFAILED;
400    }   
401
402    tac->size = ODU_VALUE_THREE*sizeof(uint8_t);
403    DU_ALLOC(tac->buf, tac->size);
404    if(!tac->buf)
405    {   
406       DU_LOG("\nERROR  -->  DU APP: TAC memory allocation failure");
407       return RFAILED;
408    }   
409    *(tac->buf) = duCfgParam.sib1Params.tac;
410    tac->bits_unused = ODU_VALUE_ZERO;
411    *trackAreaCode = tac;
412
413    return ROK;
414 }
415
416 /*******************************************************************
417  *
418  * @brief Builds PLMN list within SIB1 message
419  *
420  * @details
421  *
422  *    Function : BuildPlmnList
423  *
424  *    Functionality: Building PLMN list in SIB1 message 
425  *
426  * @params[in] CellAccessRelatedInfo_t *cellAccessInfo 
427  * @return ROK     - success
428  *         RFAILED - failure
429  *
430  * ****************************************************************/
431 uint8_t BuildPlmnList(CellAccessRelatedInfo_t *cellAccessInfo)
432 {
433    uint8_t            idx;
434    uint8_t            idx1;
435    uint8_t            idx2;
436    uint8_t            elementCnt;
437    TrackingAreaCode_t **tac;
438    RAN_AreaCode_t     **ranac;
439    CellIdentity_t     *cellIdentity;
440    uint8_t            ret;      
441    struct PLMN_IdentityInfo__plmn_IdentityList
442       *plmnIdInfo;
443
444    DU_ALLOC(cellAccessInfo->plmn_IdentityList.list.array,
445          cellAccessInfo->plmn_IdentityList.list.size);
446    if(!cellAccessInfo->plmn_IdentityList.list.array)
447    {   
448       DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
449       return RFAILED;
450    }   
451    elementCnt = cellAccessInfo->plmn_IdentityList.list.count; 
452    for(idx=0; idx<elementCnt; idx++)
453    {   
454       DU_ALLOC(cellAccessInfo->plmn_IdentityList.list.array[idx],
455             sizeof(PLMN_IdentityInfo_t));
456       if(!cellAccessInfo->plmn_IdentityList.list.array[idx])
457       {
458          DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
459          return RFAILED;
460       }
461    }
462
463    idx = 0;
464    /* PLMN list */
465    elementCnt = ODU_VALUE_ONE;
466
467    plmnIdInfo = &cellAccessInfo->plmn_IdentityList.list.array[idx]->\
468                 plmn_IdentityList;
469    plmnIdInfo->list.count = elementCnt;
470    plmnIdInfo->list.size  = elementCnt * sizeof(PLMN_IdentitY_t *);
471    DU_ALLOC(plmnIdInfo->list.array, plmnIdInfo->list.size);
472    if(!plmnIdInfo->list.array)
473    {
474       DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
475       return RFAILED;
476    }
477
478    for(idx1=0; idx1<elementCnt; idx1++)
479    {
480       DU_ALLOC(plmnIdInfo->list.array[idx1],
481             sizeof(PLMN_IdentitY_t));
482       if(!(plmnIdInfo->list.array[idx1]))
483       {
484          DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
485          return RFAILED;
486       }
487    }
488    idx1 = 0;
489    DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc,
490          sizeof(MCC_t));
491    if(!plmnIdInfo->list.array[idx1]->mcc)
492    {
493       DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
494       return RFAILED;
495    }
496
497    elementCnt = ODU_VALUE_THREE;
498    plmnIdInfo->list.array[idx1]->mcc->list.count = elementCnt;
499    plmnIdInfo->list.array[idx1]->mcc->list.size =\
500                                                  elementCnt * sizeof(MCC_MNC_Digit_t *);
501    DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc->list.array,
502          plmnIdInfo->list.array[idx1]->mcc->list.size)
503       if(!(plmnIdInfo->list.array[idx1]->mcc->list.array))
504       {
505          DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
506          return RFAILED;
507       }
508    for(idx2=0; idx2<elementCnt; idx2++)
509    {
510       DU_ALLOC(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2],
511             sizeof(MCC_MNC_Digit_t));
512       if(!plmnIdInfo->list.array[idx1]->mcc->list.array[idx2])
513       {
514          DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
515          return RFAILED;
516       }
517       *(plmnIdInfo->list.array[idx1]->mcc->list.array[idx2])=\
518                                                              duCfgParam.sib1Params.plmn.mcc[idx2];
519    }
520    idx2 = 0;
521    plmnIdInfo->list.array[idx1]->mnc.list.count = elementCnt;
522    plmnIdInfo->list.array[idx1]->mnc.list.size =\
523                                                 elementCnt * sizeof(MCC_MNC_Digit_t *);
524    DU_ALLOC(plmnIdInfo->list.array[idx1]->mnc.list.array,\
525          plmnIdInfo->list.array[idx1]->mnc.list.size);
526    if(!plmnIdInfo->list.array[idx1]->mnc.list.array)
527    {
528       DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
529       return RFAILED;
530    }
531    for(idx2=0; idx2<elementCnt; idx2++)
532    {
533       DU_ALLOC(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2],
534             sizeof(MCC_MNC_Digit_t));
535       if(!plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])
536       {
537          DU_LOG("\nERROR  -->  DU APP: BuildPlmnList memory allocation failure");
538          return RFAILED;
539       }
540       *(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])=\
541                                                             duCfgParam.sib1Params.plmn.mnc[idx2];
542    }
543
544    /* Tracking Area Code */
545    tac = &cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode;
546    ret = BuildTac(tac);
547    if(ret != ROK)
548    {
549       return RFAILED;
550    }
551
552    /* RANAC */
553    ranac = &cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac;
554    ret=BuildRanac(ranac);
555    if(ret != ROK)
556    {
557       return RFAILED;
558    }
559
560    /* CellIdentity */
561    cellIdentity = &cellAccessInfo->plmn_IdentityList.list.array[idx]->cellIdentity;
562    ret=BuildCellIdentity(cellIdentity);
563    if(ret != ROK)
564    {
565       return RFAILED;
566    }
567
568    /* cellReservedForOperatorUse */
569    cellAccessInfo->plmn_IdentityList.list.array[idx]->\
570       cellReservedForOperatorUse = duCfgParam.sib1Params.cellResvdForOpUse;
571
572
573    return ROK;
574 }
575
576 /*******************************************************************
577  *
578  * @brief  Build SIB Map Info List
579  *
580  * @details
581  *
582  *    Function : BuildSibMapInfoList
583  *
584  *    Functionality:
585  *       Build SIB MapInfo List
586  *
587  * @params[in] SIB_Mapping_t pointer
588  * @return ROK     - success
589  *         RFAILED - failure
590  *
591  * ****************************************************************/
592 uint8_t BuildSibMapInfoList(SIB_Mapping_t *sibMapInfo)
593 {
594    uint8_t   itr;         /* List iterator */
595    uint8_t   elementCnt;  /* Number of elements in list */
596    SIB_TypeInfo_t *sibTypeInfo;  /* Scheduling info */
597
598    /* SI scheduling info list */
599    DU_ALLOC(sibMapInfo->list.array, sibMapInfo->list.size);
600    if(!sibMapInfo->list.array)
601    {
602       DU_LOG("\nERROR  -->  DU APP: BuildSibMapInfoList memory allocation failure");
603       return RFAILED;
604    }
605
606    elementCnt = sibMapInfo->list.count;
607    for(itr = 0; itr < elementCnt; itr++)
608    {
609       DU_ALLOC(sibMapInfo->list.array[itr], sizeof(SIB_TypeInfo_t));
610       if(!sibMapInfo->list.array[itr])
611       {
612          DU_LOG("\nERROR  -->  DU APP: BuildSibMapInfoList memory allocation failure");
613          return RFAILED;
614       }
615    }
616
617    itr = 0;
618    sibTypeInfo = sibMapInfo->list.array[itr];
619    sibTypeInfo->type = duCfgParam.sib1Params.siSchedInfo.sibType;
620    DU_ALLOC(sibTypeInfo->valueTag, sizeof(long));
621    if(!sibTypeInfo->valueTag)
622    {
623       DU_LOG("\nERROR  -->  DU APP: BuildSibMapInfoList memory allocation failure");
624       return RFAILED;
625    }
626
627    *sibTypeInfo->valueTag = duCfgParam.sib1Params.siSchedInfo.sibValTag;
628
629    return ROK;
630 }
631
632 /*******************************************************************
633  *
634  * @brief Builds SI Scheduling info list within SIB1 message 
635  *
636  * @details
637  *
638  *    Function : BuildSiSchedInfoList 
639  *
640  *    Functionality: 
641  *        Building SI Scheduling info list in SIB1 message
642  *
643  * @params[in] struct SI_SchedulingInfo__schedulingInfoList *si_SchedulingInfo
644  * @return ROK     - success
645  *         RFAILED - failure
646  *
647  * ****************************************************************/
648 uint8_t BuildSiSchedInfoList(struct SI_SchedulingInfo__schedulingInfoList *si_SchedulingInfoList)
649 {
650    uint8_t   itr;         /* List iterator */
651    uint8_t   elementCnt;  /* Number of elements in list */
652    uint8_t   ret;
653    SchedulingInfo_t *schedInfo;  /* Scheduling info */
654
655    /* SI scheduling info list */
656    DU_ALLOC(si_SchedulingInfoList->list.array, si_SchedulingInfoList->list.size);
657    if(!si_SchedulingInfoList->list.array)
658    {
659       DU_LOG("\nERROR  -->  DU APP: BuildSiSchedInfoList memory allocation failure");
660       return RFAILED;
661    }
662
663    elementCnt = si_SchedulingInfoList->list.count;
664    for(itr = 0; itr < elementCnt; itr++)
665    {
666       DU_ALLOC(si_SchedulingInfoList->list.array[itr], sizeof(struct SchedulingInfo));
667       if(!si_SchedulingInfoList->list.array[itr])
668       {
669          DU_LOG("\nERROR  -->  DU APP: BuildSiSchedInfoList memory allocation failure");
670          return RFAILED;
671       }
672    }
673
674    itr = 0;
675    schedInfo = si_SchedulingInfoList->list.array[itr];
676    schedInfo->si_BroadcastStatus = duCfgParam.sib1Params.siSchedInfo.broadcastSta;
677    schedInfo->si_Periodicity = duCfgParam.sib1Params.siSchedInfo.preiodicity;
678
679    elementCnt = ODU_VALUE_ONE; 
680    schedInfo->sib_MappingInfo.list.count = elementCnt;
681    schedInfo->sib_MappingInfo.list.size = elementCnt * sizeof(SIB_TypeInfo_t *);
682
683    ret = BuildSibMapInfoList(&schedInfo->sib_MappingInfo);
684    if(ret != ROK)
685    {
686       return RFAILED;
687    }
688
689    return ROK;
690 }
691
692 /*******************************************************************
693  *
694  * @brief Builds SCS Specific carrier list for DL 
695  *
696  * @details
697  *
698  *    Function : BuildScsSpecificCarrierListDlSib
699  *
700  *    Functionality:
701  *       Builds Subcarrier specific carrier list for downlink
702  *
703  * @params[in] FrequencyInfoDL_SIB__scs_SpecificCarrierList pointer
704  * @return ROK     - success
705  *         RFAILED - failure
706  *
707  * ****************************************************************/
708 uint8_t BuildScsSpecificCarrierListDlSib( struct FrequencyInfoDL_SIB__scs_SpecificCarrierList *scsCarrierList)
709 {
710    uint8_t idx;
711    ScsSpecCarrier   duScsSpecCarrier;
712
713    duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
714
715    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
716    if(!scsCarrierList->list.array)
717    {
718       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed"); 
719       return RFAILED;
720    }
721
722    for(idx = 0; idx < scsCarrierList->list.count; idx++)
723    {
724       DU_ALLOC(scsCarrierList->list.array[idx], sizeof(SCS_SpecificCarrier_t));
725       if(!scsCarrierList->list.array[idx])
726       {
727          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
728          return RFAILED;
729       }
730    }
731
732    idx = 0;
733    scsCarrierList->list.array[idx]->offsetToCarrier = duScsSpecCarrier.scsOffset; 
734    scsCarrierList->list.array[idx]->subcarrierSpacing = duScsSpecCarrier.scs;
735    scsCarrierList->list.array[idx]->carrierBandwidth = duScsSpecCarrier.scsBw;
736
737    return ROK;
738 } /* End of BuildScsSpecificCarrierListDlSib */
739
740 /*******************************************************************
741  *
742  * @brief Builds common search space list 
743  *
744  * @details
745  *
746  *    Function : BuildCommonSerachSpaceList
747  *
748  *    Functionality:
749  *      Builds common search space list
750  *
751  * @params[in] PDCCH_ConfigCommon__commonSearchSpaceList pointer
752  * @return ROK     - success
753  *         RFAILED - failure
754  *
755  * ****************************************************************/
756 uint8_t BuildCommonSerachSpaceList( struct PDCCH_ConfigCommon__commonSearchSpaceList *searchSpclist)
757 {
758    uint8_t idx;
759    SearchSpace_t    *searchSpace;
760    PdcchCfgCommon   duPdcchCfg;
761
762    duPdcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdcchCfg;
763
764    DU_ALLOC(searchSpclist->list.array, searchSpclist->list.size);
765    if(!searchSpclist->list.array)
766    {
767       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
768       return RFAILED;
769    }
770
771    for(idx = 0; idx < searchSpclist->list.count; idx++)
772    {
773       DU_ALLOC(searchSpclist->list.array[idx], sizeof(SearchSpace_t));
774       if(!searchSpclist->list.array[idx])
775       {
776          DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
777          return RFAILED;
778       }
779    }
780
781    idx = 0;
782    searchSpace = searchSpclist->list.array[idx];
783
784    /* Search Space id */
785    searchSpace->searchSpaceId = duPdcchCfg.searchSpcId;
786
787    /* Control Resource Set Id */
788    DU_ALLOC(searchSpace->controlResourceSetId, sizeof(ControlResourceSetId_t));
789    if(!searchSpace->controlResourceSetId)
790    {
791       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
792       return RFAILED;
793    }
794    *searchSpace->controlResourceSetId = duPdcchCfg.ctrlRsrcSetId;
795
796    /* Monitoring Slot periodicity and offset */
797    DU_ALLOC(searchSpace->monitoringSlotPeriodicityAndOffset,\
798          sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
799    if(!searchSpace->monitoringSlotPeriodicityAndOffset)
800    {
801       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
802       return RFAILED;
803    }
804    searchSpace->monitoringSlotPeriodicityAndOffset->present = duPdcchCfg.monitorSlotPrdAndOffPresent;
805
806    switch(searchSpace->monitoringSlotPeriodicityAndOffset->present)
807    {
808       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1:
809          {
810             //searchSpace->monitoringSlotPeriodicityAndOffset->choice.s11 =  duPdcchCfg.monitorSlotPrdAndOff;
811             break;
812          }
813       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl2:
814          {
815             //TODO
816             break;
817          }
818       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl4:
819          {
820             //TODO
821             break;
822          }
823       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl5:
824          {
825             //TODO
826             break;
827          }
828       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl8:
829          {
830             //TODO
831             break;
832          }
833       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl10:
834          {
835             //TODO
836             break;
837          }
838       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl16:
839          {
840             //TODO;
841             break;
842          }
843       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl20:
844          {
845             //TODO
846             break;
847          }
848       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl40:
849          {
850             //TODO
851             break;
852          }
853       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl80:
854          {
855             //TODO
856             break;
857          }
858       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl160:
859          {
860             //TODO
861             break;
862          }
863       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl320:
864          {
865             //TODO
866             break;
867          }
868       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl640:
869          {
870             //TODO
871             break;
872          }
873       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1280:
874          {
875             //TODO
876             break;
877          }
878       case SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl2560:
879          {
880             //TODO
881             break;
882          }
883       default:
884          {
885             DU_LOG("\nERROR  -->  DU APP : Invalid value:Montoring slot periodicity and offset");
886             return RFAILED;
887          }
888    }
889
890    /* Monitoring Symbols Within Slot */
891    DU_ALLOC(searchSpace->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
892    if(!searchSpace->monitoringSymbolsWithinSlot)
893    {
894       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
895       return RFAILED;
896    }
897    searchSpace->monitoringSymbolsWithinSlot->size = 2 * sizeof(uint8_t);
898
899    DU_ALLOC(searchSpace->monitoringSymbolsWithinSlot->buf, searchSpace->monitoringSymbolsWithinSlot->size);
900    if(!searchSpace->monitoringSymbolsWithinSlot->buf)
901    {  
902       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
903       return RFAILED;
904    }
905    searchSpace->monitoringSymbolsWithinSlot->buf[0] = duPdcchCfg.monitorSymbolsInSlot[0];
906    searchSpace->monitoringSymbolsWithinSlot->buf[1] = duPdcchCfg.monitorSymbolsInSlot[1];
907    searchSpace->monitoringSymbolsWithinSlot->bits_unused = 2;
908
909    /* Number of candidates per aggregation level */
910    DU_ALLOC(searchSpace->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
911    if(!searchSpace->nrofCandidates)
912    {
913       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
914       return RFAILED;
915    }
916    searchSpace->nrofCandidates->aggregationLevel1 = duPdcchCfg.numCandAggLvl1;
917    searchSpace->nrofCandidates->aggregationLevel2 = duPdcchCfg.numCandAggLvl2;
918    searchSpace->nrofCandidates->aggregationLevel4 = duPdcchCfg.numCandAggLvl4;
919    searchSpace->nrofCandidates->aggregationLevel8 = duPdcchCfg.numCandAggLvl8;
920    searchSpace->nrofCandidates->aggregationLevel16 = duPdcchCfg.numCandAggLvl16;
921
922    /* Search Space type and  DCI Format */
923    DU_ALLOC(searchSpace->searchSpaceType, sizeof( struct SearchSpace__searchSpaceType));
924    if(!searchSpace->searchSpaceType)
925    {
926       DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
927       return RFAILED;
928    }
929
930    searchSpace->searchSpaceType->present = duPdcchCfg.searchSpcType; 
931    switch(searchSpace->searchSpaceType->present)
932    {
933       case SearchSpace__searchSpaceType_PR_NOTHING:
934          {
935             //TODO
936             break;
937          }
938       case SearchSpace__searchSpaceType_PR_common:
939          {
940             DU_ALLOC(searchSpace->searchSpaceType->choice.common, sizeof(struct SearchSpace__searchSpaceType__common));
941             if(!searchSpace->searchSpaceType->choice.common)
942             {
943                DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
944                return RFAILED;
945             }
946
947             DU_ALLOC(searchSpace->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0, \
948                sizeof(struct SearchSpace__searchSpaceType__common__dci_Format0_0_AndFormat1_0));
949             if(!searchSpace->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0)
950             {
951                DU_LOG("\nERROR  -->  DU APP : Common search space list memory alloc failed");
952                return RFAILED;
953             }
954             break;
955          }
956       case SearchSpace__searchSpaceType_PR_ue_Specific:
957          {
958             break;
959          }
960       default:
961          {
962             DU_LOG("\nERROR  -->  DU_APP: Invalid Search Space type");
963             return RFAILED;
964          }
965    }
966
967    return ROK;
968 }/* BuildCommonSerachSpaceList */
969
970 /*******************************************************************
971  *
972  * @brief Builds PDCCH configuration common 
973  *
974  * @details
975  *
976  *    Function : BuildPdcchCfgCommon
977  *
978  *    Functionality:
979  *      Builds PDCCH configuration common
980  *
981  * @params[in] BWP_DownlinkCommon__pdcch_ConfigCommon pointer
982  * @return ROK     - success
983  *         RFAILED - failure
984  *
985  * ****************************************************************/
986 uint8_t BuildPdcchCfgCommon(struct BWP_DownlinkCommon__pdcch_ConfigCommon *pdcchCfg)
987 {
988    uint8_t   ret;
989    uint8_t   elementCnt;
990    PdcchCfgCommon   duPdcchCfg;
991    PDCCH_ConfigCommon_t  *pdcchSetup;
992
993    duPdcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdcchCfg;
994
995    pdcchCfg->present = duPdcchCfg.present;
996
997    switch(pdcchCfg->present)
998    {
999       case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_NOTHING:
1000          {
1001             //TODO
1002             break;
1003          }
1004       case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_release:
1005          {
1006             //TODO
1007             break;
1008          }
1009       case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup:
1010          {
1011             DU_ALLOC(pdcchCfg->choice.setup, sizeof(PDCCH_ConfigCommon_t));
1012             if(!pdcchCfg->choice.setup)
1013             {
1014                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1015                return RFAILED;
1016             }
1017             pdcchSetup = pdcchCfg->choice.setup;
1018
1019             /* Control Resource Set Zero */
1020             DU_ALLOC(pdcchSetup->controlResourceSetZero, sizeof(ControlResourceSetZero_t)); 
1021             if(!pdcchSetup->controlResourceSetZero)
1022             {
1023                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1024                return RFAILED;
1025             }
1026             *pdcchSetup->controlResourceSetZero = duPdcchCfg.ctrlRsrcSetZero;
1027
1028             /* Search space zero */
1029             DU_ALLOC(pdcchSetup->searchSpaceZero, sizeof(SearchSpaceZero_t));
1030             if(!pdcchSetup->searchSpaceZero)
1031             {
1032                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1033                return RFAILED;
1034             }
1035             *pdcchSetup->searchSpaceZero = duPdcchCfg.searchSpcZero;
1036
1037             /* Common Search Space List */
1038             DU_ALLOC(pdcchSetup->commonSearchSpaceList, sizeof(struct PDCCH_ConfigCommon__commonSearchSpaceList));
1039             if(!pdcchSetup->commonSearchSpaceList)
1040             {
1041                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1042                return RFAILED;
1043             }
1044             elementCnt = ODU_VALUE_ONE;
1045             pdcchSetup->commonSearchSpaceList->list.count = elementCnt;
1046             pdcchSetup->commonSearchSpaceList->list.size =  elementCnt * sizeof(SearchSpace_t *);
1047             ret = BuildCommonSerachSpaceList(pdcchSetup->commonSearchSpaceList);
1048             if(ret != ROK)
1049             {
1050                DU_LOG("\nERROR  -->  DU APP : Failed to fill common search space list");
1051                return RFAILED;
1052             }
1053             CommonSerachSpaceListret=ROK;
1054
1055             /* Search Space for SIB1 */
1056             DU_ALLOC(pdcchSetup->searchSpaceSIB1, sizeof(SearchSpaceId_t));
1057             if(!pdcchSetup->searchSpaceSIB1)
1058             {
1059                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1060                return RFAILED;
1061             }
1062             *pdcchSetup->searchSpaceSIB1 = duPdcchCfg.searchSpcSib1;
1063
1064             /* Search Space for Paging */
1065             DU_ALLOC(pdcchSetup->pagingSearchSpace, sizeof(SearchSpaceId_t));
1066             if(!pdcchSetup->pagingSearchSpace)
1067             {
1068                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1069                return RFAILED;
1070             }  
1071             *pdcchSetup->pagingSearchSpace = duPdcchCfg.pagingSearchSpc;
1072
1073             /* Search space for Random Access */
1074             DU_ALLOC(pdcchSetup->ra_SearchSpace, sizeof(SearchSpaceId_t));
1075             if(!pdcchSetup->ra_SearchSpace)
1076             {
1077                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1078                return RFAILED;
1079             }             
1080             *pdcchSetup->ra_SearchSpace = duPdcchCfg.raSearchSpc;
1081
1082             break;
1083          }
1084       default :
1085          {
1086             DU_LOG("\nERROR  -->  DU APP : Invalid PDCCH Config type");
1087             return RFAILED; 
1088          }
1089    }
1090
1091    return ROK;
1092 } /* BuildPdcchCfgCommon */
1093
1094 /*******************************************************************
1095  *
1096  * @brief Builds PDSCH configuration common 
1097  *
1098  * @details
1099  *
1100  *    Function : BuildPdschCfgCommon
1101  *
1102  *    Functionality:
1103  *       Builds PDSCH configuration common
1104  *
1105  * @params[in] BWP_DownlinkCommon__pdsch_ConfigCommon pointer
1106  * @return ROK     - success
1107  *         RFAILED - failure
1108  *
1109  * ****************************************************************/
1110 uint8_t BuildPdschCfgCommon(struct BWP_DownlinkCommon__pdsch_ConfigCommon *pdschCfg)
1111 {
1112    uint8_t   idx;
1113    uint8_t   elementCnt;
1114    PdschCfgCommon   duPdschCfg;
1115    PDSCH_ConfigCommon_t  *pdschSetup;
1116    PDSCH_TimeDomainResourceAllocation_t  *timeDomRsrcAllocInfo;
1117
1118    duPdschCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdschCfg;
1119
1120    pdschCfg->present = duPdschCfg.present;
1121
1122    switch(pdschCfg->present)
1123    {
1124       case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_NOTHING:
1125          {
1126             //TODO
1127             break;
1128          }
1129       case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_release:
1130          {
1131             //TODO
1132             break;
1133          }
1134       case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup:
1135          {
1136             DU_ALLOC(pdschCfg->choice.setup, sizeof(PDSCH_ConfigCommon_t));
1137             if(!pdschCfg->choice.setup)
1138             {
1139                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1140                return RFAILED;
1141             }
1142             pdschSetup = pdschCfg->choice.setup; 
1143
1144             /* Time Domain Allocation List */
1145             DU_ALLOC(pdschSetup->pdsch_TimeDomainAllocationList, sizeof(PDSCH_TimeDomainResourceAllocationList_t));
1146             if(!pdschSetup->pdsch_TimeDomainAllocationList)
1147             {
1148                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1149                return RFAILED;
1150             }
1151
1152             elementCnt = duPdschCfg.numTimeDomRsrcAlloc;
1153             pdschSetup->pdsch_TimeDomainAllocationList->list.count = elementCnt;
1154             pdschSetup->pdsch_TimeDomainAllocationList->list.size =  \
1155                elementCnt * sizeof(PDSCH_TimeDomainResourceAllocation_t *);
1156
1157             DU_ALLOC(pdschSetup->pdsch_TimeDomainAllocationList->list.array,\
1158                   pdschSetup->pdsch_TimeDomainAllocationList->list.size);
1159             if(!pdschSetup->pdsch_TimeDomainAllocationList->list.array)
1160             {
1161                DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1162                return RFAILED;
1163             }
1164
1165             for(idx=0; idx<elementCnt; idx++)
1166             {
1167                DU_ALLOC(pdschSetup->pdsch_TimeDomainAllocationList->list.array[idx],\
1168                      sizeof(PDSCH_TimeDomainResourceAllocation_t));
1169                if(!pdschSetup->pdsch_TimeDomainAllocationList->list.array[idx])
1170                {
1171                   DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1172                   return RFAILED;
1173                }
1174             }
1175
1176             for(idx = 0; idx < pdschSetup->pdsch_TimeDomainAllocationList->list.count; idx++)
1177             {
1178                timeDomRsrcAllocInfo = pdschSetup->pdsch_TimeDomainAllocationList->list.array[idx];
1179
1180                /* K0 */
1181                DU_ALLOC(timeDomRsrcAllocInfo->k0, sizeof(long));
1182                if(!timeDomRsrcAllocInfo->k0)
1183                {
1184                   DU_LOG("\nERROR  -->  DU APP : PDCCH Config memory alloc failed");
1185                   return RFAILED;
1186                }
1187                *timeDomRsrcAllocInfo->k0 = duPdschCfg.timeDomAlloc[idx].k0;
1188
1189                timeDomRsrcAllocInfo->mappingType = duPdschCfg.timeDomAlloc[idx].mapType;
1190                timeDomRsrcAllocInfo->startSymbolAndLength = duPdschCfg.timeDomAlloc[idx].sliv;
1191             }
1192             break;
1193          }
1194       default:
1195          {
1196             DU_LOG("\nERROR  -->  DU APP: Invalid PDSCH Configuration type");
1197             return RFAILED;
1198          }
1199    }
1200
1201    return ROK;
1202 }/* BuildPdschCfgCommon */
1203
1204 /*******************************************************************
1205  *
1206  * @brief Builds DL BWP common 
1207  *
1208  * @details
1209  *
1210  *    Function : BuildBwpDlCommon
1211  *
1212  *    Functionality:
1213  *      Builds DL BWP common
1214  *
1215  * @params[in] BWP_DownlinkCommon_t pointer
1216  * @return ROK     - success
1217  *         RFAILED - failure
1218  *
1219  * ****************************************************************/
1220 uint8_t BuildBwpDlCommon(BWP_DownlinkCommon_t *bwp)
1221 {
1222    DlCfgCommon duDlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
1223
1224    /* Generic Parameters */
1225    bwp->genericParameters.locationAndBandwidth = duDlCfg.locAndBw;
1226    bwp->genericParameters.subcarrierSpacing = duDlCfg.dlScsCarrier.scs;
1227
1228    /* PDCCH Config Common */
1229    DU_ALLOC(bwp->pdcch_ConfigCommon, sizeof(struct BWP_DownlinkCommon__pdcch_ConfigCommon));
1230    if(!bwp->pdcch_ConfigCommon)
1231    {
1232       DU_LOG("\nERROR  -->  DU APP : DL BWP memory allocation failed");
1233       return RFAILED;
1234    }
1235    if((BuildPdcchCfgCommon(bwp->pdcch_ConfigCommon)) != ROK)
1236    {
1237       DU_LOG("\nERROR  -->  DU APP : Failed to fill PDCCH config common in BuildBwpDlCommon()");
1238       return RFAILED;
1239    }
1240
1241    /* PDSCH Config Common */
1242    DU_ALLOC(bwp->pdsch_ConfigCommon, sizeof(struct BWP_DownlinkCommon__pdsch_ConfigCommon));
1243    if(!bwp->pdsch_ConfigCommon)
1244    {
1245       DU_LOG("\nERROR  -->  DU APP : DL BWP memory allocation failed");
1246       return RFAILED;
1247    }
1248
1249    if((BuildPdschCfgCommon(bwp->pdsch_ConfigCommon)) != ROK)
1250    {
1251       DU_LOG("\nERROR  -->  DU APP : Failed to fill PDSCH config common in BuildBwpDlCommon()");
1252       return RFAILED;
1253    }
1254
1255    return ROK;
1256 } /* BuildBwpDlCommon */
1257
1258 /*******************************************************************
1259  *
1260  * @brief Build BCCH configuration 
1261  *
1262  * @details
1263  *
1264  *    Function : BuildBcchConfig
1265  *
1266  *    Functionality:
1267  *      Build BCCH configuration
1268  *
1269  * @params[in] BCCH_Config_t pointer
1270  * @return ROK     - success
1271  *         RFAILED - failure
1272  *
1273  * ****************************************************************/
1274
1275 uint8_t BuildBcchConfig(BCCH_Config_t *bcchCfg)
1276 {
1277    BcchCfg   duBcchCfg;
1278
1279    duBcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.bcchCfg;
1280
1281    bcchCfg->modificationPeriodCoeff = duBcchCfg.modPrdCoeff;
1282
1283    return ROK;
1284 }/* BuildBcchConfig */
1285
1286 /*******************************************************************
1287  *
1288  * @brief fills First PDCCH monitoring Paging occasions 
1289  *
1290  * @details
1291  *
1292  *    Function : fillFirstPdcchMonitoringOcc
1293  *
1294  *    Functionality:
1295  *        Fills PDCCH Monitoring PO in PCCH configuration
1296  *
1297  * @params[in] 
1298  * @return ROK     - success
1299  *         RFAILED - failure
1300  *
1301  * ****************************************************************/
1302 uint8_t fillFirstPdcchMonitoringOcc(struct PCCH_Config__firstPDCCH_MonitoringOccasionOfPO *firstPO,\
1303       PcchCfg *srcPcchCfg)
1304 {
1305    uint8_t numPO = 0, poIdx = 0;
1306
1307    firstPO->present = srcPcchCfg->firstPDCCHMontioringType;
1308
1309    numPO = srcPcchCfg->ns;
1310    if(numPO == 0)
1311    {
1312       DU_LOG("\nINFO   -->  DU APP : Paging Occasions is ZERO, no need to fill further");
1313       return ROK;
1314    }
1315
1316    /*Note: Valid values for each number of PO is from Spec 36.331: PCCH-COnfig*/
1317    switch(firstPO->present)
1318    {
1319       case PCCH_Config__firstPDCCH_MonitoringOccasionOfPO_PR_NOTHING:
1320          {
1321             break;
1322          }
1323       case PCCH_Config__firstPDCCH_MonitoringOccasionOfPO_PR_sCS15KHZoneT:
1324          {
1325             DU_ALLOC(firstPO->choice.sCS15KHZoneT, \
1326                   sizeof(struct PCCH_Config__firstPDCCH_MonitoringOccasionOfPO__sCS15KHZoneT));
1327
1328             if(firstPO->choice.sCS15KHZoneT == NULLP)
1329             {
1330                DU_LOG("\nERROR  -->  DU APP : FirstPdcchMonitoringPO Memory allocation failure");
1331                return RFAILED;
1332             }
1333             firstPO->choice.sCS15KHZoneT->list.count = numPO;
1334             firstPO->choice.sCS15KHZoneT->list.size = numPO * sizeof(long *);
1335
1336             DU_ALLOC(firstPO->choice.sCS15KHZoneT->list.array, firstPO->choice.sCS15KHZoneT->list.size);
1337             if(!firstPO->choice.sCS15KHZoneT->list.array)
1338             {
1339                DU_LOG("\nERROR  -->  DU APP : FirstPdcchMonitoringPO Memory allocation failure");
1340                return RFAILED;
1341             }
1342
1343             for(poIdx = 0; poIdx < numPO; poIdx++)
1344             {
1345                /* Spec 36.331: PCCH-Config: firstPDCCH-MonitoringOccasionOfPO [MAX of sCS15KHZoneT]
1346                 * Since FirstPDCCHMonitoring_PO is not valid thus no need to continue further*/
1347                if(srcPcchCfg->firstPDCCHMontioringInfo[poIdx] > 139)
1348                {
1349                   DU_LOG("\nERROR  -->  DU APP : Invalid Paging Ocassion value for 15kHz");
1350                   return RFAILED;
1351                }
1352                DU_ALLOC(firstPO->choice.sCS15KHZoneT->list.array[poIdx], sizeof(long));
1353                if(!firstPO->choice.sCS15KHZoneT->list.array[poIdx])
1354                {
1355                   DU_LOG("\nERROR  -->  DU APP : FirstPdcchMonitoringPO Memory allocation failure");
1356                   return RFAILED;
1357                }
1358             }
1359
1360             poIdx = 0;
1361             *firstPO->choice.sCS15KHZoneT->list.array[poIdx] = srcPcchCfg->firstPDCCHMontioringInfo[poIdx];
1362
1363             break;
1364          }
1365       case PCCH_Config__firstPDCCH_MonitoringOccasionOfPO_PR_sCS30KHZoneT_SCS15KHZhalfT:
1366          {
1367             DU_ALLOC(firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT, \
1368                   sizeof(struct PCCH_Config__firstPDCCH_MonitoringOccasionOfPO__sCS30KHZoneT_SCS15KHZhalfT));
1369
1370             if(firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT == NULLP)
1371             {
1372                DU_LOG("\nERROR  -->  DU APP : FirstPdcchMonitoringPO Memory allocation failure");
1373                return RFAILED;
1374             }
1375             firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.count = numPO;
1376             firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.size = numPO * sizeof(long *);
1377
1378             DU_ALLOC(firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.array, \
1379                   firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.size);
1380
1381             if(!firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.array)
1382             {
1383                DU_LOG("\nERROR  -->  DU APP : FirstPdcchMonitoringPO Memory allocation failure");
1384                return RFAILED;
1385             }
1386
1387             for(poIdx = 0; poIdx < numPO; poIdx++)
1388             {
1389                /* Spec 36.331: PCCH-Config:firstPDCCH-MonitoringOccasionOfPO [MAX of sCS30KHZoneT-SCS15KHZhalfT]
1390                 * Since FirstPDCCHMonitoring_PO is not valid thus no need to continue further*/
1391                if(srcPcchCfg->firstPDCCHMontioringInfo[poIdx] > 279)
1392                {
1393                   DU_LOG("\nERROR  -->  DU APP : Invalid Paging Ocassion value for 30kHz or 15kHz HAlFT");
1394                   return RFAILED;
1395                }
1396                DU_ALLOC(firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.array[poIdx], sizeof(long));
1397                if(!firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.array[poIdx])
1398                {
1399                   DU_LOG("\nERROR  -->  DU APP : FirstPdcchMonitoringPO Memory allocation failure");
1400                   return RFAILED;
1401                }
1402             }
1403
1404             poIdx = 0;
1405             *firstPO->choice.sCS30KHZoneT_SCS15KHZhalfT->list.array[poIdx] = srcPcchCfg->firstPDCCHMontioringInfo[poIdx];
1406             break;
1407          }
1408          //TODO for other cases
1409       default:
1410          {
1411             DU_LOG("\nERROR  -->  DU APP : Invalid firstPDCCH-MonitoringOccasionOfPO");
1412             return RFAILED;
1413
1414             break;
1415          }
1416    }
1417    return ROK;
1418 }
1419 /*******************************************************************
1420  *
1421  * @brief Builds PCCH configuration 
1422  *
1423  * @details
1424  *
1425  *    Function : BuildPcchConfig
1426  *
1427  *    Functionality:
1428  *        Builds PCCH configuration
1429  *
1430  * @params[in] 
1431  * @return ROK     - success
1432  *         RFAILED - failure
1433  *
1434  * ****************************************************************/
1435 uint8_t BuildPcchConfig(PCCH_Config_t *pcchCfg)
1436 {
1437    PcchCfg   duPcchCfg;
1438
1439    duPcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pcchCfg;
1440
1441    pcchCfg->defaultPagingCycle = convertPagingCycleValueToEnum(duPcchCfg.dfltPagingCycle);
1442    pcchCfg->nAndPagingFrameOffset.present =  duPcchCfg.nAndPagingFrmOffsetType;
1443    switch(pcchCfg->nAndPagingFrameOffset.present)
1444    {
1445       /**Note: PagingFrame Offset Value differs for each Paging Duration
1446        *(oneT, halfT,...). The Range of Offset given in Spec 38.331,Pcch-Config*/
1447       case PCCH_Config__nAndPagingFrameOffset_PR_NOTHING:
1448          {
1449             //TODO          
1450             break;
1451          }
1452       case PCCH_Config__nAndPagingFrameOffset_PR_oneT:
1453          {
1454             pcchCfg->nAndPagingFrameOffset.choice.oneT = NULLD;
1455             break;
1456          }
1457       case PCCH_Config__nAndPagingFrameOffset_PR_halfT:
1458          {
1459             /*Spec 38.331: PCCH_Config: nAndPagingFrameOffset [MAX value of halfT] */
1460             if(duPcchCfg.pageFrameOffset > 1)
1461             {
1462                DU_LOG("\nERROR  -->  DU APP : Invalid PagingFrameOffset for HALF_T");
1463                return RFAILED;
1464             }
1465             pcchCfg->nAndPagingFrameOffset.choice.halfT = duPcchCfg.pageFrameOffset;
1466             break;
1467          }
1468       case PCCH_Config__nAndPagingFrameOffset_PR_quarterT:
1469          {
1470             /*Spec 38.331: PCCH_Config: nAndPagingFrameOffset [MAX value of quarterT] */
1471             if(duPcchCfg.pageFrameOffset > 3)
1472             {
1473                DU_LOG("\nERROR  -->  DU APP : Invalid PagingFrameOffset for QUARTER_T");
1474                return RFAILED;
1475             }
1476             pcchCfg->nAndPagingFrameOffset.choice.quarterT = duPcchCfg.pageFrameOffset;
1477             break;
1478          }
1479       case PCCH_Config__nAndPagingFrameOffset_PR_oneEighthT:
1480          {
1481             /*Spec 38.331: PCCH_Config: nAndPagingFrameOffset [MAX value of oneEighthT] */
1482             if(duPcchCfg.pageFrameOffset > 7)
1483             {
1484                DU_LOG("\nERROR  -->  DU APP : Invalid PagingFrameOffset for ONE_EIGHTH_T");
1485                return RFAILED;
1486             }
1487             pcchCfg->nAndPagingFrameOffset.choice.oneEighthT = duPcchCfg.pageFrameOffset;
1488             break;
1489          }
1490       case PCCH_Config__nAndPagingFrameOffset_PR_oneSixteenthT:
1491          {
1492             /*Spec 38.331: PCCH_Config: nAndPagingFrameOffset [MAX value of oneSixteenthT] */
1493             if(duPcchCfg.pageFrameOffset > 15)
1494             {
1495                DU_LOG("\nERROR  -->  DU APP : Invalid PagingFrameOffset for ONE_SIXTEENTH_T");
1496                return RFAILED;
1497             }
1498             pcchCfg->nAndPagingFrameOffset.choice.oneSixteenthT = duPcchCfg.pageFrameOffset;
1499             break;
1500          }
1501       default:
1502          {
1503             DU_LOG("\nERROR  -->  DU APP : Invalid nAndPagingFrameOffset configuration");
1504             return RFAILED;
1505          }
1506    }
1507    pcchCfg->ns = convertNsValueToEnum(duPcchCfg.ns);
1508
1509    DU_ALLOC(pcchCfg->firstPDCCH_MonitoringOccasionOfPO, \
1510          sizeof(struct PCCH_Config__firstPDCCH_MonitoringOccasionOfPO));
1511    if(pcchCfg->firstPDCCH_MonitoringOccasionOfPO == NULLP)
1512    {
1513       DU_LOG("\nERROR  -->  DU APP : BuildPcchConfig >> Memory Allocation fails");
1514       return RFAILED;
1515    }
1516
1517    if(fillFirstPdcchMonitoringOcc(pcchCfg->firstPDCCH_MonitoringOccasionOfPO, &duPcchCfg) == RFAILED)
1518    {
1519       DU_LOG("\nERROR  -->  DU APP : BuildPcchConfig >> Filling of Paging Occ failed");
1520       return RFAILED;
1521    }
1522    return ROK;
1523 }/* BuildPcchConfig */
1524
1525 /*******************************************************************
1526  *
1527  * @brief Builds Frequency Info for Downlink 
1528  *
1529  * @details
1530  *
1531  *    Function : BuildFreqInfoDlSib
1532  *
1533  *    Functionality:
1534  *     Builds Frequency Info for Downlink
1535  *
1536  * @params[in] 
1537  * @return ROK     - success
1538  *         RFAILED - failure
1539  *
1540  * ****************************************************************/
1541
1542 uint8_t BuildFreqInfoDlSib(FrequencyInfoDL_SIB_t *frequencyInfoDL)
1543 {
1544    uint8_t ret;
1545    uint8_t idx;
1546    uint8_t elementCnt;
1547    DlCfgCommon  dlCfg;
1548    NR_MultiBandInfo_t  *multiBandInfo;
1549
1550    dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
1551
1552    /* NR Multi-Band Info */
1553    elementCnt = ODU_VALUE_ONE;   
1554    frequencyInfoDL->frequencyBandList.list.count = elementCnt;  
1555    frequencyInfoDL->frequencyBandList.list.size = \
1556                                                   elementCnt * sizeof(NR_MultiBandInfo_t *);
1557
1558    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, \
1559          frequencyInfoDL->frequencyBandList.list.size);
1560    if(!frequencyInfoDL->frequencyBandList.list.array)
1561    {
1562       DU_LOG("\nERROR  -->  DU APP : SIB1 DL Configuration memory allocation failed");
1563       return RFAILED;
1564    }
1565
1566    for(idx = 0; idx < elementCnt; idx++)
1567    {
1568       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[idx],\
1569             sizeof(NR_MultiBandInfo_t));
1570       if(!frequencyInfoDL->frequencyBandList.list.array[idx])
1571       {
1572          DU_LOG("\nERROR  -->  DU APP : SIB1 DL Configuration memory allocation failed");
1573          return RFAILED;
1574       }
1575    }
1576
1577    idx = 0;
1578    multiBandInfo = frequencyInfoDL->frequencyBandList.list.array[idx];
1579
1580    /* Frequency band indicator */
1581    DU_ALLOC(multiBandInfo->freqBandIndicatorNR, sizeof(FreqBandIndicatorNR_t));
1582    if(!multiBandInfo->freqBandIndicatorNR)
1583    {
1584       DU_LOG("\nERROR  -->  DU APP : SIB1 DL Configuration memory allocation failed");
1585       return RFAILED;
1586    }
1587    *multiBandInfo->freqBandIndicatorNR = dlCfg.freqBandInd;
1588
1589    /* Offset to Point A */
1590    frequencyInfoDL->offsetToPointA = dlCfg.offsetToPointA;
1591
1592    /* Subcarrier Spacing specifc carrier */
1593    elementCnt = ODU_VALUE_ONE;
1594    frequencyInfoDL->scs_SpecificCarrierList.list.count = elementCnt;
1595    frequencyInfoDL->scs_SpecificCarrierList.list.size = \
1596                                                         elementCnt * sizeof(SCS_SpecificCarrier_t *);
1597    ret= BuildScsSpecificCarrierListDlSib(&frequencyInfoDL->scs_SpecificCarrierList);
1598
1599    if(ret != ROK)
1600    {
1601       return RFAILED;
1602    }
1603    return ROK;
1604 }/* BuildFreqInfoDl */
1605
1606 /*******************************************************************
1607  *
1608  * @brief Builds DL configuration common for SIB
1609  *
1610  * @details
1611  *
1612  *    Function : BuildDlCfgCommSib
1613  *
1614  *    Functionality:
1615  *     Builds DL configuration common for SIB
1616  *
1617  * @params[in] DownlinkConfigCommonSIB_t pointer 
1618  * @return ROK     - success
1619  *         RFAILED - failure
1620  *
1621  * ****************************************************************/
1622
1623 uint8_t BuildDlCfgCommSib(DownlinkConfigCommonSIB_t *dlCfg)
1624 {
1625    /* DL frequency info */
1626    uint8_t ret;
1627    ret = BuildFreqInfoDlSib(&dlCfg->frequencyInfoDL);
1628    if(ret != ROK)
1629    {
1630       return RFAILED;
1631    }
1632    FreqInfoDlret=ROK;
1633    /* BWP Downlink Common */
1634    ret = BuildBwpDlCommon(&dlCfg->initialDownlinkBWP);
1635    if(ret != ROK)
1636    {
1637       return RFAILED;
1638    }
1639    /* BCCH Config */
1640    ret = BuildBcchConfig(&dlCfg->bcch_Config);
1641    if(ret != ROK)
1642    {
1643       return RFAILED;
1644    }
1645    /* PCCH Config */
1646    ret = BuildPcchConfig(&dlCfg->pcch_Config);
1647    if(ret != ROK)
1648    {
1649       return RFAILED;
1650    }
1651    return ROK;
1652 } /* BuildDlCfgCommSib */
1653
1654 /*******************************************************************
1655  *
1656  * @brief Builds SCS specific carrier list for UL 
1657  *
1658  * @details
1659  *
1660  *    Function : BuildScsSpecificCarrierListUlSib
1661  *
1662  *    Functionality:
1663  *       Builds SCS specific carrier list for UL
1664  *
1665  * @params[in] 
1666  * @return ROK     - success
1667  *         RFAILED - failure
1668  *
1669  * ****************************************************************/
1670
1671 uint8_t BuildScsSpecificCarrierListUlSib(struct FrequencyInfoUL_SIB__scs_SpecificCarrierList *scsCarrierList)
1672 {
1673    uint8_t idx;
1674    ScsSpecCarrier   duScsSpecCarrier;
1675
1676    duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
1677
1678    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
1679    if(!scsCarrierList->list.array)
1680    {
1681       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
1682       return RFAILED;
1683    }
1684
1685    for(idx = 0; idx < scsCarrierList->list.count; idx++)
1686    {
1687       DU_ALLOC(scsCarrierList->list.array[idx], sizeof(SCS_SpecificCarrier_t));
1688       if(!scsCarrierList->list.array[idx])
1689       {
1690          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
1691          return RFAILED;
1692       }
1693    }
1694    idx = 0;
1695    scsCarrierList->list.array[idx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
1696    scsCarrierList->list.array[idx]->subcarrierSpacing = duScsSpecCarrier.scs;
1697    scsCarrierList->list.array[idx]->carrierBandwidth = duScsSpecCarrier.scsBw;
1698
1699    return ROK;
1700 } /* End of BuildScsSpecificCarrierListUlSib */
1701
1702 /*******************************************************************
1703  *
1704  * @brief Builds frequency infor for UL 
1705  *
1706  * @details
1707  *
1708  *    Function : BuildFreqInfoUlSib
1709  *
1710  *    Functionality:
1711  *       Builds frequency infor for UL
1712  *
1713  * @params[in] FrequencyInfoUL_SIB_t pointer
1714  * @return ROK     - success
1715  *         RFAILED - failure
1716  *
1717  * ****************************************************************/
1718
1719 uint8_t BuildFreqInfoUlSib(FrequencyInfoUL_SIB_t *frequencyInfoUL)
1720 {
1721    uint8_t      elementCnt;
1722    UlCfgCommon  ulCfg;
1723    uint8_t      ret;
1724    ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
1725
1726    /* Subcarrier Spacing specifc carrier */
1727    elementCnt = ODU_VALUE_ONE;
1728    frequencyInfoUL->scs_SpecificCarrierList.list.count = elementCnt;
1729    frequencyInfoUL->scs_SpecificCarrierList.list.size = \
1730                                                         elementCnt * sizeof(SCS_SpecificCarrier_t *);
1731    ret=BuildScsSpecificCarrierListUlSib(&frequencyInfoUL->scs_SpecificCarrierList);
1732    if(ret != ROK)
1733    {
1734       return RFAILED;
1735    }
1736    /* P-MAX */
1737    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
1738    if(!frequencyInfoUL->p_Max)
1739    {
1740       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
1741       return RFAILED;
1742    }
1743    *frequencyInfoUL->p_Max = ulCfg.pMax;
1744    FreqInfoUlret=ROK;
1745    return ROK;
1746 }/* BuildFreqInfoUlSib */
1747
1748 /*******************************************************************
1749  *
1750  * @brief Builds RACH configuration common 
1751  *
1752  * @details
1753  *
1754  *    Function : BuildRachCfgCommon
1755  *
1756  *    Functionality:
1757  *      Builds RACH configuration common
1758  *
1759  * @params[in] BWP_UplinkCommon__rach_ConfigCommon pointer
1760  * @return ROK     - success
1761  *         RFAILED - failure
1762  *
1763  * ****************************************************************/
1764
1765 uint8_t  BuildRachCfgCommon(struct BWP_UplinkCommon__rach_ConfigCommon *rachCfg)
1766 {
1767    RachCfgCommon    duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
1768    RACH_ConfigCommon_t  *setup = NULLP;
1769
1770    rachCfg->present = duRachCfg.present;
1771    switch(rachCfg->present)
1772    {
1773       case BWP_UplinkCommon__rach_ConfigCommon_PR_NOTHING:
1774          {
1775             //TODO
1776             break;
1777          }
1778       case BWP_UplinkCommon__rach_ConfigCommon_PR_release:
1779          {
1780             //TODO
1781             break;
1782          }
1783       case BWP_UplinkCommon__rach_ConfigCommon_PR_setup:
1784          {
1785             DU_ALLOC(rachCfg->choice.setup, sizeof(RACH_ConfigCommon_t)); 
1786             if(!rachCfg->choice.setup)
1787             {
1788                DU_LOG("\nERROR  -->  DU APP : Rach Config memory alloc failed");
1789                return RFAILED;
1790             }
1791             setup = rachCfg->choice.setup;
1792
1793             /* Generic RACH Configuration */
1794             setup->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
1795             setup->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
1796             setup->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
1797             setup->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
1798             setup->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr; 
1799             setup->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
1800             setup->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
1801             setup->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
1802
1803             /* Total number of RA preambles */
1804             DU_ALLOC(setup->totalNumberOfRA_Preambles, sizeof(long));
1805             if(!setup->totalNumberOfRA_Preambles)
1806             {
1807                DU_LOG("\nERROR  -->  DU APP : Rach Config memory alloc failed");
1808                return RFAILED;
1809             }
1810             *setup->totalNumberOfRA_Preambles = duRachCfg.numRaPreamble;
1811
1812             /* SSB per RACH occassion and CB Preambles per SSB */
1813             DU_ALLOC(setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB,\
1814                   sizeof(struct RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB));
1815             if(!setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB)
1816             {
1817                DU_LOG("\nERROR  -->  DU APP : Rach Config memory alloc failed");
1818                return RFAILED;
1819             }
1820             setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB->present = duRachCfg.numSsbPerRachOcc;
1821
1822             switch(setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB->present)
1823             {
1824                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_NOTHING:
1825                   {
1826                      //TODO
1827                      break;
1828                   }
1829                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_oneEighth:
1830                   {
1831                      //TODO
1832                      break;
1833                   }
1834                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_oneFourth:
1835                   {
1836                      //TODO
1837                      break;
1838                   }
1839                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_oneHalf:
1840                   {
1841                      //TODO
1842                      break;
1843                   }
1844                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one:
1845                   {
1846                      setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB->choice.one = \
1847                         convertCbPreamblePerSsbValueToEnum(duRachCfg.numCbPreamblePerSsb);
1848                   }
1849                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_two:
1850                   {
1851                      //TODO
1852                      break;
1853                   }
1854                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_four:
1855                   {
1856                      //TODO
1857                      break;
1858                   }
1859                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_eight:
1860                   {
1861                      //TODO
1862                      break;
1863                   }
1864                case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_sixteen:
1865                   {
1866                      //TODO
1867                      break;
1868                   }
1869                default:
1870                   {
1871                      DU_LOG("\nERROR  -->  DU APP: Invalid value for ssb_PerRach_OccassionAndCB_PreamblesPerSSB");
1872                      return RFAILED;
1873                   }
1874             }
1875
1876             /* RA Contention Resolution Timer */
1877             setup->ra_ContentionResolutionTimer = duRachCfg.contResTimer;
1878
1879             /* RSRP Threshold SSB */
1880             DU_ALLOC(setup->rsrp_ThresholdSSB, sizeof(RSRP_Range_t));
1881             if(!setup->rsrp_ThresholdSSB)
1882             {
1883                DU_LOG("\nERROR  -->  DU APP : Rach Config memory alloc failed");
1884                return RFAILED;
1885             }
1886             *setup->rsrp_ThresholdSSB = duRachCfg.rsrpThreshSsb;
1887
1888             /* Root Sequence index */
1889             setup->prach_RootSequenceIndex.present = duRachCfg.rootSeqIdxPresent;
1890             switch(setup->prach_RootSequenceIndex.present)
1891             {
1892                case RACH_ConfigCommon__prach_RootSequenceIndex_PR_NOTHING:
1893                   {
1894                      //TODO
1895                      break;
1896                   }
1897                case RACH_ConfigCommon__prach_RootSequenceIndex_PR_l839:
1898                   {
1899                      //TODO
1900                      break;
1901                   }
1902                case RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139:
1903                   {
1904                      setup->prach_RootSequenceIndex.choice.l139 = duRachCfg.rootSeqIdx;
1905                      break;
1906                   }
1907                default:
1908                   {
1909                      DU_LOG("\nERROR  -->  DU APP: Inavlid PRACH root sequence index type");
1910                      return RFAILED;
1911                   }
1912             }
1913
1914             /* Msg 1 Subcarrier spacing */
1915             DU_ALLOC(setup->msg1_SubcarrierSpacing, sizeof(SubcarrierSpacing_t));
1916             if(!setup->msg1_SubcarrierSpacing)
1917             {
1918                DU_LOG("\nERROR  -->  DU APP : Rach Config memory alloc failed");
1919                return RFAILED;
1920             }
1921             *setup->msg1_SubcarrierSpacing = duRachCfg.msg1Scs;
1922
1923             /* Restricted Set Config */
1924             setup->restrictedSetConfig = duRachCfg.restrictedSetCfg;
1925
1926             break;
1927          }
1928       default:
1929          {
1930             DU_LOG("\nERROR  -->  DU APP : Invalid RACH Config type ");
1931             return RFAILED;
1932          }
1933    }
1934    return ROK;
1935 }/* BuildRachCfgCommon */
1936
1937 /*******************************************************************
1938  *
1939  * @brief Builds PUSCH configuration for common 
1940  *
1941  * @details
1942  *
1943  *    Function : BuildPuschCfgCommon
1944  *
1945  *    Functionality:
1946  *      Builds PUSCH configuration for common
1947  *
1948  * @params[in] 
1949  * @return ROK     - success
1950  *         RFAILED - failure
1951  *
1952  * ****************************************************************/
1953
1954 uint8_t BuildPuschCfgCommon(struct BWP_UplinkCommon__pusch_ConfigCommon *puschCfg)
1955 {
1956    uint8_t           idx = 0;
1957    uint8_t           elementCnt = 0;   
1958    PuschCfgCommon    duPuschCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.puschCfg;
1959    PUSCH_ConfigCommon_t *setup = NULLP;
1960    PUSCH_TimeDomainResourceAllocation_t  *timeDomRsrcAllocInfo = NULLP;
1961
1962
1963    puschCfg->present = duPuschCfg.puschCfgPresent;
1964    switch(puschCfg->present)
1965    {
1966       case BWP_UplinkCommon__pusch_ConfigCommon_PR_NOTHING:
1967          {
1968             //TODO
1969             break;
1970          }
1971       case BWP_UplinkCommon__pusch_ConfigCommon_PR_release:
1972          {
1973             //TODO
1974             break;
1975          }
1976       case BWP_UplinkCommon__pusch_ConfigCommon_PR_setup:
1977          {
1978             DU_ALLOC(puschCfg->choice.setup, sizeof(PUSCH_ConfigCommon_t));
1979             if(!puschCfg->choice.setup)
1980             {
1981                DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
1982                return RFAILED;
1983             }
1984             setup = puschCfg->choice.setup;
1985
1986             /* Time Domain Resource Allocation List */
1987             DU_ALLOC(setup->pusch_TimeDomainAllocationList, sizeof(PUSCH_TimeDomainResourceAllocationList_t)); 
1988             if(!setup->pusch_TimeDomainAllocationList)
1989             {
1990                DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
1991                return RFAILED;
1992             }
1993             elementCnt = duPuschCfg.numTimeDomRsrcAlloc;
1994             setup->pusch_TimeDomainAllocationList->list.count = elementCnt;
1995             setup->pusch_TimeDomainAllocationList->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
1996
1997             DU_ALLOC(setup->pusch_TimeDomainAllocationList->list.array, setup->pusch_TimeDomainAllocationList->list.size);
1998             if(!setup->pusch_TimeDomainAllocationList->list.array)
1999             {
2000                DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
2001                return RFAILED;
2002             }
2003
2004             for(idx=0; idx<elementCnt; idx++)
2005             {
2006                DU_ALLOC(setup->pusch_TimeDomainAllocationList->list.array[idx],\
2007                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
2008                if(!setup->pusch_TimeDomainAllocationList->list.array[idx])
2009                {
2010                   DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
2011                   return RFAILED;
2012                }
2013             }
2014
2015             for(idx = 0; idx < elementCnt; idx++)
2016             {
2017                timeDomRsrcAllocInfo = setup->pusch_TimeDomainAllocationList->list.array[idx];
2018
2019                /* K2 */
2020                DU_ALLOC(timeDomRsrcAllocInfo->k2, sizeof(long));
2021                if(!timeDomRsrcAllocInfo->k2)
2022                {
2023                   DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
2024                   return RFAILED;
2025                }
2026                *timeDomRsrcAllocInfo->k2 = duPuschCfg.timeDomAllocList[idx].k2;
2027                timeDomRsrcAllocInfo->mappingType = duPuschCfg.timeDomAllocList[idx].mapType;
2028                timeDomRsrcAllocInfo->startSymbolAndLength = duPuschCfg.timeDomAllocList[idx].sliv;
2029             }
2030
2031             /* Msg3 Delta Preamble */
2032             DU_ALLOC(setup->msg3_DeltaPreamble, sizeof(long));
2033             if(!setup->msg3_DeltaPreamble)
2034             {
2035                DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
2036                return RFAILED;
2037             }
2038             *setup->msg3_DeltaPreamble = duPuschCfg.msg3DeltaPreamble;
2039
2040             /* P0 Nominal with grant */
2041             DU_ALLOC(setup->p0_NominalWithGrant, sizeof(long));
2042             if(!setup->p0_NominalWithGrant)
2043             {
2044                DU_LOG("\nERROR  -->  DU APP : PUSCH Config memory alloc failed");
2045                return RFAILED;
2046             }
2047             *setup->p0_NominalWithGrant = duPuschCfg.p0NominalWithGrant;
2048
2049             break;
2050          }
2051       default:
2052          {
2053             DU_LOG("\nERROR  -->  DU APP : Invalid PUSCH configuration type ");
2054             return RFAILED;
2055          }
2056    }
2057
2058    return ROK;
2059 }/* BuildPuschCfgCommon */
2060
2061 /*******************************************************************
2062  *
2063  * @brief  Builds PUCCH configuration common
2064  *
2065  * @details
2066  *
2067  *    Function : BuildPucchCfgCommon
2068  *
2069  *    Functionality:
2070  *      Builds PUCCH configuration common
2071  *
2072  * @params[in] 
2073  * @return ROK     - success
2074  *         RFAILED - failure
2075  *
2076  * ****************************************************************/
2077
2078 uint8_t BuildPucchCfgCommon( struct BWP_UplinkCommon__pucch_ConfigCommon *pucchCfg)
2079 {
2080    PucchCfgCommon    duPucchCfg;
2081    PUCCH_ConfigCommon_t *setup;
2082
2083    duPucchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.pucchCfg;
2084
2085    pucchCfg->present = duPucchCfg.present;
2086    switch(pucchCfg->present)
2087    {
2088       case BWP_UplinkCommon__pucch_ConfigCommon_PR_NOTHING:
2089          {
2090             //TODO
2091             break;
2092          }
2093       case BWP_UplinkCommon__pucch_ConfigCommon_PR_release:
2094          {
2095             //TODO
2096             break;
2097          }
2098       case BWP_UplinkCommon__pucch_ConfigCommon_PR_setup:
2099          {
2100             DU_ALLOC(pucchCfg->choice.setup, sizeof(PUCCH_ConfigCommon_t));
2101             if(!pucchCfg->choice.setup)
2102             {
2103                DU_LOG("\nERROR  -->  DU APP : PUCCH Config memory alloc failed");
2104                return RFAILED;
2105             }
2106             setup = pucchCfg->choice.setup;
2107
2108             /* Resource Common */
2109             DU_ALLOC(setup->pucch_ResourceCommon, sizeof(long));
2110             if(!setup->pucch_ResourceCommon)
2111             {
2112                DU_LOG("\nERROR  -->  DU APP : PUCCH Config memory alloc failed");
2113                return RFAILED;
2114             }
2115             *setup->pucch_ResourceCommon = duPucchCfg.rsrcComm;
2116
2117             /* Group hopping */
2118             setup->pucch_GroupHopping = duPucchCfg.grpHop;
2119
2120             /* P0 nominal */
2121             DU_ALLOC(setup->p0_nominal, sizeof(long));
2122             if(!setup->p0_nominal)
2123             {
2124                DU_LOG("\nERROR  -->  DU APP : PUCCH Config memory alloc failed");
2125                return RFAILED;
2126             }
2127             *setup->p0_nominal = duPucchCfg.p0Nominal;
2128
2129             break;
2130          }
2131       default:
2132          {
2133             DU_LOG("\nERROR  -->  DU APP : Invalid PUCCH Config type");
2134             return RFAILED;
2135          }
2136    }
2137    return ROK;
2138 }/* BuildPucchCfgCommon */
2139
2140 /*******************************************************************
2141  *
2142  * @brief Builds UL BWP Common 
2143  *
2144  * @details
2145  *
2146  *    Function : BuildBwpUlCommon
2147  *
2148  *    Functionality:
2149  *      Builds UL BWP Common 
2150  *
2151  * @params[in] BWP_UplinkCommon_t pointer
2152  * @return ROK     - success
2153  *         RFAILED - failure
2154  *
2155  * ****************************************************************/
2156
2157 uint8_t BuildBwpUlCommon(BWP_UplinkCommon_t *bwp)
2158 {
2159    UlCfgCommon duUlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
2160
2161    /* Generic Parameters */
2162    bwp->genericParameters.locationAndBandwidth = duUlCfg.locAndBw;
2163    bwp->genericParameters.subcarrierSpacing = duUlCfg.ulScsCarrier.scs;
2164
2165    /* RACH Config Common */
2166    DU_ALLOC(bwp->rach_ConfigCommon, sizeof(struct BWP_UplinkCommon__rach_ConfigCommon));
2167    if(!bwp->rach_ConfigCommon)
2168    {
2169       DU_LOG("\nERROR  -->  DU APP : UL BWP memory allocation failed");
2170       return RFAILED;
2171    }
2172
2173    if((BuildRachCfgCommon(bwp->rach_ConfigCommon)) != ROK)
2174    {
2175       DU_LOG("\nERROR  --> DU APP : Failed to fill RACH config common in BuildBwpUlCommon()");
2176       return RFAILED;
2177    }
2178    RachCfgCommonret=ROK;
2179
2180    /* PUSCH Config Common */
2181    DU_ALLOC(bwp->pusch_ConfigCommon, sizeof(struct BWP_UplinkCommon__pusch_ConfigCommon));
2182    if(!bwp->pusch_ConfigCommon)
2183    {
2184       DU_LOG("\nERROR  -->  DU APP : UL BWP memory allocation failed");
2185       return RFAILED;
2186    }
2187
2188    if((BuildPuschCfgCommon(bwp->pusch_ConfigCommon)) != ROK)
2189    {
2190       DU_LOG("\nERROR  --> DU APP : Failed to fill PUSCH config common in BuildBwpUlCommon()");  
2191       return RFAILED;
2192    }
2193    PuschCfgCommonret = ROK;
2194
2195    /* PUCCH Config Common */
2196    DU_ALLOC(bwp->pucch_ConfigCommon, sizeof(struct BWP_UplinkCommon__pucch_ConfigCommon));
2197    if(!bwp->pucch_ConfigCommon)
2198    {
2199       DU_LOG("\nERROR  -->  DU APP : UL BWP memory allocation failed");
2200       return RFAILED;
2201    }
2202
2203    if((BuildPucchCfgCommon(bwp->pucch_ConfigCommon)) != ROK)
2204    {
2205       DU_LOG("\nERROR  --> DU APP : Failed to fill PUCCH config common in BuildBwpUlCommon()");
2206       return RFAILED;
2207    }
2208
2209    return ROK;
2210 }/* BuildBwpUlCommon */
2211
2212 /*******************************************************************
2213  *
2214  * @brief Builds UL config common for SIB 
2215  *
2216  * @details
2217  *
2218  *    Function : BuildUlCfgCommSib
2219  *
2220  *    Functionality:
2221  *      Builds UL config common for SIB
2222  *
2223  * @params[in] UplinkConfigCommonSIB_t pointer
2224  * @return ROK     - success
2225  *         RFAILED - failure
2226  *
2227  * ****************************************************************/
2228
2229 uint8_t BuildUlCfgCommSib(UplinkConfigCommonSIB_t *ulCfg)
2230 {
2231    uint8_t ret;
2232    /* UL frequency info */
2233    ret = BuildFreqInfoUlSib(&ulCfg->frequencyInfoUL);
2234    if(ret != ROK)
2235    {
2236       return RFAILED;
2237    }
2238    /* BWP Uplink Common */
2239    ret = BuildBwpUlCommon(&ulCfg->initialUplinkBWP);
2240    if(ret != ROK)
2241    {
2242       return RFAILED;
2243    }
2244    /* Time Alignment timer */
2245    ulCfg->timeAlignmentTimerCommon = \
2246                                      duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
2247
2248    return ROK;
2249 }/* BuildUlCfgCommSib */
2250
2251 /*******************************************************************
2252  *
2253  * @brief Builds TDD UL DL configuration common 
2254  *
2255  * @details
2256  *
2257  *    Function : BuildTddUlDlCfgComm
2258  *
2259  *    Functionality:
2260  *      Builds TDD UL DL configuration common
2261  *
2262  * @params[in] TDD_UL_DL_ConfigCommon_t pointer 
2263  * @return ROK     - success
2264  *         RFAILED - failure
2265  *
2266  * ****************************************************************/
2267
2268 uint8_t BuildTddUlDlCfgComm(TDD_UL_DL_ConfigCommon_t *tddCfg)
2269 {
2270    TddUlDlCfgCommon duTddCfg = duCfgParam.sib1Params.srvCellCfgCommSib.tddCfg;
2271
2272    /* Reference Subcarrier spacing */
2273    tddCfg->referenceSubcarrierSpacing = duTddCfg.refScs;
2274
2275    /* Pattern 1*/
2276    tddCfg->pattern1.dl_UL_TransmissionPeriodicity = duTddCfg.txPrd;
2277    tddCfg->pattern1.nrofDownlinkSlots = duTddCfg.numDlSlots;
2278    tddCfg->pattern1.nrofDownlinkSymbols = duTddCfg.numDlSymbols;
2279    tddCfg->pattern1.nrofUplinkSlots = duTddCfg.numUlSlots;
2280    tddCfg->pattern1.nrofUplinkSymbols = duTddCfg.numUlSymbols;
2281
2282    return ROK;
2283
2284 }/* BuildTddUlDlCfgComm */
2285
2286 /*******************************************************************
2287  * 
2288  * @brief Builds Serving cell config common in SIB1 message 
2289  * 
2290  * @details
2291  * 
2292  *     Function : BuildServCellCfgCommonSib
2293  * 
2294  *    Functionality: 
2295  *       Building Serving cell config common in SIB1 message
2296  *
2297  * @params[in] ServingCellConfigCommonSIB_t pointer
2298  * @return ROK     - success
2299  *         RFAILED - failure
2300  *
2301  * ****************************************************************/
2302 uint8_t BuildServCellCfgCommonSib(ServingCellConfigCommonSIB_t *srvCellCfg)
2303 {
2304    SrvCellCfgCommSib    duSrvCellCfg;
2305    BIT_STRING_t         *ssbPosInBurst;
2306    uint8_t              ret;
2307    duSrvCellCfg = duCfgParam.sib1Params.srvCellCfgCommSib;
2308
2309    /* SSB Position in Burst */
2310    ssbPosInBurst = &srvCellCfg->ssb_PositionsInBurst.inOneGroup;
2311    ssbPosInBurst->size = 1;
2312    DU_ALLOC(ssbPosInBurst->buf, ssbPosInBurst->size * sizeof(uint8_t));
2313    if(!ssbPosInBurst->buf)
2314    {
2315       DU_LOG("\nERROR  -->  DU APP : Serving cell config common  memory allocation failure");
2316       return RFAILED;
2317    } 
2318    ssbPosInBurst->buf[0] = duSrvCellCfg.ssbPosInBurst;  
2319    ssbPosInBurst->bits_unused = 0;
2320
2321    srvCellCfg->ssb_PeriodicityServingCell = convertSsbPeriodicityValueToEnumForSib(duSrvCellCfg.ssbPrdServingCell);
2322    srvCellCfg->ss_PBCH_BlockPower = duSrvCellCfg.ssPbchBlockPwr;
2323
2324    /* Downlink config common */
2325    ret = BuildDlCfgCommSib(&srvCellCfg->downlinkConfigCommon);
2326    if(ret != ROK)
2327    {
2328       return RFAILED;
2329    }
2330    DlCfgCommSibret = ROK;
2331
2332    /* Uplink Config Comm */
2333    DU_ALLOC(srvCellCfg->uplinkConfigCommon, sizeof(UplinkConfigCommonSIB_t));
2334    if(!srvCellCfg->uplinkConfigCommon)
2335    {
2336       DU_LOG("\nERROR  -->  DU APP : Serving cell config common  memory allocation failure");
2337       return RFAILED;
2338    }
2339    ret = BuildUlCfgCommSib(srvCellCfg->uplinkConfigCommon);
2340    if(ret != ROK)
2341    {
2342       return RFAILED;
2343    }
2344    UlCfgCommSibret=ROK;
2345
2346    /* TDD UL DL Config Comm */
2347    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
2348    if(!srvCellCfg->tdd_UL_DL_ConfigurationCommon)
2349    {
2350       DU_LOG("\nERROR  -->  DU APP : Serving cell config common  memory allocation failure");
2351       return RFAILED;
2352    }
2353    ret = BuildTddUlDlCfgComm(srvCellCfg->tdd_UL_DL_ConfigurationCommon);
2354    if(ret != ROK)
2355    {
2356       return RFAILED;
2357    }
2358    return ROK;
2359 }
2360
2361 /*******************************************************************
2362  *
2363  * @brief Builds SIB message in Served Cell Info
2364  *
2365  * @details
2366  *
2367  *    Function : BuildSib1Msg
2368  *
2369  *    Functionality: Building SIB message in Served Cell Info
2370  *
2371  * @return ROK     - success
2372  *         RFAILED - failure
2373  *
2374  * ****************************************************************/
2375 uint8_t BuildSib1Msg()
2376 {
2377    SIB1_t                   *sib1Msg;
2378    CellAccessRelatedInfo_t  *cellAccessInfo;
2379    uint8_t                  elementCnt;
2380    uint8_t                  ret1;
2381    asn_enc_rval_t           encRetVal; 
2382    uint8_t                  ret = RFAILED;
2383
2384    do
2385    {
2386       DU_ALLOC(sib1Msg, sizeof(SIB1_t));
2387       if(!sib1Msg)
2388       {   
2389          DU_LOG("\nERROR  -->  DU APP: SIB1 msg memory allocation failure");
2390          break;
2391       }   
2392
2393       elementCnt = ODU_VALUE_ONE;
2394
2395       /* PLMN list */
2396       cellAccessInfo = &sib1Msg->cellAccessRelatedInfo;
2397       cellAccessInfo->plmn_IdentityList.list.count = elementCnt;
2398       cellAccessInfo->plmn_IdentityList.list.size = elementCnt * sizeof(PLMN_IdentityInfo_t *);
2399
2400       ret1 =  BuildPlmnList(cellAccessInfo);
2401       if(ret1 != ROK)
2402       {
2403          break;
2404       }
2405       /* Connection Establish Failure Control */
2406       DU_ALLOC(sib1Msg->connEstFailureControl, sizeof(ConnEstFailureControl_t));
2407       if(!sib1Msg->connEstFailureControl)
2408       {
2409          DU_LOG("\nERROR  -->  DU APP: sib1Msg->connEstFailureControl memory allocation failure");
2410          break;
2411       }
2412       sib1Msg->connEstFailureControl->connEstFailCount =\
2413                                                         duCfgParam.sib1Params.connEstFailCnt;
2414       sib1Msg->connEstFailureControl->connEstFailOffsetValidity =\
2415                                                                  duCfgParam.sib1Params.connEstFailOffValidity;
2416
2417       /* SI Scheduling Info */
2418       DU_ALLOC(sib1Msg->si_SchedulingInfo, sizeof(SI_SchedulingInfo_t));
2419       if(!sib1Msg->si_SchedulingInfo)
2420       {
2421          DU_LOG("\nERROR  -->  DU APP: sib1Msg->si_SchedulingInfo memory allocation failure");
2422          break;
2423       } 
2424       elementCnt = ODU_VALUE_ONE;
2425       sib1Msg->si_SchedulingInfo->schedulingInfoList.list.count = elementCnt;
2426       sib1Msg->si_SchedulingInfo->schedulingInfoList.list.size = elementCnt *
2427          sizeof(struct SchedulingInfo *);
2428       ret1 = BuildSiSchedInfoList(&sib1Msg->si_SchedulingInfo->schedulingInfoList);
2429       if(ret1 != ROK)
2430       {
2431          break;
2432       }
2433       sib1Msg->si_SchedulingInfo->si_WindowLength = duCfgParam.sib1Params.siSchedInfo.winLen;
2434
2435       /* Serving Cell Config Common */
2436       DU_ALLOC(sib1Msg->servingCellConfigCommon, sizeof(ServingCellConfigCommonSIB_t));
2437       if(!sib1Msg->servingCellConfigCommon)
2438       {
2439          DU_LOG("\nERROR  -->  DU APP: sib1Msg->servingCellConfigCommon memory allocation failure");
2440          break;
2441       }
2442       ret1 =  BuildServCellCfgCommonSib(sib1Msg->servingCellConfigCommon);
2443       if(ret1 != ROK)
2444       {
2445          break;
2446       }
2447
2448       xer_fprint(stdout, &asn_DEF_SIB1, sib1Msg);
2449
2450       /* Encode the F1SetupRequest type as APER */
2451       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2452       encBufSize = 0;
2453       encRetVal = aper_encode(&asn_DEF_SIB1, 0, sib1Msg, PrepFinalEncBuf,\
2454             encBuf);
2455       printf("\nencbufSize: %d\n", encBufSize);
2456       if(encRetVal.encoded == -1)
2457       {
2458          DU_LOG("\nERROR  -->  DU APP : Could not encode SIB1 structure (at %s)\n",\
2459                encRetVal.failed_type ?
2460                encRetVal.failed_type->name :
2461                "unknown");
2462          break;
2463       }
2464       for(int i=0; i< encBufSize; i++)
2465       {
2466          printf("%x\t",encBuf[i]);
2467       }
2468       printf("\n");
2469
2470       ret = ROK;
2471       break; 
2472    }while(true);
2473
2474    FreeSib1Msg(sib1Msg);
2475
2476    return ret;
2477
2478
2479 }
2480 /*******************************************************************
2481  *
2482  * @brief      :  deallocating the memory of BuildSib1Msg 
2483  *
2484  * @details
2485  *
2486  *     Function : FreeFreqInfoDlSib
2487  *
2488  *    Functionality: Freeing memory of BuildFreqInfoDlSib 
2489  *
2490  * @params[in] : FrequencyInfoDL_SIB_t *frequencyInfoDL
2491  * @return     :  void
2492  *
2493  *******************************************************************/
2494 void FreeFreqInfoDlSib(FrequencyInfoDL_SIB_t *frequencyInfoDL)
2495 {
2496    uint8_t idx=0;
2497    uint8_t idx1=0;
2498
2499    /* Free DL frequency info */
2500    if(frequencyInfoDL->frequencyBandList.list.array)
2501    {
2502       /*Free Frequency band indicator */
2503       if(frequencyInfoDL->frequencyBandList.list.array[idx])
2504       {
2505          if(frequencyInfoDL->frequencyBandList.list.array[idx]->\
2506                freqBandIndicatorNR)
2507          { 
2508             if(frequencyInfoDL->scs_SpecificCarrierList.list.array)
2509             {
2510                for(idx1 = 0;idx1<frequencyInfoDL->scs_SpecificCarrierList.list.count;idx1++)
2511                {
2512                   if(frequencyInfoDL->scs_SpecificCarrierList.list.array[idx1])
2513                   {
2514                      DU_FREE(frequencyInfoDL->scs_SpecificCarrierList.list.\
2515                            array[idx1], sizeof(SCS_SpecificCarrier_t));
2516                   }
2517                }
2518                DU_FREE(frequencyInfoDL->scs_SpecificCarrierList.list.array,
2519                      frequencyInfoDL->scs_SpecificCarrierList.list.size);
2520             }
2521             DU_FREE(frequencyInfoDL->frequencyBandList.list.\
2522                   array[idx]->freqBandIndicatorNR, sizeof(FreqBandIndicatorNR_t));
2523          }
2524       }
2525       for(idx = 0; idx <frequencyInfoDL->frequencyBandList.list.count; idx++)
2526       {
2527          if(frequencyInfoDL->frequencyBandList.list.array[idx])
2528          { 
2529             DU_FREE(frequencyInfoDL->frequencyBandList.list.array[idx],\
2530                   sizeof(NR_MultiBandInfo_t));
2531          }
2532       }
2533       DU_FREE(frequencyInfoDL->frequencyBandList.list.array,\
2534             frequencyInfoDL->frequencyBandList.list.size);
2535    }
2536 }
2537 /*******************************************************************
2538  *
2539  * @brief  :  deallocating the memory of BuildSib1Msg
2540  *
2541  * @details
2542  *
2543  *     Function :  FreeCommonSerachSpaceList
2544  *
2545  *     Functionality:  deallocating the memory of BuildCommonSerachSpaceList
2546  *
2547  * @params[in] :struct PDCCH_ConfigCommon__commonSearchSpaceList  *searchSpclist
2548  * @return  : void
2549  *
2550  *******************************************************************/
2551 void FreeCommonSerachSpaceList( struct PDCCH_ConfigCommon__commonSearchSpaceList
2552       *searchSpclist)
2553 {
2554    uint8_t idx=0;
2555    SearchSpace_t *searchSpace= NULLP;
2556
2557    if(searchSpclist->list.array)
2558    {
2559       if( searchSpclist->list.array[idx] != NULLP)
2560       {
2561          searchSpace= searchSpclist->list.array[idx];
2562          if(searchSpace->controlResourceSetId)
2563          {
2564             if(searchSpace->monitoringSlotPeriodicityAndOffset)
2565             {
2566                if(searchSpace->monitoringSymbolsWithinSlot)
2567                {
2568                   if(searchSpace->monitoringSymbolsWithinSlot->buf)
2569                   {
2570                      if(searchSpace->nrofCandidates)
2571                      {
2572                         if(searchSpace->searchSpaceType)
2573                         {
2574                            switch(searchSpace->searchSpaceType->present)
2575                            {
2576                               case SearchSpace__searchSpaceType_PR_NOTHING:
2577                                  break;
2578                               case SearchSpace__searchSpaceType_PR_common:
2579                                  {    
2580                                     if(searchSpace->searchSpaceType->choice.common)
2581                                     {
2582                                        if(searchSpace->searchSpaceType->choice.\
2583                                              common->dci_Format0_0_AndFormat1_0)
2584                                        {
2585                                           DU_FREE(searchSpace->searchSpaceType->choice.\
2586                                                 common->dci_Format0_0_AndFormat1_0,sizeof(struct\
2587                                                    SearchSpace__searchSpaceType__common__dci_Format0_0_AndFormat1_0));
2588                                        }
2589                                        DU_FREE(searchSpace->searchSpaceType->choice.common,\
2590                                              sizeof(struct SearchSpace__searchSpaceType__common));
2591                                     }
2592                                     break;
2593                                  }
2594                               case SearchSpace__searchSpaceType_PR_ue_Specific:
2595                                  break;
2596                               default:
2597                                  break;
2598                            }
2599                            DU_FREE(searchSpace->searchSpaceType,\
2600                                  sizeof( struct SearchSpace__searchSpaceType));
2601                         }
2602                         DU_FREE(searchSpace->nrofCandidates,\
2603                               sizeof(struct SearchSpace__nrofCandidates));
2604                      }
2605                      DU_FREE(searchSpace->monitoringSymbolsWithinSlot->buf,\
2606                            searchSpace->monitoringSymbolsWithinSlot->size);
2607                   }
2608                   DU_FREE(searchSpace->monitoringSymbolsWithinSlot,\
2609                         sizeof(BIT_STRING_t));
2610                }
2611                DU_FREE(searchSpace->monitoringSlotPeriodicityAndOffset,\
2612                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
2613             }
2614             DU_FREE(searchSpace->controlResourceSetId,sizeof(ControlResourceSetId_t));
2615          }
2616       }  
2617       for(idx = 0; idx < searchSpclist->list.count; idx++)
2618       {  
2619          if(searchSpclist->list.array[idx])
2620          { 
2621             DU_FREE(searchSpclist->list.array[idx], sizeof(SearchSpace_t));
2622          }
2623       }
2624       DU_FREE(searchSpclist->list.array, searchSpclist->list.size)
2625    }
2626 }
2627 /*******************************************************************
2628  *
2629  * @brief : deallocating the memory of BuildSib1Msg
2630  *
2631  * @details
2632  *
2633  *     Function : FreeBwpDlCommon
2634  *
2635  *     Functionality :Deallocating memory of BuildBwpDlCommon
2636  *
2637  * @params[in] : BWP_DownlinkCommon_t *bwp
2638  *
2639  * @return      : void
2640  *
2641  *******************************************************************/
2642 void FreeBwpDlCommon(BWP_DownlinkCommon_t *bwp)
2643 {
2644    uint8_t idx =0;
2645    struct BWP_DownlinkCommon__pdsch_ConfigCommon *pdschCfg=bwp->pdsch_ConfigCommon;
2646    struct BWP_DownlinkCommon__pdcch_ConfigCommon *pdcchCfg=bwp->pdcch_ConfigCommon;
2647    pdcchCfg->present=duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdcchCfg.present; 
2648    pdschCfg->present=duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdschCfg.present;
2649
2650    if(bwp->pdcch_ConfigCommon)
2651    {
2652       if(bwp->pdsch_ConfigCommon)
2653       {
2654          switch( pdschCfg->present)
2655          {
2656             case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_NOTHING:
2657                {
2658                   //TODO
2659                   break;
2660                }
2661             case  BWP_DownlinkCommon__pdsch_ConfigCommon_PR_release:
2662                { 
2663                   //TODO
2664                   break;
2665                }
2666             case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup:
2667                {
2668                   if(pdschCfg->choice.setup)
2669                   {
2670                      if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList)
2671                      {
2672                         if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array)
2673                         {
2674
2675                            for(idx=0; idx<pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.count ; idx++)
2676                            {
2677                               if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]!= NULLP)
2678                               {
2679                                  if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]->k0)
2680                                  {
2681                                     DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]->k0,\
2682                                           sizeof(long)); 
2683                                  }
2684                               }
2685                            }
2686                            for(idx=0; idx<pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.count ; idx++)
2687                            {
2688                               if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]!=
2689                                     NULLP)
2690                               {
2691                                  DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx],\
2692                                        sizeof(PDSCH_TimeDomainResourceAllocation_t));
2693                               }
2694                            }
2695                            DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array,\
2696                                  pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.size);
2697                         }
2698                         DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList,\
2699                               sizeof(PDSCH_TimeDomainResourceAllocationList_t));
2700                      }
2701                      DU_FREE(pdschCfg->choice.setup,
2702                            sizeof(PDSCH_ConfigCommon_t));
2703                   }
2704                }
2705             default:
2706                break;
2707          }
2708          DU_FREE(bwp->pdsch_ConfigCommon,\
2709                sizeof(struct BWP_DownlinkCommon__pdsch_ConfigCommon));
2710       }
2711
2712       switch(pdcchCfg->present)
2713       {
2714          case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_NOTHING:
2715             {
2716                //TODO
2717                break;
2718             }
2719          case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_release:
2720             {
2721                //TODO
2722                break;
2723             }
2724          case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup:
2725             {
2726                if(pdcchCfg->choice.setup)
2727                {
2728                   /* Control Resource Set Zero */
2729                   if( pdcchCfg->choice.setup->controlResourceSetZero)
2730                   {
2731                      /* Search space zero */
2732                      if( pdcchCfg->choice.setup->searchSpaceZero)
2733                      {
2734                         /* Common Search Space List */
2735                         if( pdcchCfg->choice.setup->commonSearchSpaceList)
2736                         {
2737                            if(CommonSerachSpaceListret==ROK)
2738                            {
2739                               if(pdcchCfg->choice.setup->searchSpaceSIB1)
2740                               {
2741                                  if(pdcchCfg->choice.setup->pagingSearchSpace)
2742                                  {
2743                                     if(pdcchCfg->choice.setup->ra_SearchSpace)
2744                                     {
2745                                        DU_FREE(pdcchCfg->choice.setup->ra_SearchSpace,
2746                                              sizeof(SearchSpaceId_t));
2747                                     }
2748                                     DU_FREE( pdcchCfg->choice.setup->pagingSearchSpace,
2749                                           sizeof(SearchSpaceId_t));
2750                                  }
2751                                  DU_FREE( pdcchCfg->choice.setup->searchSpaceSIB1,
2752                                        sizeof(SearchSpaceId_t));
2753                               }
2754                            }
2755
2756                            FreeCommonSerachSpaceList(pdcchCfg->choice.setup->commonSearchSpaceList);
2757
2758                            DU_FREE( pdcchCfg->choice.setup->commonSearchSpaceList,\
2759                                  sizeof(struct
2760                                     PDCCH_ConfigCommon__commonSearchSpaceList));
2761                         }
2762                         DU_FREE( pdcchCfg->choice.setup->searchSpaceZero,
2763                               sizeof(SearchSpaceZero_t));
2764                      }
2765                      DU_FREE( pdcchCfg->choice.setup->controlResourceSetZero,
2766                            sizeof(ControlResourceSetZero_t));
2767                   }
2768                   DU_FREE(pdcchCfg->choice.setup,
2769                         sizeof(PDCCH_ConfigCommon_t));
2770                }
2771                break;
2772             }
2773          default:
2774             break;
2775       }
2776       DU_FREE(bwp->pdcch_ConfigCommon,sizeof(struct BWP_DownlinkCommon__pdcch_ConfigCommon));
2777    }
2778 }
2779
2780 /*******************************************************************
2781  *
2782  * @brief  Free PUCCH configuration common
2783  *
2784  * @details
2785  *
2786  *    Function : FreePucchCfgCommon
2787  *
2788  *    Functionality:
2789  *      Free PUCCH configuration common
2790  *
2791  * @params[in] Pointer to struct BWP_UplinkCommon__pucch_ConfigCommon
2792  * @return void
2793  *
2794  * ****************************************************************/
2795 void FreePucchCfgCommon( struct BWP_UplinkCommon__pucch_ConfigCommon *pucchCfg)
2796 {
2797    PUCCH_ConfigCommon_t *setup;
2798
2799    if(pucchCfg->choice.setup)
2800    {
2801       setup = pucchCfg->choice.setup;
2802
2803       /* Resource Common */
2804       DU_FREE(setup->pucch_ResourceCommon, sizeof(long));
2805
2806       /* P0 nominal */
2807       DU_FREE(setup->p0_nominal, sizeof(long));
2808
2809       DU_FREE(pucchCfg->choice.setup, sizeof(PUCCH_ConfigCommon_t));
2810    }
2811 }/* FreePucchCfgCommon */
2812
2813 /*******************************************************************
2814  *
2815  * @brief Free PUSCH configuration for common
2816  *
2817  * @details
2818  *
2819  *    Function : FreePuschCfgCommon
2820  *
2821  *    Functionality:
2822  *      Free PUSCH configuration for common
2823  *
2824  * @params[in] Pointer to struct BWP_UplinkCommon__pusch_ConfigCommon *puschCfg
2825  * @return void
2826  *
2827  * ****************************************************************/
2828 void FreePuschCfgCommon(struct BWP_UplinkCommon__pusch_ConfigCommon *puschCfg)
2829 {
2830    uint8_t           idx = 0;
2831    PUSCH_ConfigCommon_t *setup = NULLP;
2832    PUSCH_TimeDomainResourceAllocation_t  *timeDomRsrcAllocInfo = NULLP;
2833
2834    if(puschCfg->choice.setup)
2835    {
2836       setup = puschCfg->choice.setup;
2837
2838       /* Time Domain Resource Allocation List */
2839       if(setup->pusch_TimeDomainAllocationList)
2840       {
2841          if(setup->pusch_TimeDomainAllocationList->list.array)
2842          {
2843             for(idx=0; idx < setup->pusch_TimeDomainAllocationList->list.count; idx++)
2844             {
2845                if(setup->pusch_TimeDomainAllocationList->list.array[idx])
2846                {
2847                   timeDomRsrcAllocInfo = setup->pusch_TimeDomainAllocationList->list.array[idx];
2848
2849                   /* K2 */
2850                   DU_FREE(timeDomRsrcAllocInfo->k2, sizeof(long));
2851                   DU_FREE(setup->pusch_TimeDomainAllocationList->list.array[idx],\
2852                         sizeof(PUSCH_TimeDomainResourceAllocation_t));
2853                }
2854             }
2855             DU_FREE(setup->pusch_TimeDomainAllocationList->list.array, setup->pusch_TimeDomainAllocationList->list.size);
2856          }
2857          DU_FREE(setup->pusch_TimeDomainAllocationList, sizeof(PUSCH_TimeDomainResourceAllocationList_t));
2858       }
2859
2860       /* Msg3 Delta Preamble */
2861       DU_FREE(setup->msg3_DeltaPreamble, sizeof(long));
2862
2863       /* P0 Nominal with grant */
2864       DU_FREE(setup->p0_NominalWithGrant, sizeof(long));
2865
2866       DU_ALLOC(puschCfg->choice.setup, sizeof(PUSCH_ConfigCommon_t));
2867    }
2868 }/* BuildPuschCfgCommon */
2869
2870 /*******************************************************************
2871  *
2872  * @brief Free RACH configuration common
2873  *
2874  * @details
2875  *
2876  *    Function : FreeRachCfgCommon
2877  *
2878  *    Functionality:
2879  *      Free RACH configuration common
2880  *
2881  * @params[in] BWP_UplinkCommon__rach_ConfigCommon pointer
2882  * @return void
2883  *
2884  * ****************************************************************/
2885
2886 void FreeRachCfgCommon(struct BWP_UplinkCommon__rach_ConfigCommon *rachCfg)
2887 {
2888    RACH_ConfigCommon_t  *setup = NULLP;
2889
2890    if(rachCfg->choice.setup)
2891    {
2892       setup = rachCfg->choice.setup;
2893
2894       /* Total number of RA preambles */
2895       DU_FREE(setup->totalNumberOfRA_Preambles, sizeof(long));
2896
2897       /* SSB per RACH occassion and CB Preambles per SSB */
2898       DU_FREE(setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB,\
2899             sizeof(struct RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB));
2900
2901       /* RSRP Threshold SSB */
2902       DU_FREE(setup->rsrp_ThresholdSSB, sizeof(RSRP_Range_t));
2903
2904       /* Msg 1 Subcarrier spacing */
2905       DU_FREE(setup->msg1_SubcarrierSpacing, sizeof(SubcarrierSpacing_t));
2906
2907       DU_FREE(rachCfg->choice.setup, sizeof(RACH_ConfigCommon_t));
2908    }
2909 }/* FreeRachCfgCommon */
2910
2911 /*******************************************************************
2912  *
2913  * @brief Free UL BWP Common
2914  *
2915  * @details
2916  *
2917  *    Function : FreeBwpUlCommon
2918  *
2919  *    Functionality:
2920  *      Free UL BWP Common
2921  *
2922  * @params[in] BWP_UplinkCommon_t pointer
2923  * @return void
2924  *
2925  * ****************************************************************/
2926 void FreeBwpUlCommon(BWP_UplinkCommon_t *bwp)
2927 {
2928    /* RACH Config Common */
2929    if(bwp->rach_ConfigCommon)
2930    {
2931       FreeRachCfgCommon(bwp->rach_ConfigCommon);
2932       DU_FREE(bwp->rach_ConfigCommon, sizeof(struct BWP_UplinkCommon__rach_ConfigCommon));
2933    }
2934
2935    /* PUSCH Config Common */
2936    if(bwp->pusch_ConfigCommon)
2937    {
2938       FreePuschCfgCommon(bwp->pusch_ConfigCommon);
2939       DU_FREE(bwp->pusch_ConfigCommon, sizeof(struct BWP_UplinkCommon__pusch_ConfigCommon));
2940    }
2941
2942    /* PUCCH Config Common */
2943    if(bwp->pucch_ConfigCommon)
2944    {
2945       FreePucchCfgCommon(bwp->pucch_ConfigCommon);
2946       DU_FREE(bwp->pucch_ConfigCommon, sizeof(struct BWP_UplinkCommon__pucch_ConfigCommon));
2947    }
2948 }/* FreeBwpUlCommon */
2949
2950 /*******************************************************************
2951  *
2952  * @brief Free frequency infor for UL
2953  *
2954  * @details
2955  *
2956  *    Function : FreeFreqInfoUlSib
2957  *
2958  *    Functionality:
2959  *       Free frequency infor for UL
2960  *
2961  * @params[in] FrequencyInfoUL_SIB_t pointer
2962  * @return void
2963  *
2964  * ****************************************************************/
2965
2966 void FreeFreqInfoUlSib(FrequencyInfoUL_SIB_t *frequencyInfoUL)
2967 {
2968    uint8_t idx = 0;
2969    struct FrequencyInfoUL_SIB__scs_SpecificCarrierList *scsCarrierList = &frequencyInfoUL->scs_SpecificCarrierList;
2970
2971    /* Subcarrier Spacing specifc carrier */
2972    if(scsCarrierList->list.array)
2973    {
2974       for(idx = 0; idx < scsCarrierList->list.count; idx++)
2975       {
2976          DU_FREE(scsCarrierList->list.array[idx], sizeof(SCS_SpecificCarrier_t));
2977       }
2978       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
2979    }
2980
2981    /* P-MAX */
2982    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
2983 }/* FreeFreqInfoUlSib */
2984
2985 /*******************************************************************
2986  *
2987  * @brief : Deallocating memory of  SIB1 message
2988  *
2989  * @details
2990  *
2991  *   Function : FreeServCellCfgCommonSib
2992  *
2993  *   Functionality: Deallocating memory of BuildServCellCfgCommonSib
2994  *
2995  * @params[in] : ServingCellConfigCommonSIB_t *srvCellCfg
2996  * @return     : void
2997  *
2998  *******************************************************************/
2999 void FreeServCellCfgCommonSib(ServingCellConfigCommonSIB_t *srvCellCfg)
3000 {
3001    BIT_STRING_t *ssbPosInBurst = NULLP;
3002    DownlinkConfigCommonSIB_t *dlCfg = NULLP;
3003    UplinkConfigCommonSIB_t *ulCfg = NULLP;
3004
3005    /* SSB Position in Burst buffer */
3006    ssbPosInBurst = &srvCellCfg->ssb_PositionsInBurst.inOneGroup;
3007    DU_FREE(ssbPosInBurst->buf, ssbPosInBurst->size * sizeof(uint8_t));
3008
3009    /* Free Donwlink config common SIB */
3010    dlCfg = &srvCellCfg->downlinkConfigCommon;
3011    FreeFreqInfoDlSib(&dlCfg->frequencyInfoDL);
3012    FreeBwpDlCommon(&dlCfg->initialDownlinkBWP);
3013
3014    /* Uplink Config Comm */
3015    if(srvCellCfg->uplinkConfigCommon)
3016    {
3017       ulCfg = srvCellCfg->uplinkConfigCommon;
3018       FreeFreqInfoUlSib(&ulCfg->frequencyInfoUL);
3019       FreeBwpUlCommon(&ulCfg->initialUplinkBWP);
3020       DU_FREE(srvCellCfg->uplinkConfigCommon, sizeof(UplinkConfigCommonSIB_t));  
3021    }
3022
3023    /* TDD UL DL Config Comm */
3024    DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
3025 }
3026
3027 /*******************************************************************
3028  *
3029  * @brief   : Deallcating memory of the function BuildSib1Msg
3030  *
3031  * @details
3032  *
3033  *     Function :  FreeSib1Msg
3034  *
3035  *    Functionality: Deallcating memory of the function BuildSib1Msg
3036  *
3037  * @params[in] ServingCellConfigCommonSIB_t pointer
3038  * @return   void
3039  *
3040  *******************************************************************/
3041 void FreeSib1Msg(SIB1_t *sib1Msg)
3042 {
3043    uint8_t idx=0;
3044    uint8_t idx1=0;
3045    uint8_t idx2=0, arrIdx =0, sibMapInfoIdx=0; 
3046    CellIdentity_t           *cellIdentity = NULLP;
3047    SchedulingInfo_t *schedInfo;
3048    CellAccessRelatedInfo_t  *cellAccessInfo ;
3049    struct PLMN_IdentityInfo__plmn_IdentityList     *plmnIdInfo;
3050
3051
3052    if(sib1Msg != NULLP)
3053    {
3054       cellAccessInfo = &sib1Msg->cellAccessRelatedInfo;
3055       if(cellAccessInfo->plmn_IdentityList.list.array !=NULLP)
3056       {
3057          if(cellAccessInfo->plmn_IdentityList.list.array[idx]!=NULLP)
3058          {
3059             plmnIdInfo =
3060                &cellAccessInfo->plmn_IdentityList.list.array[idx]->plmn_IdentityList;
3061
3062             if(plmnIdInfo->list.array !=NULLP)
3063             {
3064                if(plmnIdInfo->list.array[idx])
3065                {
3066                   if(plmnIdInfo->list.array[idx]->mcc)
3067                   {
3068                      if((plmnIdInfo->list.array[idx]->mcc->list.array))
3069                      {
3070                         if(plmnIdInfo->list.array[idx]->mnc.list.array)
3071                         {             
3072                            /*Free Tracking Area Code */
3073                            if(cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode)
3074                            {        
3075                               /*Free RANAC */
3076                               if(cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode->buf)
3077                               {    
3078                                  /* Free CellIdentity */
3079                                  if(cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac)
3080                                  {
3081                                     cellIdentity
3082                                        =&cellAccessInfo->plmn_IdentityList.\
3083                                        list.array[idx]->cellIdentity;
3084                                     if(cellIdentity->buf)
3085                                     {
3086                                        /*Free Connection Establish Failure Control */
3087                                        if(sib1Msg->connEstFailureControl)
3088                                        {
3089                                           /*Free Serving Cell Config Common */
3090                                           if(sib1Msg->si_SchedulingInfo)
3091                                           {
3092                                              /* Free Serving Cell Config Common* */
3093                                              if(sib1Msg->servingCellConfigCommon)
3094                                              {
3095                                                 /*Free BuildServCellCfgCommonSib*/
3096                                                 FreeServCellCfgCommonSib(\
3097                                                       sib1Msg->servingCellConfigCommon);
3098
3099                                                 DU_FREE(sib1Msg->servingCellConfigCommon,
3100                                                       sizeof(ServingCellConfigCommonSIB_t));
3101                                              }
3102                                              //TODO PBORLA
3103                                              if(sib1Msg->si_SchedulingInfo->schedulingInfoList.list.array)
3104                                              {
3105                                                 for(arrIdx = 0; arrIdx < sib1Msg->si_SchedulingInfo->schedulingInfoList.list.count; arrIdx++)
3106                                                 {
3107                                                    schedInfo = sib1Msg->si_SchedulingInfo->schedulingInfoList.list.array[arrIdx];
3108                                                    if(schedInfo->sib_MappingInfo.list.array)
3109                                                    {
3110                                                       for(sibMapInfoIdx = 0; sibMapInfoIdx< schedInfo->sib_MappingInfo.list.count; sibMapInfoIdx++)
3111                                                       {
3112                                                          DU_FREE(schedInfo->sib_MappingInfo.list.array[sibMapInfoIdx]->valueTag, sizeof(long));
3113                                                          DU_FREE(schedInfo->sib_MappingInfo.list.array[sibMapInfoIdx], sizeof(SIB_TypeInfo_t));
3114                                                       }
3115                                                       DU_FREE(schedInfo->sib_MappingInfo.list.array, schedInfo->sib_MappingInfo.list.size)
3116                                                    }
3117                                                    DU_FREE(sib1Msg->si_SchedulingInfo->schedulingInfoList.list.array[arrIdx], sizeof(struct SchedulingInfo));  
3118                                                 }
3119                                                 DU_FREE(sib1Msg->si_SchedulingInfo->schedulingInfoList.list.array,\
3120                                                       sib1Msg->si_SchedulingInfo->schedulingInfoList.list.size);
3121                                              }
3122
3123                                              DU_FREE(sib1Msg->si_SchedulingInfo,
3124                                                    sizeof(SI_SchedulingInfo_t));
3125                                           }
3126
3127                                           DU_FREE(sib1Msg->connEstFailureControl,
3128                                                 sizeof(ConnEstFailureControl_t));
3129                                        }
3130                                        DU_FREE(cellIdentity->buf,cellIdentity->size);
3131
3132                                     }
3133                                     DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac, sizeof(RAN_AreaCode_t)); 
3134
3135                                  }
3136                                  DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode->buf,\
3137                                        cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode->size);
3138
3139                               }
3140                               DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode\
3141                                     , sizeof(TrackingAreaCode_t));
3142                            }
3143
3144                            for(idx2=0; idx2<plmnIdInfo->list.array[idx1]->mnc.list.count; idx2++)
3145                            {
3146                               if(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2])
3147                               {
3148                                  DU_FREE(plmnIdInfo->list.array[idx1]->mnc.list.array[idx2],
3149                                        sizeof(MCC_MNC_Digit_t));
3150                               } 
3151                            }
3152                            DU_FREE(plmnIdInfo->list.array[idx]->mnc.list.array,
3153                                  plmnIdInfo->list.array[idx1]->mnc.list.size);
3154                         }
3155
3156                         for(idx1=0; idx1<plmnIdInfo->list.array[idx]->mcc->list.count; idx1++)
3157                         {
3158                            if(plmnIdInfo->list.array[idx]->mcc->list.array[idx1]!=NULLP)
3159                            {
3160                               DU_FREE(plmnIdInfo->list.array[idx]->mcc->list.array[idx1],\
3161                                     sizeof(MCC_MNC_Digit_t));
3162                            }
3163
3164                         }
3165                         DU_FREE(plmnIdInfo->list.array[idx]->mcc->list.array,\
3166                               plmnIdInfo->list.array[idx]->mcc->list.size)
3167                      }
3168                      DU_FREE(plmnIdInfo->list.array[idx]->mcc,sizeof(MCC_t));
3169                   }
3170                }
3171                for(idx1=0; idx1<plmnIdInfo->list.count; idx1++)
3172                {
3173                   if((plmnIdInfo->list.array[idx1]))
3174                   {
3175                      DU_FREE(plmnIdInfo->list.array[idx1],
3176                            sizeof(PLMN_IdentitY_t));
3177                   }
3178                }
3179                DU_FREE(plmnIdInfo->list.array, plmnIdInfo->list.size);
3180             }
3181          }
3182          for(idx=0; idx<cellAccessInfo->plmn_IdentityList.list.count; idx++)
3183          {
3184             if(cellAccessInfo->plmn_IdentityList.list.array[idx]!=NULLP)
3185             { 
3186                DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx],
3187                      sizeof(PLMN_IdentityInfo_t));
3188             }
3189          }
3190          DU_FREE(cellAccessInfo->plmn_IdentityList.list.array,
3191                cellAccessInfo->plmn_IdentityList.list.size);
3192       }
3193       DU_FREE(sib1Msg, sizeof(SIB1_t)); 
3194    }
3195
3196 }
3197
3198 /**********************************************************************
3199   End of file
3200  **********************************************************************/