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