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