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