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