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