L1-L2 Integration fixes.[Issue-ID: ODUHIGH-252]
[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_utils.h"
28 #include "BCCH-BCH-Message.h"
29 #include "MIB.h"
30 #include "PLMN-IdentityInfo.h"
31 #include "PLMN-IdentitY.h"
32 #include "SIB-TypeInfo.h"
33 #include "SchedulingInfo.h"
34 #include "SI-SchedulingInfo.h"
35 #include "ConnEstFailureControl.h"
36 #include "FrequencyInfoDL-SIB.h"
37 #include "SearchSpace.h"
38 #include "SCS-SpecificCarrier.h"
39 #include "NR-MultiBandInfo.h"
40 #include "PDCCH-ConfigCommon.h"
41 #include "PDSCH-TimeDomainResourceAllocation.h"
42 #include "PDSCH-TimeDomainResourceAllocationList.h"
43 #include "PDSCH-ConfigCommon.h"
44 #include "BWP-DownlinkCommon.h"
45 #include "DownlinkConfigCommonSIB.h"
46 #include "RACH-ConfigCommon.h"
47 #include "PUSCH-TimeDomainResourceAllocation.h"
48 #include "PUSCH-TimeDomainResourceAllocationList.h"
49 #include "PUSCH-ConfigCommon.h"
50 #include "PUCCH-ConfigCommon.h"
51 #include "UplinkConfigCommonSIB.h"
52 #include "TDD-UL-DL-ConfigCommon.h"
53 #include "ServingCellConfigCommonSIB.h"
54 #include "MCC.h"
55 #include "SIB1.h"
56 #include "odu_common_codec.h"
57 #include "du_sys_info_hdl.h"
58
59 void FreeSib1Msg(SIB1_t *sib1Msg);
60 uint8_t FreqInfoUlret = RFAILED;
61 uint8_t RachCfgCommonret = RFAILED;
62 uint8_t PuschCfgCommonret = RFAILED;
63 uint8_t UlCfgCommSibret = RFAILED;
64 uint8_t FreqInfoDlret = RFAILED;
65 uint8_t DlCfgCommSibret = RFAILED;
66 uint8_t CommonSerachSpaceListret = RFAILED;
67
68 /*******************************************************************
69  *
70  * @brief Builds MIB
71  *
72  * @details
73  *
74  *    Function : BuildMib
75  *
76  *    Functionality: Building MIB
77  *
78  * @return ROK     - success
79  *         RFAILED - failure
80  *
81  * ****************************************************************/
82 uint8_t BuildMib(MIB_t *mib)
83 {
84    mib->systemFrameNumber.size = sizeof(uint8_t);
85    DU_ALLOC(mib->systemFrameNumber.buf, mib->systemFrameNumber.size);
86    if(!(mib->systemFrameNumber.buf))
87    {
88       DU_LOG("DU APP: MIB msg memory allocation failure");
89       return RFAILED;
90    }
91
92    *(mib->systemFrameNumber.buf) =  duCfgParam.mibParams.sysFrmNum;
93    mib->systemFrameNumber.bits_unused = ODU_VALUE_TWO;
94
95    mib->subCarrierSpacingCommon = duCfgParam.mibParams.subCarrierSpacingCommon;
96    mib->ssb_SubcarrierOffset = duCfgParam.mibParams.ssb_SubcarrierOffset;
97    mib->dmrs_TypeA_Position = duCfgParam.mibParams.dmrs_TypeA_Position;
98    mib->pdcch_ConfigSIB1.controlResourceSetZero = duCfgParam.mibParams.controlResourceSetZero;
99    mib->pdcch_ConfigSIB1.searchSpaceZero = duCfgParam.mibParams.searchSpaceZero;
100    mib->cellBarred = duCfgParam.mibParams.cellBarred;
101    mib->intraFreqReselection = duCfgParam.mibParams.intraFreqReselection;
102    mib->spare.size = sizeof(uint8_t);
103    DU_ALLOC(mib->spare.buf, mib->spare.size);
104    if(!mib->spare.buf)
105    {
106       DU_LOG("DU APP: MIB msg memory allocation failure");
107       return RFAILED;
108    }
109    *(mib->spare.buf) = SPARE;
110    mib->spare.bits_unused = ODU_VALUE_SEVEN;
111    return ROK;
112 }
113 /*******************************************************************
114  *
115  * @brief Free MIB PDU for broadcast
116  *
117  * @details
118  *
119  *    Function : FreeMibPdu
120  *
121  *    Functionality: Deallocating MIB PDU for system broadcast
122  *
123  * @param[in]: BCCH_BCH_Message_t *bcchMsg
124  *
125  * @return void         
126  *
127  * ****************************************************************/
128 void FreeMibPdu(BCCH_BCH_Message_t *bcchMsg)
129 {
130    if(!bcchMsg)
131    {
132       if(!bcchMsg->message.choice.mib)
133       {
134          if(!(bcchMsg->message.choice.mib->systemFrameNumber.buf))
135          {
136             if(!bcchMsg->message.choice.mib->spare.buf)
137             {
138                DU_FREE(bcchMsg->message.choice.mib->spare.buf,\
139                      bcchMsg->message.choice.mib->spare.size);
140             }
141             DU_FREE(bcchMsg->message.choice.mib->systemFrameNumber.buf,
142                   bcchMsg->message.choice.mib->systemFrameNumber.size);
143          }
144          DU_FREE(bcchMsg->message.choice.mib, sizeof(MIB_t));
145       }
146       DU_FREE(bcchMsg, sizeof(BCCH_BCH_Message_t));
147    }
148 }
149 /*******************************************************************
150  *
151  * @brief Builds MIB PDU for broadcast
152  *
153  * @details
154  *
155  *    Function : BuildMibPdu
156  *
157  *    Functionality: Building MIB PDU for system broadcast
158  *
159  * @return ROK     - success
160  *         RFAILED - failure
161  *
162  * ****************************************************************/
163 uint8_t BuildMibPdu()
164 {
165    uint8_t BuildMibret;
166    uint8_t ret = RFAILED;
167    BCCH_BCH_Message_t *bcchMsg;
168    asn_enc_rval_t encRetVal;        /* Encoder return value */
169    while(true)
170    {
171       DU_ALLOC(bcchMsg, sizeof(BCCH_BCH_Message_t));
172       if(!bcchMsg)
173       {
174          DU_LOG("\nMemory allocation failure in BuildMibPdu");
175          break;
176       }
177
178       bcchMsg->message.present = BCCH_BCH_MessageType_PR_mib;
179       DU_ALLOC(bcchMsg->message.choice.mib, sizeof(MIB_t));
180       if(!bcchMsg->message.choice.mib)
181       {
182          DU_LOG("\nMemory allocation failure in BuildMibPdu");
183          break;
184       }
185       BuildMibret = BuildMib(bcchMsg->message.choice.mib);
186       if(BuildMibret != ROK)
187       {
188          break;
189       }
190       xer_fprint(stdout, &asn_DEF_BCCH_BCH_Message, bcchMsg);
191       memset(encBuf, 0, ENC_BUF_MAX_LEN);
192       encBufSize = 0;
193       encRetVal = aper_encode(&asn_DEF_BCCH_BCH_Message, 0,
194             bcchMsg, PrepFinalEncBuf, encBuf);
195       printf("\nencbufSize:%d\n", encBufSize);
196       if(encRetVal.encoded      == -1) 
197       {   
198          DU_LOG("\nDU APP: Could not encode BCCH BCH Message Type structure(at %s)\n", 
199                encRetVal.failed_type?\
200                encRetVal.failed_type->name
201                :"unknown");
202          break;
203       }    
204
205       /* Print encoded buffer */
206       for(int i=0; i< encBufSize; i++)
207       {
208          printf("%x\t",encBuf[i]);
209       } 
210       printf("\n");
211
212       ret = ROK;
213       break;
214    }
215    /* Free allocated memory */
216    FreeMibPdu(bcchMsg);
217
218    return ret;
219
220 }
221 /*******************************************************************
222  *
223  * @brief free MIB message in Served Cell Info
224  *
225  * @details
226  *
227  *    Function : FreeMibMsg
228  *
229  *    Functionality: deallocating MIB message in Served Cell Info
230  *
231  * @param[in]   MIB_t *mibMsg
232  *
233  * @return void
234  *        
235  *
236  * ****************************************************************/
237 void FreeMibMsg( MIB_t *mibMsg)
238 {
239    if(!mibMsg)
240    {
241       if(!(mibMsg->systemFrameNumber.buf))
242       {   
243          if(!mibMsg->spare.buf)
244          {
245             DU_FREE(mibMsg->spare.buf, mibMsg->spare.size);
246          }
247          DU_FREE(mibMsg->systemFrameNumber.buf,
248                mibMsg->systemFrameNumber.size);
249       }
250       DU_FREE(mibMsg, sizeof(MIB_t));
251    }
252 }
253 /*******************************************************************
254  *
255  * @brief Builds MIB message in Served Cell Info
256  *
257  * @details
258  *
259  *    Function : BuildMibMsg
260  *
261  *    Functionality: Building MIB message in Served Cell Info
262  *
263  * @return ROK     - success
264  *         RFAILED - failure
265  *
266  * ****************************************************************/
267 uint8_t BuildMibMsg()
268 {
269    MIB_t          *mibMsg;
270    asn_enc_rval_t encRetVal;        /* Encoder return value */
271    uint8_t ret = RFAILED;
272    uint8_t BuildMibret;
273    while(true)
274    {
275       DU_ALLOC(mibMsg, sizeof(MIB_t));
276       if(!mibMsg)
277       {
278          DU_LOG("DU APP: MIB msg memory allocation failure");
279          return RFAILED;
280       }
281       BuildMibret =  BuildMib(mibMsg);
282       if(BuildMibret != ROK)
283       {
284          break;
285       }
286       xer_fprint(stdout, &asn_DEF_MIB, mibMsg);
287       memset(encBuf, 0, ENC_BUF_MAX_LEN);
288       encBufSize = 0;
289       encRetVal = aper_encode(&asn_DEF_MIB, 0,
290             mibMsg, PrepFinalEncBuf, encBuf);
291       printf("\nencbufSize:%d\n", encBufSize);
292       if(encRetVal.encoded      == -1) 
293       {   
294          DU_LOG("\nDU APP: Could not encode MIB structure(at %s)\n", 
295                encRetVal.failed_type?\
296                encRetVal.failed_type->name
297                :"unknown");
298          break;
299       }  
300
301       /* Print encoded buffer */
302       for(int i=0; i< encBufSize; i++)
303       {
304          printf("%x\t",encBuf[i]);
305       } 
306       printf("\n");
307
308       /* Free allocated memory */
309       ret = ROK;
310       break;
311    }
312
313    FreeMibMsg(mibMsg);
314
315    return ret;
316
317 }
318
319 /*******************************************************************
320  *
321  * @brief Builds CellIdentity  within SIB1 message
322  *
323  * @details
324  *
325  *    Function : BuildCellIdentity
326  *
327  *    Functionality: Building RAN area code in SIB1 message 
328  *
329  * @params[in] RAN_AreaCode_t **ranAreaCode 
330  * @return ROK     - success
331  *         RFAILED - failure
332  *
333  * ****************************************************************/
334 uint8_t BuildCellIdentity(CellIdentity_t  *cellIdentity)
335 {
336    cellIdentity->size = ODU_VALUE_FIVE*sizeof(uint8_t);
337    cellIdentity->bits_unused = ODU_VALUE_FOUR;
338
339    DU_ALLOC(cellIdentity->buf, cellIdentity->size);
340    if(!cellIdentity->buf)
341    {   
342       DU_LOG("DU APP: CellIdentity memory allocation failure");
343       return RFAILED;
344    }   
345    *cellIdentity->buf = 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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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 : BuildScsSpecificCarrierListDl
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 BuildScsSpecificCarrierListDl( 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("\nDU 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("\nDU 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 BuildScsSpecificCarrierListDl */
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("\nDU 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("\nDU 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("\nDU 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("\nDU APP : Common search space list memory alloc failed");
804       return RFAILED;
805    }
806    searchSpace->monitoringSlotPeriodicityAndOffset->present = \
807    duPdcchCfg.monitorSlotPrdAndOffPresent;
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("\nDU APP : Invalid value:Montoring slot periodicity and offset");
888          return RFAILED;
889       }
890    }
891
892    /* Monitoring Symbols Within Slot */
893    DU_ALLOC(searchSpace->monitoringSymbolsWithinSlot,\
894    sizeof(BIT_STRING_t));
895    if(!searchSpace->monitoringSymbolsWithinSlot)
896    {
897       DU_LOG("\nDU APP : Common search space list memory alloc failed");
898       return RFAILED;
899    }
900    searchSpace->monitoringSymbolsWithinSlot->size = 2*sizeof(uint8_t);
901    DU_ALLOC(searchSpace->monitoringSymbolsWithinSlot->buf, \
902    searchSpace->monitoringSymbolsWithinSlot->size );
903    if(!searchSpace->monitoringSymbolsWithinSlot->buf)
904    {  
905       DU_LOG("\nDU APP : Common search space list memory alloc failed");
906       return RFAILED;
907    }
908    searchSpace->monitoringSymbolsWithinSlot->buf[0] = duPdcchCfg.monitorSymbolsInSlot[0];
909    searchSpace->monitoringSymbolsWithinSlot->buf[1] = duPdcchCfg.monitorSymbolsInSlot[1];
910    searchSpace->monitoringSymbolsWithinSlot->bits_unused = 2;
911
912    /* Number of candidates per aggregation level */
913    DU_ALLOC(searchSpace->nrofCandidates,\
914          sizeof(struct SearchSpace__nrofCandidates));
915    if(!searchSpace->nrofCandidates)
916    {
917       DU_LOG("\nDU APP : Common search space list memory alloc failed");
918       return RFAILED;
919    }
920    searchSpace->nrofCandidates->aggregationLevel1 = duPdcchCfg.numCandAggLvl1;
921    searchSpace->nrofCandidates->aggregationLevel2 = duPdcchCfg.numCandAggLvl2;
922    searchSpace->nrofCandidates->aggregationLevel4 = duPdcchCfg.numCandAggLvl4;
923    searchSpace->nrofCandidates->aggregationLevel8 = duPdcchCfg.numCandAggLvl8;
924    searchSpace->nrofCandidates->aggregationLevel16 = duPdcchCfg.numCandAggLvl16;
925
926    /* Search Space type and  DCI Format */
927    DU_ALLOC(searchSpace->searchSpaceType,\
928    sizeof( struct SearchSpace__searchSpaceType));
929    if(!searchSpace->searchSpaceType)
930    {
931       DU_LOG("\nDU APP : Common search space list memory alloc failed");
932       return RFAILED;
933    }
934
935    searchSpace->searchSpaceType->present = duPdcchCfg.searchSpcType; 
936    switch(searchSpace->searchSpaceType->present)
937    {
938       case SearchSpace__searchSpaceType_PR_NOTHING:
939       {
940          //TODO
941          break;
942       }
943       case SearchSpace__searchSpaceType_PR_common:
944       {
945          DU_ALLOC(searchSpace->searchSpaceType->choice.common, sizeof(struct SearchSpace__searchSpaceType__common));
946          if(!searchSpace->searchSpaceType->choice.common)
947          {
948             DU_LOG("\nDU APP : Common search space list memory alloc failed");
949             return RFAILED;
950          }
951
952          DU_ALLOC(searchSpace->searchSpaceType->choice.common->\
953          dci_Format0_0_AndFormat1_0, sizeof(struct \
954          SearchSpace__searchSpaceType__common__dci_Format0_0_AndFormat1_0));
955          if(!searchSpace->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0)
956          {
957             DU_LOG("\nDU APP : Common search space list memory alloc failed");
958             return RFAILED;
959          }
960          break;
961       }
962       case SearchSpace__searchSpaceType_PR_ue_Specific:
963       {
964          break;
965       }
966       default:
967       {
968          DU_LOG("\nDU_APP: Invalid Search Space type");
969          return RFAILED;
970       }
971    }
972
973    return ROK;
974 }/* BuildCommonSerachSpaceList */
975
976 /*******************************************************************
977  *
978  * @brief Builds PDCCH configuration common 
979  *
980  * @details
981  *
982  *    Function : BuildPdcchCfgCommon
983  *
984  *    Functionality:
985  *      Builds PDCCH configuration common
986  *
987  * @params[in] BWP_DownlinkCommon__pdcch_ConfigCommon pointer
988  * @return ROK     - success
989  *         RFAILED - failure
990  *
991  * ****************************************************************/
992 uint8_t BuildPdcchCfgCommon(struct BWP_DownlinkCommon__pdcch_ConfigCommon *pdcchCfg)
993 {
994    uint8_t   ret;
995    uint8_t   elementCnt;
996    PdcchCfgCommon   duPdcchCfg;
997    PDCCH_ConfigCommon_t  *pdcchSetup;
998
999    duPdcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdcchCfg;
1000
1001    pdcchCfg->present = duPdcchCfg.present;
1002
1003    switch(pdcchCfg->present)
1004    {
1005       case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_NOTHING:
1006       {
1007          //TODO
1008          break;
1009       }
1010       case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_release:
1011       {
1012          //TODO
1013          break;
1014       }
1015       case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup:
1016       {
1017          DU_ALLOC(pdcchCfg->choice.setup, sizeof(PDCCH_ConfigCommon_t));
1018          if(!pdcchCfg->choice.setup)
1019          {
1020             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1021             return RFAILED;
1022          }
1023          pdcchSetup = pdcchCfg->choice.setup;
1024
1025          /* Control Resource Set Zero */
1026          DU_ALLOC(pdcchSetup->controlResourceSetZero, sizeof(ControlResourceSetZero_t)); 
1027          if(!pdcchSetup->controlResourceSetZero)
1028          {
1029             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1030             return RFAILED;
1031          }
1032          *pdcchSetup->controlResourceSetZero = duPdcchCfg.ctrlRsrcSetZero;
1033
1034          /* Search space zero */
1035          DU_ALLOC(pdcchSetup->searchSpaceZero, sizeof(SearchSpaceZero_t));
1036          if(!pdcchSetup->searchSpaceZero)
1037          {
1038             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1039             return RFAILED;
1040          }
1041          *pdcchSetup->searchSpaceZero = duPdcchCfg.searchSpcZero;
1042
1043          /* Common Search Space List */
1044          DU_ALLOC(pdcchSetup->commonSearchSpaceList,\
1045                   sizeof(struct PDCCH_ConfigCommon__commonSearchSpaceList));
1046          if(!pdcchSetup->commonSearchSpaceList)
1047          {
1048             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1049             return RFAILED;
1050          }
1051          elementCnt = ODU_VALUE_ONE;
1052          pdcchSetup->commonSearchSpaceList->list.count = elementCnt;
1053          pdcchSetup->commonSearchSpaceList->list.size =  elementCnt * sizeof(SearchSpace_t *);
1054          ret = BuildCommonSerachSpaceList(pdcchSetup->commonSearchSpaceList);
1055          if(ret != ROK)
1056          {
1057             return RFAILED;
1058          }
1059          CommonSerachSpaceListret=ROK;
1060
1061          /* Search Space for SIB1 */
1062          DU_ALLOC(pdcchSetup->searchSpaceSIB1, sizeof(SearchSpaceId_t));
1063          if(!pdcchSetup->searchSpaceSIB1)
1064          {
1065             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1066             return RFAILED;
1067          }
1068          *pdcchSetup->searchSpaceSIB1 = duPdcchCfg.searchSpcSib1;
1069
1070          /* Serach Space for Paging */
1071          DU_ALLOC(pdcchSetup->pagingSearchSpace, sizeof(SearchSpaceId_t));
1072          if(!pdcchSetup->pagingSearchSpace)
1073          {
1074             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1075             return RFAILED;
1076          }  
1077          *pdcchSetup->pagingSearchSpace = duPdcchCfg.pagingSearchSpc;
1078
1079          /* Search space for Random Access */
1080          DU_ALLOC(pdcchSetup->ra_SearchSpace, sizeof(SearchSpaceId_t));
1081          if(!pdcchSetup->ra_SearchSpace)
1082          {
1083             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1084             return RFAILED;
1085          }             
1086          *pdcchSetup->ra_SearchSpace = duPdcchCfg.raSearchSpc;
1087
1088          break;
1089       }
1090       default :
1091       {
1092          DU_LOG("\nDU APP : Invalid PDCCH Config type");
1093          return RFAILED; 
1094       }
1095    }
1096
1097    return ROK;
1098 } /* BuildPdcchCfgCommon */
1099
1100 /*******************************************************************
1101  *
1102  * @brief Builds PDSCH configuration common 
1103  *
1104  * @details
1105  *
1106  *    Function : BuildPdschCfgCommon
1107  *
1108  *    Functionality:
1109  *       Builds PDSCH configuration common
1110  *
1111  * @params[in] BWP_DownlinkCommon__pdsch_ConfigCommon pointer
1112  * @return ROK     - success
1113  *         RFAILED - failure
1114  *
1115  * ****************************************************************/
1116 uint8_t BuildPdschCfgCommon(struct BWP_DownlinkCommon__pdsch_ConfigCommon *pdschCfg)
1117 {
1118    uint8_t   idx;
1119    uint8_t   elementCnt;
1120    PdschCfgCommon   duPdschCfg;
1121    PDSCH_ConfigCommon_t  *pdschSetup;
1122    PDSCH_TimeDomainResourceAllocation_t  *timeDomRsrcAllocInfo;
1123
1124    duPdschCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdschCfg;
1125
1126    pdschCfg->present = duPdschCfg.present;
1127
1128    switch(pdschCfg->present)
1129    {
1130       case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_NOTHING:
1131       {
1132          //TODO
1133          break;
1134       }
1135       case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_release:
1136       {
1137          //TODO
1138          break;
1139       }
1140       case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup:
1141       {
1142          DU_ALLOC(pdschCfg->choice.setup, sizeof(PDSCH_ConfigCommon_t));
1143          if(!pdschCfg->choice.setup)
1144          {
1145             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1146             return RFAILED;
1147          }
1148          pdschSetup = pdschCfg->choice.setup; 
1149
1150          /* Time Domain Allocation List */
1151          DU_ALLOC(pdschSetup->pdsch_TimeDomainAllocationList, \
1152                   sizeof(PDSCH_TimeDomainResourceAllocationList_t));
1153          if(!pdschSetup->pdsch_TimeDomainAllocationList)
1154          {
1155             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1156             return RFAILED;
1157          }
1158          elementCnt = ODU_VALUE_ONE;
1159          pdschSetup->pdsch_TimeDomainAllocationList->list.count = elementCnt;
1160          pdschSetup->pdsch_TimeDomainAllocationList->list.size =  elementCnt * sizeof(PDSCH_TimeDomainResourceAllocation_t *);
1161
1162          DU_ALLOC(pdschSetup->pdsch_TimeDomainAllocationList->list.array,\
1163          pdschSetup->pdsch_TimeDomainAllocationList->list.size);
1164          if(!pdschSetup->pdsch_TimeDomainAllocationList->list.array)
1165          {
1166             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1167             return RFAILED;
1168          }
1169
1170          for(idx=0; idx<elementCnt; idx++)
1171          {
1172             DU_ALLOC(pdschSetup->pdsch_TimeDomainAllocationList->list.array[idx],\
1173             sizeof(PDSCH_TimeDomainResourceAllocation_t));
1174             if(!pdschSetup->pdsch_TimeDomainAllocationList->list.array[idx])
1175             {
1176                DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1177                return RFAILED;
1178             }
1179          }
1180
1181          idx = 0;
1182          timeDomRsrcAllocInfo = pdschSetup->pdsch_TimeDomainAllocationList->list.array[idx];
1183
1184          /* K0 */
1185          DU_ALLOC(timeDomRsrcAllocInfo->k0, sizeof(long));
1186          if(!timeDomRsrcAllocInfo->k0)
1187          {
1188             DU_LOG("\nDU APP : PDCCH Config memory alloc failed");
1189             return RFAILED;
1190          }
1191          *timeDomRsrcAllocInfo->k0 = duPdschCfg.k0;
1192
1193          timeDomRsrcAllocInfo->mappingType = duPdschCfg.mapType;
1194          timeDomRsrcAllocInfo->startSymbolAndLength = duPdschCfg.sliv;
1195
1196          break;
1197       }
1198       default:
1199       {
1200          DU_LOG("\nDU APP: Invalid PDSCH Configuration type");
1201          return RFAILED;
1202       }
1203    }
1204
1205    return ROK;
1206 }/* BuildPdschCfgCommon */
1207
1208 /*******************************************************************
1209  *
1210  * @brief Builds DL BWP common 
1211  *
1212  * @details
1213  *
1214  *    Function : BuildBwpDlCommon
1215  *
1216  *    Functionality:
1217  *      Builds DL BWP common
1218  *
1219  * @params[in] BWP_DownlinkCommon_t pointer
1220  * @return ROK     - success
1221  *         RFAILED - failure
1222  *
1223  * ****************************************************************/
1224 uint8_t BuildBwpDlCommon(BWP_DownlinkCommon_t *bwp)
1225 {
1226    uint8_t ret;
1227    DlCfgCommon duDlCfg;
1228
1229    duDlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
1230
1231    bwp->genericParameters.locationAndBandwidth = duDlCfg.locAndBw;
1232    bwp->genericParameters.subcarrierSpacing = duDlCfg.dlScsCarrier.scs;
1233
1234    /* PDCCH Config Common */
1235    DU_ALLOC(bwp->pdcch_ConfigCommon, \
1236          sizeof(struct BWP_DownlinkCommon__pdcch_ConfigCommon));
1237    if(!bwp->pdcch_ConfigCommon)
1238    {
1239       DU_LOG("\nDU APP : DL BWP memory allocation failed");
1240       return RFAILED;
1241    }
1242    ret=BuildPdcchCfgCommon(bwp->pdcch_ConfigCommon);
1243    if(ret != ROK)
1244    {
1245       return RFAILED;
1246    }
1247    /* PDSCH Config Common */
1248    DU_ALLOC(bwp->pdsch_ConfigCommon, \
1249          sizeof(struct BWP_DownlinkCommon__pdsch_ConfigCommon));
1250    if(!bwp->pdsch_ConfigCommon)
1251    {
1252       DU_LOG("\nDU APP : DL BWP memory allocation failed");
1253       return RFAILED;
1254    }
1255    ret=BuildPdschCfgCommon(bwp->pdsch_ConfigCommon);
1256    if(ret != ROK)
1257    {
1258       return RFAILED;
1259    }
1260    return ROK;
1261 } /* BuildBwpDlCommon */
1262
1263 /*******************************************************************
1264  *
1265  * @brief Build BCCH configuration 
1266  *
1267  * @details
1268  *
1269  *    Function : BuildBcchConfig
1270  *
1271  *    Functionality:
1272  *      Build BCCH configuration
1273  *
1274  * @params[in] BCCH_Config_t pointer
1275  * @return ROK     - success
1276  *         RFAILED - failure
1277  *
1278  * ****************************************************************/
1279
1280 uint8_t BuildBcchConfig(BCCH_Config_t *bcchCfg)
1281 {
1282    BcchCfg   duBcchCfg;
1283
1284    duBcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.bcchCfg;
1285
1286    bcchCfg->modificationPeriodCoeff = duBcchCfg.modPrdCoeff;
1287
1288    return ROK;
1289 }/* BuildBcchConfig */
1290
1291 /*******************************************************************
1292  *
1293  * @brief Builds PCCH configuration 
1294  *
1295  * @details
1296  *
1297  *    Function : BuildPcchConfig
1298  *
1299  *    Functionality:
1300  *        Builds PCCH configuration
1301  *
1302  * @params[in] 
1303  * @return ROK     - success
1304  *         RFAILED - failure
1305  *
1306  * ****************************************************************/
1307 uint8_t BuildPcchConfig(PCCH_Config_t *pcchCfg)
1308 {
1309    PcchCfg   duPcchCfg;
1310
1311    duPcchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pcchCfg;
1312
1313    pcchCfg->defaultPagingCycle = duPcchCfg.dfltPagingCycle;
1314    pcchCfg->nAndPagingFrameOffset.present =  duPcchCfg.nAndPagingFrmOffPresent;
1315    switch(pcchCfg->nAndPagingFrameOffset.present)
1316    {
1317       case PCCH_Config__nAndPagingFrameOffset_PR_NOTHING:
1318       {
1319          //TODO
1320          break;
1321       }
1322       case PCCH_Config__nAndPagingFrameOffset_PR_oneT:
1323       {
1324          //TODO
1325          break;
1326       }
1327       case PCCH_Config__nAndPagingFrameOffset_PR_halfT:
1328       {
1329          //TODO
1330          break;
1331       }
1332       case PCCH_Config__nAndPagingFrameOffset_PR_quarterT:
1333       {
1334          //TODO
1335          break;
1336       }
1337       case PCCH_Config__nAndPagingFrameOffset_PR_oneEighthT:
1338       {
1339          //TODO
1340          break;
1341       }
1342       case PCCH_Config__nAndPagingFrameOffset_PR_oneSixteenthT:
1343       {
1344          //TODO
1345          break;
1346       }
1347       default:
1348       {
1349          DU_LOG("\nDU APP : Invalid nAndPagingFrameOffset configuration");
1350          return RFAILED;
1351       }
1352    }
1353    pcchCfg->ns = duPcchCfg.numPagingOcc;
1354
1355    return ROK;
1356 }/* BuildPcchConfig */
1357
1358 /*******************************************************************
1359  *
1360  * @brief Builds Frequency Info for Downlink 
1361  *
1362  * @details
1363  *
1364  *    Function : BuildFreqInfoDl
1365  *
1366  *    Functionality:
1367  *     Builds Frequency Info for Downlink
1368  *
1369  * @params[in] 
1370  * @return ROK     - success
1371  *         RFAILED - failure
1372  *
1373  * ****************************************************************/
1374
1375 uint8_t BuildFreqInfoDl(FrequencyInfoDL_SIB_t *frequencyInfoDL)
1376 {
1377    uint8_t ret;
1378    uint8_t idx;
1379    uint8_t elementCnt;
1380    DlCfgCommon  dlCfg;
1381    NR_MultiBandInfo_t  *multiBandInfo;
1382
1383    dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
1384
1385    /* NR Multi-Band Info */
1386    elementCnt = ODU_VALUE_ONE;   
1387    frequencyInfoDL->frequencyBandList.list.count = elementCnt;  
1388    frequencyInfoDL->frequencyBandList.list.size = \
1389    elementCnt * sizeof(NR_MultiBandInfo_t *);
1390
1391    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, \
1392    frequencyInfoDL->frequencyBandList.list.size);
1393    if(!frequencyInfoDL->frequencyBandList.list.array)
1394    {
1395       DU_LOG("\nDU APP : SIB1 DL Configuration memory allocation failed");
1396       return RFAILED;
1397    }
1398
1399    for(idx = 0; idx < elementCnt; idx++)
1400    {
1401       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[idx],\
1402       sizeof(NR_MultiBandInfo_t));
1403       if(!frequencyInfoDL->frequencyBandList.list.array[idx])
1404       {
1405          DU_LOG("\nDU APP : SIB1 DL Configuration memory allocation failed");
1406          return RFAILED;
1407       }
1408    }
1409
1410    idx = 0;
1411    multiBandInfo = frequencyInfoDL->frequencyBandList.list.array[idx];
1412
1413    /* Frequency band indicator */
1414    DU_ALLOC(multiBandInfo->freqBandIndicatorNR, sizeof(FreqBandIndicatorNR_t));
1415    if(!multiBandInfo->freqBandIndicatorNR)
1416    {
1417       DU_LOG("\nDU APP : SIB1 DL Configuration memory allocation failed");
1418       return RFAILED;
1419    }
1420    *multiBandInfo->freqBandIndicatorNR = dlCfg.freqBandInd;
1421
1422    /* Offset to Point A */
1423    frequencyInfoDL->offsetToPointA = dlCfg.offsetToPointA;
1424
1425    /* Subcarrier Spacing specifc carrier */
1426    elementCnt = ODU_VALUE_ONE;
1427    frequencyInfoDL->scs_SpecificCarrierList.list.count = elementCnt;
1428    frequencyInfoDL->scs_SpecificCarrierList.list.size = \
1429    elementCnt * sizeof(SCS_SpecificCarrier_t *);
1430    ret= BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
1431
1432    if(ret != ROK)
1433    {
1434       return RFAILED;
1435    }
1436    return ROK;
1437 }/* BuildFreqInfoDl */
1438
1439 /*******************************************************************
1440  *
1441  * @brief Builds DL configuration common for SIB
1442  *
1443  * @details
1444  *
1445  *    Function : BuildDlCfgCommSib
1446  *
1447  *    Functionality:
1448  *     Builds DL configuration common for SIB
1449  *
1450  * @params[in] DownlinkConfigCommonSIB_t pointer 
1451  * @return ROK     - success
1452  *         RFAILED - failure
1453  *
1454  * ****************************************************************/
1455
1456 uint8_t BuildDlCfgCommSib(DownlinkConfigCommonSIB_t *dlCfg)
1457 {
1458    /* DL frequency info */
1459    uint8_t ret;
1460    ret = BuildFreqInfoDl(&dlCfg->frequencyInfoDL);
1461    if(ret != ROK)
1462    {
1463       return RFAILED;
1464    }
1465    FreqInfoDlret=ROK;
1466    /* BWP Downlink Common */
1467    ret = BuildBwpDlCommon(&dlCfg->initialDownlinkBWP);
1468    if(ret != ROK)
1469    {
1470       return RFAILED;
1471    }
1472    /* BCCH Config */
1473    ret = BuildBcchConfig(&dlCfg->bcch_Config);
1474    if(ret != ROK)
1475    {
1476       return RFAILED;
1477    }
1478    /* PCCH Config */
1479    ret = BuildPcchConfig(&dlCfg->pcch_Config);
1480    if(ret != ROK)
1481    {
1482       return RFAILED;
1483    }
1484    return ROK;
1485 } /* BuildDlCfgCommSib */
1486
1487 /*******************************************************************
1488  *
1489  * @brief Builds SCS specific carrier list for UL 
1490  *
1491  * @details
1492  *
1493  *    Function : BuildScsSpecificCarrierListUl
1494  *
1495  *    Functionality:
1496  *       Builds SCS specific carrier list for UL
1497  *
1498  * @params[in] 
1499  * @return ROK     - success
1500  *         RFAILED - failure
1501  *
1502  * ****************************************************************/
1503
1504 uint8_t BuildScsSpecificCarrierListUl
1505 (
1506 struct FrequencyInfoUL_SIB__scs_SpecificCarrierList *scsCarrierList
1507 )
1508 {
1509    uint8_t idx;
1510    ScsSpecCarrier   duScsSpecCarrier;
1511
1512    duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
1513
1514    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
1515    if(!scsCarrierList->list.array)
1516    {
1517       DU_LOG("\nDU APP : SCS Specific Carrier list memory allocation failed");
1518       return RFAILED;
1519    }
1520
1521    for(idx = 0; idx < scsCarrierList->list.count; idx++)
1522    {
1523       DU_ALLOC(scsCarrierList->list.array[idx], sizeof(SCS_SpecificCarrier_t));
1524       if(!scsCarrierList->list.array[idx])
1525       {
1526          DU_LOG("\nDU APP : SCS Specific Carrier list memory allocation failed");
1527          return RFAILED;
1528       }
1529    }
1530    idx = 0;
1531    scsCarrierList->list.array[idx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
1532    scsCarrierList->list.array[idx]->subcarrierSpacing = duScsSpecCarrier.scs;
1533    scsCarrierList->list.array[idx]->carrierBandwidth = duScsSpecCarrier.scsBw;
1534
1535    return ROK;
1536 } /* End of BuildScsSpecificCarrierListUl */
1537
1538 /*******************************************************************
1539  *
1540  * @brief Builds frequency infor for UL 
1541  *
1542  * @details
1543  *
1544  *    Function : BuildFreqInfoUl
1545  *
1546  *    Functionality:
1547  *       Builds frequency infor for UL
1548  *
1549  * @params[in] FrequencyInfoUL_SIB_t pointer
1550  * @return ROK     - success
1551  *         RFAILED - failure
1552  *
1553  * ****************************************************************/
1554
1555 uint8_t BuildFreqInfoUl(FrequencyInfoUL_SIB_t *frequencyInfoUL)
1556 {
1557    uint8_t      elementCnt;
1558    UlCfgCommon  ulCfg;
1559    uint8_t      ret;
1560    ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
1561
1562    /* Subcarrier Spacing specifc carrier */
1563    elementCnt = ODU_VALUE_ONE;
1564    frequencyInfoUL->scs_SpecificCarrierList.list.count = elementCnt;
1565    frequencyInfoUL->scs_SpecificCarrierList.list.size = \
1566    elementCnt * sizeof(SCS_SpecificCarrier_t *);
1567    ret=BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
1568    if(ret != ROK)
1569    {
1570       return RFAILED;
1571    }
1572    /* P-MAX */
1573    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
1574    if(!frequencyInfoUL->p_Max)
1575    {
1576       DU_LOG("\nDU APP : UL Frequency Infoo  memory allocation failure");
1577       return RFAILED;
1578    }
1579    *frequencyInfoUL->p_Max = ulCfg.pMax;
1580    FreqInfoUlret=ROK;
1581    return ROK;
1582 }/* BuildFreqInfoUl */
1583
1584 /*******************************************************************
1585  *
1586  * @brief Builds RACH configuration common 
1587  *
1588  * @details
1589  *
1590  *    Function : BuildRachCfgCommon
1591  *
1592  *    Functionality:
1593  *      Builds RACH configuration common
1594  *
1595  * @params[in] BWP_UplinkCommon__rach_ConfigCommon pointer
1596  * @return ROK     - success
1597  *         RFAILED - failure
1598  *
1599  * ****************************************************************/
1600
1601 uint8_t  BuildRachCfgCommon(struct BWP_UplinkCommon__rach_ConfigCommon *rachCfg)
1602 {
1603    RachCfgCommon    duRachCfg;
1604    RACH_ConfigCommon_t  *setup;
1605
1606    duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
1607
1608    rachCfg->present = duRachCfg.present;
1609    switch(rachCfg->present)
1610    {
1611       case BWP_UplinkCommon__rach_ConfigCommon_PR_NOTHING:
1612       {
1613          //TODO
1614          break;
1615       }
1616       case BWP_UplinkCommon__rach_ConfigCommon_PR_release:
1617       {
1618          //TODO
1619          break;
1620       }
1621       case BWP_UplinkCommon__rach_ConfigCommon_PR_setup:
1622       {
1623          DU_ALLOC(rachCfg->choice.setup, sizeof(RACH_ConfigCommon_t)); 
1624          if(!rachCfg->choice.setup)
1625          {
1626             DU_LOG("\nDU APP : Rach Config memory alloc failed");
1627             return RFAILED;
1628          }
1629          setup = rachCfg->choice.setup;
1630
1631          /* Generic RACH Configuration */
1632          setup->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
1633          setup->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
1634          setup->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
1635          setup->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
1636          setup->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr; 
1637          setup->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
1638          setup->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
1639          setup->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
1640
1641          /* Total number of RA preambles */
1642          DU_ALLOC(setup->totalNumberOfRA_Preambles, sizeof(long));
1643          if(!setup->totalNumberOfRA_Preambles)
1644          {
1645             DU_LOG("\nDU APP : Rach Config memory alloc failed");
1646             return RFAILED;
1647          }
1648          *setup->totalNumberOfRA_Preambles = duRachCfg.numRaPreamble;
1649
1650          /* SSB per RACH occassion and CB Preambles per SSB */
1651          DU_ALLOC(setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB,\
1652          sizeof(struct RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB));
1653          if(!setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB)
1654          {
1655             DU_LOG("\nDU APP : Rach Config memory alloc failed");
1656             return RFAILED;
1657          }
1658          setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB->present = \
1659          duRachCfg.ssbPerRachOccPresent;
1660          switch(setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB->present)
1661          {
1662             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_NOTHING:
1663             {
1664                //TODO
1665                break;
1666             }
1667             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_oneEighth:
1668             {
1669                //TODO
1670                break;
1671             }
1672             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_oneFourth:
1673             {
1674                //TODO
1675                break;
1676             }
1677             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_oneHalf:
1678             {
1679                //TODO
1680                break;
1681             }
1682             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one:
1683             {
1684               setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB->choice.one =\
1685               duRachCfg.numSsbPerRachOcc;
1686             }
1687             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_two:
1688             {
1689                //TODO
1690                break;
1691             }
1692             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_four:
1693             {
1694                //TODO
1695                break;
1696             }
1697             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_eight:
1698             {
1699                //TODO
1700                 break;
1701             }
1702             case RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_sixteen:
1703             {
1704                //TODO
1705                break;
1706             }
1707             default:
1708             {
1709                DU_LOG("\nDU APP: Invalid value for \
1710                ssb_PerRach_OccassionAndCB_PreamblesPerSSB");
1711                return RFAILED;
1712             }
1713          }
1714
1715          /* RA Contention Resolution Timer */
1716          setup->ra_ContentionResolutionTimer = duRachCfg.contResTimer;
1717
1718          /* RSRP Threshold SSB */
1719          DU_ALLOC(setup->rsrp_ThresholdSSB, sizeof(RSRP_Range_t));
1720          if(!setup->rsrp_ThresholdSSB)
1721          {
1722             DU_LOG("\nDU APP : Rach Config memory alloc failed");
1723             return RFAILED;
1724          }
1725          *setup->rsrp_ThresholdSSB = duRachCfg.rsrpThreshSsb;
1726
1727          /* Root Sequence index */
1728          setup->prach_RootSequenceIndex.present = duRachCfg.rootSeqIdxPresent;
1729          switch(setup->prach_RootSequenceIndex.present)
1730          {
1731             case RACH_ConfigCommon__prach_RootSequenceIndex_PR_NOTHING:
1732             {
1733                //TODO
1734                break;
1735             }
1736             case RACH_ConfigCommon__prach_RootSequenceIndex_PR_l839:
1737             {
1738                //TODO
1739                break;
1740             }
1741             case RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139:
1742             {
1743                setup->prach_RootSequenceIndex.choice.l139 = duRachCfg.rootSeqIdx;
1744                break;
1745             }
1746             default:
1747             {
1748                DU_LOG("\nDU APP: Inavlid PRACH root sequence index type");
1749                return RFAILED;
1750             }
1751          }
1752
1753          /* Msg 1 Subcarrier spacing */
1754          DU_ALLOC(setup->msg1_SubcarrierSpacing, sizeof(SubcarrierSpacing_t));
1755          if(!setup->msg1_SubcarrierSpacing)
1756          {
1757             DU_LOG("\nDU APP : Rach Config memory alloc failed");
1758             return RFAILED;
1759          }
1760          *setup->msg1_SubcarrierSpacing = duRachCfg.msg1Scs;
1761
1762          /* Restricted Set Config */
1763          setup->restrictedSetConfig = duRachCfg.restrictedSetCfg;
1764
1765          break;
1766       }
1767       default:
1768       {
1769          DU_LOG("\nDU APP : Invalid RACH Config type ");
1770          return RFAILED;
1771       }
1772    }
1773    return ROK;
1774 }/* BuildRachCfgCommon */
1775
1776 /*******************************************************************
1777  *
1778  * @brief Builds PUSCH configuration for common 
1779  *
1780  * @details
1781  *
1782  *    Function : BuildPuschCfgCommon
1783  *
1784  *    Functionality:
1785  *      Builds PUSCH configuration for common
1786  *
1787  * @params[in] 
1788  * @return ROK     - success
1789  *         RFAILED - failure
1790  *
1791  * ****************************************************************/
1792
1793 uint8_t BuildPuschCfgCommon(struct BWP_UplinkCommon__pusch_ConfigCommon *puschCfg)
1794 {
1795    uint8_t           idx;
1796    uint8_t           elementCnt;   
1797    PuschCfgCommon    duPuschCfg;
1798    PUSCH_ConfigCommon_t *setup;
1799    PUSCH_TimeDomainResourceAllocation_t  *timeDomRsrcAllocInfo;
1800
1801    duPuschCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.puschCfg;
1802
1803    puschCfg->present = duPuschCfg.present;
1804    switch(puschCfg->present)
1805    {
1806       case BWP_UplinkCommon__pusch_ConfigCommon_PR_NOTHING:
1807       {
1808          //TODO
1809          break;
1810       }
1811       case BWP_UplinkCommon__pusch_ConfigCommon_PR_release:
1812       {
1813          //TODO
1814          break;
1815       }
1816       case BWP_UplinkCommon__pusch_ConfigCommon_PR_setup:
1817       {
1818          DU_ALLOC(puschCfg->choice.setup, sizeof(PUSCH_ConfigCommon_t));
1819          if(!puschCfg->choice.setup)
1820          {
1821             DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1822             return RFAILED;
1823          }
1824          setup = puschCfg->choice.setup;
1825
1826          /* Time Domain Resource Allocation List */
1827          DU_ALLOC(setup->pusch_TimeDomainAllocationList,\
1828          sizeof(PUSCH_TimeDomainResourceAllocationList_t)); 
1829          if(!setup->pusch_TimeDomainAllocationList)
1830          {
1831             DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1832             return RFAILED;
1833          }
1834          elementCnt = ODU_VALUE_ONE;
1835          setup->pusch_TimeDomainAllocationList->list.count = elementCnt;
1836          setup->pusch_TimeDomainAllocationList->list.size = \
1837          elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
1838
1839          DU_ALLOC(setup->pusch_TimeDomainAllocationList->list.array, \
1840          setup->pusch_TimeDomainAllocationList->list.size);
1841          if(!setup->pusch_TimeDomainAllocationList->list.array)
1842          {
1843             DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1844             return RFAILED;
1845          }
1846
1847          for(idx=0; idx<elementCnt; idx++)
1848          {
1849             DU_ALLOC(setup->pusch_TimeDomainAllocationList->list.array[idx],\
1850             sizeof(PUSCH_TimeDomainResourceAllocation_t));
1851             if(!setup->pusch_TimeDomainAllocationList->list.array[idx])
1852             {
1853                DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1854                return RFAILED;
1855             }
1856          }
1857
1858          idx = 0;
1859          timeDomRsrcAllocInfo = setup->pusch_TimeDomainAllocationList->list.array[idx];
1860
1861          /* K2 */
1862          DU_ALLOC(timeDomRsrcAllocInfo->k2, sizeof(long));
1863          if(!timeDomRsrcAllocInfo->k2)
1864          {
1865             DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1866             return RFAILED;
1867          }
1868          *timeDomRsrcAllocInfo->k2 = duPuschCfg.k2;
1869
1870          timeDomRsrcAllocInfo->mappingType = duPuschCfg.mapType;
1871          timeDomRsrcAllocInfo->startSymbolAndLength = duPuschCfg.sliv;
1872
1873          /* Msg3 Delta Preamble */
1874          DU_ALLOC(setup->msg3_DeltaPreamble, sizeof(long));
1875          if(!setup->msg3_DeltaPreamble)
1876          {
1877             DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1878             return RFAILED;
1879          }
1880          *setup->msg3_DeltaPreamble = duPuschCfg.msg3DeltaPreamble;
1881
1882          /* P0 Nominal with grnat */
1883          DU_ALLOC(setup->p0_NominalWithGrant, sizeof(long));
1884          if(!setup->p0_NominalWithGrant)
1885          {
1886             DU_LOG("\nDU APP : PUSCH Config memory alloc failed");
1887             return RFAILED;
1888          }
1889          *setup->p0_NominalWithGrant = duPuschCfg.p0NominalWithGrant;
1890
1891          break;
1892       }
1893       default:
1894       {
1895          DU_LOG("\nDU APP : Invalid PUSCH configuration type ");
1896          return RFAILED;
1897       }
1898    }
1899
1900    return ROK;
1901 }/* BuildPuschCfgCommon */
1902
1903 /*******************************************************************
1904  *
1905  * @brief  Builds PUCCH configuration common
1906  *
1907  * @details
1908  *
1909  *    Function : BuildPucchCfgCommon
1910  *
1911  *    Functionality:
1912  *      Builds PUCCH configuration common
1913  *
1914  * @params[in] 
1915  * @return ROK     - success
1916  *         RFAILED - failure
1917  *
1918  * ****************************************************************/
1919
1920 uint8_t BuildPucchCfgCommon( struct BWP_UplinkCommon__pucch_ConfigCommon *pucchCfg)
1921 {
1922    PucchCfgCommon    duPucchCfg;
1923    PUCCH_ConfigCommon_t *setup;
1924
1925    duPucchCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.pucchCfg;
1926
1927    pucchCfg->present = duPucchCfg.present;
1928    switch(pucchCfg->present)
1929    {
1930       case BWP_UplinkCommon__pucch_ConfigCommon_PR_NOTHING:
1931       {
1932          //TODO
1933          break;
1934       }
1935       case BWP_UplinkCommon__pucch_ConfigCommon_PR_release:
1936       {
1937          //TODO
1938          break;
1939       }
1940       case BWP_UplinkCommon__pucch_ConfigCommon_PR_setup:
1941       {
1942          DU_ALLOC(pucchCfg->choice.setup, sizeof(PUCCH_ConfigCommon_t));
1943          if(!pucchCfg->choice.setup)
1944          {
1945             DU_LOG("\nDU APP : PUCCH Config memory alloc failed");
1946             return RFAILED;
1947          }
1948          setup = pucchCfg->choice.setup;
1949
1950          /* Resource Common */
1951          DU_ALLOC(setup->pucch_ResourceCommon, sizeof(long));
1952          if(!setup->pucch_ResourceCommon)
1953          {
1954             DU_LOG("\nDU APP : PUCCH Config memory alloc failed");
1955             return RFAILED;
1956          }
1957          *setup->pucch_ResourceCommon = duPucchCfg.rsrcComm;
1958
1959          /* Group hopping */
1960          setup->pucch_GroupHopping = duPucchCfg.grpHop;
1961
1962          /* P0 nominal */
1963          DU_ALLOC(setup->p0_nominal, sizeof(long));
1964          if(!setup->p0_nominal)
1965          {
1966             DU_LOG("\nDU APP : PUCCH Config memory alloc failed");
1967             return RFAILED;
1968          }
1969          *setup->p0_nominal = duPucchCfg.p0Nominal;
1970
1971          break;
1972       }
1973       default:
1974       {
1975          DU_LOG("\nDU APP : Invalid PUCCH Config type");
1976          return RFAILED;
1977       }
1978    }
1979    return ROK;
1980 }/* BuildPucchCfgCommon */
1981
1982 /*******************************************************************
1983  *
1984  * @brief Builds UL BWP Common 
1985  *
1986  * @details
1987  *
1988  *    Function : BuildBwpUlCommon
1989  *
1990  *    Functionality:
1991  *      Builds UL BWP Common 
1992  *
1993  * @params[in] BWP_UplinkCommon_t pointer
1994  * @return ROK     - success
1995  *         RFAILED - failure
1996  *
1997  * ****************************************************************/
1998
1999 uint8_t BuildBwpUlCommon(BWP_UplinkCommon_t *bwp)
2000 {
2001    uint8_t     ret;
2002    UlCfgCommon duUlCfg;
2003
2004    duUlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
2005
2006    bwp->genericParameters.locationAndBandwidth = duUlCfg.locAndBw;
2007    bwp->genericParameters.subcarrierSpacing = duUlCfg.ulScsCarrier.scs;
2008
2009    /* RACH Config Common */
2010    DU_ALLOC(bwp->rach_ConfigCommon,\
2011    sizeof(struct BWP_UplinkCommon__rach_ConfigCommon));
2012    if(!bwp->rach_ConfigCommon)
2013    {
2014       DU_LOG("\nDU APP : UL BWP memory allocation failed");
2015       return RFAILED;
2016    }
2017    ret = BuildRachCfgCommon(bwp->rach_ConfigCommon);
2018    if(ret != ROK)
2019    {
2020       return RFAILED;
2021    }
2022    RachCfgCommonret=ROK;
2023
2024    /* PUSCH Config Common */
2025    DU_ALLOC(bwp->pusch_ConfigCommon,\
2026    sizeof(struct BWP_UplinkCommon__pusch_ConfigCommon));
2027    if(!bwp->pusch_ConfigCommon)
2028    {
2029       DU_LOG("\nDU APP : UL BWP memory allocation failed");
2030       return RFAILED;
2031    } 
2032    ret = BuildPuschCfgCommon(bwp->pusch_ConfigCommon);
2033    if(ret != ROK)
2034    {
2035       return RFAILED;
2036    }
2037    PuschCfgCommonret = ROK;
2038
2039    /* PUCCH Config Common */
2040    DU_ALLOC(bwp->pucch_ConfigCommon,\
2041    sizeof(struct BWP_UplinkCommon__pucch_ConfigCommon));
2042    if(!bwp->pucch_ConfigCommon)
2043    {
2044       DU_LOG("\nDU APP : UL BWP memory allocation failed");
2045       return RFAILED;
2046    } 
2047    ret = BuildPucchCfgCommon(bwp->pucch_ConfigCommon);
2048    if(ret != ROK)
2049    {
2050       return RFAILED;
2051    }
2052    return ROK;
2053 }/* BuildBwpUlCommon */
2054
2055 /*******************************************************************
2056  *
2057  * @brief Builds UL config common for SIB 
2058  *
2059  * @details
2060  *
2061  *    Function : BuildUlCfgCommSib
2062  *
2063  *    Functionality:
2064  *      Builds UL config common for SIB
2065  *
2066  * @params[in] UplinkConfigCommonSIB_t pointer
2067  * @return ROK     - success
2068  *         RFAILED - failure
2069  *
2070  * ****************************************************************/
2071
2072 uint8_t BuildUlCfgCommSib(UplinkConfigCommonSIB_t *ulCfg)
2073 {
2074    uint8_t ret;
2075    /* UL frequency info */
2076    ret = BuildFreqInfoUl(&ulCfg->frequencyInfoUL);
2077    if(ret != ROK)
2078    {
2079       return RFAILED;
2080    }
2081    /* BWP Uplink Common */
2082    ret = BuildBwpUlCommon(&ulCfg->initialUplinkBWP);
2083    if(ret != ROK)
2084    {
2085       return RFAILED;
2086    }
2087    /* Time Alignment timer */
2088    ulCfg->timeAlignmentTimerCommon = \
2089    duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
2090
2091    return ROK;
2092 }/* BuildUlCfgCommSib */
2093
2094 /*******************************************************************
2095  *
2096  * @brief Builds TDD UL DL configuration common 
2097  *
2098  * @details
2099  *
2100  *    Function : BuildTddUlDlCfgComm
2101  *
2102  *    Functionality:
2103  *      Builds TDD UL DL configuration common
2104  *
2105  * @params[in] TDD_UL_DL_ConfigCommon_t pointer 
2106  * @return ROK     - success
2107  *         RFAILED - failure
2108  *
2109  * ****************************************************************/
2110
2111 uint8_t BuildTddUlDlCfgComm(TDD_UL_DL_ConfigCommon_t *tddCfg)
2112 {
2113    TddUlDlCfgCommon duTddCfg;
2114
2115    duTddCfg = duCfgParam.sib1Params.srvCellCfgCommSib.tddCfg;
2116
2117    /* Reference Subcarrier spacing */
2118    tddCfg->referenceSubcarrierSpacing = duTddCfg.refScs;
2119
2120    /* Pattern 1*/
2121    tddCfg->pattern1.dl_UL_TransmissionPeriodicity = duTddCfg.txPrd;
2122    tddCfg->pattern1.nrofDownlinkSlots = duTddCfg.numDlSlots;
2123    tddCfg->pattern1.nrofDownlinkSymbols = duTddCfg.numDlSymbols;
2124    tddCfg->pattern1.nrofUplinkSlots = duTddCfg.numUlSlots;
2125    tddCfg->pattern1.nrofUplinkSymbols = duTddCfg.numUlSymbols;
2126
2127    return ROK;
2128
2129 }/* BuildTddUlDlCfgComm */
2130
2131 /*******************************************************************
2132  * 
2133  * @brief Builds Serving cell config common in SIB1 message 
2134  * 
2135  * @details
2136  * 
2137  *     Function : BuildServCellCfgCommonSib
2138  * 
2139  *    Functionality: 
2140  *       Building Serving cell config common in SIB1 message
2141  *
2142  * @params[in] ServingCellConfigCommonSIB_t pointer
2143  * @return ROK     - success
2144  *         RFAILED - failure
2145  *
2146  * ****************************************************************/
2147 uint8_t BuildServCellCfgCommonSib(ServingCellConfigCommonSIB_t *srvCellCfg)
2148 {
2149    SrvCellCfgCommSib    duSrvCellCfg;
2150    BIT_STRING_t         *ssbPosInBurst;
2151    uint8_t              ret;
2152    duSrvCellCfg = duCfgParam.sib1Params.srvCellCfgCommSib;
2153
2154    /* SSB Position in Burst */
2155    ssbPosInBurst = &srvCellCfg->ssb_PositionsInBurst.inOneGroup;
2156    ssbPosInBurst->size = 1;
2157    DU_ALLOC(ssbPosInBurst->buf, ssbPosInBurst->size * sizeof(uint8_t));
2158    if(!ssbPosInBurst->buf)
2159    {
2160       DU_LOG("\nDU APP : Serving cell config common  memory allocation failure");
2161       return RFAILED;
2162    } 
2163    ssbPosInBurst->buf[0] = duSrvCellCfg.ssbPosInBurst;  
2164    ssbPosInBurst->bits_unused = 0;
2165
2166    switch(duSrvCellCfg.ssbPrdServingCell)
2167    {
2168       case SSB_PERIODICITY_5MS:
2169          srvCellCfg->ssb_PeriodicityServingCell = \
2170          ServingCellConfigCommonSIB__ssb_PeriodicityServingCell_ms5;
2171          break;
2172       case SSB_PERIODICITY_10MS:
2173          srvCellCfg->ssb_PeriodicityServingCell = \
2174          ServingCellConfigCommonSIB__ssb_PeriodicityServingCell_ms10;
2175          break;
2176       case SSB_PERIODICITY_20MS:
2177          srvCellCfg->ssb_PeriodicityServingCell = \
2178          ServingCellConfigCommonSIB__ssb_PeriodicityServingCell_ms20;
2179          break;
2180       case SSB_PERIODICITY_40MS:
2181          srvCellCfg->ssb_PeriodicityServingCell = \
2182          ServingCellConfigCommonSIB__ssb_PeriodicityServingCell_ms40;
2183          break;
2184       case SSB_PERIODICITY_80MS:
2185          srvCellCfg->ssb_PeriodicityServingCell = \
2186          ServingCellConfigCommonSIB__ssb_PeriodicityServingCell_ms80;
2187          break;
2188       case SSB_PERIODICITY_160MS:
2189          srvCellCfg->ssb_PeriodicityServingCell = \
2190          ServingCellConfigCommonSIB__ssb_PeriodicityServingCell_ms160;
2191          break;
2192    }
2193
2194    srvCellCfg->ss_PBCH_BlockPower = duSrvCellCfg.ssPbchBlockPwr;
2195
2196    /* Downlink config common */
2197    ret = BuildDlCfgCommSib(&srvCellCfg->downlinkConfigCommon);
2198    if(ret != ROK)
2199    {
2200       return RFAILED;
2201    }
2202    DlCfgCommSibret = ROK;
2203
2204    /* Uplink Config Comm */
2205    DU_ALLOC(srvCellCfg->uplinkConfigCommon, sizeof(UplinkConfigCommonSIB_t));
2206    if(!srvCellCfg->uplinkConfigCommon)
2207    {
2208       DU_LOG("\nDU APP : Serving cell config common  memory allocation failure");
2209       return RFAILED;
2210    }
2211    ret = BuildUlCfgCommSib(srvCellCfg->uplinkConfigCommon);
2212    if(ret != ROK)
2213    {
2214       return RFAILED;
2215    }
2216    UlCfgCommSibret=ROK;
2217
2218    /* TDD UL DL Config Comm */
2219    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
2220    if(!srvCellCfg->tdd_UL_DL_ConfigurationCommon)
2221    {
2222       DU_LOG("\nDU APP : Serving cell config common  memory allocation failure");
2223       return RFAILED;
2224    }
2225    ret = BuildTddUlDlCfgComm(srvCellCfg->tdd_UL_DL_ConfigurationCommon);
2226    if(ret != ROK)
2227    {
2228       return RFAILED;
2229    }
2230    return ROK;
2231 }
2232
2233 /*******************************************************************
2234  *
2235  * @brief Builds SIB message in Served Cell Info
2236  *
2237  * @details
2238  *
2239  *    Function : BuildSib1Msg
2240  *
2241  *    Functionality: Building SIB message in Served Cell Info
2242  *
2243  * @return ROK     - success
2244  *         RFAILED - failure
2245  *
2246  * ****************************************************************/
2247 uint8_t BuildSib1Msg()
2248 {
2249    SIB1_t                   *sib1Msg;
2250    CellAccessRelatedInfo_t  *cellAccessInfo;
2251    uint8_t                  elementCnt;
2252    uint8_t                  ret1;
2253    asn_enc_rval_t           encRetVal; 
2254    uint8_t                  ret = RFAILED;
2255
2256    do
2257    {
2258       DU_ALLOC(sib1Msg, sizeof(SIB1_t));
2259       if(!sib1Msg)
2260       {   
2261          DU_LOG("DU APP: SIB1 msg memory allocation failure");
2262          break;
2263       }   
2264
2265       elementCnt = ODU_VALUE_ONE;
2266
2267       /* PLMN list */
2268       cellAccessInfo = &sib1Msg->cellAccessRelatedInfo;
2269       cellAccessInfo->plmn_IdentityList.list.count = elementCnt;
2270       cellAccessInfo->plmn_IdentityList.list.size = elementCnt * sizeof(PLMN_IdentityInfo_t *);
2271
2272       ret1 =  BuildPlmnList(cellAccessInfo);
2273       if(ret1 != ROK)
2274       {
2275          break;
2276       }
2277       /* Connection Establish Failure Control */
2278       DU_ALLOC(sib1Msg->connEstFailureControl, sizeof(ConnEstFailureControl_t));
2279       if(!sib1Msg->connEstFailureControl)
2280       {
2281          DU_LOG("DU APP: sib1Msg->connEstFailureControl memory allocation failure");
2282          break;
2283       }
2284       sib1Msg->connEstFailureControl->connEstFailCount =\
2285       duCfgParam.sib1Params.connEstFailCnt;
2286       sib1Msg->connEstFailureControl->connEstFailOffsetValidity =\
2287       duCfgParam.sib1Params.connEstFailOffValidity;
2288
2289       /* SI Scheduling Info */
2290       DU_ALLOC(sib1Msg->si_SchedulingInfo, sizeof(SI_SchedulingInfo_t));
2291       if(!sib1Msg->si_SchedulingInfo)
2292       {
2293          DU_LOG("DU APP: sib1Msg->si_SchedulingInfo memory allocation failure");
2294          break;
2295       } 
2296       elementCnt = ODU_VALUE_ONE;
2297       sib1Msg->si_SchedulingInfo->schedulingInfoList.list.count = elementCnt;
2298       sib1Msg->si_SchedulingInfo->schedulingInfoList.list.size = elementCnt *
2299          sizeof(struct SchedulingInfo *);
2300       ret1 = BuildSiSchedInfoList(&sib1Msg->si_SchedulingInfo->schedulingInfoList);
2301       if(ret1 != ROK)
2302       {
2303          break;
2304       }
2305       sib1Msg->si_SchedulingInfo->si_WindowLength = duCfgParam.sib1Params.siSchedInfo.winLen;
2306
2307       /* Serving Cell Config Common */
2308       DU_ALLOC(sib1Msg->servingCellConfigCommon, sizeof(ServingCellConfigCommonSIB_t));
2309       if(!sib1Msg->servingCellConfigCommon)
2310       {
2311          DU_LOG("DU APP: sib1Msg->servingCellConfigCommon memory allocation failure");
2312          break;
2313       }
2314       ret1 =  BuildServCellCfgCommonSib(sib1Msg->servingCellConfigCommon);
2315       if(ret1 != ROK)
2316       {
2317          break;
2318       }
2319
2320       xer_fprint(stdout, &asn_DEF_SIB1, sib1Msg);
2321
2322       /* Encode the F1SetupRequest type as APER */
2323       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2324       encBufSize = 0;
2325       encRetVal = aper_encode(&asn_DEF_SIB1, 0, sib1Msg, PrepFinalEncBuf,\
2326             encBuf);
2327       printf("\nencbufSize: %d\n", encBufSize);
2328       if(encRetVal.encoded == -1)
2329       {
2330          DU_LOG("\nDU APP : Could not encode SIB1 structure (at %s)\n",\
2331                encRetVal.failed_type ?
2332                encRetVal.failed_type->name :
2333                "unknown");
2334          break;
2335       }
2336       for(int i=0; i< encBufSize; i++)
2337       {
2338          printf("%x\t",encBuf[i]);
2339       }
2340       printf("\n");
2341
2342       ret = ROK;
2343       break; 
2344    }while(true);
2345
2346    FreeSib1Msg(sib1Msg);
2347
2348    return ret;
2349
2350
2351 }
2352 /*******************************************************************
2353  *
2354  * @brief      :  deallocating the memory of BuildSib1Msg 
2355  *
2356  * @details
2357  *
2358  *     Function : FreeFreqInfoDl
2359  *
2360  *    Functionality: Freeing memory of BuildFreqInfoDl 
2361  *
2362  * @params[in] : FrequencyInfoDL_SIB_t *frequencyInfoDL
2363  * @return     :  void
2364  *
2365  *******************************************************************/
2366 void FreeFreqInfoDl(FrequencyInfoDL_SIB_t *frequencyInfoDL)
2367 {
2368    uint8_t idx=0;
2369    uint8_t idx1=0;
2370
2371    /* Free DL frequency info */
2372    if(!frequencyInfoDL->frequencyBandList.list.array)
2373    {
2374       /*Free Frequency band indicator */
2375       if(!frequencyInfoDL->frequencyBandList.list.array[idx])
2376       {
2377          if(!frequencyInfoDL->frequencyBandList.list.array[idx]->\
2378                freqBandIndicatorNR)
2379          { 
2380             if(!frequencyInfoDL->scs_SpecificCarrierList.list.array)
2381             {
2382                for(idx1 = 0;idx1<frequencyInfoDL->scs_SpecificCarrierList.list.count;idx1++)
2383                {
2384                   if(!frequencyInfoDL->scs_SpecificCarrierList.list.array[idx1])
2385                   {
2386                      DU_FREE(frequencyInfoDL->scs_SpecificCarrierList.list.\
2387                            array[idx1], sizeof(SCS_SpecificCarrier_t));
2388                   }
2389                }
2390                DU_FREE(frequencyInfoDL->scs_SpecificCarrierList.list.array,
2391                      frequencyInfoDL->scs_SpecificCarrierList.list.size);
2392             }
2393             DU_FREE(frequencyInfoDL->frequencyBandList.list.\
2394                   array[idx]->freqBandIndicatorNR, sizeof(FreqBandIndicatorNR_t));
2395          }
2396       }
2397       for(idx = 0; idx <frequencyInfoDL->frequencyBandList.list.count; idx++)
2398       {
2399          if(!frequencyInfoDL->frequencyBandList.list.array[idx])
2400          { 
2401             DU_FREE(frequencyInfoDL->frequencyBandList.list.array[idx],\
2402                   sizeof(NR_MultiBandInfo_t));
2403          }
2404       }
2405       DU_FREE(frequencyInfoDL->frequencyBandList.list.array,\
2406             frequencyInfoDL->frequencyBandList.list.size);
2407    }
2408 }
2409 /*******************************************************************
2410  *
2411  * @brief  :  deallocating the memory of BuildSib1Msg
2412  *
2413  * @details
2414  *
2415  *     Function :  FreeCommonSerachSpaceList
2416  *
2417  *     Functionality:  deallocating the memory of BuildCommonSerachSpaceList
2418  *
2419  * @params[in] :struct PDCCH_ConfigCommon__commonSearchSpaceList  *searchSpclist
2420  * @return  : void
2421  *
2422  *******************************************************************/
2423 void FreeCommonSerachSpaceList( struct PDCCH_ConfigCommon__commonSearchSpaceList
2424       *searchSpclist)
2425 {
2426    uint8_t idx=0;
2427    SearchSpace_t *searchSpace= NULLP;
2428
2429    if(!searchSpclist->list.array)
2430    {
2431       if( searchSpclist->list.array[idx] != NULLP)
2432       {
2433          searchSpace= searchSpclist->list.array[idx];
2434          if(!searchSpace->controlResourceSetId)
2435          {
2436             if(!searchSpace->monitoringSlotPeriodicityAndOffset)
2437             {
2438                if(!searchSpace->monitoringSymbolsWithinSlot)
2439                {
2440                   if(!searchSpace->monitoringSymbolsWithinSlot->buf)
2441                   {
2442                      if(!searchSpace->nrofCandidates)
2443                      {
2444                         if(!searchSpace->searchSpaceType)
2445                         {
2446                            switch(searchSpace->searchSpaceType->present)
2447                            {
2448                               case SearchSpace__searchSpaceType_PR_NOTHING:
2449                                  break;
2450                               case SearchSpace__searchSpaceType_PR_common:
2451                               {    
2452                                  if(!searchSpace->searchSpaceType->choice.common)
2453                                  {
2454                                     if(!searchSpace->searchSpaceType->choice.\
2455                                           common->dci_Format0_0_AndFormat1_0)
2456                                     {
2457                                        DU_FREE(searchSpace->searchSpaceType->choice.\
2458                                              common->dci_Format0_0_AndFormat1_0,sizeof(struct\
2459                                                 SearchSpace__searchSpaceType__common__dci_Format0_0_AndFormat1_0));
2460                                     }
2461                                     DU_FREE(searchSpace->searchSpaceType->choice.common,\
2462                                           sizeof(struct SearchSpace__searchSpaceType__common));
2463                                  }
2464                                  break;
2465                               }
2466                               case SearchSpace__searchSpaceType_PR_ue_Specific:
2467                                  break;
2468                               default:
2469                                  break;
2470                            }
2471                            DU_FREE(searchSpace->searchSpaceType,\
2472                                  sizeof( struct SearchSpace__searchSpaceType));
2473                         }
2474                         DU_FREE(searchSpace->nrofCandidates,\
2475                               sizeof(struct SearchSpace__nrofCandidates));
2476                      }
2477                      DU_FREE(searchSpace->monitoringSymbolsWithinSlot->buf,\
2478                            searchSpace->monitoringSymbolsWithinSlot->size);
2479                   }
2480                   DU_FREE(searchSpace->monitoringSymbolsWithinSlot,\
2481                         sizeof(BIT_STRING_t));
2482                }
2483                DU_FREE(searchSpace->monitoringSlotPeriodicityAndOffset,\
2484                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
2485             }
2486             DU_FREE(searchSpace->controlResourceSetId,sizeof(ControlResourceSetId_t));
2487          }
2488       }  
2489       for(idx = 0; idx < searchSpclist->list.count; idx++)
2490       {  
2491          if(!searchSpclist->list.array[idx])
2492          { 
2493             DU_FREE(searchSpclist->list.array[idx], sizeof(SearchSpace_t));
2494          }
2495       }
2496       DU_FREE(searchSpclist->list.array, searchSpclist->list.size)
2497    }
2498 }
2499 /*******************************************************************
2500  *
2501  * @brief : deallocating the memory of BuildSib1Msg
2502  *
2503  * @details
2504  *
2505  *     Function : FreeBwpDlCommon
2506  *
2507  *     Functionality :Deallocating memory of BuildBwpDlCommon
2508  *
2509  * @params[in] : BWP_DownlinkCommon_t *bwp
2510  *
2511  * @return      : void
2512  *
2513  *******************************************************************/
2514 void FreeBwpDlCommon(BWP_DownlinkCommon_t *bwp)
2515 {
2516    uint8_t idx =0;
2517    struct BWP_DownlinkCommon__pdsch_ConfigCommon *pdschCfg=bwp->pdsch_ConfigCommon;
2518    struct BWP_DownlinkCommon__pdcch_ConfigCommon *pdcchCfg=bwp->pdcch_ConfigCommon;
2519    pdcchCfg->present=duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdcchCfg.present; 
2520    pdschCfg->present=duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.pdschCfg.present;
2521
2522    if(!bwp->pdcch_ConfigCommon)
2523    {
2524       if(!bwp->pdsch_ConfigCommon)
2525       {
2526          switch( pdschCfg->present)
2527          {
2528             case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_NOTHING:
2529             {
2530                //TODO
2531                break;
2532             }
2533             case  BWP_DownlinkCommon__pdsch_ConfigCommon_PR_release:
2534             { 
2535                //TODO
2536                break;
2537             }
2538             case BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup:
2539             {
2540                if(!pdschCfg->choice.setup)
2541                {
2542                   if(!pdschCfg->choice.setup->pdsch_TimeDomainAllocationList)
2543                   {
2544                      if(!pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array)
2545                      {
2546                         if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]!= NULLP)
2547                         {
2548                            if(!pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]->k0)
2549                            {
2550                               DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]->k0,\
2551                                     sizeof(long)); 
2552                            }
2553                         }
2554                         for(idx=0; idx<pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.count ; idx++)
2555                         {
2556                            if(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx]!=
2557                                  NULLP)
2558                            {
2559                               DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array[idx],\
2560                                     sizeof(PDSCH_TimeDomainResourceAllocation_t));
2561                            }
2562                         }
2563                         DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.array,\
2564                               pdschCfg->choice.setup->pdsch_TimeDomainAllocationList->list.size);
2565                      }
2566                      DU_FREE(pdschCfg->choice.setup->pdsch_TimeDomainAllocationList,\
2567                            sizeof(PDSCH_TimeDomainResourceAllocationList_t));
2568                   }
2569                   DU_FREE(pdschCfg->choice.setup,
2570                         sizeof(PDSCH_ConfigCommon_t));
2571                }
2572             }
2573             default:
2574                break;
2575          }
2576          DU_FREE(bwp->pdsch_ConfigCommon,\
2577                sizeof(struct BWP_DownlinkCommon__pdsch_ConfigCommon));
2578       }
2579
2580       switch(pdcchCfg->present)
2581       {
2582          case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_NOTHING:
2583          {
2584             //TODO
2585             break;
2586          }
2587          case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_release:
2588          {
2589             //TODO
2590             break;
2591          }
2592          case BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup:
2593          {
2594             if(!pdcchCfg->choice.setup)
2595             {
2596                /* Control Resource Set Zero */
2597                if(! pdcchCfg->choice.setup->controlResourceSetZero)
2598                {
2599                   /* Search space zero */
2600                   if(! pdcchCfg->choice.setup->searchSpaceZero)
2601                   {
2602                      /* Common Search Space List */
2603                      if(! pdcchCfg->choice.setup->commonSearchSpaceList)
2604                      {
2605                         if(CommonSerachSpaceListret==ROK)
2606                         {
2607                            if(!pdcchCfg->choice.setup->searchSpaceSIB1)
2608                            {
2609                               if(!pdcchCfg->choice.setup->pagingSearchSpace)
2610                               {
2611                                  if(!pdcchCfg->choice.setup->ra_SearchSpace)
2612                                  {
2613                                     DU_FREE(pdcchCfg->choice.setup->ra_SearchSpace,
2614                                           sizeof(SearchSpaceId_t));
2615                                  }
2616                                  DU_FREE( pdcchCfg->choice.setup->pagingSearchSpace,
2617                                        sizeof(SearchSpaceId_t));
2618                               }
2619                               DU_FREE( pdcchCfg->choice.setup->searchSpaceSIB1,
2620                                     sizeof(SearchSpaceId_t));
2621                            }
2622                         }
2623
2624                         FreeCommonSerachSpaceList(pdcchCfg->choice.setup->commonSearchSpaceList);
2625
2626                         DU_FREE( pdcchCfg->choice.setup->commonSearchSpaceList,\
2627                               sizeof(struct
2628                                  PDCCH_ConfigCommon__commonSearchSpaceList));
2629                      }
2630                      DU_FREE( pdcchCfg->choice.setup->searchSpaceZero,
2631                            sizeof(SearchSpaceZero_t));
2632                   }
2633                   DU_FREE( pdcchCfg->choice.setup->controlResourceSetZero,
2634                         sizeof(ControlResourceSetZero_t));
2635                }
2636                DU_FREE(pdcchCfg->choice.setup,
2637                      sizeof(PDCCH_ConfigCommon_t));
2638             }
2639             break;
2640          }
2641          default:
2642             break;
2643       }
2644       DU_FREE(bwp->pdcch_ConfigCommon,sizeof(struct BWP_DownlinkCommon__pdcch_ConfigCommon));
2645    }
2646 }
2647 /*******************************************************************
2648  *
2649  * @brief  deallocating the memory of BuildSib1Msg
2650  *
2651  * @details
2652  *
2653  *     Function: FreeUlCfgCommSib
2654  *
2655  *     Functionality deallocating the memory of BuildUlCfgCommSib
2656  *
2657  * @params[in] : UplinkConfigCommonSIB_t *ulCfg
2658  *
2659  * @return : void
2660  *
2661  *******************************************************************/
2662 void FreeUlCfgCommSib(UplinkConfigCommonSIB_t *ulCfg)
2663 {
2664    uint8_t                 idx=0;
2665    RACH_ConfigCommon_t    *setup;
2666    BWP_UplinkCommon_t     *bwp=&ulCfg->initialUplinkBWP;
2667    struct FrequencyInfoUL_SIB__scs_SpecificCarrierList *scsCarrierList;
2668    struct BWP_UplinkCommon__rach_ConfigCommon  *rachCfg;
2669    struct BWP_UplinkCommon__pucch_ConfigCommon *pucchCfg;
2670    struct BWP_UplinkCommon__pusch_ConfigCommon *puschCfg;
2671    puschCfg=ulCfg->initialUplinkBWP.pusch_ConfigCommon;
2672    rachCfg =bwp->rach_ConfigCommon;
2673    scsCarrierList    = &ulCfg->frequencyInfoUL.scs_SpecificCarrierList;
2674
2675    if(!scsCarrierList->list.array)
2676    {
2677       if(!ulCfg->frequencyInfoUL.p_Max)
2678       {
2679          if(FreqInfoUlret == ROK)
2680          {
2681             if(!bwp->rach_ConfigCommon)
2682             {
2683                if(RachCfgCommonret== ROK)
2684                {
2685                   if(!bwp->pusch_ConfigCommon)
2686                   {
2687
2688                      if(PuschCfgCommonret==ROK)
2689                      {
2690                         if(!bwp->pucch_ConfigCommon)
2691                         {
2692                            pucchCfg=bwp->pucch_ConfigCommon;
2693                            switch(pucchCfg->present)
2694                            {
2695                               case BWP_UplinkCommon__pucch_ConfigCommon_PR_NOTHING:
2696                                  break;
2697                               case BWP_UplinkCommon__pucch_ConfigCommon_PR_release:
2698                                  break;
2699                               case BWP_UplinkCommon__pucch_ConfigCommon_PR_setup:
2700                               {
2701                                  if(!pucchCfg->choice.setup)
2702                                  {
2703
2704                                     if(!pucchCfg->choice.setup->pucch_ResourceCommon)
2705                                     {
2706                                        if(!pucchCfg->choice.setup->p0_nominal)
2707                                        {
2708                                           DU_FREE(pucchCfg->choice.setup->p0_nominal,
2709                                                 sizeof(long));
2710                                        }
2711                                        DU_FREE(pucchCfg->choice.setup->pucch_ResourceCommon,
2712                                              sizeof(long));
2713                                     }
2714                                     DU_FREE(pucchCfg->choice.setup,
2715                                           sizeof(PUCCH_ConfigCommon_t));
2716                                  }
2717                               }
2718                               default:
2719                                  break;
2720                            }
2721                            DU_FREE(bwp->pucch_ConfigCommon,\
2722                            sizeof(struct BWP_UplinkCommon__pucch_ConfigCommon));
2723                         }
2724                      }
2725                      switch(puschCfg->present)
2726                      {
2727                         case BWP_UplinkCommon__pusch_ConfigCommon_PR_NOTHING:
2728                            break;
2729                         case BWP_UplinkCommon__pusch_ConfigCommon_PR_release:
2730                            break;
2731                         case BWP_UplinkCommon__pusch_ConfigCommon_PR_setup:
2732                         {
2733                            if(!puschCfg->choice.setup)
2734                            {
2735
2736                               if(! puschCfg->choice.setup->pusch_TimeDomainAllocationList)
2737                               {
2738                                  if(! puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.array)
2739                                  {
2740                                     if(!puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.array[idx])
2741                                     {
2742                                        if(!puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.array[idx]->k2)
2743                                        {
2744                                           if(! puschCfg->choice.setup->msg3_DeltaPreamble)
2745                                           {
2746                                              if(!puschCfg->choice.setup->p0_NominalWithGrant)
2747                                              {
2748                                                 DU_FREE(puschCfg->choice.setup->p0_NominalWithGrant,
2749                                                       sizeof(long));
2750                                              }
2751                                              DU_FREE(puschCfg->choice.setup->msg3_DeltaPreamble,
2752                                                    sizeof(long));
2753                                           }
2754                                           DU_FREE(puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.\
2755                                                 array[idx]->k2, sizeof(long));
2756                                        }
2757                                     }
2758                                     for(idx=0;
2759                                           idx<puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.count;
2760                                           idx++)
2761                                     {
2762                                        if(!puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.array[idx])
2763                                        {
2764                                           DU_FREE(puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.array[idx],\
2765                                                 sizeof(PUSCH_TimeDomainResourceAllocation_t));
2766                                        }
2767                                     }
2768                                     DU_FREE(puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.array,\
2769                                           puschCfg->choice.setup->pusch_TimeDomainAllocationList->list.size);
2770                                  }
2771                                  DU_FREE(puschCfg->choice.setup->pusch_TimeDomainAllocationList,\
2772                                        sizeof(PUSCH_TimeDomainResourceAllocationList_t));
2773                               }
2774                               DU_FREE(puschCfg->choice.setup,
2775                                     sizeof(PUSCH_ConfigCommon_t));
2776                            }
2777                         }
2778                         default :
2779                            break;
2780                      }
2781
2782                      DU_FREE(bwp->pusch_ConfigCommon,\
2783                            sizeof(struct BWP_UplinkCommon__pusch_ConfigCommon));
2784                   }
2785                }
2786                switch(rachCfg->present)
2787                {
2788                   case BWP_UplinkCommon__rach_ConfigCommon_PR_NOTHING:
2789                      break;
2790                   case BWP_UplinkCommon__rach_ConfigCommon_PR_release:
2791                      break;
2792                   case BWP_UplinkCommon__rach_ConfigCommon_PR_setup:
2793                   {
2794                      if(!rachCfg->choice.setup)
2795                      {
2796                         setup = rachCfg->choice.setup;
2797                         if(!setup->totalNumberOfRA_Preambles)
2798                         {
2799                            if(!setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB)
2800                            {
2801                               if(!setup->rsrp_ThresholdSSB)
2802                               {
2803                                  if(!setup->msg1_SubcarrierSpacing)
2804                                  {
2805                                     DU_FREE(setup->msg1_SubcarrierSpacing,
2806                                           sizeof(SubcarrierSpacing_t));
2807                                  }
2808                                  DU_FREE(setup->rsrp_ThresholdSSB,
2809                                        sizeof(RSRP_Range_t));
2810                               }
2811                               DU_FREE(setup->ssb_perRACH_OccasionAndCB_PreamblesPerSSB,\
2812                                     sizeof(struct
2813                                        RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB));
2814                            }
2815                            DU_FREE(setup->totalNumberOfRA_Preambles,
2816                                  sizeof(long));
2817                         }
2818
2819                         DU_FREE(rachCfg->choice.setup,
2820                               sizeof(RACH_ConfigCommon_t));
2821                      }
2822                   }
2823                   default:
2824                      break;
2825                }
2826                DU_FREE(bwp->rach_ConfigCommon,\
2827                sizeof(struct BWP_UplinkCommon__rach_ConfigCommon));
2828             }
2829          }
2830          DU_FREE(ulCfg->frequencyInfoUL.p_Max, sizeof(P_Max_t));
2831       }    
2832       for(idx = 0; idx < scsCarrierList->list.count; idx++)
2833       {
2834          if(!scsCarrierList->list.array[idx])
2835          {
2836             DU_FREE(scsCarrierList->list.array[idx],
2837                   sizeof(SCS_SpecificCarrier_t));
2838          }
2839       }
2840       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
2841    }
2842 }
2843 /*******************************************************************
2844  *
2845  * @brief : Deallocating memory of  SIB1 message
2846  *
2847  * @details
2848  *
2849  *   Function : FreeServCellCfgCommonSib
2850  *
2851  *   Functionality: Deallocating memory of BuildServCellCfgCommonSib
2852  *
2853  * @params[in] : ServingCellConfigCommonSIB_t *srvCellCfg
2854  * @return     : void
2855  *
2856  *******************************************************************/
2857 void FreeServCellCfgCommonSib(ServingCellConfigCommonSIB_t *srvCellCfg)
2858 {
2859    BIT_STRING_t         *ssbPosInBurst;
2860    ssbPosInBurst = &srvCellCfg->ssb_PositionsInBurst.inOneGroup;
2861    DownlinkConfigCommonSIB_t *dlCfg=&srvCellCfg->downlinkConfigCommon;
2862
2863    if(!ssbPosInBurst->buf)
2864    {
2865       /* Free DL frequency info */
2866       if(FreqInfoDlret == ROK)
2867       {
2868          if(DlCfgCommSibret == ROK)
2869          {
2870             /* Uplink Config Comm */
2871             if(!srvCellCfg->uplinkConfigCommon)
2872             {
2873                if(UlCfgCommSibret==ROK)
2874                {
2875                   /* TDD UL DL Config Comm */
2876                   if(!srvCellCfg->tdd_UL_DL_ConfigurationCommon)
2877                   {
2878                      DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationCommon,
2879                            sizeof(TDD_UL_DL_ConfigCommon_t));
2880                   }
2881                }
2882                FreeUlCfgCommSib(srvCellCfg->uplinkConfigCommon);
2883                DU_FREE(srvCellCfg->uplinkConfigCommon,
2884                      sizeof(UplinkConfigCommonSIB_t));  
2885             }
2886          }
2887          FreeBwpDlCommon(&dlCfg->initialDownlinkBWP);
2888       }
2889       FreeFreqInfoDl(&dlCfg->frequencyInfoDL);
2890       DU_FREE(ssbPosInBurst->buf, ssbPosInBurst->size * sizeof(uint8_t));
2891    }
2892 }
2893 /*******************************************************************
2894  *
2895  * @brief   : Deallcating memory of the function BuildSib1Msg
2896  *
2897  * @details
2898  *
2899  *     Function :  FreeSib1Msg
2900  *
2901  *    Functionality: Deallcating memory of the function BuildSib1Msg
2902  *
2903  * @params[in] ServingCellConfigCommonSIB_t pointer
2904  * @return   void
2905  *
2906  *******************************************************************/
2907 void FreeSib1Msg(SIB1_t *sib1Msg)
2908 {
2909    uint8_t idx=0;
2910    uint8_t idx1=0;
2911    uint8_t idx2=0; 
2912    CellIdentity_t           *cellIdentity = NULLP;
2913    CellAccessRelatedInfo_t  *cellAccessInfo ;
2914    struct PLMN_IdentityInfo__plmn_IdentityList     *plmnIdInfo;
2915
2916
2917    if(sib1Msg != NULLP)
2918    {
2919       cellAccessInfo = &sib1Msg->cellAccessRelatedInfo;
2920       if(cellAccessInfo->plmn_IdentityList.list.array !=NULLP)
2921       {
2922          if(cellAccessInfo->plmn_IdentityList.list.array[idx]!=NULLP)
2923          {
2924             plmnIdInfo =
2925                &cellAccessInfo->plmn_IdentityList.list.array[idx]->plmn_IdentityList;
2926
2927             if(plmnIdInfo->list.array !=NULLP)
2928             {
2929                if(!plmnIdInfo->list.array[idx])
2930                {
2931                   if(!plmnIdInfo->list.array[idx]->mcc)
2932                   {
2933                      if(!(plmnIdInfo->list.array[idx]->mcc->list.array))
2934                      {
2935                         if(!plmnIdInfo->list.array[idx]->mnc.list.array)
2936                         {             
2937                            /*Free Tracking Area Code */
2938                            if(!cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode)
2939                            {        
2940                               /*Free RANAC */
2941                               if(!cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode->buf)
2942                               {    
2943                                  /* Free CellIdentity */
2944                                  if(!cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac)
2945                                  {
2946                                     cellIdentity
2947                                        =&cellAccessInfo->plmn_IdentityList.\
2948                                        list.array[idx]->cellIdentity;
2949                                     if(!cellIdentity->buf)
2950                                     {
2951                                        /*Free Connection Establish Failure Control */
2952                                        if(!sib1Msg->connEstFailureControl)
2953                                        {
2954                                           /*Free Serving Cell Config Common */
2955                                           if(!sib1Msg->si_SchedulingInfo)
2956                                           {
2957                                              /* Free Serving Cell Config Common* */
2958                                              if(!sib1Msg->servingCellConfigCommon)
2959                                              {
2960                                                 /*Free BuildServCellCfgCommonSib*/
2961                                                 FreeServCellCfgCommonSib(\
2962                                                       sib1Msg->servingCellConfigCommon);
2963
2964                                                 DU_FREE(sib1Msg->servingCellConfigCommon,
2965                                                       sizeof(ServingCellConfigCommonSIB_t));
2966                                              }
2967
2968                                              DU_FREE(sib1Msg->si_SchedulingInfo,
2969                                                    sizeof(SI_SchedulingInfo_t));
2970                                           }
2971
2972                                           DU_FREE(sib1Msg->connEstFailureControl,
2973                                                 sizeof(ConnEstFailureControl_t));
2974                                        }
2975                                        DU_FREE(cellIdentity->buf,cellIdentity->size);
2976
2977                                     }
2978                                     DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx]->ranac, sizeof(RAN_AreaCode_t)); 
2979
2980                                  }
2981                                  DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode->buf,\
2982                                        cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode->size);
2983
2984                               }
2985                               DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx]->trackingAreaCode\
2986                                     , sizeof(TrackingAreaCode_t));
2987                            }
2988
2989                            for(idx2=0; idx2<plmnIdInfo->list.array[idx1]->mnc.list.count; idx2++)
2990                            {
2991                               if(!plmnIdInfo->list.array[idx2]->mnc.list.array[idx2])
2992                               {
2993                                  DU_FREE(plmnIdInfo->list.array[idx2]->mnc.list.array[idx2],
2994                                        sizeof(MCC_MNC_Digit_t));
2995                               } 
2996                            }
2997                            DU_FREE(plmnIdInfo->list.array[idx]->mnc.list.array,
2998                                  plmnIdInfo->list.array[idx1]->mnc.list.size);
2999                         }
3000
3001                         for(idx1=0; idx1<plmnIdInfo->list.array[idx]->mcc->list.count; idx1++)
3002                         {
3003                            if(plmnIdInfo->list.array[idx]->mcc->list.array[idx1]!=NULLP)
3004                            {
3005                               DU_FREE(plmnIdInfo->list.array[idx]->mcc->list.array[idx1],\
3006                                     sizeof(MCC_MNC_Digit_t));
3007                            }
3008
3009                         }
3010                         DU_FREE(plmnIdInfo->list.array[idx]->mcc->list.array,\
3011                               plmnIdInfo->list.array[idx]->mcc->list.size)
3012                      }
3013                      DU_FREE(plmnIdInfo->list.array[idx]->mcc,sizeof(MCC_t));
3014                   }
3015                }
3016                for(idx1=0; idx1<plmnIdInfo->list.count; idx1++)
3017                {
3018                   if(!(plmnIdInfo->list.array[idx1]))
3019                   {
3020                      DU_FREE(plmnIdInfo->list.array[idx1],
3021                            sizeof(PLMN_IdentitY_t));
3022                   }
3023                }
3024                DU_FREE(plmnIdInfo->list.array, plmnIdInfo->list.size);
3025             }
3026          }
3027          for(idx=0; idx<cellAccessInfo->plmn_IdentityList.list.count; idx++)
3028          {
3029             if(cellAccessInfo->plmn_IdentityList.list.array[idx]!=NULLP)
3030             { 
3031                DU_FREE(cellAccessInfo->plmn_IdentityList.list.array[idx],
3032                      sizeof(PLMN_IdentityInfo_t));
3033             }
3034          }
3035          DU_FREE(cellAccessInfo->plmn_IdentityList.list.array,
3036                cellAccessInfo->plmn_IdentityList.list.size);
3037       }
3038       DU_FREE(sib1Msg, sizeof(SIB1_t)); 
3039    }
3040
3041 }
3042
3043 /**********************************************************************
3044   End of file
3045  **********************************************************************/