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