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