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