[Task-ID: ODUHIGH-502] Fixes in F1 Setup Request message building
[o-du/l2.git] / src / du_app / du_f1ap_msg_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 F1AP message handler functions */
20 #include "common_def.h"
21 #include "ckw.h"
22 #include "ckw.x"
23 #include "kwu.h"
24 #include "kwu.x"
25 #include "lkw.h"
26 #include "lrg.h"
27 #include "legtp.h"
28 #include "lkw.x"
29 #include "lrg.x"
30 #include "F1AP-PDU.h"
31 #include "InitiatingMessage.h"
32 #include "SuccessfulOutcome.h"
33 #include "du_app_mac_inf.h"
34 #include "du_cfg.h"
35 #include "du_app_rlc_inf.h"
36 #include "du_mgr_main.h"
37 #include "du_mgr.h"
38 #include "du_utils.h"
39 #include "du_ue_mgr.h"
40 #include "RAT-Type.h"
41 #include "NRFreqInfo.h"
42 #include "NRCGI.h"
43 #include "TDD-Info.h"
44 #include "NR-Mode-Info.h"
45 #include "ServedPLMNs-List.h"
46 #include "GNB-DU-Served-Cells-List.h"
47 #include "Served-Cell-Information.h"
48 #include "ProtocolExtensionContainer.h"
49 #include "RRC-Version.h"
50 #include "FDD-Info.h"
51 #include "FreqBandNrItem.h"
52 #include "ServedPLMNs-Item.h"
53 #include "GNB-DU-Served-Cells-Item.h"
54 #include "SliceSupportItem.h"
55 #include "FeatureSetUplinkPerCC.h"
56 #include "SliceSupportItem.h"
57 #include "Served-Cells-To-Modify-Item.h"
58 #include "Served-Cells-To-Delete-List.h"
59 #include "Served-Cells-To-Delete-Item.h"
60 #include "QoSInformation.h"
61 #include "ULUPTNLInformation-ToBeSetup-List.h"
62 #include "DRB-Information.h"
63 #include "DRBs-ToBeSetup-Item.h"
64 #include "DRBs-ToBeSetupMod-Item.h"
65 #include "DRBs-ToBeModified-Item.h"
66 #include "CUtoDURRCInformation.h"
67 #include "SCell-ToBeSetup-List.h"
68 #include "SRBs-ToBeSetup-List.h"
69 #include "DRBs-ToBeSetup-List.h"
70 #include "SRBs-ToBeSetup-Item.h"
71 #include "DRBs-ToBeModified-List.h"
72 #include "RRCContainer.h"
73 #include "UE-CapabilityRAT-ContainerList.h"
74 #include "DRBs-Setup-List.h"
75 #include "CellGroupConfig.h"
76 #include "ResetAll.h"
77 #include "ResetType.h"
78 #include "Cells-to-be-Activated-List.h"
79 #include "GNB-CU-Name.h"
80 #include "SRBs-SetupMod-List.h"
81 #include "DRBs-SetupMod-List.h"
82 #include "DRBs-ToBeSetupMod-List.h"
83 #include "PagingCell-Item.h"
84 #include "PagingCell-list.h"
85 #include "QoS-Characteristics.h"
86 #include "ULUPTNLInformation-ToBeSetup-Item.h"
87 #include "Flows-Mapped-To-DRB-Item.h"
88 #include "NonDynamic5QIDescriptor.h"
89 #include "Dynamic5QIDescriptor.h"
90 #include "FeatureSetDownlinkPerCC.h"
91 #include "FeatureSets.h"
92 #include "UE-NR-Capability.h"
93 #include "UE-CapabilityRAT-Container.h"
94 #include "UE-CapabilityRAT-ContainerListRRC.h"
95 #include "GNB-DU-System-Information.h"
96 #include "CellGroupConfigRrc.h"
97 #include "MAC-CellGroupConfig.h"
98 #include "SchedulingRequestConfig.h"
99 #include "SchedulingRequestToAddMod.h"
100 #include "BSR-Config.h"
101 #include "TAG-Config.h"
102 #include "TAG.h"
103 #include "PHR-Config.h"
104 #include "RLC-Config.h"
105 #include "UL-AM-RLC.h"
106 #include "DL-AM-RLC.h"
107 #include "LogicalChannelConfig.h"
108 #include "RLC-BearerConfig.h"
109 #include "PhysicalCellGroupConfig.h"
110 #include "SpCellConfig.h"
111 #include "TDD-UL-DL-ConfigDedicated.h"
112 #include "ServingCellConfig.h"
113 #include "ControlResourceSet.h"
114 #include "SearchSpace.h"
115 #include "PDCCH-Config.h"
116 #include "PDSCH-TimeDomainResourceAllocation.h"
117 #include "PDSCH-TimeDomainResourceAllocationList.h"
118 #include "PDSCH-CodeBlockGroupTransmission.h"
119 #include "PDSCH-ServingCellConfig.h"
120 #include "DMRS-DownlinkConfig.h"
121 #include "PDSCH-Config.h"
122 #include "BWP-DownlinkDedicated.h"
123 #include "BWP-Downlink.h"
124 #include "PUSCH-TimeDomainResourceAllocation.h"
125 #include "PUSCH-TimeDomainResourceAllocationList.h"
126 #include "DMRS-UplinkConfig.h"
127 #include "PUSCH-Config.h"
128 #include "SRS-ResourceId.h"
129 #include "SRS-Resource.h"
130 #include "SRS-ResourceSet.h"
131 #include "SRS-Config.h"
132 #include "BWP-UplinkDedicated.h"
133 #include "PUSCH-ServingCellConfig.h"
134 #include "UplinkConfig.h"
135 #include "DUtoCURRCContainer.h"
136 #include "GBR-QoSFlowInformation.h"
137 #include "QoSFlowLevelQoSParameters.h"
138 #include "PUCCH-Config.h"
139 #include "PUCCH-ResourceSet.h"
140 #include "PUCCH-Resource.h"
141 #include "PUCCH-PowerControl.h"
142 #include "P0-PUCCH.h"
143 #include "PUCCH-PathlossReferenceRS.h"
144 #include "PUCCH-format0.h"
145 #include "PUCCH-format1.h"
146 #include "PUCCH-format2.h"
147 #include "PUCCH-format3.h"
148 #include "PUCCH-format4.h"
149 #include "PUCCH-FormatConfig.h"
150 #include "SchedulingRequestResourceConfig.h"
151 #include<ProtocolIE-Field.h>
152 #include "ProtocolExtensionField.h"
153 #include "odu_common_codec.h"
154 #include "du_mgr.h"
155 #include "du_cell_mgr.h"
156 #include "du_f1ap_msg_hdl.h"
157 #include "DRBs-Setup-Item.h"
158 #include "DLUPTNLInformation-ToBeSetup-List.h"
159 #include "DLUPTNLInformation-ToBeSetup-Item.h"
160 #include "UPTransportLayerInformation.h"
161 #include "GTPTunnel.h"
162 #include "SupportedSULFreqBandItem.h"
163 #include "du_e2ap_msg_hdl.h"
164 #include "du_f1ap_conversions.h"
165 #include "CNUEPagingIdentity.h"
166 #include "PCCH-Config.h"
167 #include "SCS-SpecificCarrier.h"
168 #include "FrequencyInfoDL.h"
169 #include "DownlinkConfigCommon.h"
170 #include "FrequencyInfoUL.h"
171 #include "UplinkConfigCommon.h"
172 #include "TDD-UL-DL-ConfigCommon.h"
173 #include "RACH-ConfigDedicated.h"
174 #include "CFRA-SSB-Resource.h"
175 #include "BWP-UplinkCommon.h"
176 #include "ReconfigurationWithSync.h"
177 #include "du_sys_info_hdl.h"
178 #include "DRX-ConfigRrc.h"
179 #include "MeasurementTimingConfigurationRrc.h"
180 #include "MeasurementTimingConfigurationRrc-IEs.h"
181 #include "MeasTimingList.h"
182 #include "MeasTiming.h"
183
184 #ifdef O1_ENABLE
185 #include "CmInterface.h"
186 extern StartupConfig g_cfg;
187 #endif
188
189 DuCfgParams duCfgParam;
190
191 /******************************************************************
192  *
193  * @brief Function to fetch lcId based on DRB Id
194  *
195  * @details
196  *
197  *    Function : fetchLcId
198  *
199  *    @params[in] drbId
200  *
201  *    Functionality: Function to fetch lcId based on DRB Id
202  *
203  * Returns: lcId - SUCCESS
204  *          RFAILED - FAILURE
205  *****************************************************************/
206
207 uint8_t fetchLcId(uint8_t drbId)
208 {
209    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
210
211    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
212    {
213       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
214       {
215          if(duCb.actvCellLst[cellIdx] != NULLP)
216          {
217             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
218             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
219             {
220                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
221                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
222                {
223                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
224                   return lcId;
225                }
226             }
227          }
228       }
229    }
230    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
231    return RFAILED;
232 }
233
234 /*******************************************************************
235 *
236 * @brief Adding F1AP pdu to reserved pdu list
237 *
238 * @details
239 *
240 *    Function : addToReservedF1apPduList 
241 *
242 *    Functionality: Adding F1AP pdu to reserved pdu list.
243 *     These pdu are awaiting aknowledgment from CU
244 *
245 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
246 *
247 * @return ROK - success
248 *         RFAILED - failure
249 *
250 * ****************************************************************/
251 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
252 {
253    CmLList         *node = NULLP;
254    ReservedF1apPduInfo *pduInfo = NULLP;
255    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
256    if(pduInfo)
257    {
258       DU_ALLOC(node, sizeof(CmLList));
259       if(node)
260       {
261          pduInfo->transId = transId;
262          pduInfo->f1apMsg = (void*) f1apPdu;
263
264          node->node = (PTR)pduInfo;
265          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
266       }
267    }
268 }
269
270 /*******************************************************************
271 *
272 * @brief searching for F1AP pdu from ReservedF1apPduList 
273 *
274 * @details
275 *
276 *    Function : searchFromReservedF1apPduList 
277 *
278 *    Functionality: searching for F1AP pdu information
279 *
280 * @params[in] uint8_t transId
281 *
282 * @return pointer to F1AP_PDU_t
283 *
284 * ****************************************************************/
285
286 CmLList *searchFromReservedF1apPduList(uint8_t transId)
287 {
288    CmLList         *node;
289    ReservedF1apPduInfo *f1apPdu;
290    if(duCb.reservedF1apPduList.count)
291    {
292       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
293       while(node)
294       {
295          f1apPdu = (ReservedF1apPduInfo*)node->node;
296          if(f1apPdu->transId == transId)
297          {
298             return node;
299          }
300          node = node->next;
301       }
302    }
303    return NULL;
304 }
305
306 /*******************************************************************
307 *
308 * @brief deleting F1AP pdu information from ReservedF1apPduList
309 *
310 * @details
311 *
312 *    Function : deleteFromReservedF1apPduList 
313 *
314 *    Functionality: deleting pdu information from ReservedF1apPduList
315 *
316 * @params[in] CmLList *node 
317 *
318 * @return void 
319 *
320 * ****************************************************************/
321
322 void deleteFromReservedF1apPduList(CmLList *node)
323 {
324    ReservedF1apPduInfo *f1apPdu;
325
326    if(node != NULL)
327    {
328       f1apPdu = (ReservedF1apPduInfo *)node->node;
329       cmLListDelFrm(&duCb.reservedF1apPduList, node);
330       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
331       DU_FREE(node, sizeof(CmLList));
332       node = NULL;
333    }
334 }
335
336 /*******************************************************************
337  *
338  * @brief Builds Uplink Info for NR 
339  *
340  * @details
341  *
342  *    Function : BuildULNRInfo
343  *
344  *    Functionality: Building NR Uplink Info
345  *
346  * @params[in] NRFreqInfo_t *ulnrfreq
347  * @return ROK     - success
348  *         RFAILED - failure
349  *
350  * ****************************************************************/
351 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
352 {
353    uint8_t idx=0;
354    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
355                        fdd.ulNrFreqInfo.nrArfcn;
356    ulnrfreq->freqBandListNr.list.count = 1;
357    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
358    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
359    if(ulnrfreq->freqBandListNr.list.array == NULLP)
360    {
361       return RFAILED;
362    }
363    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
364    {
365       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
366       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
367       {
368          return RFAILED;
369       }
370    }
371    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
372                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
373                                                                  freqBand[0].nrFreqBand;
374    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
375    return ROK;
376 }
377 /*******************************************************************
378  *
379  * @brief Builds Downlink NR Info 
380  *
381  * @details
382  *
383  *    Function : BuildDLNRInfo
384  *
385  *    Functionality: Building Downlink NR Info
386  *    
387  * @params[in] NRFreqInfo_t *dlnrfreq
388  * @return ROK     - success
389  *         RFAILED - failure
390  *
391  * ****************************************************************/
392 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
393 {
394    uint8_t idx=0;
395    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
396                        fdd.dlNrFreqInfo.nrArfcn;
397    dlnrfreq->freqBandListNr.list.count = 1;
398    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
399    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
400    if(dlnrfreq->freqBandListNr.list.array == NULLP)
401    {
402       return RFAILED;   
403    }
404    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
405    {
406       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
407       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
408       {
409          return RFAILED;
410       }
411    }   
412    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
413                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
414                                                                  freqBand[0].nrFreqBand;
415    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
416
417    return ROK;
418 }
419
420 /*******************************************************************
421  *
422  * @brief Builds Nrcgi 
423  *
424  * @details
425  *
426  *    Function : BuildNrcgi
427  *
428  *    Functionality: Building the PLMN ID and NR Cell id
429  *
430  * @params[in] NRCGI_t *nrcgi
431  * @return ROK     - success
432  *         RFAILED - failure
433  *
434  * ****************************************************************/
435 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
436 {
437    uint8_t ret;
438    uint8_t byteSize = 5;
439    /* Allocate Buffer Memory */
440    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
441    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
442    if(nrcgi->pLMN_Identity.buf == NULLP)
443    {
444       return RFAILED;
445    }
446    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
447          nrcgi->pLMN_Identity.buf); // Building PLMN function
448    if(ret != ROK)
449    {
450       return RFAILED;
451    }
452    /*nrCellIdentity*/
453    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
454    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
455    if(nrcgi->nRCellIdentity.buf == NULLP)
456    {
457       return RFAILED;
458    }
459    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
460
461    return ROK;
462 }
463 /*******************************************************************
464  *
465  * @brief Builds FiveGStac 
466  *
467  * @details
468  *
469  *    Function : BuildFiveGSTac
470  *
471  *    Functionality: Building the FiveGSTac
472  *
473  * @params[in] OCTET_STRING_t *fivegsTac
474  * @return ROK     - success
475  *         RFAILED - failure
476  *
477  * ****************************************************************/
478 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
479 {
480    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
481    if(servcell->fiveGS_TAC == NULLP)
482    {
483       return RFAILED;
484    }
485    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
486    DU_ALLOC(servcell->fiveGS_TAC->buf,\
487          sizeof(servcell->fiveGS_TAC->size));
488    if(servcell->fiveGS_TAC->buf == NULLP)
489    {
490       return RFAILED;
491    }
492    servcell->fiveGS_TAC->buf[0] = 0;
493    servcell->fiveGS_TAC->buf[1] = 0;
494    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
495    return ROK;  
496 }
497
498 /*******************************************************************
499  *
500  * @brief fill nr frequency information
501  *
502  * @details
503  *
504  *    Function : fillNrTddInfo 
505  *
506  *    Functionality: fill nr frequency information
507  *
508  * @params[in] NRFreqInfo_t freqInfo
509  * @return ROK     - success
510  *         RFAILED - failure
511  *
512  * ****************************************************************/
513 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
514 {
515    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
516    NRFreqInfo_t *freqInfo = NULLP;
517
518    if(tddInfo == NULLP)
519    {
520       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
521       return RFAILED;
522    }
523    
524    freqInfo = &tddInfo->nRFreqInfo;
525    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
526
527    freqInfo->freqBandListNr.list.count = elementCnt; 
528    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
529    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
530    if(!freqInfo->freqBandListNr.list.array)
531    {
532       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
533       return RFAILED;
534    }
535
536    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
537    {
538       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
539       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
540       {
541          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
542          return RFAILED;
543       }
544
545       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
546       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
547
548       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
549       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
550       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
551
552       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
553             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
554       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
555       {
556          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
557          return RFAILED;
558       }
559
560       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
561       {
562          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
563                sizeof(SupportedSULFreqBandItem_t));
564          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
565          {
566             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
567             return RFAILED;
568          }
569
570          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
571          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
572       }
573    }
574
575    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
576    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
577
578    return ROK;
579 }
580
581 /*******************************************************************
582  *
583  * @brief Builds NR Mode 
584  *
585  * @details
586  *
587  *    Function : BuildNrMode
588  *
589  *    Functionality: Building the NR Mode
590  *
591  * @params[in] NR_Mode_Info_t *fdd
592  * @return ROK     - success
593  *         RFAILED - failure
594  *
595  * ****************************************************************/
596 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
597 {
598    uint8_t BuildDLNRInforet=0;
599    uint8_t BuildULNRInforet=0; 
600    
601 #ifdef NR_TDD
602    mode->present = NR_Mode_Info_PR_tDD;
603 #else
604    mode->present = NR_Mode_Info_PR_fDD;
605 #endif   
606    
607    if(mode->present == NR_Mode_Info_PR_fDD)
608    {
609       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
610       if(mode->choice.fDD == NULLP)
611       {
612          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
613          return RFAILED;
614       }
615       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
616       if(BuildULNRInforet != ROK)
617       {
618          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
619          return RFAILED;    
620       }
621       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
622       if(BuildDLNRInforet != ROK)
623       {
624          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
625          return RFAILED;
626       }
627       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
628                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
629                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
630       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
631                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
632                                                           f1Mode.mode.fdd.ulTxBw.nrb;
633       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
634                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
635                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
636       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
637                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
638                                                           f1Mode.mode.fdd.dlTxBw.nrb;
639    }
640    else if(mode->present == NR_Mode_Info_PR_tDD) 
641    {
642       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
643       if(mode->choice.tDD == NULLP)
644       {
645          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
646          return RFAILED;
647       }
648
649       if(fillNrTddInfo(mode->choice.tDD) != ROK)
650       {
651          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
652          return RFAILED;
653       }
654
655    }
656
657    return ROK;
658 }
659 /*******************************************************************
660  *
661  * @brief Builds IE Extensions for Served PLMNs 
662  *
663  * @details
664  *
665  *    Function : BuildExtensions
666  *
667  *    Functionality: Building the IE Extensions
668  *
669  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
670  * @return ROK     - success
671  *         RFAILED - failure
672  *
673  * ****************************************************************/
674 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
675 {
676    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
677    uint8_t elementCnt=0, extensionCnt=0;
678
679    extensionCnt=IE_EXTENSION_LIST_COUNT;
680    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
681    if((*ieExtend) == NULLP)
682    {
683       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
684       return RFAILED;
685    }
686    (*ieExtend)->list.count = extensionCnt;
687    (*ieExtend)->list.size = \
688                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
689    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
690    if((*ieExtend)->list.array == NULLP)
691    {
692       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
693       return RFAILED;
694    }
695    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
696    {
697       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
698             sizeof(ServedPLMNs_ItemExtIEs_t));
699       if((*ieExtend)->list.array[plmnidx] == NULLP)
700       {
701          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
702          return RFAILED;
703       }
704    }
705    
706    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
707    idx = 0;
708    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
709    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
710    (*ieExtend)->list.array[idx]->extensionValue.present = \
711    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
712    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
713       list.count = elementCnt;
714    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
715       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
716       list.count * sizeof(SliceSupportItem_t *);
717
718    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
719          list.array, elementCnt * sizeof(SliceSupportItem_t *));
720    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
721          list.array == NULLP)
722    {
723       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
724       return RFAILED;
725    }
726
727    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
728    {
729       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
730             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
731       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
732             list.array[sliceLstIdx] == NULLP) 
733       {
734          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
735          return RFAILED;
736       }
737       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
738          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
739       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
740             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
741             extensionValue.choice.SliceSupportList.\
742             list.array[sliceLstIdx]->sNSSAI.sST.size);
743       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
744             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
745       {
746          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
747          return RFAILED;
748       }
749       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
750          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
751          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
752       
753       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
754             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
755       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
756             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
757       {
758          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
759          return RFAILED;
760       }
761       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
762          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
763       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
764             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
765             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
766       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
767             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
768       {
769          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
770          return RFAILED;
771       }
772       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
773       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
774       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
775       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
776    }
777    return ROK;
778 }
779 /*******************************************************************
780  *
781  * @brief Builds Served PLMN 
782  *
783  * @details
784  *
785  *    Function : BuildServedPlmn
786  *
787  *    Functionality: Building the Served PLMN
788  *
789  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
790  * @return ROK     - success
791  *         RFAILED - failure
792  *
793  * ****************************************************************/
794 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
795 {  
796    uint8_t  plmnidx;
797    uint8_t  servPlmnCnt=1;
798    uint8_t buildPlmnIdret=0;
799    uint8_t BuildExtensionsret=0;
800    srvplmn->list.count = servPlmnCnt;
801    srvplmn->list.size = \
802                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
803    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
804    if(srvplmn->list.array == NULLP)
805    {
806       return RFAILED;
807    }
808    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
809    {   
810       DU_ALLOC(srvplmn->list.array[plmnidx],\
811             sizeof(ServedPLMNs_Item_t));
812       if(srvplmn->list.array[plmnidx] == NULLP)
813       {
814          return RFAILED;
815       }  
816    }
817    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
818    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
819    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
820          srvplmn->list.array[0]->pLMN_Identity.buf);
821    if(buildPlmnIdret!= ROK)
822    {
823       return RFAILED;
824    }
825    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
826    if(BuildExtensionsret!= ROK)
827    {
828       return RFAILED;
829    }
830    return ROK;
831 }
832
833 /*******************************************************************
834  *
835  * @brief Frees Measurement Timing configuration 
836  *
837  * @details
838  *
839  *    Function : FreeMeasTimingConf
840  *
841  *    Functionality: Frees Timing Configuration
842  *
843  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
844  * @return ROK     - success
845  *         RFAILED - failure
846  *
847  * ****************************************************************/
848 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
849 {
850    uint8_t measIeIdx = 0;
851    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
852
853    if(measTimingConfRrc.criticalExtensions.choice.c1)
854    {
855       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
856       {
857          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
858          if(measTimingConfIEs->measTiming)
859          {
860             if(measTimingConfIEs->measTiming->list.array)
861             {
862                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
863                {
864                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
865                   {
866                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
867                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
868                   }
869                }
870                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
871             }
872             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
873          }
874          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
875       }
876       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
877    }
878 }
879
880 /*******************************************************************
881  *
882  * @brief Builds MEasuerment Timing Configuration
883  *
884  * @details
885  *
886  *    Function : BuildMeasTimingConf
887  *
888  *    Functionality: Building Measurement Timing Configuration
889  *
890  * @params[in] Pointer to octet string to store Measurement timing
891  *             Configuration
892  * @return ROK     - success
893  *         RFAILED - failure
894  *
895  * ****************************************************************/
896 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
897 {
898    uint8_t ret = RFAILED;
899    uint8_t elementCnt = 0;
900    uint8_t measIeIdx = 0;
901    asn_enc_rval_t encRetVal;
902    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
903    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
904    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
905
906    while(true)
907    {
908       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
909       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
910       if(!measTimingConfRrc.criticalExtensions.choice.c1)
911       {
912          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
913          break;
914       }
915       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
916
917       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
918       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
919       {
920          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
921          break;
922       }
923       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
924
925       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
926       if(!measTimingConfIEs->measTiming)
927       {
928          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
929          break;
930       }
931
932       elementCnt = 1;  
933       measTimingConfIEs->measTiming->list.count = elementCnt;
934       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
935       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
936       if(!measTimingConfIEs->measTiming->list.array)
937       {
938          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
939          break;
940       }
941
942       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
943       {
944          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
945          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
946          {
947             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
948             break;
949          }
950       }
951       if(measIeIdx < elementCnt)
952       {
953          break;
954       }
955
956       measIeIdx = 0;
957       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
958       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
959       {
960          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
961          break;
962       }
963       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
964       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
965       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
966       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
967       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
968       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
969
970       /* Encode the F1SetupRequest type as APER */
971       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
972
973       memset(encBuf, 0, ENC_BUF_MAX_LEN);
974       encBufSize = 0;
975       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
976
977       /* Encode results */
978       if(encRetVal.encoded == ENCODE_FAIL)
979       {     
980          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
981                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
982          break;
983       }     
984       else  
985       {     
986          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
987 #ifdef DEBUG_ASN_PRINT
988          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
989          {
990             printf("%x",encBuf[measIeIdx]);
991          }
992 #endif
993
994          measTimingConf->size = encBufSize;
995          DU_ALLOC(measTimingConf->buf, encBufSize);
996          if(measTimingConf->buf == NULLP)
997          {
998             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
999             return RFAILED;
1000          }
1001          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1002
1003          FreeMeasTimingConf(measTimingConfRrc);
1004
1005          ret = ROK;
1006          break;
1007       }
1008    }
1009    return ret;
1010 }
1011
1012 /*******************************************************************
1013  *
1014  * @brief Builds Served Cell List
1015  *
1016  * @details
1017  *
1018  *    Function : BuildServedCellList
1019  *
1020  *    Functionality: Building Served Cell List
1021  *
1022  * @params[in] PLMNID plmn
1023  * @return ROK     - success
1024  *         RFAILED - failure
1025  *
1026  * ****************************************************************/
1027
1028 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1029 {
1030    uint8_t  BuildNrcgiret=0;
1031    uint8_t  BuildFiveGSTacret=0;
1032    uint8_t  BuildServedPlmnret=0;
1033    uint8_t  BuildNrModeret=0;
1034    uint8_t  idx;
1035    uint8_t  plmnidx;
1036    uint8_t  plmnCnt=1;
1037    GNB_DU_Served_Cells_Item_t *srvCellItem;
1038    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1039    duServedCell->list.count = plmnCnt;
1040
1041    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1042    if(duServedCell->list.array == NULLP)
1043    {
1044       return RFAILED;
1045    }
1046    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1047    {
1048       DU_ALLOC(duServedCell->list.array[plmnidx],\
1049             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1050       if(duServedCell->list.array[plmnidx] == NULLP)
1051       {
1052          return RFAILED;
1053       }
1054    }
1055    idx = 0;
1056    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1057    duServedCell->list.array[idx]->criticality = Criticality_reject;
1058    duServedCell->list.array[idx]->value.present = \
1059                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1060    srvCellItem = \
1061                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1062    /*nRCGI*/
1063    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1064    if(BuildNrcgiret != ROK)
1065    {
1066       return RFAILED;
1067    }
1068    /*nRPCI*/
1069    srvCellItem->served_Cell_Information.nRPCI = \
1070                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1071
1072    /* fiveGS_TAC */
1073    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1074    if(BuildFiveGSTacret != ROK)
1075    {
1076       return RFAILED;
1077    }
1078
1079    /* Served PLMNs */
1080    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1081    if(BuildServedPlmnret !=ROK)
1082    {
1083       return RFAILED;
1084    }
1085
1086    /* nR Mode Info with FDD/TDD */
1087    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1088    if(BuildNrModeret != ROK)
1089    {
1090       return RFAILED;
1091    }
1092
1093    /*Measurement timing Config*/
1094    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1095       return RFAILED;
1096
1097    /* GNB DU System Information */
1098    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1099          sizeof(GNB_DU_System_Information_t));
1100    if(!srvCellItem->gNB_DU_System_Information)
1101    {
1102       return RFAILED;
1103    }
1104    /* MIB */
1105    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1106    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1107          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1108    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1109    {
1110       return RFAILED;
1111    }
1112    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1113                    srvCellItem->gNB_DU_System_Information->mIB_message.size);
1114
1115    /* SIB1 */
1116    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1117                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1118
1119    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1120          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1121    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1122    {
1123       return RFAILED;
1124    }
1125    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1126    {
1127       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1128                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1129    }
1130    return ROK; 
1131 }                                                                                                                  
1132 /*******************************************************************
1133  *
1134  * @brief Builds RRC Version 
1135  *
1136  * @details
1137  *
1138  *    Function : BuildRrcVer
1139  *
1140  *    Functionality: Building RRC Version
1141  *
1142  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1143  * @return ROK     - success
1144  *         RFAILED - failure
1145  *
1146  * ****************************************************************/
1147 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1148 {
1149    uint8_t rrcExt;
1150    uint8_t rrcLatest;
1151    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1152    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1153    if(rrcVer->latest_RRC_Version.buf == NULLP)
1154    {
1155       return RFAILED;
1156    }
1157    rrcVer->latest_RRC_Version.buf[0] = 0;
1158    rrcVer->latest_RRC_Version.bits_unused = 5;
1159    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1160    if(rrcVer->iE_Extensions == NULLP)
1161    {  
1162       return RFAILED;
1163    }
1164    rrcVer->iE_Extensions->list.count = 1;
1165    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1166    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1167    if(rrcVer->iE_Extensions->list.array == NULLP)
1168    {
1169       return RFAILED;
1170    }
1171    rrcExt = 0;
1172    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1173          sizeof(RRC_Version_ExtIEs_t));
1174    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1175    {
1176       return RFAILED;
1177    }
1178    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1179                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1180    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1181    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1182                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1183    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1184       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1185    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1186          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1187          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1188    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1189          .Latest_RRC_Version_Enhanced.buf == NULLP)
1190    {
1191       return RFAILED;
1192    }
1193    rrcLatest = 0;
1194    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1195       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1196    rrcLatest++;
1197    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1198       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1199    rrcLatest++;
1200    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1201       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1202    return ROK;
1203 }
1204 /*******************************************************************
1205  *
1206  * @brief Sends F1 msg over SCTP
1207  *
1208  * @details
1209  *
1210  *    Function : sendF1APMsg
1211  *
1212  *    Functionality: Sends F1 msg over SCTP
1213  *
1214  * @params[in] Region region
1215  *             Pool pool
1216  * @return ROK     - success
1217  *         RFAILED - failure
1218  *
1219  * ****************************************************************/
1220 uint8_t sendF1APMsg()
1221 {
1222    Buffer *mBuf = NULLP;
1223   
1224    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1225    {
1226       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1227       {
1228             ODU_PRINT_MSG(mBuf, 0,0);
1229
1230             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1231             {
1232                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1233                ODU_PUT_MSG_BUF(mBuf);
1234                return RFAILED;
1235             }
1236       }
1237       else
1238       {
1239          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1240          ODU_PUT_MSG_BUF(mBuf);
1241          return RFAILED;
1242       }
1243       ODU_PUT_MSG_BUF(mBuf);
1244    }
1245    else
1246    {
1247       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1248       return RFAILED;
1249    }
1250    return ROK; 
1251 } /* sendF1APMsg */
1252
1253 /*******************************************************************
1254  *
1255  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1256  *
1257  * @details
1258  *
1259  *    Function :  FreeRrcVer
1260  *
1261  *    Functionality: deallocating the memory of function BuildRrcVer
1262  *
1263  * @params[in] RRC_Version_t *rrcVer
1264  * 
1265  * @return void
1266  *
1267  *****************************************************************/
1268 void FreeRrcVer(RRC_Version_t *rrcVer)
1269 {
1270    if(rrcVer->latest_RRC_Version.buf != NULLP)
1271    {
1272       if(rrcVer->iE_Extensions != NULLP)
1273       {
1274          if(rrcVer->iE_Extensions->list.array != NULLP)
1275          {
1276             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1277             {
1278                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1279                      != NULLP)
1280                {
1281                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1282                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1283                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1284                }
1285                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1286             }
1287             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1288          }
1289          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1290       }
1291       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1292    }
1293 }
1294
1295 /*******************************************************************
1296  *
1297  * @brief Deallocating memory of TDD NrFreqInfo 
1298  *
1299  * @details
1300  *
1301  *    Function : freeTddNrFreqInfo 
1302  *
1303  *    Functionality: freeTddNrFreqInfo 
1304  *
1305  * @params[in]  F1AP_PDU_t *f1apDuCfg
1306  *
1307  * @return ROK     - void
1308  *
1309  * ****************************************************************/
1310 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1311 {
1312    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1313
1314    if(freqInfo->freqBandListNr.list.array)
1315    {
1316       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1317       {
1318          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1319          {
1320             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1321             {
1322                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1323                {
1324                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1325                         sizeof(SupportedSULFreqBandItem_t));
1326                }
1327                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1328                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1329
1330             }
1331             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1332          }
1333       }
1334       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1335    }
1336 }
1337
1338 /*******************************************************************
1339  *
1340  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1341  *
1342  * @details
1343  *
1344  *    Function : freeFddNrFreqInfo 
1345  *
1346  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1347  *
1348  * @params[in]  
1349  *
1350  * @return ROK     - void
1351  *
1352  * ****************************************************************/
1353 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1354 {
1355    uint8_t arrIdx =0;
1356
1357    if(fDD != NULLP)
1358    {
1359       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1360       {
1361          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1362                array[arrIdx], sizeof(FreqBandNrItem_t));
1363          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1364                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1365       }
1366
1367       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1368       {
1369          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1370                array[arrIdx], sizeof(FreqBandNrItem_t));
1371          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1372                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1373       }
1374       DU_FREE(fDD,sizeof(FDD_Info_t));
1375    }
1376 }
1377
1378 /*******************************************************************
1379  *
1380  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1381  *
1382  * @details
1383  *
1384  *    Function :  FreeServedCellList
1385  *
1386  *    Functionality:  deallocating the memory of function BuildServedCellList
1387
1388  *
1389  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1390  *
1391  * @return void
1392  *
1393  * ****************************************************************/
1394 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1395 {
1396    uint8_t   plmnCnt= 1;
1397    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1398    uint8_t  plmnIdx=0, sliceIdx=0;
1399    GNB_DU_Served_Cells_Item_t *srvCellItem;
1400    ServedPLMNs_Item_t  *servedPlmnItem;
1401    SliceSupportItem_t  *sliceSupportItem;
1402
1403    if(duServedCell->list.array!=NULLP)
1404    {
1405       if(duServedCell->list.array[0]!=NULLP)
1406       {
1407          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1408
1409          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1410                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1411          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1412                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1413
1414          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1415          {
1416             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1417                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1418             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1419          }
1420
1421          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1422          {
1423             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1424             {
1425                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1426                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1427
1428                if(servedPlmnItem->iE_Extensions != NULLP)
1429                {
1430                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1431                   {
1432                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1433                      {
1434                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1435                               SliceSupportList.list.array != NULLP)
1436                         {
1437                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1438                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1439                            {
1440                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1441                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1442                               {
1443                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1444                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1445
1446                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1447
1448                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1449                                  {
1450                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1451                                           sliceSupportItem->sNSSAI.sD->size);
1452                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1453                                  }
1454
1455                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1456                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1457                               }
1458                            }
1459                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1460                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1461                                  extensionValue.choice.SliceSupportList.list.size);
1462                         }
1463                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1464                               sizeof(ServedPLMNs_ItemExtIEs_t));
1465                      }
1466                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1467                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1468                   }
1469                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1470                }
1471                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1472                      sizeof(ServedPLMNs_Item_t));
1473             }
1474             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1475                   sizeof(ServedPLMNs_Item_t *));
1476          }
1477
1478          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1479          {
1480             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1481          }
1482          else   
1483          {
1484             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1485             {
1486                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1487                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1488             }
1489          }
1490          
1491          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1492                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1493
1494          if(srvCellItem->gNB_DU_System_Information != NULLP)
1495          {
1496             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1497             {
1498                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1499                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1500             }
1501
1502             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1503             { 
1504                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1505                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1506             }
1507
1508             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1509          }
1510
1511          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1512       }
1513       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1514    }
1515 }
1516
1517 /*******************************************************************
1518  *
1519  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1520  *
1521  * @details
1522  *
1523  *    Function :  FreeF1SetupReq
1524  *
1525  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1526  *
1527  * @params[in] F1AP_PDU_t *f1apMsg
1528  *
1529  * @return void
1530  *
1531  * ****************************************************************/
1532 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1533 {
1534    uint8_t ieIdx, ieIdx2;
1535    F1SetupRequest_t *f1SetupReq=NULLP;
1536
1537    if(f1apMsg != NULLP)
1538    {
1539       if(f1apMsg->choice.initiatingMessage != NULLP)
1540       {
1541          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1542          if(f1SetupReq->protocolIEs.list.array != NULLP)
1543          {
1544             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1545             {
1546                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1547                {
1548                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1549                   {
1550                      case ProtocolIE_ID_id_TransactionID:
1551                         break;
1552                      case ProtocolIE_ID_id_gNB_DU_ID:
1553                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1554                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1555                         break;
1556                      case ProtocolIE_ID_id_gNB_DU_Name:
1557                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1558                               strlen((char *)duCfgParam.duName));
1559                         break;
1560                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1561                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1562                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1563                         break;
1564                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1565                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1566                         break;
1567                      default:
1568                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1569                         break;
1570                   }
1571                }
1572             }
1573             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1574             {
1575                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1576             }
1577             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1578                   f1SetupReq->protocolIEs.list.size);
1579          }
1580          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1581       }
1582       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1583    }
1584 }
1585
1586 /*******************************************************************
1587  *
1588  * @brief Builds and Send the F1SetupRequest
1589  *
1590  * @details
1591  *
1592  *    Function : BuildAndSendF1SetupReq
1593  *
1594  * Functionality:Fills the F1SetupRequest
1595  *
1596  * @return ROK     - success
1597  *         RFAILED - failure
1598  *
1599  ******************************************************************/
1600 uint8_t BuildAndSendF1SetupReq()
1601 {
1602    uint8_t   ret, ieIdx, elementCnt;
1603    F1AP_PDU_t                 *f1apMsg = NULLP;
1604    F1SetupRequest_t           *f1SetupReq=NULLP;
1605    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1606    RRC_Version_t              *rrcVer=NULLP;
1607    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1608    ret= RFAILED;
1609
1610    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1611    do
1612    {
1613       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1614       if(f1apMsg == NULLP)
1615       {
1616          break;
1617       }
1618       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1619       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1620       if(f1apMsg->choice.initiatingMessage == NULLP)
1621       {
1622          break;
1623       }
1624       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1625       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1626       f1apMsg->choice.initiatingMessage->value.present = \
1627                                                          InitiatingMessage__value_PR_F1SetupRequest;
1628
1629       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1630
1631       elementCnt = 5;
1632
1633       f1SetupReq->protocolIEs.list.count = elementCnt;
1634       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t );
1635
1636       /* Initialize the F1Setup members */
1637       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1638       if(f1SetupReq->protocolIEs.list.array == NULLP)
1639       {
1640          break;
1641       }
1642       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1643       {
1644          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1645                sizeof(F1SetupRequestIEs_t));
1646          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1647          {
1648             break;
1649          }
1650       }
1651
1652       ieIdx = 0;
1653       /*TransactionID*/
1654       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1655       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1656       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1657                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1658       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1659                                                                               TRANS_ID;
1660
1661       /*DU ID*/
1662       ieIdx++;
1663       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1664       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1665       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1666                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1667       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1668                                                                               sizeof(uint8_t);
1669
1670       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1671             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1672       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1673             NULLP)
1674       {
1675          break;
1676       }
1677
1678       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1679                                                                                 duCfgParam.duId;
1680       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1681        * However this string is decoded successfully on online decoders.
1682        * Since this is an optional IE and the value received in it are not
1683        * used as of now, eliminating this IE for now to avoid wireshark error.
1684        */
1685       /*DU Name*/
1686       if(duCfgParam.duName != NULL)
1687       {
1688          ieIdx++;
1689          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1690          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1691          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1692          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1693          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1694                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1695          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1696          {
1697             break;
1698          }
1699          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1700                (char*)duCfgParam.duName);
1701       }
1702
1703       /*Served Cell list */
1704       ieIdx++;
1705       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1706                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1707       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1708       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1709                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1710       duServedCell = &f1SetupReq->protocolIEs.list.\
1711                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1712       if(BuildServedCellList(duServedCell))
1713       {
1714          break;
1715       }
1716
1717       /*RRC Version*/
1718       ieIdx++;
1719       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1720                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1721       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1722       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1723                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1724       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1725       if(BuildRrcVer(rrcVer))
1726       {
1727          break;
1728       }
1729
1730       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1731
1732       /* Encode the F1SetupRequest type as APER */
1733       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1734       encBufSize = 0;
1735       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1736             encBuf);
1737
1738       /* Encode results */
1739       if(encRetVal.encoded == ENCODE_FAIL)
1740       {
1741          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1742                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1743          break;
1744       }
1745       else
1746       {
1747          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1748 #ifdef DEBUG_ASN_PRINT
1749          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1750          {
1751             printf("%x",encBuf[ieIdx]);
1752          }
1753 #endif
1754
1755          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1756          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1757          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1758          {
1759             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1760             return RFAILED;
1761          }
1762          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1763       }
1764
1765       /* Sending msg */
1766       if(sendF1APMsg() != ROK)
1767       {
1768          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1769          break;
1770       }
1771
1772       ret=ROK;
1773       break;
1774    }while(true);
1775
1776    FreeF1SetupReq(f1apMsg);
1777
1778    return ret;
1779 }/* End of BuildAndSendF1SetupReq */
1780
1781 /*******************************************************************
1782  *
1783  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1784  *
1785  * @details
1786  *
1787  *    Function : freeCellsToModifyItem 
1788  *
1789  *    Functionality: Deallocating memory of variables allocated in
1790  *                    BuildAndSendDUConfigUpdate function
1791  *
1792  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1793  *
1794  * @return ROK     - void
1795  *
1796  * ****************************************************************/
1797
1798 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1799 {
1800    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1801    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1802    SliceSupportItem_t *sliceSupportItem = NULLP;
1803
1804    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1805    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1806
1807    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1808            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1809    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1810          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1811
1812    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1813    {
1814       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1815       {
1816          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1817
1818          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1819
1820          if(servedPlmnItem->iE_Extensions != NULLP)
1821          {
1822             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1823             {
1824                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1825                {
1826                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1827                         list.array != NULLP)
1828                   {
1829                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1830                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1831                      {
1832                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1833                               list.array[sliceLstIdx] != NULLP)
1834                         {
1835
1836                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1837                                               SliceSupportList.list.array[sliceLstIdx];
1838
1839                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1840                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1841                            {
1842                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1843                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1844                            }
1845                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1846                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1847                         }
1848                      }
1849                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1850                            choice.SliceSupportList.list.array,\
1851                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1852                            extensionValue.choice.SliceSupportList.list.size);
1853                   }
1854                }
1855                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1856                {
1857                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1858                }
1859                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1860             }
1861             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1862          }
1863       }
1864       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1865       {
1866          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1867       }
1868       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1869          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1870    }
1871    
1872    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1873    {
1874       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1875    }  
1876    else
1877    {
1878       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1879       {
1880          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1881          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1882       }
1883    }
1884    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1885       modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1886 }
1887
1888 /*******************************************************************
1889  *
1890  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1891  *
1892  * @details
1893  *
1894  *    Function : FreeDUConfigUpdate
1895  *
1896  *    Functionality: Deallocating memory of variables allocated in
1897  *                    BuildAndSendDUConfigUpdate function
1898  *
1899  * @params[in]  F1AP_PDU_t *f1apDuCfg
1900  *
1901  * @return ROK     - void
1902  *
1903  * ****************************************************************/
1904 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1905 {
1906    uint8_t  ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1907    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1908    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1909    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1910    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1911    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1912
1913    if(f1apDuCfg != NULLP)
1914    {
1915       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1916       {
1917          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1918                        value.choice.GNBDUConfigurationUpdate;
1919          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1920          {
1921             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1922             {
1923                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1924                {
1925                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1926                   {
1927                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1928                         {
1929                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1930                                            value.choice.Served_Cells_To_Modify_List;
1931                            if(cellsToModify->list.array != NULLP)
1932                            {
1933                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1934                               {
1935                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1936                                  {
1937                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1938                                           Served_Cells_To_Modify_Item);
1939                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1940                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1941                                  }
1942                               }
1943                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1944                            }
1945                            break;
1946                         }
1947                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1948                         {
1949                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1950                                            value.choice.Served_Cells_To_Delete_List;
1951                            if(cellsToDelete->list.array != NULLP)
1952                            {
1953                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1954                               {
1955                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1956                                  {
1957                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1958                                           cellsToDelete->list.array[cellDeleteIdx]);
1959                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1960                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1961                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1962                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1963                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1964                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1965                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1966                                  }
1967                               }
1968                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1969                            }
1970
1971                            break;
1972                         }
1973                      case ProtocolIE_ID_id_gNB_DU_ID:
1974                         {
1975                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1976                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1977                            break;
1978                         }
1979                   }
1980                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1981                         sizeof(GNBDUConfigurationUpdateIEs_t));
1982                }
1983             }
1984             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
1985          }
1986          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
1987       }
1988       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
1989    }
1990 }
1991
1992 /*******************************************************************
1993  *
1994  * @brief Fills Served Plmns required in ServCellInfo IE
1995  *
1996  * @details
1997  *
1998  *    Function : fillServedPlmns
1999  *
2000  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2001  *
2002  * @params[in] Pointer to ServedPLMNs_List_t *
2003  *
2004  * @return ROK     - success
2005  *         RFAILED - failure
2006  *
2007  *****************************************************************/
2008
2009 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2010 {
2011    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2012
2013    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2014    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2015          array[arrayIdx]->pLMN_Identity.size);
2016    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2017    {
2018       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2019       return RFAILED;
2020    }
2021    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2022          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2023    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2024    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2025    {
2026       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2027       return RFAILED;
2028    }
2029
2030    ieListCnt=1;
2031    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2032    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2033    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2034          iE_Extensions->list.size);
2035    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2036    {
2037       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2038       return RFAILED;
2039    }
2040    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2041    {
2042       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2043             sizeof(ServedPLMNs_ItemExtIEs_t));
2044       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2045       {
2046          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2047          return RFAILED;
2048       }
2049    }
2050    
2051    ieIdx = 0;
2052    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2053    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2054    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2055    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2056    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2057    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2058       list.count = elementCnt;
2059    servedPlmn->list.array[arrayIdx]->\
2060       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2061       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2062    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2063          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2064          list.array,servedPlmn->list.array[arrayIdx]->\
2065          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2066    if(servedPlmn->list.array[arrayIdx]->\
2067          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2068          list.array == NULLP)
2069    {
2070       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2071       return RFAILED;
2072    }
2073
2074    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2075    {
2076       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2077       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2078       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2079       if(servedPlmn->list.array[arrayIdx]->\
2080       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2081       list.array[sliceLstIdx] == NULLP)
2082       {   
2083          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2084          return RFAILED;
2085       }
2086       
2087       servedPlmn->list.array[arrayIdx]->\
2088       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2089       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2090       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2091       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2092       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2093       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2094       sNSSAI.sST.size);
2095       
2096       if(servedPlmn->list.array[arrayIdx]->\
2097       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2098       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2099       {
2100          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2101          return RFAILED;
2102       }
2103       servedPlmn->list.array[arrayIdx]->\
2104       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2105       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2106       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2107
2108       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2109       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2110       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2111       if(servedPlmn->list.array[arrayIdx]->\
2112       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2113       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2114       {
2115          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2116          return RFAILED;
2117       }
2118       servedPlmn->list.array[arrayIdx]->\
2119       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2120       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2121       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2122       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2123       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2124       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2125       list.array[sliceLstIdx]->sNSSAI.sD->size);
2126       if(servedPlmn->list.array[arrayIdx]->\
2127       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2128       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2129       {
2130          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2131          return RFAILED;
2132       }
2133       memcpy(servedPlmn->list.array[arrayIdx]->\
2134       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2135       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2136       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2137       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2138       list.array[sliceLstIdx]->sNSSAI.sD->size);
2139    }
2140    return ROK;
2141 }
2142
2143 /*******************************************************************
2144  *
2145  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2146  *
2147  * @details
2148  *
2149  *    Function : fillNrFddInfo
2150  *
2151  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2152  *
2153  * @params[in] FDD_Info_t *fDD
2154  *
2155  * @return ROK     - success
2156  *         RFAILED - failure
2157  *
2158  *****************************************************************/
2159
2160 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2161 {
2162    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2163       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2164    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2165    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2166    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2167          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2168    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2169    {
2170       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2171       return RFAILED;
2172    }
2173
2174    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2175       sizeof(FreqBandNrItem_t));
2176    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2177    {
2178       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2179       return RFAILED;
2180    }
2181    
2182    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2183       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2184       freqBand[0].nrFreqBand;
2185    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2186    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2187       dlNrFreqInfo.nrArfcn;
2188    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2189    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2190    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2191    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2192    {
2193       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2194       return RFAILED;
2195    }
2196    
2197    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2198    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2199    {
2200       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2201       return RFAILED;
2202    }
2203
2204    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2205       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2206       freqBand[0].nrFreqBand;
2207    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2208    
2209    /*Transmission Bandwidth*/
2210    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2211       f1Mode.mode.fdd.ulTxBw.nrScs;
2212    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2213       f1Mode.mode.fdd.ulTxBw.nrb;
2214    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2215       f1Mode.mode.fdd.dlTxBw.nrScs;
2216    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2217       f1Mode.mode.fdd.dlTxBw.nrb;
2218
2219    return ROK;
2220 }
2221
2222 /*******************************************************************
2223  *
2224  * @brief Fills ServCellInfo IE
2225  *
2226  * @details
2227  *
2228  *    Function : fillServedCellInfo
2229  *
2230  *    Functionality: Fills ServCellInfo
2231  *
2232  * @params[in] Pointer to Served_Cell_Information_t *
2233  *
2234  * @return ROK     - success
2235  *         RFAILED - failure
2236  *
2237  *****************************************************************/
2238
2239 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2240 {
2241    uint8_t ieIdx, ieListCnt;
2242
2243    /*nRCGI*/
2244    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2245    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2246          srvCellInfo->nRCGI.pLMN_Identity.size);
2247    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2248    {
2249       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2250       return RFAILED;
2251    }
2252    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2253          srvCellInfo->nRCGI.pLMN_Identity.buf);
2254    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2255    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2256          srvCellInfo->nRCGI.nRCellIdentity.size);
2257    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2258    {   
2259       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2260       return RFAILED;
2261    }
2262    
2263    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2264    /*nRPCI*/
2265    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2266
2267    /*servedPLMNs*/
2268    ieListCnt = 1;
2269    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2270    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2271    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2272    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2273    {
2274       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2275       return RFAILED;
2276    }
2277    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2278    {
2279       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2280       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2281       {
2282          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2283          return RFAILED;
2284       }
2285    }
2286    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2287    {
2288       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2289       return RFAILED;
2290    }
2291
2292 #ifndef NR_TDD
2293    /*nR Mode Info with FDD*/
2294    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2295    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2296    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2297    {
2298       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2299       return RFAILED;
2300    }
2301    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2302    {
2303        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2304       return RFAILED;
2305    }
2306 #else
2307    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2308    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2309    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2310    {
2311       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2312       return RFAILED;
2313    }
2314    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2315    {
2316       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2317       return RFAILED;
2318    }
2319 #endif
2320
2321    /*Measurement timing Config*/
2322    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2323       return RFAILED;
2324
2325    return ROK;
2326 }
2327
2328 /*******************************************************************
2329  *
2330  * @brief Fills ServCellToModItem IE
2331  *
2332  * @details
2333  *
2334  *    Function : fillServCellToModItem
2335  *
2336  *    Functionality: Fills ServCellToModItem IE
2337  *
2338  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2339  *
2340  * @return ROK     - success
2341  *         RFAILED - failure
2342  *
2343  *****************************************************************/
2344
2345 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2346 {
2347    /*pLMN_Identity*/
2348    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2349    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2350    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2351    {
2352       return RFAILED;
2353    }
2354    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2355          modifyItem->oldNRCGI.pLMN_Identity.buf);
2356
2357    /*nRCellIdentity*/
2358    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2359    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2360          modifyItem->oldNRCGI.nRCellIdentity.size);
2361    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2362    {
2363       return RFAILED;
2364    }
2365    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2366
2367    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2368       return RFAILED;
2369    else
2370       return ROK;
2371 }
2372
2373 /*******************************************************************
2374  *
2375  * @brief Builds ServCellToModList
2376  *
2377  * @details
2378  *
2379  *    Function : buildServCellToModList
2380  *
2381  *    Functionality: Builds the serv cell to Mod List
2382  *
2383  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2384  *
2385  * @return ROK     - success
2386  *         RFAILED - failure
2387  *
2388  *****************************************************************/
2389
2390 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2391 {
2392    uint8_t ieListCnt, ieIdx;
2393    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2394
2395    ieListCnt = 1;
2396    cellsToModify->list.count = ieListCnt;
2397    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2398    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2399    if(cellsToModify->list.array == NULLP)
2400    {
2401       return RFAILED;
2402    }
2403    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2404    {
2405       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2406       if(cellsToModify->list.array[ieIdx] == NULLP)
2407       {
2408          return RFAILED;
2409       }
2410    }
2411    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2412    cellsToModify->list.array[0]->criticality = Criticality_reject;
2413    cellsToModify->list.array[0]->value.present =\
2414       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2415    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2416
2417    if(fillServCellToModItem(modifyItem))
2418       return RFAILED;
2419    else
2420       return ROK;
2421 }
2422 /*******************************************************************
2423  *
2424  * @brief filling the DeleteItemList
2425  *
2426  * @details
2427  *
2428  *    Function : fillCellToDeleteItem 
2429  *
2430  *    Functionality: Filling the DeleteItemIe 
2431  *
2432  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2433  *
2434  * @return ROK     - success
2435  *         RFAILED - failure
2436  *
2437  *****************************************************************/
2438 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2439 {
2440    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2441    
2442    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2443    deleteItemIe->criticality = Criticality_reject;
2444    deleteItemIe->value.present =\
2445    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2446    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2447
2448    /*pLMN_Identity*/
2449    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2450    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2451    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2452    {
2453       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2454       return RFAILED;
2455    }
2456    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2457          deleteItem->oldNRCGI.pLMN_Identity.buf);
2458
2459    /*nRCellIdentity*/
2460    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2461    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2462          deleteItem->oldNRCGI.nRCellIdentity.size);
2463    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2464    {
2465       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2466       return RFAILED;
2467    }
2468    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2469    return ROK;
2470
2471 /*******************************************************************
2472  *
2473  * @brief Builds ServCellToDeleteList
2474  *
2475  * @details
2476  *
2477  *    Function : buildServCellToDeleteList
2478  *
2479  *    Functionality: Builds the serv cell to delete List
2480  *
2481  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2482  *
2483  * @return ROK     - success
2484  *         RFAILED - failure
2485  *
2486  *****************************************************************/
2487  
2488 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2489 {
2490    uint8_t ieListCnt, arrIdx;
2491    
2492    ieListCnt = 1;
2493    cellsToDelete->list.count = ieListCnt;
2494    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2495    
2496    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2497    if(cellsToDelete->list.array == NULLP)
2498    {
2499       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2500       return RFAILED;
2501    }
2502    
2503    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2504    {
2505       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2506       if(cellsToDelete->list.array[arrIdx] == NULLP)
2507       {
2508          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2509          return RFAILED;
2510       }
2511    }
2512    
2513    arrIdx=0;
2514    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2515    {
2516       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2517       return RFAILED;
2518    }
2519    return ROK;
2520 }
2521
2522 /*******************************************************************
2523  *
2524  * @brief Builds and sends the DUConfigUpdate
2525  *
2526  * @details
2527  *
2528  *    Function : BuildAndSendDUConfigUpdate
2529  *
2530  *    Functionality: Constructs the DU Update message and sends
2531  *                   it to the CU through SCTP.
2532  *
2533  * @params[in] void **buf,Buffer to which encoded pattern is written into
2534  * @params[in] int *size,size of buffer
2535  *
2536  * @return ROK     - success
2537  *         RFAILED - failure
2538  *
2539  * ****************************************************************/
2540 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2541 {
2542    uint8_t ret =0, ieIdx=0, elementCnt=0;
2543    bool memAlloctionFailure = false;
2544    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2545    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2546    asn_enc_rval_t encRetVal;     /* Encoder return value */
2547    
2548    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2549    ret= RFAILED;
2550
2551    while(true)
2552    {
2553       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2554       /* Allocate the memory for F1DuCfg */
2555       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2556       if(f1apDuCfg == NULLP)
2557       {
2558          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2559          break;
2560       }
2561
2562       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2563       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2564       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2565       {
2566          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2567          break;
2568       }
2569
2570       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2571                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2572       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2573       f1apDuCfg->choice.initiatingMessage->value.present = \
2574                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2575       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2576                     choice.GNBDUConfigurationUpdate;
2577       elementCnt = 3;
2578       duCfgUpdate->protocolIEs.list.count = elementCnt;
2579       duCfgUpdate->protocolIEs.list.size = \
2580                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2581
2582       /* Initialize the F1Setup members */
2583       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2584       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2585       {
2586          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2587          break;
2588       }
2589       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2590       {
2591          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2592          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2593          {
2594             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2595             memAlloctionFailure = true;
2596             break;
2597          }
2598       }
2599       
2600       if(memAlloctionFailure == true)
2601       {
2602          break;
2603       }
2604       /*TransactionID*/
2605       ieIdx = 0;
2606       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2607       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2608       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2609       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2610       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2611       
2612       ieIdx++;
2613       if(servCellAction == SERV_CELL_TO_MODIFY)
2614       {
2615          /*Served Cell to Modify */
2616          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2617          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2618          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2619          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2620          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2621          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2622                   Served_Cells_To_Modify_List))
2623          {
2624             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2625             break;
2626          }
2627       }
2628       else
2629       {
2630          /*Served Cell to Delete */ 
2631          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2632          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2633          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2634          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2635          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2636          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2637          Served_Cells_To_Delete_List)!=ROK)
2638          {
2639             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2640             break;
2641          }
2642          
2643       }
2644       // NOTE :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2645       /*GNB DU ID */
2646       ieIdx++;
2647       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2648       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2649       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2650       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2651       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2652       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2653             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2654       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2655       {
2656          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2657          break;
2658       }
2659       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2660
2661       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2662
2663       /* Encode the DU Config Update type as APER */
2664       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2665       encBufSize = 0;
2666       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2667
2668       /* Checking encode results */
2669       if(encRetVal.encoded == ENCODE_FAIL)
2670       {
2671          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2672                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2673          break;
2674       }
2675       else
2676       {
2677          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2678 #ifdef DEBUG_ASN_PRINT
2679          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2680          {
2681             printf("%x",encBuf[ieIdx]);
2682          }
2683 #endif
2684       }
2685       /* Sending msg */
2686       if(sendF1APMsg() != ROK)
2687       {
2688          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2689          break;
2690       }
2691
2692       ret = ROK;
2693       break;
2694    }
2695   
2696    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2697    return ret;
2698 }
2699
2700
2701 /*******************************************************************
2702  *
2703  * @brief free the ULRRCMessageTransfer
2704  *
2705  * @details
2706  *
2707  *    Function : FreeULRRCMessageTransfer
2708  *
2709  *    Functionality: Deallocating the memory of variable allocated in
2710  *                      FreeULRRCMessageTransfer
2711  *
2712  * @params[in]
2713  *
2714  * @return ROK     - void
2715  *
2716  ******************************************************************/
2717 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2718 {
2719    uint8_t idx1;
2720    ULRRCMessageTransfer_t  *ulRRCMsg;
2721
2722    if(f1apMsg != NULLP)
2723    { 
2724       if(f1apMsg->choice.initiatingMessage != NULLP)
2725       {
2726          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2727          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2728          {
2729             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2730             {
2731                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2732                {
2733                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2734                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2735                   {
2736                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2737                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2738                   }
2739                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2740                }
2741             }
2742             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2743          }
2744          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2745       }
2746       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2747    }
2748 }
2749 /*******************************************************************
2750  *
2751  * @brief Builds and sends the ULRRCMessageTransfer 
2752  *
2753  * @details
2754  *
2755  *    Function : BuildAndSendULRRCMessageTransfer
2756  *
2757  *    Functionality: Constructs the UL RRC Message Transfer and sends
2758  *                   it to the CU through SCTP.
2759  *
2760  * @params[in] 
2761  *
2762  * @return ROK     - success
2763  *         RFAILED - failure
2764  *
2765  * ****************************************************************/
2766 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2767       uint16_t msgLen, uint8_t *rrcMsg)
2768 {
2769    uint8_t                 elementCnt=0, idx1=0, idx=0;
2770    uint8_t                 ret = RFAILED;
2771    F1AP_PDU_t              *f1apMsg = NULLP;
2772    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2773    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2774    
2775    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2776
2777    while(true)
2778    {
2779       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2780
2781       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2782       if(f1apMsg == NULLP)
2783       {
2784          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2785          break;
2786       }
2787       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2788       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2789       if(f1apMsg->choice.initiatingMessage == NULLP)
2790       {
2791          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2792          break;
2793       }
2794       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2795       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2796       f1apMsg->choice.initiatingMessage->value.present = \
2797                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2798       ulRRCMsg =
2799          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2800       elementCnt = 4;
2801       ulRRCMsg->protocolIEs.list.count = elementCnt;
2802       ulRRCMsg->protocolIEs.list.size = \
2803                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2804
2805       /* Initialize the F1Setup members */
2806       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2807       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2808       {
2809          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2810          break;
2811       }
2812       for(idx=0; idx<elementCnt; idx++)
2813       {
2814          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2815          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2816          {
2817             break;
2818          }
2819       }
2820
2821       idx1 = 0;
2822
2823       /*GNB CU UE F1AP ID*/
2824       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2825       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2826       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2827                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2828       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2829
2830       /*GNB DU UE F1AP ID*/
2831       idx1++;
2832       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2833       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2834       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2835                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2836       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2837
2838       /*SRBID*/
2839       idx1++;
2840       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2841       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2842       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2843                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2844       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2845
2846       /*RRCContainer*/
2847       idx1++;
2848       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2849       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2850       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2851                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2852       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2853       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2854             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2855       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2856       {
2857          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2858          break;
2859       }
2860       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2861       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2862             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2863
2864       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2865
2866       /* Encode the F1SetupRequest type as APER */
2867       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2868       encBufSize = 0;
2869       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2870             encBuf);
2871       /* Encode results */
2872       if(encRetVal.encoded == ENCODE_FAIL)
2873       {
2874          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2875                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2876          break;
2877       }
2878       else
2879       {
2880          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2881 #ifdef DEBUG_ASN_PRINT
2882          for(int i=0; i< encBufSize; i++)
2883          {
2884             printf("%x",encBuf[i]);
2885          }
2886 #endif
2887       }
2888
2889       /* Sending  msg  */
2890       if(sendF1APMsg()  !=      ROK)
2891       {
2892          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2893          break;
2894       }
2895       ret = ROK;
2896       break;
2897    }
2898    FreeULRRCMessageTransfer(f1apMsg);
2899
2900    return ret;
2901 }/* End of BuildAndSendULRRCMessageTransfer*/
2902
2903 /*******************************************************************
2904  *
2905  * @brief Builds tag config 
2906  *
2907  * @details
2908  *
2909  *    Function : BuildTagConfig 
2910  *
2911  *    Functionality: Builds tag config in MacCellGroupConfig
2912  *
2913  * @params[in] TAG_Config *tag_Config
2914  *
2915  * @return ROK     - success
2916  *         RFAILED - failure
2917  *
2918  * ****************************************************************/
2919 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2920 {
2921    struct TAG_Config__tag_ToAddModList *tagList;
2922    uint8_t                     idx, elementCnt;
2923
2924    tagConfig->tag_ToReleaseList = NULLP;
2925    tagConfig->tag_ToAddModList = NULLP;
2926    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2927    if(!tagConfig->tag_ToAddModList)
2928    {
2929       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2930       return RFAILED;
2931    }
2932
2933    if(ueCb == NULLP)
2934       elementCnt = ODU_VALUE_ONE;
2935    else
2936       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2937
2938    tagList = tagConfig->tag_ToAddModList;
2939    tagList->list.count = elementCnt;
2940    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2941
2942    tagList->list.array = NULLP;
2943    DU_ALLOC(tagList->list.array, tagList->list.size);
2944    if(!tagList->list.array)
2945    {
2946       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2947       return RFAILED;
2948    }
2949
2950    for(idx=0; idx<tagList->list.count; idx++)
2951    {
2952       tagList->list.array[idx] = NULLP;
2953       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2954       if(!tagList->list.array[idx])
2955       {
2956          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2957          return RFAILED;
2958       }
2959    }
2960
2961    if(ueCb == NULLP)
2962    {
2963       idx = 0;
2964       tagList->list.array[idx]->tag_Id = TAG_ID;
2965       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2966    }
2967    else
2968    {
2969       for(idx=0; idx<tagList->list.count; idx++)
2970       {
2971          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2972          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2973       }
2974    }
2975
2976    return ROK;
2977 }
2978
2979 /*******************************************************************
2980  *
2981  * @brief Builds PHR Config 
2982  *
2983  * @details
2984  *
2985  *    Function : BuildPhrConfig
2986  *
2987  *    Functionality: Builds phrConfig in MacCellGroupConfig
2988  *
2989  * @params[in] PHR Config *
2990  *
2991  * @return ROK     - success
2992  *         RFAILED - failure
2993  *
2994  * ****************************************************************/
2995 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2996 {
2997
2998    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2999    phrConfig->choice.setup = NULLP;
3000    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3001    if(!phrConfig->choice.setup)
3002    {
3003       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3004       return RFAILED;
3005    }
3006
3007    if(ueCb == NULLP)
3008    {
3009       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3010       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3011       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3012       phrConfig->choice.setup->multiplePHR              = false;
3013       phrConfig->choice.setup->dummy                    = false;
3014       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3015       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3016    }
3017    else
3018    {
3019       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3020       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3021       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3022       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3023       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3024       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3025       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3026    }
3027
3028    return ROK;
3029 }
3030
3031 /*******************************************************************
3032  *
3033  * @brief Builds BSR Config 
3034  *
3035  * @details
3036  *
3037  *    Function : BuildBsrConfig
3038  *
3039  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3040  *
3041  * @params[in] BSR_Config *bsrConfig
3042  *
3043  * @return ROK     - success
3044  *         RFAILED - failure
3045  *
3046  * ****************************************************************/
3047 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3048 {
3049    if(ueCb == NULLP)
3050    {
3051       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3052       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3053       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3054    }
3055    else
3056    {
3057       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3058       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3059
3060       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3061       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3062       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3063       {
3064          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3065          return RFAILED;
3066       }
3067       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3068    }
3069
3070    return ROK;
3071 }
3072
3073 /*******************************************************************
3074  *
3075  * @brief Builds scheduling request config 
3076  *
3077  * @details
3078  *
3079  *    Function : BuildSchedulingReqConfig 
3080  *
3081  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3082  *
3083  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3084  *
3085  * @return ROK     - success
3086  *         RFAILED - failure
3087  *
3088  * ****************************************************************/
3089 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3090 {
3091    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3092    uint8_t                     idx, elementCnt;
3093
3094    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3095    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3096          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3097    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3098    {
3099       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3100       return RFAILED;
3101    }
3102
3103    if(ueCb == NULLP)
3104       elementCnt = ODU_VALUE_ONE;
3105    else
3106       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3107
3108    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3109    schReqList->list.count = elementCnt;
3110    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3111
3112    schReqList->list.array = NULLP;
3113    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3114    if(!schReqList->list.array)
3115    {
3116       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3117       return RFAILED;
3118    }
3119
3120    for(idx=0; idx<schReqList->list.count; idx++)
3121    {
3122       schReqList->list.array[idx] = NULLP;
3123       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3124       if(!schReqList->list.array[idx])
3125       {
3126          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3127          return RFAILED;
3128       }
3129    }
3130
3131    if(ueCb == NULLP)
3132    {
3133       idx = 0;
3134       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3135
3136       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3137       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3138       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3139       {
3140          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3141          return RFAILED;
3142       }
3143       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3144       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3145    }
3146    else
3147    {
3148       for(idx=0; idx<schReqList->list.count; idx++)
3149       {
3150          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3151
3152          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3153          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3154          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3155          {
3156             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3157             return RFAILED;
3158          }
3159          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3160          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3161       }
3162    }
3163
3164    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3165
3166    return ROK;
3167 }
3168
3169 /*******************************************************************
3170  *
3171  * @brief Builds RLC Configuration for AM mode
3172  *
3173  * @details
3174  *
3175  *    Function : BuildRlcConfigAm
3176  *
3177  *    Functionality: 
3178  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3179  *
3180  * @params[in] AmBearerCfg *amCfg
3181  *             RLC_Config_t  *rlcConfig
3182  *
3183  * @return ROK     - success
3184  *         RFAILED - failure
3185  *
3186  * ****************************************************************/
3187 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3188 {
3189    rlcConfig->choice.am = NULLP;
3190    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3191    if(!rlcConfig->choice.am)
3192    {
3193       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3194       return RFAILED;
3195    }
3196
3197    /* Fill AM UL configuration */
3198    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3199    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3200    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3201    {
3202       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3203       return RFAILED;
3204    }
3205
3206    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3207    if(amCfg == NULLP)
3208    {
3209       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3210       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3211       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3212       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3213       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3214    }
3215    else
3216    {
3217       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3218       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3219       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3220       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3221       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3222    }
3223
3224    /* Fill AM DL configuraion */
3225    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3226    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3227    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3228    {
3229       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3230       return RFAILED;
3231    }
3232
3233    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3234    if(amCfg == NULLP)
3235    {
3236       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3237       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3238       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3239    }
3240    else /* Fill AM configuration from DU database */
3241    {
3242       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3243       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3244       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3245    }
3246    return ROK;
3247 }
3248
3249 /*******************************************************************
3250  *
3251  * @brief Builds RLC Config for UM Bidirection
3252  *
3253  * @details
3254  *
3255  *    Function : BuildRlcConfig UmBiDir
3256  *
3257  *    Functionality: 
3258  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3259  *
3260  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3261  *             RLC_Config_t *rlcConfig
3262  *
3263  * @return ROK     - success
3264  *         RFAILED - failure
3265  *
3266  * ****************************************************************/
3267 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3268 {
3269    rlcConfig->choice.um_Bi_Directional = NULLP;
3270    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3271    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3272    {
3273       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3274       return RFAILED;
3275    }
3276
3277    /* Fill UM Bidirectional UL configuration */
3278    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3279    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3280    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3281    {
3282       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3283       return RFAILED;
3284    }
3285
3286    if(umBiDirCfg != NULLP)
3287    {
3288       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3289    }
3290
3291    /* Fill UM Bidirectional DL configuration */
3292    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3293    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3294    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3295    {
3296       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3297       return RFAILED;
3298    }
3299
3300    if(umBiDirCfg != NULLP)
3301    {
3302       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3303       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3304    }
3305
3306    return ROK;
3307 }
3308
3309 /*******************************************************************
3310  *
3311  * @brief Builds RLC Config for UM Uni directional UL
3312  *
3313  * @details
3314  *
3315  *    Function : BuildRlcConfigUmUniDirUl
3316  *
3317  *    Functionality: 
3318  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3319  *
3320  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3321  *             RLC_Config_t *rlcConfig
3322  *
3323  * @return ROK     - success
3324  *         RFAILED - failure
3325  *
3326  * ****************************************************************/
3327 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3328 {
3329    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3330    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3331    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3332    {
3333       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3334       return RFAILED;
3335    }
3336
3337    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3338    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3339    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3340    {
3341       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3342       return RFAILED;
3343    }
3344
3345    if(umUniDirDlCfg != NULLP)
3346    {
3347       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3348    }
3349
3350    return ROK;
3351 }
3352
3353 /*******************************************************************
3354  *
3355  * @brief Builds RLC Config for UM Uni directional DL
3356  *
3357  * @details
3358  *
3359  *    Function : BuildRlcConfigUmUniDirDl
3360  *
3361  *    Functionality: 
3362  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3363  *
3364  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3365  *             RLC_Config_t *rlcConfig
3366  *
3367  * @return ROK     - success
3368  *         RFAILED - failure
3369  *
3370  * ****************************************************************/
3371 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3372 {
3373    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3374    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3375    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3376    {
3377       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3378       return RFAILED;
3379    }
3380
3381    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3382    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3383    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3384    {
3385       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3386       return RFAILED;
3387    }
3388
3389    if(umUniDirUlCfg != NULLP)
3390    {
3391       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3392       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3393    }
3394
3395    return ROK;
3396 }
3397
3398 /*******************************************************************
3399  *
3400  * @brief Builds RLC Config
3401  *
3402  * @details
3403  *
3404  *    Function : BuildRlcConfig
3405  *
3406  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3407  *
3408  * @params[in] RLC_Config_t *rlcConfig
3409  *
3410  * @return ROK     - success
3411  *         RFAILED - failure
3412  *
3413  * ****************************************************************/
3414 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3415 {
3416    
3417    /* Fill default values if rbCfg is NULL */
3418    if(rbCfg == NULLP)
3419    {
3420       rlcConfig->present = RLC_Config_PR_am;
3421       BuildRlcConfigAm(NULLP, rlcConfig);
3422    }
3423    /* If RbCfg is present, fill RLC configurations from DU Database */
3424    else
3425    {
3426       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3427       switch(rlcConfig->present)
3428       {
3429          case RLC_Config_PR_am:
3430             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3431             break;
3432          case RLC_Config_PR_um_Bi_Directional:
3433             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3434             break;
3435          case RLC_Config_PR_um_Uni_Directional_UL:
3436             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3437             break;
3438          case RLC_Config_PR_um_Uni_Directional_DL:
3439             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3440             break;
3441          case RLC_Config_PR_NOTHING:
3442          default:
3443             break;
3444       }
3445    }
3446
3447    return ROK;
3448 }
3449
3450 /*******************************************************************
3451  *
3452  * @brief Builds MAC LC Config
3453  *
3454  * @details
3455  *
3456  *    Function : BuildMacLCConfig 
3457  *
3458  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3459  *
3460  * @params[in] struct LogicalChannelConfig macLcConfig
3461  *
3462  * @return ROK     - success
3463  *         RFAILED - failure
3464  *
3465  * ****************************************************************/
3466 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3467 {
3468    macLcConfig->ul_SpecificParameters = NULLP;
3469    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3470    if(!macLcConfig->ul_SpecificParameters)
3471    {
3472       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3473       return RFAILED;
3474    }
3475
3476    if(lcCfgDb == NULLP)
3477    {
3478       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3479       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3480       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3481    }
3482    else
3483    {
3484       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3485       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3486       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3487    }
3488
3489    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3490    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3491    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3492    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3493
3494    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3495    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3496    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3497    {
3498       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3499       return RFAILED;
3500    }
3501
3502    if(lcCfgDb == NULLP)
3503       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3504    else
3505       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3506
3507    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3508    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3509    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3510    {
3511       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3512       return RFAILED;
3513    }
3514
3515    if(lcCfgDb == NULLP)
3516       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3517    else
3518       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3519
3520    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3521    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3522    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3523
3524    return ROK;
3525 }
3526
3527 /*******************************************************************
3528  *
3529  * @brief Builds RLC Bearer to Add/Mod list
3530  *
3531  * @details
3532  *
3533  *    Function :BuildRlcBearerToAddModList 
3534  *
3535  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3536  *
3537  * @params[in] rlc_BearerToAddModList
3538  *
3539  * @return ROK     - success
3540  *         RFAILED - failure
3541  *
3542  * ****************************************************************/
3543 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3544 {
3545    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3546
3547    if(ueCb == NULLP)
3548       elementCnt = 1;
3549    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3550       elementCnt = ueCb->duRlcUeCfg.numLcs;
3551    else
3552    {
3553       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3554       {
3555          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3556             elementCnt++;
3557       }
3558    }
3559    rlcBearerList->list.count = elementCnt;
3560    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3561
3562    rlcBearerList->list.array = NULLP;
3563    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3564    if(!rlcBearerList->list.array)
3565    {
3566       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3567       return RFAILED;
3568    }
3569
3570    for(idx=0; idx<rlcBearerList->list.count; idx++)
3571    {
3572       rlcBearerList->list.array[idx] = NULLP;
3573       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3574       if(!rlcBearerList->list.array[idx])
3575       {
3576          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3577          return RFAILED;
3578       }
3579    }
3580
3581    if(ueCb == NULLP)
3582    {
3583       idx=0;
3584       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3585       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3586       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3587       {     
3588          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3589          return RFAILED;
3590       }     
3591       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3592       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3593       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3594
3595       /* Fill RLC related Configurations for this Radio Bearer */
3596       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3597       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3598       if(!rlcBearerList->list.array[idx]->rlc_Config)
3599       {
3600          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3601          return RFAILED;
3602       }
3603       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3604       {
3605          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3606          return RFAILED;
3607       }
3608
3609       /* Fill MAC related configurations for this Radio Bearer */
3610       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3611       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3612       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3613       {
3614          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3615          return RFAILED;
3616       }
3617       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3618       {
3619          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3620          return RFAILED;
3621       }
3622    }
3623    else
3624    {
3625       idx=0;
3626       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3627       {
3628          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3629             continue;
3630
3631          /* Fill Logical channel identity */
3632          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3633
3634          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3635          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3636          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3637          {
3638             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3639             return RFAILED;
3640          }
3641          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3642                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3643          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3644          {
3645             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3646                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3647                break;
3648             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3649                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3650                break;
3651             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3652             default:
3653                break;
3654          }
3655          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3656
3657          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3658
3659          /* Fill RLC related Configurations for this Radio Bearer */
3660          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3661          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3662          if(!rlcBearerList->list.array[idx]->rlc_Config)
3663          {
3664             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3665             return RFAILED;
3666          }
3667          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3668          {
3669             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3670             return RFAILED;
3671          }
3672
3673          /* Fill MAC related configurations for this Radio Bearer */
3674          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3675          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3676          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3677          {
3678             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3679             return RFAILED;
3680          }
3681          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3682          {
3683             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3684             {
3685                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3686                {
3687                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3688                   return RFAILED;
3689                }
3690                break;
3691             }
3692          }
3693
3694          idx++;
3695       }
3696    }
3697    return ROK;
3698 }
3699
3700 /*******************************************************************
3701  *
3702  * @brief Build Control resource set to add/modify list 
3703  *
3704  * @details
3705  *
3706  *    Function : BuildControlRSetToAddModList
3707  *
3708  *    Functionality: Build Control resource set to add/modify list
3709  *
3710  * @params[in] 
3711  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3712  *
3713  * @return ROK     - success
3714  *         RFAILED - failure
3715  *
3716  * ****************************************************************/
3717 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3718 {
3719    uint8_t idx;
3720    uint8_t elementCnt;
3721    uint8_t numBytes, bitsUnused;
3722    struct ControlResourceSet *controlRSet;
3723    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3724    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3725
3726    if(pdcchCfg == NULLP)
3727       elementCnt = 1;
3728    else
3729       elementCnt = pdcchCfg->numCRsetToAddMod;
3730
3731    controlRSetList->list.count = elementCnt;
3732    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3733
3734    controlRSetList->list.array = NULLP;
3735    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3736    if(!controlRSetList->list.array)
3737    {
3738       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3739       return RFAILED;
3740    }
3741
3742    for(idx = 0; idx < elementCnt; idx++)
3743    {
3744       controlRSetList->list.array[idx] = NULLP;
3745       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3746       if(!controlRSetList->list.array[idx])
3747       {
3748          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3749          return RFAILED;
3750       }
3751    }
3752
3753    for(idx = 0; idx < elementCnt; idx++)
3754    {
3755       controlRSet = controlRSetList->list.array[idx];
3756
3757       if(pdcchCfg == NULLP)
3758          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3759       else
3760          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3761
3762       /* size 6 bytes
3763        * 3 LSBs unsued
3764        * Bit string stored ff0000000000
3765        */
3766       numBytes = 6;
3767       bitsUnused = 3;
3768       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3769
3770       controlRSet->frequencyDomainResources.buf = NULLP;
3771       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3772       if(!controlRSet->frequencyDomainResources.buf)
3773       {
3774          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3775          return RFAILED;
3776       }
3777
3778       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3779
3780       if(pdcchCfg == NULLP)
3781       {
3782          coreset0EndPrb = CORESET0_END_PRB;
3783          coreset1StartPrb = coreset0EndPrb + 6;
3784          coreset1NumPrb = CORESET1_NUM_PRB;
3785          /* calculate the PRBs */
3786          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3787          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3788          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3789
3790          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3791          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3792          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3793       }
3794       else
3795       {
3796          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3797          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3798          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3799          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3800          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3801       }
3802       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3803       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3804       controlRSet->tci_PresentInDCI = NULLP;
3805
3806 #if 0
3807       uint8_t tciStateIdx;
3808
3809       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3810             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3811       if(!controlRset->tci_StatesPDCCH_ToAddList)
3812       {
3813          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3814          return RFAILED;
3815       }
3816
3817       elementCnt = 1;
3818       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3819       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3820       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3821             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3822          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3823          {
3824             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3825             return RFAILED;
3826          }
3827
3828       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3829       {
3830          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3831          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3832          {
3833             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3834             return RFAILED;
3835          }
3836       }
3837
3838       tciStateIdx = 0;
3839       /* TODO */
3840       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3841
3842       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3843       if(!controlRset->tci_PresentInDCI)
3844       {
3845          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3846          return RFAILED;
3847       }
3848       /* TODO */
3849       *(controlRset->tci_PresentInDCI);
3850 #endif
3851
3852       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3853       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3854       if(!controlRSet->pdcch_DMRS_ScramblingID)
3855       {
3856          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3857          return RFAILED;
3858       }
3859       if(pdcchCfg == NULLP)
3860          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3861       else
3862          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3863    }
3864    return ROK;
3865 } /* End BuildControlRSetToAddModList */
3866
3867 /*******************************************************************
3868  *
3869  * @brief Build search space to add/modify list
3870  *
3871  * @details
3872  *
3873  *    Function : BuildSearchSpcToAddModList
3874  *
3875  *    Functionality: Build search space to add/modify list
3876  *
3877  * @params[in] 
3878  * @return ROK     - success
3879  *         RFAILED - failure
3880  *
3881  * ****************************************************************/
3882 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3883 {
3884    uint8_t idx;
3885    uint8_t numBytes;
3886    uint8_t byteIdx;
3887    uint8_t bitsUnused;
3888    uint8_t elementCnt;
3889    struct SearchSpace *searchSpc;
3890
3891    if(pdcchCfg == NULLP)
3892       elementCnt = 1;
3893    else
3894       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3895
3896    searchSpcList->list.count = elementCnt;
3897    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3898
3899    searchSpcList->list.array = NULLP;
3900    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3901    if(!searchSpcList->list.array)
3902    {
3903       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3904       return RFAILED;
3905    }
3906
3907    for(idx = 0; idx < elementCnt; idx++)
3908    {
3909       searchSpcList->list.array[idx] = NULLP;
3910       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3911       if(!searchSpcList->list.array[idx])
3912       {
3913          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3914          return RFAILED;
3915       }
3916    }
3917
3918    for(idx = 0; idx < elementCnt; idx++)
3919    {
3920       searchSpc = searchSpcList->list.array[idx];
3921
3922       if(pdcchCfg == NULLP)
3923          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3924       else
3925          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3926
3927       searchSpc->controlResourceSetId = NULLP;
3928       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3929       if(!searchSpc->controlResourceSetId)
3930       {
3931          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3932          return RFAILED;
3933       }
3934       if(pdcchCfg == NULLP)
3935          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3936       else
3937          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3938
3939       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3940       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3941       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3942       {
3943          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3944          return RFAILED;
3945       }
3946       if(pdcchCfg == NULLP)
3947          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3948       else
3949          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3950
3951       searchSpc->duration = NULLP;
3952       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3953       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3954       if(!searchSpc->monitoringSymbolsWithinSlot)
3955       {
3956          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3957          return RFAILED;
3958       }
3959
3960       /* Values taken from reference logs :
3961        * size 2 bytes
3962        * 2 LSBs unsued
3963        * Bit string stores 8000
3964        */
3965       numBytes = 2;
3966       bitsUnused = 2;
3967       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3968       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3969       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3970       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3971       {
3972          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3973          return RFAILED;
3974       }
3975       if(pdcchCfg == NULLP)
3976       {
3977          byteIdx = 0;
3978          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3979          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3980       }
3981       else
3982          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3983       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3984
3985       searchSpc->nrofCandidates = NULLP;
3986       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3987       if(!searchSpc->nrofCandidates)
3988       {
3989          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3990          return RFAILED;
3991       }
3992
3993       if(pdcchCfg == NULLP)
3994       {
3995          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3996          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3997          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3998          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3999          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4000       }
4001       else
4002       {
4003          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4004          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4005          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4006          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4007          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4008       }
4009
4010       searchSpc->searchSpaceType = NULLP;
4011       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4012       if(!searchSpc->searchSpaceType)
4013       {
4014          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4015          return RFAILED;
4016       }
4017       if(pdcchCfg == NULLP)
4018          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4019       else
4020          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4021
4022       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4023       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4024       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4025       {
4026          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4027          return RFAILED;
4028       }  
4029       if(pdcchCfg == NULLP)
4030          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4031       else
4032          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4033    }
4034    return ROK;
4035 }/* End BuildSearchSpcToAddModList */
4036
4037 /*******************************************************************
4038  *
4039  * @brief Builds BWP DL dedicated PDCCH config
4040  *
4041  * @details
4042  *
4043  *    Function : BuildBWPDlDedPdcchCfg
4044  *
4045  *    Functionality: Builds BWP DL dedicated PDCCH config
4046  *
4047  * @params[in] struct PDCCH_Config *pdcchCfg
4048  *
4049  * @return ROK     - success
4050  *         RFAILED - failure
4051  *
4052  * ****************************************************************/
4053 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4054 {
4055    pdcchCfg->controlResourceSetToAddModList = NULLP;
4056    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4057    if(!pdcchCfg->controlResourceSetToAddModList)
4058    {
4059       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4060       return RFAILED;
4061    }
4062
4063    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4064    {
4065       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4066       return RFAILED;
4067    }
4068
4069    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4070
4071    pdcchCfg->searchSpacesToAddModList = NULLP;
4072    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4073    if(!pdcchCfg->searchSpacesToAddModList)
4074    {
4075       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4076       return RFAILED;
4077    }
4078
4079    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4080    {
4081       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4082       return RFAILED;
4083    }
4084
4085    pdcchCfg->searchSpacesToReleaseList = NULLP;
4086    pdcchCfg->downlinkPreemption = NULLP;
4087    pdcchCfg->tpc_PUSCH = NULLP;
4088    pdcchCfg->tpc_PUCCH = NULLP;
4089    pdcchCfg->tpc_SRS = NULLP;
4090
4091    return ROK;
4092 }
4093
4094 /*******************************************************************
4095  *
4096  * @brief Builds DMRS DL PDSCH Mapping type A
4097  *
4098  * @details
4099  *
4100  *    Function : BuildDMRSDLPdschMapTypeA
4101  *
4102  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4103  *
4104  * @params[in]
4105  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4106  * @return ROK     - success
4107  *         RFAILED - failure
4108  *
4109  * ****************************************************************/
4110 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4111 {
4112    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4113    dmrsDlCfg->choice.setup = NULLP;
4114    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4115    if(!dmrsDlCfg->choice.setup)
4116    {
4117       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4118       return RFAILED;
4119    }
4120
4121    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4122    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4123    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4124    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4125    {
4126       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4127       return RFAILED;
4128    }
4129    if(pdschCfg == NULLP)
4130       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4131    else
4132       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4133
4134    dmrsDlCfg->choice.setup->maxLength = NULLP;
4135    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4136    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4137    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4138
4139    return ROK;
4140 }
4141
4142 /*******************************************************************
4143  *
4144  * @brief Builds TCI states to add/modify list
4145  *
4146  * @details
4147  *
4148  *    Function : BuildTCIStatesToAddModList
4149  *
4150  *    Functionality:Builds TCI states to add/modify list
4151  *
4152  * @params[in] 
4153  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4154  *
4155  * @return ROK     - success
4156  *         RFAILED - failure
4157  *
4158  * ****************************************************************/
4159 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4160 {
4161    return ROK;
4162 }
4163
4164 /*******************************************************************
4165  *
4166  * @brief Builds PDSCH time domain allocation list
4167  *
4168  * @details
4169  *
4170  *    Function : BuildPdschTimeDomAllocList
4171  *
4172  *    Functionality: Builds PDSCH time domain allocation list
4173  *
4174  * @params[in] 
4175  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4176  *
4177  * @return ROK     - success
4178  *         RFAILED - failure
4179  *
4180  * ****************************************************************/
4181 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4182 {
4183    uint8_t idx;
4184    uint8_t elementCnt;
4185    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4186
4187    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4188
4189    timeDomAllocList->choice.setup = NULLP;
4190    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4191    if(!timeDomAllocList->choice.setup)
4192    {
4193       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4194       return RFAILED;
4195    }
4196
4197 if(pdschCfg == NULLP)
4198    elementCnt = 2;
4199 else
4200 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4201    timeDomAllocList->choice.setup->list.count = elementCnt;
4202    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4203
4204    timeDomAllocList->choice.setup->list.array = NULLP;
4205    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4206    if(!timeDomAllocList->choice.setup->list.array)
4207    {
4208       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4209       return RFAILED;
4210    }
4211
4212    for(idx = 0; idx < elementCnt; idx++)
4213    {
4214       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4215       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4216             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4217       if(!timeDomAllocList->choice.setup->list.array[idx])
4218       {
4219          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4220          return RFAILED;
4221       }
4222    }
4223
4224    if(pdschCfg == NULLP)
4225    {
4226       idx = 0;
4227       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4228       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4229       if(!timeDomAlloc->k0)
4230       {
4231          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4232          return RFAILED;
4233       }
4234       *(timeDomAlloc->k0) = 0;
4235       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4236       timeDomAlloc->startSymbolAndLength = \
4237                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4238
4239       idx++;
4240       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4241       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4242       if(!timeDomAlloc->k0)
4243       {
4244          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4245          return RFAILED;
4246       }
4247       *(timeDomAlloc->k0) = 1;
4248       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4249       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4250    }
4251    else
4252    {
4253       for(idx = 0; idx < elementCnt; idx++)
4254       {
4255          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4256          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4257          {
4258             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4259             if(!timeDomAlloc->k0)
4260             {
4261                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4262                return RFAILED;
4263             }
4264             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4265          }
4266          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4267          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4268       }
4269    }
4270
4271    return ROK;
4272 }
4273
4274 /*******************************************************************
4275  *
4276  * @brief Builds PDSCH PRB Bundling type
4277  *
4278  * @details
4279  *
4280  *    Function : BuildPdschPrbBundlingType
4281  *
4282  *    Functionality: Builds PDSCH PRB Bundling type
4283  *
4284  * @params[in] 
4285  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4286  *
4287  * @return ROK     - success
4288  *         RFAILED - failure
4289  *
4290  * ****************************************************************/
4291 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4292 {
4293    if(pdschCfg == NULLP)
4294       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4295    else
4296       prbBndlType->present = pdschCfg->bundlingType;
4297
4298    prbBndlType->choice.staticBundling = NULLP;
4299    DU_ALLOC(prbBndlType->choice.staticBundling, \
4300          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4301    if(!prbBndlType->choice.staticBundling)
4302    {
4303       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4304       return RFAILED;
4305    }
4306    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4307
4308    return ROK;
4309 }
4310
4311 /*******************************************************************
4312  *
4313  * @brief Builds BWP DL dedicated PDSCH config 
4314  *
4315  * @details
4316  *
4317  *    Function : BuildBWPDlDedPdschCfg
4318  *
4319  *    Functionality: Builds BWP DL dedicated PDSCH config
4320  *
4321  * @params[in] struct PDSCH_Config *pdschCfg
4322  *
4323  * @return ROK     - success
4324  *         RFAILED - failure
4325  *
4326  * ****************************************************************/
4327 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4328 {
4329    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4330
4331    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4332    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4333    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4334    {
4335       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4336       return RFAILED;
4337    }
4338
4339    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4340    {
4341       return RFAILED;
4342    }
4343
4344    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4345    pdschCfg->tci_StatesToAddModList = NULLP;
4346    pdschCfg->tci_StatesToReleaseList = NULLP;
4347    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4348 #if 0
4349    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4350    if(!pdschCfg->tci_StatesToAddModList)
4351    {
4352       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4353       return RFAILED;
4354    }
4355    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4356    {
4357       return RFAILED;
4358    }
4359 #endif
4360
4361 if(pdschCfgDb == NULLP)
4362    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4363 else
4364 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4365
4366    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4367    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4368    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4369    {
4370       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4371       return RFAILED;
4372    }
4373    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4374    {
4375       return RFAILED;
4376    }
4377
4378    pdschCfg->pdsch_AggregationFactor = NULLP;
4379    pdschCfg->rateMatchPatternToAddModList = NULLP;
4380    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4381    pdschCfg->rateMatchPatternGroup1 = NULLP;
4382    pdschCfg->rateMatchPatternGroup2 = NULLP;
4383    if(pdschCfgDb == NULLP)
4384       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4385    else
4386       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4387    pdschCfg->mcs_Table = NULLP;
4388
4389    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4390    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4391    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4392    {
4393       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4394       return RFAILED;
4395    }
4396    if(pdschCfgDb == NULLP)
4397       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4398    else
4399       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4400
4401    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4402    {
4403       return RFAILED;
4404    }
4405
4406    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4407    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4408    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4409    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4410    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4411    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4412    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4413
4414    return ROK;
4415 }
4416
4417 /*******************************************************************
4418  *
4419  * @brief Builds intitial DL BWP
4420  * @details
4421  *
4422  *    Function : BuildInitialDlBWP 
4423  *
4424  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4425  *
4426  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4427  *
4428  * @return ROK     - success
4429  *         RFAILED - failure
4430  *
4431  * ****************************************************************/
4432 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4433 {
4434    PdcchConfig *pdcchCfg = NULLP;
4435    PdschConfig *pdschCfg = NULLP;
4436
4437    if(initiDlBwp)
4438    {
4439       if(initiDlBwp->pdcchPresent)
4440          pdcchCfg = &initiDlBwp->pdcchCfg;
4441       if(initiDlBwp->pdschPresent)
4442          pdschCfg = &initiDlBwp->pdschCfg;
4443    }
4444
4445    dlBwp->pdcch_Config = NULLP;
4446    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4447    if(!dlBwp->pdcch_Config)
4448    {
4449       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4450       return RFAILED;
4451    }
4452    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4453
4454    dlBwp->pdcch_Config->choice.setup = NULLP;
4455    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4456    if(!dlBwp->pdcch_Config->choice.setup)
4457    {
4458       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4459       return RFAILED;
4460    }
4461    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4462    {
4463       return RFAILED;
4464    }
4465
4466    dlBwp->pdsch_Config = NULLP;
4467    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4468    if(!dlBwp->pdsch_Config)
4469    {
4470       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4471       return RFAILED;
4472    }
4473    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4474
4475    dlBwp->pdsch_Config->choice.setup = NULLP;
4476    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4477    if(!dlBwp->pdsch_Config->choice.setup)
4478    {
4479       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4480       return RFAILED;
4481    }
4482
4483    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4484    {
4485       return RFAILED;
4486    }
4487
4488    dlBwp->sps_Config = NULLP;
4489    dlBwp->radioLinkMonitoringConfig = NULLP; 
4490    return ROK;
4491 }
4492
4493 /*******************************************************************
4494  *
4495  * @brief Builds DMRS UL Pusch Mapping type A
4496  *
4497  * @details
4498  *
4499  *    Function : BuildDMRSULPuschMapTypeA
4500  *
4501  *    Functionality: Builds DMRS UL Pusch Mapping type A
4502  *
4503  * @params[in] 
4504  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4505  * @return ROK     - success
4506  *         RFAILED - failure
4507  *
4508  * ****************************************************************/
4509 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4510 {
4511    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4512    dmrsUlCfg->choice.setup= NULLP;
4513    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4514    if(!dmrsUlCfg->choice.setup)
4515    {
4516       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4517       return RFAILED;
4518    }
4519
4520    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4521    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4522    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4523    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4524    {
4525       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4526       return RFAILED;
4527    }
4528    if(ulDmrsCfgDb == NULLP)
4529       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4530    else
4531       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4532
4533    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4534    dmrsUlCfg->choice.setup->maxLength = NULLP;
4535    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4536    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4537    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4538    {
4539       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4540       return RFAILED;
4541    }
4542
4543    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4544    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4545          sizeof(long));
4546    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4547    {
4548       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4549       return RFAILED;
4550    }
4551    if(ulDmrsCfgDb == NULLP)
4552       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4553    else
4554       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4555
4556    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4557    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4558    return ROK;
4559 }
4560
4561 /*******************************************************************
4562  *
4563  * @brief Build PUSCH time domain allocation list
4564  *
4565  * @details
4566  *
4567  *    Function : BuildPuschTimeDomAllocList
4568  *
4569  *    Functionality: Build PUSCH time domain allocation list
4570  *
4571  * @params[in] 
4572  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4573  *
4574  * @return ROK     - success
4575  *         RFAILED - failure
4576  *
4577  * ****************************************************************/
4578 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4579 {
4580    uint8_t idx;
4581    uint8_t elementCnt;
4582    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4583
4584    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4585    timeDomAllocList->choice.setup = NULLP;
4586    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4587    if(!timeDomAllocList->choice.setup)
4588    {
4589       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4590       return RFAILED;
4591    }
4592
4593    if(puschCfgDb == NULLP)
4594       elementCnt = 2;
4595    else
4596       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4597
4598    timeDomAllocList->choice.setup->list.count = elementCnt;
4599    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4600    timeDomAllocList->choice.setup->list.array = NULLP;
4601    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4602    if(!timeDomAllocList->choice.setup->list.array)
4603    {
4604       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4605       return RFAILED;
4606    }
4607
4608    for(idx = 0; idx < elementCnt; idx++)
4609    {
4610       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4611       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4612       if(!timeDomAllocList->choice.setup->list.array[idx])
4613       {
4614          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4615          return RFAILED;
4616       }
4617    }
4618
4619    for(idx = 0; idx < elementCnt; idx++)
4620    {
4621       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4622       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4623       if(!timeDomAlloc->k2)
4624       {
4625          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4626          return RFAILED;
4627       }
4628       if(puschCfgDb == NULLP)
4629       {
4630          if(idx == 0)
4631             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4632          else if(idx == 1)
4633             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4634
4635          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4636          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4637       }
4638       else
4639       {
4640          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4641          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4642          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4643       }
4644    }
4645
4646    return ROK;
4647 }
4648
4649 /*******************************************************************
4650  *
4651  * @brief Builds BWP UL dedicated PUSCH Config
4652  *
4653  * @details
4654  *
4655  *    Function : BuildBWPUlDedPuschCfg
4656  *
4657  *    Functionality:
4658  *      Builds BWP UL dedicated PUSCH Config
4659  *
4660  * @params[in] : PUSCH_Config_t *puschCfg
4661  *    
4662  * @return ROK     - success
4663  *         RFAILED - failure
4664  *
4665  * ****************************************************************/
4666 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4667 {
4668    DmrsUlCfg *ulDmrsCfg = NULLP;
4669    
4670    if(puschCfgDb)
4671       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4672
4673    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4674    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4675    if(!puschCfg->dataScramblingIdentityPUSCH)
4676    {
4677       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4678       return RFAILED;
4679    }
4680    if(puschCfgDb == NULLP)
4681       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4682    else
4683       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4684
4685    puschCfg->txConfig = NULLP;
4686    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4687    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4688    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4689    {
4690       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4691       return RFAILED;
4692    }
4693
4694    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4695    {
4696       return RFAILED;
4697    }
4698
4699    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4700    puschCfg->pusch_PowerControl = NULLP;
4701    puschCfg->frequencyHopping = NULLP;
4702    puschCfg->frequencyHoppingOffsetLists = NULLP;
4703
4704    if(puschCfgDb == NULLP)
4705       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4706    else
4707       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4708
4709    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4710    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4711    if(!puschCfg->pusch_TimeDomainAllocationList)
4712    {
4713       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4714       return RFAILED;
4715    }
4716
4717    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4718    {
4719       return RFAILED;
4720    }
4721
4722    puschCfg->pusch_AggregationFactor = NULLP;
4723    puschCfg->mcs_Table = NULLP;
4724    puschCfg->mcs_TableTransformPrecoder = NULLP;
4725    puschCfg->transformPrecoder = NULLP;
4726    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4727    if(!puschCfg->transformPrecoder)
4728    {
4729       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4730       return RFAILED;
4731    }
4732    if(puschCfgDb == NULLP)
4733       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4734    else
4735       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4736
4737    puschCfg->codebookSubset = NULLP;
4738    puschCfg->maxRank = NULLP;
4739    puschCfg->rbg_Size = NULLP;
4740    puschCfg->uci_OnPUSCH = NULLP;
4741    puschCfg->tp_pi2BPSK = NULLP;
4742
4743    return ROK;
4744 }
4745
4746 /*******************************************************************
4747  *
4748  * @brief Builds PUCCH resource set add/modify list
4749  *
4750  * @details
4751  *
4752  *    Function : BuildPucchRsrcSetAddModList
4753  *
4754  *    Functionality:
4755  *      Builds PUCCH resource set add/modify list
4756  *
4757  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4758  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4759  *
4760  * @return ROK     - success
4761  *         RFAILED - failure
4762  *
4763  * ****************************************************************/
4764 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4765    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4766 {
4767    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4768    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4769
4770    if(rsrcSetCfgDb == NULLP)
4771       elementCnt = 1;
4772    else
4773       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4774
4775    resourceSetToAddModList->list.count = elementCnt;
4776    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4777    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4778    if(resourceSetToAddModList->list.array == NULLP)
4779    {
4780       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4781       return RFAILED;
4782    }
4783    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4784    {
4785       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4786       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4787       {
4788          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4789          return RFAILED;
4790       }
4791    }
4792
4793    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4794    {
4795       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4796
4797       /* Resource set Id */
4798       if(rsrcSetCfgDb == NULLP)
4799          rsrcSet->pucch_ResourceSetId = 1;
4800       else
4801          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4802  
4803       /* Resource list of a resource set */
4804       if(rsrcSetCfgDb == NULLP)
4805          elementCnt = 1;
4806       else
4807          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4808       rsrcSet->resourceList.list.count = elementCnt;
4809       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4810       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4811       if(rsrcSet->resourceList.list.array == NULLP)
4812       {
4813          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4814          return RFAILED;
4815       }
4816
4817       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4818       {
4819          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4820          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4821          {
4822             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4823             return RFAILED;
4824          }
4825       }
4826       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4827       {
4828          if(rsrcSetCfgDb == NULLP)
4829             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4830          else
4831             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4832       }
4833
4834       /* Max payload size (minus 1) in a Resource set */
4835       rsrcSet->maxPayloadMinus1 = NULLP;
4836       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4837       {
4838          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4839          if(rsrcSet->maxPayloadMinus1 == NULLP)
4840          {
4841             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4842             return RFAILED;
4843          }
4844          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4845       }
4846    }
4847    return ROK;
4848 }
4849
4850 /*******************************************************************
4851  *
4852  * @brief Builds PUCCH resource add/modify list
4853  *
4854  * @details
4855  *
4856  *    Function : BuildPucchRsrcAdddModList
4857  *
4858  *    Functionality:
4859  *      Builds PUCCH resource add/modify list
4860  *
4861  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4862  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4863  *
4864  * @return ROK     - success
4865  *         RFAILED - failure
4866  *
4867  * ****************************************************************/
4868 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4869 {
4870    uint8_t elementCnt = 0, rsrcIdx = 0;
4871    PUCCH_Resource_t *rsrc = NULLP;
4872
4873    if(rsrcCfgDb == NULLP)
4874       elementCnt = 1;
4875    else
4876       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4877    resourceToAddModList->list.count = elementCnt;
4878    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4879    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4880    if(resourceToAddModList->list.array == NULLP)
4881    {
4882       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4883       return RFAILED;
4884    }
4885    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4886    {
4887       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4888       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4889       {
4890          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4891          return RFAILED;
4892       }
4893    }
4894
4895    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4896    {
4897       rsrc = resourceToAddModList->list.array[rsrcIdx];
4898
4899       if(rsrcCfgDb == NULLP)
4900       {
4901          rsrc->pucch_ResourceId = 1;
4902          rsrc->startingPRB = 0;
4903          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4904          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4905          if(rsrc->format.choice.format1 == NULLP)
4906          {
4907             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4908             return RFAILED;
4909          }  
4910          rsrc->format.choice.format1->initialCyclicShift = 0;
4911          rsrc->format.choice.format1->nrofSymbols = 4;
4912          rsrc->format.choice.format1->startingSymbolIndex = 0;
4913          rsrc->format.choice.format1->timeDomainOCC = 0;
4914       }
4915       else
4916       {
4917          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4918          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4919          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4920          {
4921             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4922             if(rsrc->intraSlotFrequencyHopping == NULLP)
4923             {
4924                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4925                return RFAILED;
4926             }
4927             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4928          }
4929          else
4930             rsrc->intraSlotFrequencyHopping = NULLP;
4931
4932          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4933          {
4934             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4935             if(rsrc->secondHopPRB == NULLP)
4936             {
4937                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4938                return RFAILED;
4939             }
4940             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4941          }
4942          else
4943             rsrc->secondHopPRB = NULLP;
4944          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4945
4946          switch(rsrc->format.present)
4947          {
4948             case PUCCH_Resource__format_PR_NOTHING:
4949                break;
4950             case PUCCH_Resource__format_PR_format0:
4951                {
4952                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4953                   if(rsrc->format.choice.format0 == NULLP)
4954                   {
4955                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4956                      return RFAILED;
4957                   }
4958                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4959                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4960                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4961                   break;
4962                }
4963
4964             case PUCCH_Resource__format_PR_format1:
4965                {
4966                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4967                   if(rsrc->format.choice.format1 == NULLP)
4968                   {
4969                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4970                      return RFAILED;
4971                   }  
4972                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4973                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4974                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4975                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4976                   break;
4977                }
4978
4979             case PUCCH_Resource__format_PR_format2:
4980                {
4981                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4982                   if(rsrc->format.choice.format2 == NULLP)
4983                   {
4984                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4985                      return RFAILED;
4986                   } 
4987                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4988                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4989                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4990                   break;
4991                }
4992
4993             case PUCCH_Resource__format_PR_format3:
4994                {
4995                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4996                   if(rsrc->format.choice.format3 == NULLP)
4997                   {
4998                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4999                      return RFAILED;
5000                   }
5001                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5002                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5003                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5004                   break;
5005                }
5006
5007             case PUCCH_Resource__format_PR_format4:
5008                {
5009                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5010                   if(rsrc->format.choice.format4 == NULLP)
5011                   {
5012                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5013                      return RFAILED;
5014                   }
5015                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5016                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5017                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5018                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5019                   break;
5020                }
5021          }
5022       }
5023    }
5024    return ROK;
5025 }
5026
5027 /*******************************************************************
5028  *
5029  * @brief Builds PUCCH format  config
5030  *
5031  * @details
5032  *
5033  *    Function : BuildPucchFormat
5034  *
5035  *    Functionality: Builds PUCCH format  config
5036  *
5037  * @params[in] : PucchFormatCfg *formatDb
5038  *               PUCCH_FormatConfig_t *format
5039  *
5040  * @return ROK     - success
5041  *         RFAILED - failure
5042  *
5043  * ****************************************************************/
5044 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5045 {
5046    /* Inter Slot Fequency hopping */
5047    format->interslotFrequencyHopping = NULLP;
5048    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5049    {
5050       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5051       if(format->interslotFrequencyHopping)
5052       {
5053          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5054          return RFAILED;
5055       }
5056       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5057    }
5058
5059    /* Additional DMRS */
5060    format->additionalDMRS = NULLP;
5061    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5062    {
5063       DU_ALLOC(format->additionalDMRS, sizeof(long));
5064       if(format->additionalDMRS)
5065       {
5066          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5067          return RFAILED;
5068       }
5069       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5070    }
5071
5072     /* Maximum code rate */
5073    format->maxCodeRate = NULLP;
5074    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5075    {
5076       DU_ALLOC(format->maxCodeRate, sizeof(long));
5077       if(format->maxCodeRate)
5078       {
5079          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5080          return RFAILED;
5081       }  
5082       *(format->maxCodeRate) = formatDb->maxCodeRate;
5083    }
5084  
5085    /* Number of slots */
5086    format->nrofSlots = NULLP;
5087    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5088    {
5089       DU_ALLOC(format->nrofSlots, sizeof(long));
5090       if(format->nrofSlots == NULLP)
5091       {
5092          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5093          return RFAILED;
5094       }
5095       if(formatDb == NULLP)
5096          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5097       else
5098          *(format->nrofSlots) = formatDb->numSlots;
5099    }
5100
5101    /* Pi2BPSK*/
5102    format->pi2BPSK = NULLP;
5103    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5104    {
5105       DU_ALLOC(format->pi2BPSK, sizeof(long));
5106       if(format->pi2BPSK)
5107       {     
5108          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5109          return RFAILED;
5110       }     
5111       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5112    }
5113
5114    /* Simultaneous HARQ ACK and CSI */
5115    format->simultaneousHARQ_ACK_CSI = NULLP;
5116    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5117    {
5118       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5119       if(format->simultaneousHARQ_ACK_CSI)
5120       {     
5121          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5122          return RFAILED;
5123       }     
5124       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5125    }
5126
5127    return ROK;
5128 }
5129
5130
5131 /*******************************************************************
5132  *
5133  * @brief Builds PUCCH scheduling request list
5134  *
5135  * @details
5136  *
5137  *    Function : BuildPucchSchReqAddModList
5138  *
5139  *    Functionality:
5140  *      Builds PUCCH scheduling request list
5141  *
5142  * @params[in] : PucchSchedReqCfg *schReqDb
5143  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5144  *
5145  * @return ROK     - success
5146  *         RFAILED - failure
5147  *
5148  * ****************************************************************/
5149 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5150    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5151 {
5152    uint8_t elementCnt = 0, schReqIdx = 0;
5153    SchedulingRequestResourceConfig_t *schReqRsrc;
5154
5155    elementCnt = schReqDb->schedAddModListCount;
5156    schReqRsrcToAddModList->list.count = elementCnt;
5157    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5158
5159    schReqRsrcToAddModList->list.array = NULLP;
5160    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5161    if(schReqRsrcToAddModList->list.array == NULLP)
5162    {
5163       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5164       return RFAILED;
5165    }
5166
5167    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5168    {
5169       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5170       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5171       {
5172          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5173          return RFAILED;
5174       }
5175    }
5176
5177    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5178    {
5179       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5180       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5181       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5182
5183       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5184       {
5185          schReqRsrc->periodicityAndOffset = NULLP;
5186          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5187          if(schReqRsrc->periodicityAndOffset == NULLP)
5188          {
5189             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5190             return RFAILED;
5191          }
5192
5193          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5194          switch(schReqRsrc->periodicityAndOffset->present)
5195          {
5196             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5197                break;
5198             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5199                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5200                break;
5201             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5202                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5203                break;
5204             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5205                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5206                break;
5207             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5208                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5209                break;
5210             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5211                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5212                break;
5213             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5214                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5215                break;
5216             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5217                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5218                break;
5219             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5220                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5221                break;
5222             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5223                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5224                break;
5225             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5226                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5227                break;
5228             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5229                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5230                break;
5231             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5232                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5233                break;
5234             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5235                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5236                break;
5237             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5238                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5239                break;
5240             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5241                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5242                break;
5243          }
5244       }
5245
5246       if(schReqDb->schedAddModList[schReqIdx].resrc)
5247       {
5248          schReqRsrc->resource = NULLP;
5249          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5250          if(schReqRsrc->resource == NULLP)
5251          {
5252             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5253             return RFAILED;
5254          }
5255          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5256
5257       }
5258    }
5259    return ROK;
5260 }
5261
5262 /*******************************************************************
5263  *
5264  * @brief Builds PUCCH multi csi resource list
5265  *
5266  * @details
5267  *
5268  *    Function : BuildPucchMultiCsiRsrcList
5269  *
5270  *    Functionality:
5271  *      Builds PUCCH multi csi resource list
5272  *
5273  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5274  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5275  *
5276  * @return ROK     - success
5277  *         RFAILED - failure
5278  *
5279  * ****************************************************************/
5280 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5281 {
5282    uint8_t elementCnt = 0, rsrcIdx = 0;
5283
5284    elementCnt = multiCsiDb->multiCsiResrcListCount;
5285    multiCsiRsrcList->list.count = elementCnt;
5286    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5287    multiCsiRsrcList->list.array = NULLP;
5288    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5289    if(multiCsiRsrcList->list.array == NULLP)
5290    {
5291       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5292       return RFAILED;
5293    }
5294
5295    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5296    {
5297       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5298       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5299       {
5300          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5301          return RFAILED;
5302       }
5303    }
5304
5305    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5306    {
5307       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5308    }
5309    return ROK;
5310 }
5311
5312 /*******************************************************************
5313  *
5314  * @brief Builds DL data -to- Ul Ack list
5315  *
5316  * @details
5317  *
5318  *    Function : BuildDlDataToUlAckList
5319  *
5320  *    Functionality: Builds DL data -to- Ul Ack list
5321  *
5322  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5323  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5324  *
5325  * @return ROK     - success
5326  *         RFAILED - failure
5327  *
5328  * ****************************************************************/
5329 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5330 {
5331    uint8_t elementCnt = 0, arrIdx = 0;
5332
5333    if(dlDataToUlAckDb == NULLP)
5334       elementCnt = 2;
5335    else
5336       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5337
5338    dlDataToUlACKList->list.count = elementCnt;
5339    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5340    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5341    if(dlDataToUlACKList->list.array == NULLP)
5342    {
5343       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5344       return RFAILED;
5345    }   
5346
5347    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5348    {
5349       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5350       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5351       {
5352          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5353          return RFAILED;
5354       }   
5355    }
5356
5357    if(dlDataToUlAckDb == NULLP)
5358    {
5359       arrIdx = 0;
5360       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5361       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5362    }
5363    else
5364    {
5365       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5366       {
5367          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5368       }
5369    }
5370    return ROK;
5371 }
5372
5373 /*******************************************************************
5374  *
5375  * @brief Builds BWP UL dedicated PUCCH Config
5376  *
5377  * @details
5378  *
5379  *    Function : BuildBWPUlDedPucchCfg
5380  *
5381  *    Functionality:
5382  *      Builds BWP UL dedicated PUCCH Config
5383  *
5384  * @params[in] : PUCCH_Config_t *pucchCfg
5385  *
5386  * @return ROK     - success
5387  *         RFAILED - failure
5388  *
5389  * ****************************************************************/
5390 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5391 {
5392    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5393    PucchResrcCfg *rsrcCfgDb = NULLP;
5394    PucchFormatCfg *format1Db = NULLP;
5395    PucchFormatCfg *format2Db = NULLP;
5396    PucchFormatCfg *format3Db = NULLP;
5397    PucchFormatCfg *format4Db = NULLP;
5398    PucchSchedReqCfg *schReqDb = NULLP;   
5399    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5400    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5401
5402    if(pucchCfgDb)
5403    {
5404       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5405       rsrcCfgDb = pucchCfgDb->resrc;
5406       format1Db = pucchCfgDb->format1;
5407       format2Db = pucchCfgDb->format2;
5408       format3Db = pucchCfgDb->format3;
5409       format4Db = pucchCfgDb->format4;
5410       schReqDb = pucchCfgDb->schedReq;
5411       multiCsiDb = pucchCfgDb->multiCsiCfg;
5412       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5413    }
5414
5415    /* RESOURCE SET */
5416    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5417    if(pucchCfg->resourceSetToAddModList == NULL)
5418    {
5419       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5420       return RFAILED;
5421    }
5422
5423    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5424    {
5425       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5426       return RFAILED;
5427    }
5428
5429    /* PUCCH RESOURCE */
5430    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5431    if(pucchCfg->resourceToAddModList == NULLP)
5432    {
5433       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5434       return RFAILED;
5435    }
5436
5437    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5438    {
5439       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5440       return RFAILED;
5441    }
5442
5443    /* PUCCH Format 1 */
5444    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5445    if(pucchCfg->format1 == NULLP)
5446    {
5447       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5448       return RFAILED;
5449    }
5450    
5451    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5452    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5453    if(pucchCfg->format1->choice.setup == NULLP)
5454    {
5455       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5456       return RFAILED;
5457    }
5458
5459    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5460    {
5461       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5462       return RFAILED;
5463    }
5464
5465    /* PUCCH Format 2 */
5466    if(format2Db)
5467    {
5468       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5469       if(pucchCfg->format2 == NULLP)
5470       {
5471          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5472          return RFAILED;
5473       }
5474
5475       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5476       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5477       if(pucchCfg->format2->choice.setup == NULLP)
5478       {
5479          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5480          return RFAILED;
5481       }
5482
5483       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5484       {
5485          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5486          return RFAILED;
5487       }
5488    }
5489
5490    /* PUCCH Format 3 */
5491    if(format3Db)
5492    {
5493       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5494       if(pucchCfg->format3 == NULLP)
5495       {
5496          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5497          return RFAILED;
5498       }
5499
5500       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5501       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5502       if(pucchCfg->format3->choice.setup == NULLP)
5503       {
5504          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5505          return RFAILED;
5506       }
5507
5508       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5509       {
5510          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5511          return RFAILED;
5512       }
5513    }
5514
5515    /* PUCCH Format 4 */
5516    if(format4Db)
5517    {
5518       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5519       if(pucchCfg->format4 == NULLP)
5520       {
5521          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5522          return RFAILED;
5523       }
5524
5525       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5526       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5527       if(pucchCfg->format4->choice.setup == NULLP)
5528       {
5529          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5530          return RFAILED;
5531       }
5532
5533       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5534       {
5535          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5536          return RFAILED;
5537       }
5538    }
5539
5540    /* Scheduling Request */
5541    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5542    {
5543       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5544       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5545       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5546       {
5547          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5548          return RFAILED;
5549       }
5550
5551       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5552       {
5553          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5554          return RFAILED;
5555       }
5556    }
5557
5558    /* Multi CSI */
5559    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5560    {
5561       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5562       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5563       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5564       {
5565          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5566          return RFAILED;
5567       }
5568
5569       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5570       {
5571          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5572          return RFAILED;
5573       }
5574    }
5575
5576    /* DL DATA TO UL ACK */
5577    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5578    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5579    {
5580       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5581       return RFAILED;
5582    }
5583
5584    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5585    {
5586       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5587       return RFAILED;
5588    }
5589    
5590    /* TODO : spatial relation info add/mod list and power control*/
5591
5592    return ROK;
5593 }
5594
5595 /*******************************************************************
5596  *
5597  * @brief Fills SRS resource to add/modify list 
5598  *
5599  * @details
5600  *
5601  *    Function : BuildSrsRsrcAddModList
5602  *
5603  *    Functionality: Fills SRS resource to add/modify list
5604  *
5605  * @params[in] 
5606  * @return ROK     - success
5607  *         RFAILED - failure
5608  *
5609  * ****************************************************************/
5610 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5611 {
5612    uint8_t   elementCnt;
5613    uint8_t   rsrcIdx;
5614
5615    elementCnt = 1;
5616    resourceList->list.count = elementCnt;
5617    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5618    resourceList->list.array = NULLP;
5619    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5620    if(!resourceList->list.array)
5621    {
5622       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5623       return RFAILED;
5624    }
5625
5626    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5627    {
5628       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5629       if(!resourceList->list.array[rsrcIdx])
5630       {
5631          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5632          return RFAILED;
5633       }
5634    }
5635
5636    rsrcIdx = 0;
5637    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5638    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5639    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5640
5641    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5642    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5643          sizeof(struct SRS_Resource__transmissionComb__n2));
5644    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5645    {
5646       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5647       return RFAILED;
5648    }
5649    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5650       = SRS_COMB_OFFSET_N2;
5651    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5652       = SRS_CYCLIC_SHIFT_N2;
5653
5654    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5655                                                                       PUSCH_START_SYMBOL;
5656    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5657                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5658    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5659                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5660
5661    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5662    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5663    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5664    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5665    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5666    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5667                                                                SRS_Resource__groupOrSequenceHopping_neither;
5668
5669    /* Setting resource type to aperiodic for intergration purposes */
5670    resourceList->list.array[rsrcIdx]->resourceType.present = \
5671                                                              SRS_Resource__resourceType_PR_aperiodic;
5672    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5673    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5674          sizeof(struct SRS_Resource__resourceType__aperiodic));
5675    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5676    {
5677       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5678       return RFAILED;
5679    }
5680
5681    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5682
5683    return ROK;
5684 }
5685
5686 /*******************************************************************
5687  *
5688  * @brief Build SRS resource set Add/mod list
5689  *
5690  * @details
5691  *
5692  *    Function : BuildSrsRsrcSetAddModList
5693  *
5694  *    Functionality: Build SRS resource set Add/mod list
5695  *
5696  * @params[in] 
5697  * @return ROK     - success
5698  *         RFAILED - failure
5699  *
5700  * ****************************************************************/
5701    uint8_t BuildSrsRsrcSetAddModList
5702 (
5703  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5704  )
5705 {
5706    uint8_t  elementCnt;
5707    uint8_t  rSetIdx;
5708    uint8_t  rsrcIdx;
5709    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5710
5711    elementCnt = 1;
5712    rsrcSetList->list.count = elementCnt;
5713    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5714    rsrcSetList->list.array = NULLP;
5715    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5716    if(!rsrcSetList->list.array)
5717    {
5718       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5719       return RFAILED;
5720    }
5721
5722    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5723    {
5724       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5725       if(!rsrcSetList->list.array[rSetIdx])
5726       {
5727          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5728          return RFAILED;
5729       }
5730    }
5731
5732    rSetIdx = 0;
5733    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5734
5735    /* Fill Resource Id list in resource set */
5736    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5737    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5738          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5739    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5740    {
5741       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5742       return RFAILED;
5743    }
5744
5745    elementCnt = 1;
5746    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5747    rsrcIdList->list.count = elementCnt;
5748    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5749    rsrcIdList->list.array = NULLP;
5750    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5751    if(!rsrcIdList->list.array)
5752    {
5753       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5754       return RFAILED;
5755    }
5756
5757    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5758    {
5759       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5760       if(!rsrcIdList->list.array[rsrcIdx])
5761       {
5762          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5763          return RFAILED;
5764       }
5765    }
5766
5767    rsrcIdx = 0;
5768    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5769
5770    /* Fill resource type */
5771    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5772                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5773
5774    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5775    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5776          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5777    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5778    {
5779       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5780       return RFAILED;
5781    }
5782    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5783       = APERIODIC_SRS_RESRC_TRIGGER;
5784
5785    /* TODO : Fill values for below IEs as expected by Viavi */
5786    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5787    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5788
5789
5790    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5791    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5792    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5793    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5794    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5795
5796    return ROK;
5797 }
5798
5799 /*******************************************************************
5800  *
5801  * @brief Builds BWP UL dedicated SRS Config
5802  *
5803  * @details
5804  *
5805  *    Function : BuildBWPUlDedSrsCfg
5806  *
5807  *    Functionality: Builds BWP UL dedicated SRS Config
5808  *
5809  * @params[in] SRS Config 
5810  * @return ROK     - success
5811  *         RFAILED - failure
5812  *
5813  * ****************************************************************/
5814 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5815 {
5816    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5817    srsCfg->srs_ResourceSetToAddModList = NULLP;
5818    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5819          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5820    if(!srsCfg->srs_ResourceSetToAddModList)
5821    {
5822       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5823       return RFAILED;
5824    }
5825    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5826    {
5827       return RFAILED;
5828    }
5829
5830    srsCfg->srs_ResourceToReleaseList = NULLP;
5831
5832    /* Resource to Add/Modify list */
5833    srsCfg->srs_ResourceToAddModList = NULLP;
5834    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5835          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5836    if(!srsCfg->srs_ResourceToAddModList)
5837    {
5838       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5839       return RFAILED;
5840    }
5841
5842    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5843    {
5844       return RFAILED;
5845    }
5846    srsCfg->tpc_Accumulation = NULLP;
5847
5848    return ROK;
5849 }
5850
5851
5852
5853 /*******************************************************************
5854  *
5855  * @brief Builds Pusch Serving cell Config
5856  *
5857  * @details
5858  *
5859  *    Function : BuildPuschSrvCellCfg
5860  *
5861  *    Functionality: Builds Pusch Serving cell Config
5862  *
5863  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5864  *
5865  * @return ROK     - success
5866  *         RFAILED - failure
5867  *
5868  * ****************************************************************/
5869 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5870 {
5871    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5872    puschCfg->choice.setup = NULLP;
5873    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5874    if(!puschCfg->choice.setup)
5875    {
5876       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5877       return RFAILED;
5878    }
5879
5880    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5881    puschCfg->choice.setup->rateMatching = NULLP;
5882    puschCfg->choice.setup->xOverhead = NULLP;
5883    puschCfg->choice.setup->ext1 = NULLP;
5884
5885    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5886    if(!puschCfg->choice.setup->ext1)
5887    {
5888       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5889       return RFAILED;
5890    }
5891
5892    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5893    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5894    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5895    {
5896       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5897       return RFAILED;
5898    }
5899    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5900
5901    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5902    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5903    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5904    {
5905       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5906       return RFAILED;
5907    }
5908    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5909
5910    return ROK;
5911 }
5912
5913 /*******************************************************************
5914  *
5915  * @brief Builds inital UL BWP
5916  *
5917  * @details
5918  *
5919  *    Function : BuildInitialUlBWP
5920  *
5921  *    Functionality: Builds initial UL BWP
5922  *
5923  * @params[in] BWP_UplinkDedicated_t *ulBwp
5924  * @return ROK     - success
5925  *         RFAILED - failure
5926  *
5927  * ****************************************************************/
5928 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5929 {
5930    PucchCfg *pucchCfg = NULLP;
5931    PuschCfg *puschCfg = NULLP;
5932
5933    if(initUlBwp)
5934    {
5935       if(initUlBwp->pucchPresent)
5936          pucchCfg = &initUlBwp->pucchCfg;
5937       if(initUlBwp->puschPresent)
5938          puschCfg = &initUlBwp->puschCfg;
5939    }
5940
5941    ulBwp->pucch_Config = NULLP;
5942    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5943    if(!ulBwp->pucch_Config)
5944    {
5945       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5946       return RFAILED;
5947    }
5948
5949    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5950    ulBwp->pucch_Config->choice.setup = NULLP;
5951    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5952    if(!ulBwp->pucch_Config->choice.setup)
5953    {
5954       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5955       return RFAILED;
5956    }
5957
5958    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5959    {
5960       return RFAILED;
5961    }
5962
5963    /* Fill BWP UL dedicated PUSCH config */
5964    ulBwp->pusch_Config = NULLP;
5965    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5966    if(!ulBwp->pusch_Config)
5967    {
5968       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5969       return RFAILED;
5970    }
5971
5972    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5973    ulBwp->pusch_Config->choice.setup = NULLP;
5974    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5975    if(!ulBwp->pusch_Config->choice.setup)
5976    {
5977       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5978       return RFAILED;
5979    }
5980
5981    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5982    {
5983       return RFAILED;
5984    }
5985
5986    ulBwp->configuredGrantConfig = NULLP;
5987
5988    /* Fill BPW UL dedicated SRS config */
5989    ulBwp->srs_Config = NULLP;
5990    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5991    if(!ulBwp->srs_Config)
5992    {
5993       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5994       return RFAILED;
5995    }
5996
5997    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5998    ulBwp->srs_Config->choice.setup = NULLP;
5999    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6000    if(!ulBwp->srs_Config->choice.setup)
6001    {
6002       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6003       return RFAILED;
6004    }
6005
6006    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6007    {
6008       return RFAILED;   
6009    }
6010
6011    ulBwp->beamFailureRecoveryConfig = NULLP;
6012
6013    return ROK;
6014 }
6015
6016 /*******************************************************************
6017  *
6018  * @brief Builds UL config
6019  * @details
6020  *
6021  *    Function : BuildUlCfg 
6022  *
6023  *    Functionality: Builds UL config in spCellCfgDed
6024  *
6025  * @params[in] UplinkConfig_t *ulCfg
6026  *
6027  * @return ROK     - success
6028  *         RFAILED - failure
6029  *
6030  * ****************************************************************/
6031 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6032 {
6033    InitialUlBwp *initUlBwp = NULLP;
6034
6035    if(servCellRecfg)
6036    {
6037       initUlBwp = &servCellRecfg->initUlBwp;
6038    }
6039
6040    ulCfg->initialUplinkBWP = NULLP;
6041    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6042    if(!ulCfg->initialUplinkBWP)
6043    {
6044       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6045       return RFAILED;
6046    }
6047
6048    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6049    {
6050       return RFAILED;
6051    }
6052
6053    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6054    ulCfg->uplinkBWP_ToAddModList = NULLP;
6055    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6056    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6057    if(!ulCfg->firstActiveUplinkBWP_Id)
6058    {
6059       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6060       return RFAILED;
6061    }
6062    if(servCellRecfg == NULLP)
6063       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6064    else
6065       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6066
6067    ulCfg->pusch_ServingCellConfig = NULLP;
6068    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6069    if(!ulCfg->pusch_ServingCellConfig)
6070    {
6071       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6072       return RFAILED;
6073    }
6074
6075    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6076    {
6077       return RFAILED;
6078    }
6079
6080    ulCfg->carrierSwitching = NULLP;
6081    ulCfg->ext1 = NULLP;
6082    return ROK;
6083 }
6084
6085 /*******************************************************************
6086  *
6087  * @brief Builds PDSCH serving cell config
6088  * @details
6089  *
6090  *    Function : BuildPdschSrvCellCfg
6091  *
6092  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6093  *
6094  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6095  *
6096  * @return ROK     - success
6097  *         RFAILED - failure
6098  *
6099  * ****************************************************************/
6100 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6101 {
6102    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6103    pdschCfg->choice.setup = NULLP;
6104    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6105    if(!pdschCfg->choice.setup)
6106    {
6107       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6108       return RFAILED;
6109    }
6110
6111    /* Code Block Group Transmission */
6112    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6113    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6114    {
6115       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6116       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6117       {
6118          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6119          return RFAILED;
6120       }
6121
6122       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6123       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6124       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6125       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6126       {
6127          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6128          return RFAILED;
6129       }
6130
6131       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6132          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6133       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6134          *(pdschServCellDb->codeBlkGrpFlushInd);
6135    }
6136
6137    /* xOverhead */
6138    pdschCfg->choice.setup->xOverhead = NULLP;
6139    if(pdschServCellDb && pdschServCellDb->xOverhead)
6140    {
6141       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6142       if(pdschCfg->choice.setup->xOverhead == NULLP)
6143       {
6144          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6145          return RFAILED;
6146       }
6147       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6148    }
6149
6150    /* Number of HARQ processes */
6151    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6152    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6153    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6154    {
6155       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6156       return RFAILED;
6157    }
6158
6159    if(pdschServCellDb == NULLP)
6160    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6161    else
6162    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6163
6164    pdschCfg->choice.setup->pucch_Cell = NULLP;
6165
6166    /* Extension */
6167    pdschCfg->choice.setup->ext1 = NULLP;
6168    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6169    {
6170       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6171       if(pdschCfg->choice.setup->ext1 == NULLP)
6172       {
6173          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6174          return RFAILED;
6175       }
6176
6177       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6178       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6179       {
6180          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6181          return RFAILED;
6182       }
6183       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6184    }
6185
6186    return ROK;
6187 }
6188
6189 /*******************************************************************
6190  *
6191  * @brief Builds CSI Meas config
6192  * @details
6193  *
6194  *    Function : BuildCsiMeasCfg 
6195  *
6196  *    Functionality: Builds CSI Meas config in spCellCfgDed
6197  *
6198  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6199  *
6200  * @return ROK     - success
6201  *         RFAILED - failure
6202  *
6203  * ****************************************************************/
6204 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6205 {
6206
6207    return ROK;
6208 }
6209
6210 /*******************************************************************
6211  *
6212  * @brief Builds DL BWP to add/modify list
6213  * @details
6214  *
6215  *    Function : BuildDlBwpToAddModList
6216  *
6217  *    Functionality: Builds DL BWP to add/modify list
6218  *
6219  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6220  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6221  *
6222  * @return ROK     - success
6223  *         RFAILED - failure
6224  *
6225  * ****************************************************************/ 
6226 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6227 {
6228    uint8_t elementCnt, idx;
6229
6230    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6231    dlBwpAddModList->list.count = elementCnt;
6232    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6233    dlBwpAddModList->list.array = NULLP;
6234    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6235    if(dlBwpAddModList->list.array == NULLP)
6236    {
6237       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6238       return RFAILED;
6239    }
6240
6241    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6242    {
6243       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6244       if(dlBwpAddModList->list.array[idx] == NULLP)
6245       {
6246          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6247          return RFAILED;
6248       }
6249    }
6250
6251    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6252    {
6253       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6254       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6255       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6256    }
6257    return ROK;
6258 }
6259
6260 /*******************************************************************
6261  *
6262  * @brief Builds Spcell config dedicated
6263  * @details
6264  *
6265  *    Function : BuildSpCellCfgDed
6266  *
6267  *    Functionality: Builds sp cell config dedicated in spCellCfg
6268  *
6269  * @params[in] ServingCellConfig_t srvCellCfg
6270  *
6271  * @return ROK     - success
6272  *         RFAILED - failure
6273  *
6274  * ****************************************************************/
6275 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6276 {
6277    ServCellRecfgInfo *servCellRecfg = NULLP;
6278    InitialDlBwp *initDlBwp = NULLP;
6279    PdschServCellCfg *pdschServCellDb = NULLP;
6280
6281    if(ueCb)
6282    {
6283       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6284       initDlBwp = &servCellRecfg->initDlBwp;
6285       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6286    }
6287
6288    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6289
6290    srvCellCfg->initialDownlinkBWP = NULLP;
6291    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6292    if(!srvCellCfg->initialDownlinkBWP)
6293    {
6294       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6295       return RFAILED;
6296    }
6297
6298    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6299    {
6300       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6301       return RFAILED;
6302    }
6303
6304    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6305
6306    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6307    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6308    {
6309       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6310       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6311       {
6312          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6313          return RFAILED;
6314       }
6315
6316       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6317       {
6318          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6319          return RFAILED;
6320       }
6321    }
6322
6323    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6324    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6325    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6326    {
6327       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6328       return RFAILED;
6329    }
6330    if(ueCb == NULLP)
6331       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6332    else
6333       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6334
6335    srvCellCfg->bwp_InactivityTimer = NULLP;
6336
6337    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6338    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6339    if(!srvCellCfg->defaultDownlinkBWP_Id)
6340    {
6341       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6342       return RFAILED;
6343    }
6344    if(ueCb == NULLP)
6345       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6346    else
6347       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6348
6349    srvCellCfg->uplinkConfig = NULLP;
6350    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6351    if(!srvCellCfg->uplinkConfig)
6352    {
6353       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6354       return RFAILED;
6355    }
6356
6357    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6358    {
6359       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6360       return RFAILED;
6361    }
6362    srvCellCfg->supplementaryUplink = NULLP;
6363    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6364
6365    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6366    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6367    if(!srvCellCfg->pdsch_ServingCellConfig)
6368    {
6369       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6370       return RFAILED;
6371    }
6372
6373    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6374    {
6375       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6376       return RFAILED;
6377    }
6378
6379    srvCellCfg->csi_MeasConfig = NULLP;
6380 #if 0
6381    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6382       if(!srvCellCfg->csi_MeasConfig)
6383       {
6384          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6385          return RFAILED;
6386       }
6387
6388    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6389    {
6390       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6391       return RFAILED;
6392    }
6393 #endif
6394    srvCellCfg->sCellDeactivationTimer = NULLP;
6395    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6396    srvCellCfg->tag_Id = TAG_ID;
6397    srvCellCfg->dummy = NULLP;
6398    srvCellCfg->pathlossReferenceLinking = NULLP;
6399    srvCellCfg->servingCellMO = NULLP;
6400    srvCellCfg->ext1 = NULLP;
6401
6402    return ROK;
6403 }
6404
6405 /*******************************************************************
6406  *
6407  * @brief Fills SCS specific carrier list in DL frequency info
6408  *
6409  * @details
6410  *
6411  *    Function : BuildScsSpecificCarrierListDl
6412  *
6413  *    Functionality: Fills SCS specific carrier list in DL frequency info
6414  *
6415  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6416  *
6417  * @return ROK     - success
6418  *         RFAILED - failure
6419  *
6420  * ****************************************************************/
6421 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6422 {
6423    uint8_t elementCnt = 0, listIdx = 0;
6424    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6425
6426    elementCnt = ODU_VALUE_ONE;
6427    scsCarrierList->list.count = elementCnt;
6428    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6429
6430    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6431    if(!scsCarrierList->list.array)
6432    {
6433       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6434          in BuildScsSpecificCarrierListDl()");
6435       return RFAILED;
6436    }
6437
6438    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6439    {
6440       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6441       if(!scsCarrierList->list.array[listIdx])
6442       {    
6443          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6444             element in BuildScsSpecificCarrierListDl()");
6445          return RFAILED;
6446       }    
6447    }
6448
6449    listIdx = 0;
6450    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6451    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6452    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6453
6454    return ROK;
6455 }
6456
6457 /*******************************************************************
6458  *
6459  * @brief Fills DL frequency info in DL config common
6460  *
6461  * @details
6462  *
6463  *    Function : BuildFreqInfoDl
6464  *
6465  *    Functionality: Fills DL frequency info in DL config common
6466  *
6467  * @params[in] Pointer to DownlinkConfigCommon_t
6468  *
6469  * @return ROK     - success
6470  *         RFAILED - failure
6471  *
6472  * ****************************************************************/
6473 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6474 {
6475    uint8_t freqBandIdx = 0, elementCnt = 0;
6476    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6477
6478    /* TODO : Fill SSB Absolute Frequency */
6479    /*
6480       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6481       if(!frequencyInfoDL->absoluteFrequencySSB)
6482       {
6483       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6484       return RFAILED;
6485       }
6486       frequencyInfoDL->absoluteFrequencySSB = ?;
6487       */
6488
6489    /* NR Multi Frequency Band List */
6490    elementCnt = ODU_VALUE_ONE;
6491    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6492    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6493
6494    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6495    if(!frequencyInfoDL->frequencyBandList.list.array)
6496    {
6497       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6498       return RFAILED;
6499    }
6500
6501    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6502    {
6503       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6504       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6505       {
6506          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6507          return RFAILED;
6508       }
6509    }
6510
6511    freqBandIdx = 0;
6512    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6513
6514    /* TODO : Absolute Frequency to Point A */
6515    //frequencyInfoDL->absoluteFrequencyPointA
6516
6517    /* Subcarrier Spacing specifc carrier List */
6518    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6519    {
6520       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6521       return RFAILED;
6522    }
6523
6524    return ROK;
6525
6526 }
6527
6528 /*******************************************************************
6529  *
6530  * @brief Fills DL config common in Serving cell config common
6531  *
6532  * @details
6533  *
6534  *    Function : BuildDlConfigCommon
6535  *
6536  *    Functionality: Fills DL config common in Serving cell config common
6537  *
6538  * @params[in] Pointer to DownlinkConfigCommon_t
6539  *
6540  * @return ROK     - success
6541  *         RFAILED - failure
6542  *
6543  * ****************************************************************/
6544 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6545 {
6546    /* DL Frequency Info */
6547    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6548    if(!dlCfgCommon->frequencyInfoDL)
6549    {
6550       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6551       return RFAILED;
6552    }
6553    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6554    {
6555       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6556       return RFAILED;
6557    }
6558
6559    /* DL BWP config common */
6560    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6561    if(!dlCfgCommon->initialDownlinkBWP)
6562    {
6563       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6564       return RFAILED;
6565    }
6566    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6567    {
6568       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6569       return RFAILED;
6570    }
6571
6572    return ROK;
6573 }
6574
6575 /*******************************************************************
6576  *
6577  * @brief Fills SCS specific carrier list in UL frequency Info
6578  *
6579  * @details
6580  *
6581  *    Function : BuildScsSpecificCarrierListUl
6582  *
6583  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6584  *
6585  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6586  *
6587  * @return ROK     - success
6588  *         RFAILED - failure
6589  *
6590  * ****************************************************************/
6591 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6592 {
6593    uint8_t elementCnt = 0, listIdx = 0; 
6594    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6595
6596    elementCnt = ODU_VALUE_ONE;
6597    scsCarrierList->list.count = elementCnt;
6598    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6599
6600    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6601    if(!scsCarrierList->list.array)
6602    {
6603       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6604       return RFAILED;
6605    }
6606
6607    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6608    {
6609       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6610       if(!scsCarrierList->list.array[listIdx])
6611       {    
6612          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6613          return RFAILED;
6614       }    
6615    }
6616    listIdx = 0; 
6617    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6618    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6619    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6620
6621    return ROK;
6622 }
6623
6624 /*******************************************************************
6625  *
6626  * @brief Fills frequency info in UL config common
6627  *
6628  * @details
6629  *
6630  *    Function : BuildFreqInfoUl
6631  *
6632  *    Functionality: Fills frequency info in UL config common
6633  *
6634  * @params[in] Pointer to FrequencyInfoUL_t
6635  *
6636  * @return ROK     - success
6637  *         RFAILED - failure
6638  *
6639  * ****************************************************************/
6640 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6641 {
6642    uint8_t elementCnt = 0, listIdx= 0;
6643    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6644
6645    /* NR Multi Frequency Band List */
6646    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6647    if(!frequencyInfoUL->frequencyBandList)
6648    {
6649       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6650       return RFAILED;
6651    }
6652
6653    elementCnt = ODU_VALUE_ONE;
6654    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6655    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6656
6657    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6658    if(!frequencyInfoUL->frequencyBandList->list.array)
6659    {
6660       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6661       return RFAILED;
6662    }
6663
6664    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6665    {
6666       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6667       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6668       {
6669          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6670          return RFAILED;
6671       }
6672    }
6673
6674    listIdx = 0;
6675    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6676
6677    /* TODO : Fill Absolute frequency point A */
6678    /*
6679       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6680       if(!frequencyInfoUL->absoluteFrequencyPointA)
6681       {
6682       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6683       return RFAILED;
6684       }
6685     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6686     */
6687
6688    /* Subcarrier Spacing specifc carrier */
6689    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6690    {
6691       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6692       return RFAILED;
6693    }
6694
6695    /* P-MAX */
6696    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6697    if(!frequencyInfoUL->p_Max)
6698    {
6699       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6700       return RFAILED;
6701    }
6702    *frequencyInfoUL->p_Max = ulCfg.pMax;
6703
6704    return ROK;
6705 }
6706
6707 /*******************************************************************
6708  *
6709  * @brief Fills UL config common in Serving cell config common
6710  *
6711  * @details
6712  *
6713  *    Function : BuildUlConfigCommon
6714  *
6715  *    Functionality: Fills UL config common in Serving cell config common
6716  *
6717  * @params[in] Pointer to UplinkConfigCommon_t
6718  *
6719  * @return ROK     - success
6720  *         RFAILED - failure
6721  *
6722  * ****************************************************************/
6723 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6724 {
6725    /* UL Frequency Info */
6726    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6727    if(!ulCfgCommon->frequencyInfoUL)
6728    {
6729       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6730       return RFAILED;
6731    }
6732
6733    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6734    {
6735       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6736       return RFAILED;
6737    }
6738
6739    /* UL BWP common */
6740    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6741    if(!ulCfgCommon->initialUplinkBWP)
6742    {
6743       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6744       return RFAILED;
6745    }
6746
6747    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6748    {
6749       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6750       return RFAILED;
6751    }
6752
6753    /* Time Alignment timer */
6754    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6755
6756    return ROK;
6757 }
6758
6759 /*******************************************************************
6760  *
6761  * @brief Fills SSB position in burst in SP cell config common
6762  *
6763  * @details
6764  *
6765  *    Function : BuildSsbPosInBurst
6766  *
6767  *    Functionality: 
6768  *       Fills SSB position in burst in SP cell config common
6769  *
6770  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6771  *
6772  * @return ROK     - success
6773  *         RFAILED - failure
6774  *
6775  * ****************************************************************/
6776 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6777 {
6778    uint8_t bitStringSizeInBytes = 0;
6779
6780    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6781
6782    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6783    bitStringSizeInBytes = 1;
6784    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6785
6786    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6787    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6788    {
6789       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6790       return RFAILED;
6791    }
6792
6793    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6794                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6795    {
6796       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6797       return RFAILED;
6798    }
6799
6800    return ROK;
6801 }
6802
6803 /*******************************************************************
6804  *
6805  * @brief Fills SP cell config common in Reconfig with Sync
6806  *
6807  * @details
6808  *
6809  *    Function : BuildSpCellConfigCommon
6810  *
6811  *    Functionality: Fills SP cell config common in Reconfig with Sync
6812  *
6813  * @params[in] Pointer to ServingCellConfigCommon_t
6814  *
6815  * @return ROK     - success
6816  *         RFAILED - failure
6817  *
6818  * ****************************************************************/
6819 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6820 {
6821    /* Physical Cell Identity */
6822    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6823    if(!spCellConfigCommon->physCellId)
6824    {
6825       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6826       return RFAILED;
6827    } 
6828    *(spCellConfigCommon->physCellId) = NR_PCI;
6829
6830    /* Downlink Config Common */
6831    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6832    if(!spCellConfigCommon->downlinkConfigCommon)
6833    {
6834       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6835       return RFAILED;
6836    }
6837    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6838    {
6839       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6840       return RFAILED;
6841    }
6842
6843    /* Uplinlink Config Common */
6844    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6845    if(!spCellConfigCommon->uplinkConfigCommon)
6846    {
6847       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6848       return RFAILED;
6849    }
6850    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6851    {
6852       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6853       return RFAILED;
6854    }
6855
6856    /* Timing Advance offset */
6857    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6858    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6859    {
6860       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6861       return RFAILED;
6862    }
6863    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6864
6865    /* SSB Position In Burst */
6866    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6867    if(!spCellConfigCommon->ssb_PositionsInBurst)
6868    {
6869       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6870       return RFAILED;
6871    }
6872    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6873    {
6874       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6875       return RFAILED;
6876    }
6877
6878    /* SSB Periodicity in Serving cell */
6879    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6880    if(!spCellConfigCommon->ssb_periodicityServingCell)
6881    {
6882       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6883          BuildSpCellConfigCommon()");
6884       return RFAILED;
6885    }
6886    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6887       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6888
6889    /* DMRS Type A position */
6890    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6891
6892    /* SSB subcarrier spacing */
6893    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6894    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6895    {
6896       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6897       return RFAILED;
6898    }
6899    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6900
6901    /* TDD UL-DL configuration common */
6902    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6903    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6904    {
6905       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6906       return RFAILED;
6907    }
6908    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6909    {
6910       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6911       return RFAILED;
6912    }
6913
6914    /* SS PBCH Block Power */
6915    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6916
6917    return ROK;
6918 }
6919
6920 /*******************************************************************
6921  *
6922  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
6923  *
6924  * @details
6925  *
6926  *    Function : BuildRecfgWithSync
6927  *
6928  *    Functionality: 
6929  *       Fills dedicated RACH configuration in Reconfiguration with sync
6930  *
6931  * @params[in] DU UE CB
6932  *             Pointer to Rach config dedicated struct
6933  *
6934  * @return ROK     - success
6935  *         RFAILED - failure
6936  *
6937  * ****************************************************************/
6938 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
6939 {
6940    uint8_t elementCnt = 0, listIdx = 0;
6941    CFRA_t *cfra = NULLP;
6942    struct CFRA__resources__ssb *ssbResource = NULLP;
6943    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
6944
6945    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
6946
6947    /* Uplink */
6948    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
6949    if(!rachCfgDed->choice.uplink)
6950    {
6951       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
6952       return RFAILED;
6953    }
6954
6955    /* CFRA : Contention free Random Access */
6956    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
6957    if(!rachCfgDed->choice.uplink->cfra)
6958    {
6959       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
6960       return RFAILED;
6961    }
6962    cfra = rachCfgDed->choice.uplink->cfra;
6963
6964    /* CFRA occassions */
6965    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
6966    if(!cfra->occasions)
6967    {
6968       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
6969       return RFAILED;
6970    }
6971
6972    /* CFRA occassions : RACH generic configuration */
6973    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
6974    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
6975    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
6976    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
6977    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
6978    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
6979    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
6980    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
6981
6982    /* CFRA occassions : SSB per RACH occasion */
6983    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
6984    if(!cfra->occasions->ssb_perRACH_Occasion)
6985    {
6986       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
6987       return RFAILED;
6988    }
6989    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
6990
6991    /* CFRA resource */
6992    cfra->resources.present = CFRA__resources_PR_ssb;
6993
6994    /* CFRA resource : SSB */
6995    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
6996    if(!cfra->resources.choice.ssb)
6997    {
6998       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
6999       return RFAILED;
7000    }
7001    ssbResource = cfra->resources.choice.ssb;
7002
7003    /* CFRA SSB resource list */
7004    elementCnt = ueCb->cfraResource.numSsb;
7005    ssbResource->ssb_ResourceList.list.count = elementCnt;
7006    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7007
7008    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7009    if(!ssbResource->ssb_ResourceList.list.array)
7010    {
7011       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7012       return RFAILED;
7013    }
7014
7015    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7016    {
7017       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7018       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7019       {
7020          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7021          return RFAILED;
7022       }
7023       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7024       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7025    }
7026
7027    return ROK;
7028 }
7029
7030 /*******************************************************************
7031  *
7032  * @brief Fills reconfiguration with sync in SP cell config
7033  *
7034  * @details
7035  *
7036  *    Function : BuildRecfgWithSync
7037  *
7038  *    Functionality: Fills reconfiguration with sync in SP cell config
7039  *
7040  * @params[in] DU UE CB
7041  *             Pointer to ReconfigurationWithSync_t
7042  *
7043  * @return ROK     - success
7044  *         RFAILED - failure
7045  *
7046  * ****************************************************************/
7047 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7048 {
7049    /* SP Cell Config Common */  
7050    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7051    if(!recfgWithSync->spCellConfigCommon)
7052    {
7053       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7054       return RFAILED;
7055    }
7056
7057    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7058    {
7059       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7060       return RFAILED;
7061    }
7062
7063    /* New UE Identity */
7064    recfgWithSync->newUE_Identity = ueCb->crnti;
7065
7066    /* T304 timer */
7067    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7068
7069    /* RACH configuration dedicated */
7070    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7071    if(!recfgWithSync->rach_ConfigDedicated)
7072    {
7073       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7074       return RFAILED;
7075    }
7076
7077    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7078    {
7079       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7080       return RFAILED;
7081    }
7082
7083    return ROK;
7084 }
7085
7086 /*******************************************************************
7087  *
7088  * @brief Builds Spcell config 
7089  *
7090  * @details
7091  *
7092  *    Function : BuildSpCellCfg 
7093  *
7094  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7095  *
7096  * @params[in] SpCellConfig_t spCellCfg
7097  *
7098  * @return ROK     - success
7099  *         RFAILED - failure
7100  *
7101  * ****************************************************************/
7102 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7103 {
7104    spCellCfg->servCellIndex = NULLP;
7105    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7106    if(!spCellCfg->servCellIndex)
7107    {
7108       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7109       return RFAILED;
7110    }
7111
7112    if(ueCb == NULLP)
7113       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7114    else
7115       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7116
7117    spCellCfg->reconfigurationWithSync = NULLP;
7118    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7119    {
7120       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7121       if(!spCellCfg->reconfigurationWithSync)
7122       {
7123          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7124          return RFAILED;
7125       }
7126
7127       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7128       {
7129          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7130          return RFAILED;
7131       }
7132    }
7133
7134    spCellCfg->rlf_TimersAndConstants = NULLP;
7135    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7136
7137    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7138    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7139    {
7140       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7141       return RFAILED;
7142    }
7143    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7144
7145    spCellCfg->spCellConfigDedicated = NULLP;
7146    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7147    if(!spCellCfg->spCellConfigDedicated)
7148    {
7149       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7150       return RFAILED;
7151    }
7152    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7153    {
7154       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7155       return RFAILED;
7156    }
7157
7158    return ROK;
7159 }
7160
7161 /*******************************************************************
7162  *
7163  * @brief Builds Phy cell group config 
7164  *
7165  * @details
7166  *
7167  *    Function : BuildPhyCellGrpCfg 
7168  *
7169  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7170  *
7171  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7172  *
7173  * @return ROK     - success
7174  *         RFAILED - failure
7175  *
7176  * ****************************************************************/
7177 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7178 {
7179    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7180    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7181
7182    phyCellGrpCfg->p_NR_FR1 = NULLP;
7183    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7184    if(!phyCellGrpCfg->p_NR_FR1)
7185    {
7186       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7187       return RFAILED;
7188    }
7189
7190    if(ueCb == NULLP)
7191    {
7192       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7193       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7194    }
7195    else
7196    {
7197       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7198       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7199    }
7200
7201    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7202    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7203    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7204    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7205    phyCellGrpCfg->cs_RNTI = NULLP;
7206    phyCellGrpCfg->ext1 = NULLP;
7207    phyCellGrpCfg->ext2 = NULLP;
7208
7209    return ROK;
7210 }
7211 #ifdef NR_DRX
7212 /*******************************************************************
7213  *
7214  * @brief fill long cycle offset value of drx
7215  *
7216  * @details
7217  *
7218  *    Function : fillLongCycleOffsetValFromDuCb 
7219  *
7220  *    Functionality: fill long cycle offset value of drx
7221  *
7222  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7223  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7224  *
7225  * @return ROK     - success
7226  *         RFAILED - failure
7227  *
7228  * ****************************************************************/
7229 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7230 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7231 {
7232    
7233    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7234    switch(drx_LongCycleStartOffset->present)
7235    {
7236       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7237          {
7238             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7239             break;
7240          }
7241       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7242          {
7243             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7244             break;
7245          }
7246       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7247          {
7248             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7249             break;
7250          }
7251       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7252          {
7253             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7254             break;
7255          }
7256       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7257          {
7258             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7259             break;
7260          }
7261       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7262          {
7263             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7264             break;
7265          }
7266       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7267          {
7268             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7269             break;
7270          }
7271       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7272          {
7273             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7274             break;
7275          }
7276       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7277          {
7278             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7279             break;
7280          }
7281       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7282          {
7283             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7284             break;
7285          }
7286       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7287          {
7288             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7289             break;
7290          }
7291       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7292          {
7293             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7294             break;
7295          }
7296       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7297          {
7298             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7299             break;
7300          }
7301       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7302          {
7303             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7304             break;
7305          }
7306       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7307          {
7308             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7309             break;
7310          }
7311       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7312          {
7313             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7314             break;
7315          }
7316       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7317          {
7318             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7319             break;
7320          }
7321       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7322          {
7323             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7324             break;
7325          }
7326       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7327          {
7328             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7329             break;
7330          }
7331       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7332          {
7333             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7334             break;
7335          }
7336       default :
7337          break;
7338    }
7339 }
7340 /*******************************************************************
7341  *
7342  * @brief Builds drx config IE 
7343  *
7344  * @details
7345  *
7346  *    Function : BuildDrxConfigRrc 
7347  *
7348  *    Functionality: Build drx config in MacCellGrpCfg 
7349  *
7350  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7351  *
7352  * @return ROK     - success
7353  *         RFAILED - failure
7354  *
7355  * ****************************************************************/
7356 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7357 {
7358    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7359    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7360    if(!drxCfg->choice.setup)
7361    {
7362       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7363       return RFAILED;
7364    }
7365    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7366    {
7367       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7368       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7369       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7370    }
7371    else
7372    {
7373       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7374       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7375       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7376    }
7377    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7378    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7379    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7380    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7381    drxRetransmissionTimerDl);
7382    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7383    drxRetransmissionTimerUl);
7384    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7385    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7386    
7387    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7388    {
7389       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7390       if(drxCfg->choice.setup->shortDRX)
7391       {
7392          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7393          shortDrx.drxShortCycle);
7394          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7395       }
7396       else
7397       {
7398          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7399          return RFAILED;
7400       }
7401    }
7402    return ROK;
7403 }
7404 #endif
7405 /*******************************************************************
7406  *
7407  * @brief Builds Mac cell group config 
7408  *
7409  * @details
7410  *
7411  *    Function : BuildMacCellGrpCfg 
7412  *
7413  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7414  *
7415  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7416  *
7417  * @return ROK     - success
7418  *         RFAILED - failure
7419  *
7420  * ****************************************************************/
7421 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7422 {
7423    macCellGrpCfg->drx_ConfigRrc = NULLP;
7424 #ifdef NR_DRX   
7425    if(ueCb)
7426    {
7427       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7428       if(!macCellGrpCfg->drx_ConfigRrc)
7429       {
7430          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7431          return RFAILED;
7432       }
7433       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7434       {
7435          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7436          return RFAILED;
7437       }
7438    }
7439 #endif
7440    macCellGrpCfg->schedulingRequestConfig = NULLP;
7441    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7442    if(!macCellGrpCfg->schedulingRequestConfig)
7443    {
7444       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7445       return RFAILED;
7446    }
7447
7448    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7449    {
7450       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7451       return RFAILED;
7452    }
7453
7454    macCellGrpCfg->bsr_Config = NULLP;
7455    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7456    if(!macCellGrpCfg->bsr_Config)
7457    {
7458       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7459       return RFAILED;
7460    }
7461
7462    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7463    {
7464       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7465       return RFAILED;
7466    }
7467
7468    macCellGrpCfg->tag_Config = NULLP;
7469    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7470    if(!macCellGrpCfg->tag_Config)
7471    {
7472       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7473       return RFAILED;
7474    }
7475
7476    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7477    {
7478       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7479       return RFAILED;
7480    }
7481
7482    macCellGrpCfg->phr_Config = NULLP;
7483    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7484    if(!macCellGrpCfg->phr_Config)
7485    {
7486       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7487       return RFAILED;
7488    }
7489
7490    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7491    {
7492       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7493       return RFAILED;
7494    }
7495
7496    macCellGrpCfg->skipUplinkTxDynamic = false;
7497    macCellGrpCfg->ext1 = NULLP;
7498
7499    return ROK;
7500 }
7501 /*******************************************************************
7502  *
7503  * @brief Frees memeory allocated for SearchSpcToAddModList
7504  *
7505  * @details
7506  *
7507  *    Function : FreeSearchSpcToAddModList
7508  *
7509  *    Functionality: Deallocating memory of SearchSpcToAddModList
7510  *
7511  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7512  *
7513  * @return void
7514  *
7515  4221 * ****************************************************************/
7516 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7517 {
7518    uint8_t idx1=0;
7519    uint8_t idx2=0;
7520    struct  SearchSpace *searchSpc=NULLP;
7521
7522    if(searchSpcList->list.array)
7523    {
7524       if(searchSpcList->list.array[idx2])
7525       {
7526          searchSpc = searchSpcList->list.array[idx2];
7527          if(searchSpc->controlResourceSetId)
7528          {
7529             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7530             {
7531                if(searchSpc->monitoringSymbolsWithinSlot)
7532                {
7533                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7534                   {
7535                      if(searchSpc->nrofCandidates)
7536                      {
7537                         if(searchSpc->searchSpaceType)
7538                         {
7539                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7540                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7541                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7542                                     SearchSpace__searchSpaceType));
7543                         }
7544                         DU_FREE(searchSpc->nrofCandidates,
7545                               sizeof(struct SearchSpace__nrofCandidates));
7546                      }
7547                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7548                            searchSpc->monitoringSymbolsWithinSlot->size);
7549                   }
7550                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7551                         sizeof(BIT_STRING_t));
7552                }
7553                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7554                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7555             }
7556             DU_FREE(searchSpc->controlResourceSetId,
7557                   sizeof(ControlResourceSetId_t));
7558          }
7559       }
7560       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7561       {
7562          DU_FREE(searchSpcList->list.array[idx1],
7563                sizeof(struct SearchSpace));
7564       }
7565       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7566    }
7567 }
7568 /*******************************************************************
7569  *
7570  * @brief Frees memory allocated for PdschTimeDomAllocList
7571  *
7572  * @details
7573  *
7574  *    Function : FreePdschTimeDomAllocList
7575  *
7576  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7577  *
7578  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7579  *
7580  * @return void
7581  *
7582  * ****************************************************************/
7583 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7584 {
7585    uint8_t idx1=0;
7586
7587    if(timeDomAllocList->choice.setup)
7588    {
7589       if(timeDomAllocList->choice.setup->list.array)
7590       {
7591          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7592          {
7593             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7594             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7595                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7596          }
7597          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7598                timeDomAllocList->choice.setup->list.size);
7599       }
7600       DU_FREE(timeDomAllocList->choice.setup,\
7601             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7602    }
7603 }
7604 /*******************************************************************
7605  *
7606  * @brief Frees memory allocated for PuschTimeDomAllocList
7607  *
7608  *@details
7609  *
7610  *    Function : FreePuschTimeDomAllocList
7611  *
7612  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7613  *
7614  * @params[in] PUSCH_Config_t *puschCfg
7615  *
7616  * @return void
7617  *
7618  * ****************************************************************/
7619 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7620 {
7621    uint8_t rsrcListIdx=0;
7622    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7623
7624    if(puschCfg->pusch_TimeDomainAllocationList)
7625    {
7626       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7627       if(timeDomAllocList_t->choice.setup)
7628       {
7629          if(timeDomAllocList_t->choice.setup->list.array)
7630          {
7631             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7632             {
7633                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7634                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7635                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7636             }
7637             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7638                   timeDomAllocList_t->choice.setup->list.size);
7639          }
7640          DU_FREE(timeDomAllocList_t->choice.setup, \
7641                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7642       }
7643       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7644       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7645             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7646    }
7647
7648 }
7649
7650 /*******************************************************************
7651  *
7652  * @brief Frees memory allocated for Dedicated PUCCH config
7653  *
7654  * @details
7655  *
7656  *    Function : FreeBWPUlDedPucchCfg
7657  *
7658  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7659  *
7660  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7661  *
7662  * @return void
7663  *
7664  * ****************************************************************/
7665 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7666 {
7667    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7668    PUCCH_Config_t *pucchCfg = NULLP;
7669    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7670    PUCCH_Resource_t *rsrc = NULLP;
7671
7672    if(ulBwpPucchCfg)
7673    {
7674       if(ulBwpPucchCfg->choice.setup)
7675       {
7676          pucchCfg = ulBwpPucchCfg->choice.setup;
7677
7678          //Free resource set list
7679          if(pucchCfg->resourceSetToAddModList)
7680          {
7681             if(pucchCfg->resourceSetToAddModList->list.array)
7682             {
7683                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7684                {
7685                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7686                   if(rsrcSet->resourceList.list.array)
7687                   {
7688                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7689                      {
7690                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7691                      }
7692                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7693                   }
7694                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7695                }
7696                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7697             }
7698             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7699          }
7700
7701          //Free resource list
7702          if(pucchCfg->resourceToAddModList)
7703          {
7704             if(pucchCfg->resourceToAddModList->list.array)
7705             {
7706                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7707                {
7708                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7709                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7710                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7711                }
7712                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7713             }
7714             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7715          }
7716
7717          //PUCCH Format 1
7718          if(pucchCfg->format1)
7719          {
7720             if(pucchCfg->format1->choice.setup)
7721             {
7722                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7723                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7724             }
7725             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7726          }
7727          
7728          //DL DATA TO UL ACK
7729          if(pucchCfg->dl_DataToUL_ACK)
7730          {
7731             if(pucchCfg->dl_DataToUL_ACK->list.array)
7732             {
7733                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7734                {
7735                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7736                }
7737                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7738             }
7739             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7740          }
7741
7742          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7743       }
7744       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7745    }
7746 }
7747
7748 /*******************************************************************
7749  *
7750  * @brief Frees memory allocated for InitialUlBWP
7751  *
7752  * @details
7753  *
7754  *    Function : FreeInitialUlBWP
7755  *
7756  *    Functionality: Deallocating memory of InitialUlBWP
7757  *
7758  * @params[in] BWP_UplinkDedicated_t *ulBwp
7759  *
7760  * @return void
7761  *
7762  * ****************************************************************/
7763 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7764 {
7765    uint8_t  rSetIdx, rsrcIdx;
7766    SRS_Config_t   *srsCfg = NULLP;
7767    PUSCH_Config_t *puschCfg = NULLP;
7768    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7769    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7770    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7771    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7772
7773    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7774
7775    if(ulBwp->pusch_Config)
7776    {
7777       if(ulBwp->pusch_Config->choice.setup)
7778       {
7779          puschCfg=ulBwp->pusch_Config->choice.setup;
7780          if(puschCfg->dataScramblingIdentityPUSCH)
7781          {
7782             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7783             {
7784                FreePuschTimeDomAllocList(puschCfg);
7785                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7786                if(dmrsUlCfg->choice.setup)
7787                {
7788                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7789                   {
7790                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7791                      {
7792                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7793                               sizeof(long));
7794                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7795                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7796                      }
7797                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7798                            sizeof(long));
7799                   }
7800                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7801                }
7802                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7803                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7804             }
7805             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7806          }
7807          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7808       }
7809       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7810
7811       /* Free SRS-Config */
7812       if(ulBwp->srs_Config)
7813       {
7814          if(ulBwp->srs_Config->choice.setup)
7815          {
7816             srsCfg = ulBwp->srs_Config->choice.setup;
7817
7818             /* Free Resource Set to add/mod list */
7819             if(srsCfg->srs_ResourceSetToAddModList)
7820             {
7821                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7822                if(rsrcSetList->list.array)
7823                {
7824                   rSetIdx = 0;
7825
7826                   /* Free SRS resource Id list in this SRS resource set */
7827                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7828                   {
7829                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7830
7831                      if(rsrcIdList->list.array)
7832                      {
7833                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7834                         {
7835                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7836                         }
7837                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7838                      }
7839                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7840                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7841                   }
7842
7843                   /* Free resource type info for this SRS resource set */
7844                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7845                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7846
7847                   /* Free memory for each resource set */
7848                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7849                   {
7850                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7851                   }
7852                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7853                }
7854                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7855                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7856             }
7857
7858             /* Free resource to add/modd list */
7859             if(srsCfg->srs_ResourceToAddModList)
7860             {
7861                resourceList = srsCfg->srs_ResourceToAddModList;
7862                if(resourceList->list.array)
7863                {
7864                   rsrcIdx = 0;
7865                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7866                         sizeof(struct SRS_Resource__transmissionComb__n2));
7867                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7868                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7869
7870                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7871                   {
7872                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7873                   }
7874                   DU_FREE(resourceList->list.array, resourceList->list.size);
7875                }
7876                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7877                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7878             }
7879
7880             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7881          }
7882          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7883       }
7884    }
7885 }       
7886 /*******************************************************************
7887  *
7888  * @brief Frees memory allocated for initialUplinkBWP
7889  *
7890  * @details
7891  *
7892  *    Function : FreeinitialUplinkBWP
7893  *
7894  *    Functionality: Deallocating memory of initialUplinkBWP
7895  *
7896  * @params[in] UplinkConfig_t *ulCfg
7897  *
7898  * @return void
7899  *         
7900  *
7901  * ****************************************************************/
7902 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7903 {
7904    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7905    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7906
7907    if(ulCfg->initialUplinkBWP)
7908    {
7909       ulBwp=ulCfg->initialUplinkBWP;
7910       if(ulCfg->firstActiveUplinkBWP_Id)
7911       {
7912          if(ulCfg->pusch_ServingCellConfig)
7913          {
7914             puschCfg=ulCfg->pusch_ServingCellConfig;
7915             if(puschCfg->choice.setup)
7916             {
7917                if(puschCfg->choice.setup->ext1)
7918                {
7919                   DU_FREE(puschCfg->choice.setup->ext1->\
7920                         processingType2Enabled,sizeof(BOOLEAN_t));
7921                   DU_FREE(puschCfg->choice.setup->ext1->\
7922                         maxMIMO_Layers,sizeof(long));
7923                   DU_FREE(puschCfg->choice.setup->ext1, \
7924                         sizeof(struct PUSCH_ServingCellConfig__ext1));
7925                }
7926                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
7927             }
7928             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
7929          }
7930          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
7931       }
7932       FreeInitialUlBWP(ulBwp);
7933       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
7934    }
7935 }
7936 /*******************************************************************
7937  *
7938  * @brief Frees emmory allocated for BWPDlDedPdschCfg
7939  *
7940  * @details
7941  *
7942  *    Function : FreeBWPDlDedPdschCfg
7943  *
7944  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
7945  *
7946  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7947  *
7948  * @return void
7949  *
7950  *
7951  * ****************************************************************/
7952 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
7953 {
7954    struct PDSCH_Config *pdschCfg=NULLP;
7955    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7956    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7957    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7958
7959    if(dlBwp->pdsch_Config->choice.setup)
7960    {
7961       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7962       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7963       {
7964          if(pdschCfg->pdsch_TimeDomainAllocationList)
7965          {
7966             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7967             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7968             {
7969                prbBndlType=&pdschCfg->prb_BundlingType;
7970                DU_FREE(prbBndlType->choice.staticBundling,\
7971                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
7972                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
7973             }
7974             FreePdschTimeDomAllocList(timeDomAllocList);
7975             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
7976                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
7977          }
7978          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7979          if(dmrsDlCfg->choice.setup)
7980          {
7981             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
7982                   sizeof(long));
7983             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
7984          }
7985          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
7986                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
7987       }
7988       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
7989    }
7990 }
7991 /*******************************************************************
7992  *
7993  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
7994  *
7995  * @details
7996  *
7997  *    Function : FreeBWPDlDedPdcchCfg
7998  *
7999  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8000  *
8001  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8002  *
8003  * @return void
8004  *         
8005  *
8006  * ****************************************************************/
8007 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8008 {
8009    uint8_t idx1=0;
8010    uint8_t idx2=0;
8011    struct PDCCH_Config *pdcchCfg=NULLP;
8012    struct ControlResourceSet *controlRSet=NULLP;
8013    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8014
8015    if(dlBwp->pdcch_Config->choice.setup)
8016    {
8017       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8018       if(pdcchCfg->controlResourceSetToAddModList)
8019       {
8020          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8021          if(controlRSetList->list.array)
8022          {
8023             controlRSet = controlRSetList->list.array[idx2];
8024             if(controlRSet)
8025             {
8026                if(controlRSet->frequencyDomainResources.buf)
8027                {
8028                   if(controlRSet->pdcch_DMRS_ScramblingID)
8029                   {
8030                      if(pdcchCfg->searchSpacesToAddModList)
8031                      {
8032                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8033                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8034                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8035                      }
8036                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8037                   }
8038                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8039                         controlRSet->frequencyDomainResources.size);
8040                }
8041             }
8042             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8043             {
8044                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8045             }
8046             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8047          }
8048          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8049                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8050       }
8051       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8052    }
8053 }       
8054
8055 /*******************************************************************
8056  *
8057  * @brief Free SCS specific carrier list in DL frequency info
8058  *
8059  * @details
8060  *
8061  *    Function : FreeScsSpecificCarrierListDl
8062  *
8063  *    Functionality: Free SCS specific carrier list in DL frequency info
8064  *
8065  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8066  *
8067  * @return void
8068  *
8069  * ****************************************************************/
8070 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8071 {
8072    uint8_t listIdx = 0;
8073
8074    if(!scsCarrierList->list.array)
8075    {
8076       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8077       {
8078          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8079       }
8080       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8081    }
8082 }
8083
8084 /*******************************************************************
8085  *
8086  * @brief Free DL frequency info in DL config common
8087  *
8088  * @details
8089  *
8090  *    Function : FreeFreqInfoDl
8091  *
8092  *    Functionality: Free DL frequency info in DL config common
8093  *
8094  * @params[in] Pointer to DownlinkConfigCommon_t
8095  *
8096  * @return void
8097  *
8098  * ****************************************************************/
8099 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8100 {
8101    uint8_t freqBandIdx = 0;
8102
8103    /* SSB Absolute Frequency */
8104    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8105
8106    /* NR Multi Frequency Band List */
8107    if(frequencyInfoDL->frequencyBandList.list.array)
8108    {
8109       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8110       {
8111          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8112       }
8113       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8114    }
8115
8116    /* Subcarrier Spacing specifc carrier List */
8117    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8118 }
8119
8120 /*******************************************************************
8121  *
8122  * @brief Free DL config common in Serving cell config common
8123  *
8124  * @details
8125  *
8126  *    Function : FreeDlConfigCommon
8127  *
8128  *    Functionality: Free DL config common in Serving cell config common
8129  *
8130  * @params[in] Pointer to DownlinkConfigCommon_t
8131  *
8132  * @return void
8133  *
8134  * ****************************************************************/
8135 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8136 {
8137    /* DL Frequency Info */
8138    if(dlCfgCommon->frequencyInfoDL)
8139    {
8140       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8141       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8142    }
8143
8144    /* DL BWP config common */
8145    if(dlCfgCommon->initialDownlinkBWP)
8146    {
8147       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8148       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8149    }
8150 }
8151
8152 /*******************************************************************
8153  *
8154  * @brief Free SCS specific carrier list in UL frequency Info
8155  *
8156  * @details
8157  *
8158  *    Function : FreeScsSpecificCarrierListUl
8159  *
8160  *    Functionality: Free SCS specific carrier list in UL frequency Info
8161  *
8162  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8163  *
8164  * @return void
8165  *
8166  * ****************************************************************/
8167 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8168 {
8169    uint8_t listIdx = 0;
8170
8171    if(scsCarrierList->list.array)
8172    {
8173       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8174       {
8175          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8176       }
8177       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8178    }
8179 }
8180
8181 /*******************************************************************
8182  *
8183  * @brief Free frequency info in UL config common
8184  *
8185  * @details
8186  *
8187  *    Function : FreeFreqInfoUl
8188  *
8189  *    Functionality: Free frequency info in UL config common
8190  *
8191  * @params[in] Pointer to FrequencyInfoUL_t
8192  *
8193  * @return void
8194  *
8195  * ****************************************************************/
8196 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8197 {
8198    uint8_t listIdx= 0;
8199
8200    /* NR Multi Frequency Band List */
8201    if(!frequencyInfoUL->frequencyBandList)
8202    {
8203       if(frequencyInfoUL->frequencyBandList->list.array)
8204       {
8205          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8206          {
8207             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8208          }
8209          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8210       }
8211       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8212    }
8213
8214    /* Absolute frequency point A */
8215    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8216
8217    /* Subcarrier Spacing specifc carrier */
8218    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8219
8220    /* P-MAX */
8221    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8222 }
8223
8224 /*******************************************************************
8225  *
8226  * @brief Free UL config common in Serving cell config common
8227  *
8228  * @details
8229  *
8230  *    Function : FreeUlConfigCommon
8231  *
8232  *    Functionality: Free UL config common in Serving cell config common
8233  *
8234  * @params[in] Pointer to UplinkConfigCommon_t
8235  *
8236  * @return void
8237  *
8238  * ****************************************************************/
8239 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8240 {
8241    /* UL Frequency Info */
8242    if(ulCfgCommon->frequencyInfoUL)
8243    {
8244       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8245       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8246    }
8247
8248    /* UL BWP common */
8249    if(ulCfgCommon->initialUplinkBWP)
8250    {
8251       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8252       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8253    }
8254 }
8255
8256 /*******************************************************************
8257  *
8258  * @brief Free SP cell config common in Reconfig with Sync
8259  *
8260  * @details
8261  *
8262  *    Function : FreeSpCellConfigCommon
8263  *
8264  *    Functionality: Free SP cell config common in Reconfig with Sync
8265  *
8266  * @params[in] Pointer to ServingCellConfigCommon_t
8267  *
8268  * @return void
8269  *
8270  * ****************************************************************/
8271 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8272 {
8273    /* Free Physical cell identity */
8274    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8275
8276    /* Free Downlink Config common */
8277    if(spCellConfigCommon->downlinkConfigCommon)
8278    {
8279       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8280       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8281    }
8282
8283    /* Free Uplink Config common */
8284    if(spCellConfigCommon->uplinkConfigCommon)
8285    {
8286       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8287       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8288    }
8289
8290    /* Free Timing Advance offset */
8291    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8292
8293    /* Free SSB Position in Burst */
8294    if(spCellConfigCommon->ssb_PositionsInBurst)
8295    {
8296       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8297          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8298       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8299    }
8300
8301    /* Free SSB Periodicity in Serving cell */
8302    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8303
8304    /* Free SSB subcarrier spacing */
8305    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8306
8307    /* TDD UL-DL configuration common */
8308    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8309 }
8310
8311 /*******************************************************************
8312  *
8313  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8314  *
8315  * @details
8316  *
8317  *    Function : FreeRecfgWithSync
8318  *
8319  *    Functionality:
8320  *       Free dedicated RACH configuration in Reconfiguration with sync
8321  *
8322  * @params[in] Pinter to Rach config dedicated struct
8323  *
8324  * @return void
8325  *
8326  * ****************************************************************/
8327 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8328 {
8329    uint8_t listIdx = 0;
8330    CFRA_t *cfra = NULLP;
8331    struct CFRA__resources__ssb *ssbResource = NULLP;
8332
8333    /* Uplink */
8334    if(rachCfgDed->choice.uplink)
8335    {
8336       /* CFRA : Contention free Random Access */
8337       if(rachCfgDed->choice.uplink->cfra)
8338       {
8339          cfra = rachCfgDed->choice.uplink->cfra;
8340
8341          /* CFRA occassions */
8342          if(cfra->occasions)
8343          {
8344             /* CFRA occassions : SSB per RACH occasion */
8345             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8346             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8347          }
8348
8349          /* CFRA resource */
8350          cfra->resources.present = CFRA__resources_PR_ssb;
8351
8352          /* CFRA resource : SSB */
8353          if(cfra->resources.choice.ssb)
8354          {
8355             ssbResource = cfra->resources.choice.ssb;
8356
8357             /* CFRA SSB resource list */
8358             if(ssbResource->ssb_ResourceList.list.array)
8359             {
8360                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8361                {
8362                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8363                }
8364                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8365             }
8366             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8367          }
8368          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8369       }
8370       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8371    }
8372 }
8373
8374 /*******************************************************************
8375  *
8376  * @brief Frees reconfiguration with sync in SP cell config
8377  *
8378  * @details
8379  *
8380  *    Function : FreeRecfgWithSync
8381  *
8382  *    Functionality: Fress reconfiguration with sync in SP cell config
8383  *
8384  * @params[in] Pointer to ReconfigurationWithSync_t
8385  *
8386  * @return void
8387  *
8388  * ****************************************************************/
8389 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8390 {
8391    /* Free SP Cell config common */
8392    if(recfgWithSync->spCellConfigCommon)
8393    {
8394       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8395       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8396    }
8397
8398    /* Free Dedicated RACH configuration */
8399    if(recfgWithSync->rach_ConfigDedicated)
8400    {
8401       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8402       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8403    }
8404 }
8405
8406 /*******************************************************************
8407  *
8408  * @brief Frees emmory allocated for DUToCURRCContainer 
8409  *
8410  * @details
8411  *
8412  *    Function : FreeMemDuToCuRrcCont
8413  *
8414  *    Functionality: Deallocating memory of DuToCuRrcContainer
8415  *
8416  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8417  *
8418  * @return ROK     - success
8419  *         RFAILED - failure
8420  *
8421  * ****************************************************************/
8422 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8423 {
8424    uint8_t idx=0;
8425    SpCellConfig_t *spCellCfg=NULLP;
8426    ServingCellConfig_t *srvCellCfg=NULLP;
8427    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8428    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8429    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8430    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8431    struct RLC_Config *rlcConfig=NULLP;
8432    struct LogicalChannelConfig *macLcConfig=NULLP;
8433    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8434    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8435    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8436    struct TAG_Config *tagConfig=NULLP;
8437    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8438    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8439    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8440
8441    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8442    if(rlcBearerList)
8443    {
8444       if(rlcBearerList->list.array)
8445       {
8446          for(idx=0; idx<rlcBearerList->list.count; idx++)
8447          {
8448             if(rlcBearerList->list.array[idx])
8449             {  
8450                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8451                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8452                if(rlcConfig)
8453                {
8454                   switch(rlcConfig->present)
8455                   {
8456                      case RLC_Config_PR_NOTHING:
8457                         break;
8458
8459                      case RLC_Config_PR_am:
8460                         {
8461                            if(rlcConfig->choice.am)
8462                            {
8463                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8464                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8465                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8466                            }
8467                            break;
8468                         }
8469                      case RLC_Config_PR_um_Bi_Directional:
8470                         {
8471                            if(rlcConfig->choice.um_Bi_Directional)
8472                            {
8473                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8474                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8475                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8476                            }
8477                            break;
8478                         }
8479                      case RLC_Config_PR_um_Uni_Directional_UL:
8480                         {
8481                            if(rlcConfig->choice.um_Uni_Directional_UL)
8482                            {
8483                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8484                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8485                            }
8486                            break;
8487                         }
8488                      case RLC_Config_PR_um_Uni_Directional_DL:
8489                         {
8490                            if(rlcConfig->choice.um_Uni_Directional_DL )
8491                            {
8492                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8493                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8494                            }
8495                            break;
8496                         }
8497                   }     
8498                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8499                }
8500                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8501                if(macLcConfig)
8502                {
8503                   if(macLcConfig->ul_SpecificParameters)
8504                   {
8505                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8506                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8507                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8508                   }
8509                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8510                }
8511                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8512             }   
8513          }
8514          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8515       }
8516       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8517    }
8518
8519    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8520    if(macCellGrpCfg)
8521    {
8522       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8523
8524       if(drxCfg)
8525       {
8526           switch(drxCfg->present)
8527           {
8528             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8529                break;
8530             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8531             {
8532                if(drxCfg->choice.setup)
8533                {
8534                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8535                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8536                }
8537             }
8538             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8539                break;
8540           }
8541           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8542       }
8543       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8544       if(schedulingRequestConfig)
8545       {
8546          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8547          if(schReqList)
8548          {
8549             if(schReqList->list.array)
8550             {
8551                for(idx=0;idx<schReqList->list.count; idx++)
8552                {
8553                   if(schReqList->list.array[idx])
8554                   {
8555                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8556                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8557                   }
8558                }
8559                DU_FREE(schReqList->list.array, schReqList->list.size);
8560             }
8561             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8562                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8563             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8564       }
8565       if(macCellGrpCfg->bsr_Config)
8566       {
8567          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8568          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8569       }
8570       tagConfig = macCellGrpCfg->tag_Config;
8571       if(tagConfig)
8572       {
8573          tagList = tagConfig->tag_ToAddModList;
8574          if(tagList)
8575          {
8576             if(tagList->list.array)
8577             {
8578                for(idx=0; idx<tagList->list.count; idx++)
8579                {
8580                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8581                }
8582                DU_FREE(tagList->list.array, tagList->list.size);
8583             }
8584             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8585          }
8586          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8587       }
8588
8589       phrConfig = macCellGrpCfg->phr_Config;
8590       if(phrConfig)
8591       {
8592          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8593          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8594       }
8595
8596       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8597    }
8598
8599    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8600    if(phyCellGrpCfg)
8601    {
8602       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8603       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8604    }
8605
8606    spCellCfg = cellGrpCfg->spCellConfig;
8607    if(spCellCfg)
8608    {
8609       /* Free serving cell index */
8610       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8611
8612       /* Free Reconfiguration with sync */
8613       if(spCellCfg->reconfigurationWithSync)
8614       {
8615          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8616          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8617       }
8618
8619       /* Free rlmInSyncOutOfSyncThreshold */
8620       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8621
8622       /* Free SP Cell config dedicated */
8623       if(spCellCfg->spCellConfigDedicated)
8624       {
8625          srvCellCfg = spCellCfg->spCellConfigDedicated;
8626
8627          /* Free TDD UL-DL config dedicated */
8628          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8629
8630          /* Free Initial Downlink BWP */
8631          if(srvCellCfg->initialDownlinkBWP)
8632          {
8633             dlBwp = srvCellCfg->initialDownlinkBWP;
8634
8635             /* Free DL BWP PDCCH Config */
8636             if(dlBwp->pdcch_Config)
8637             {
8638                FreeBWPDlDedPdcchCfg(dlBwp);
8639                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8640             }
8641
8642             /* Free DL BWP PDSCH config */
8643             if(dlBwp->pdsch_Config)
8644             {
8645                FreeBWPDlDedPdschCfg(dlBwp);
8646                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8647             }
8648             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8649          }
8650
8651          /* Free First Active Downlink BWP */
8652          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8653
8654          /* Free Default downlink BWP */
8655          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8656
8657          /* Free Uplink config */
8658          if(srvCellCfg->uplinkConfig)
8659          {
8660             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8661             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8662          }
8663
8664          /* Free PDSCH serving cell config */
8665          if(srvCellCfg->pdsch_ServingCellConfig)
8666          {
8667             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8668             if(pdschCfg->choice.setup)
8669             {
8670                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8671                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8672             }
8673             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8674          }
8675
8676          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8677       }
8678       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8679    }
8680    return ROK;
8681 }
8682
8683 /*******************************************************************
8684  *
8685  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8686  *
8687  * @details
8688  *
8689  *    Function : BuildCellGroupConfigRrc
8690  *
8691  *    Functionality: Builds and copied Cell group config buffer into 
8692  *       DuToCuRrcContainer
8693  *
8694  * @params[in] idx, index in F1AP msg
8695  *             DuToCuRRCContainer, DuToCuRRCContainer
8696  *
8697  * @return ROK     - success
8698  *         RFAILED - failure
8699  *
8700  * ****************************************************************/
8701 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8702 {
8703    uint8_t  ret = ROK;
8704    CellGroupConfigRrc_t  cellGrpCfg;
8705    asn_enc_rval_t        encRetVal;
8706    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8707    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8708
8709    while(true)
8710    {
8711       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8712
8713       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8714       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8715       if(!cellGrpCfg.rlc_BearerToAddModList)
8716       {
8717          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8718          ret = RFAILED;
8719          break;
8720       }
8721       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8722       {
8723          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8724          ret = RFAILED;
8725          break;
8726       }
8727
8728       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8729       cellGrpCfg.mac_CellGroupConfig = NULLP;
8730       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8731       if(!cellGrpCfg.mac_CellGroupConfig)
8732       {
8733          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8734          ret = RFAILED;
8735          break;
8736       }
8737       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8738       {
8739          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8740          ret = RFAILED;
8741          break;
8742       }
8743
8744       cellGrpCfg.physicalCellGroupConfig = NULLP;
8745       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8746       if(!cellGrpCfg.physicalCellGroupConfig)
8747       {
8748          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8749          ret = RFAILED;
8750          break;
8751       }
8752       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8753       {
8754          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8755          ret = RFAILED;
8756          break;
8757       }
8758
8759       cellGrpCfg.spCellConfig = NULLP;
8760       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8761       if(!cellGrpCfg.spCellConfig)
8762       {
8763          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8764          ret = RFAILED;
8765          break;
8766       }
8767       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8768       {
8769          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8770          ret = RFAILED;
8771          break;
8772       }
8773
8774       cellGrpCfg.sCellToAddModList = NULLP;
8775       cellGrpCfg.sCellToReleaseList = NULLP;
8776       cellGrpCfg.ext1 = NULLP;
8777
8778       /* encode cellGrpCfg into duToCuRrcContainer */
8779       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8780       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8781       encBufSize = 0;
8782       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8783       /* Encode results */
8784       if(encRetVal.encoded == ENCODE_FAIL)
8785       {
8786          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8787                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8788          ret = RFAILED;
8789          break;
8790       }
8791       else
8792       {
8793          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8794 #ifdef DEBUG_ASN_PRINT
8795          for(int i=0; i< encBufSize; i++)
8796          {
8797             printf("%x",encBuf[i]);
8798          }
8799 #endif
8800       }
8801
8802       duToCuRrcContainer->size = encBufSize;
8803       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8804       if(!duToCuRrcContainer->buf)
8805       {
8806          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8807          ret = RFAILED;
8808          break;
8809       }
8810       if(ret == ROK)
8811       {
8812          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8813       }
8814       break;
8815    }
8816    FreeMemDuToCuRrcCont(&cellGrpCfg);
8817    return ret;
8818 }
8819
8820 /*******************************************************************
8821  *
8822  * @brief Free memory allocated in InitialULRRCMessage
8823  *
8824  * @details
8825  *
8826  *    Function : freeInitUlRrcMsgTransfer
8827  *
8828  *    Functionality: Free memory allocated in InitialULRRCMessage
8829  *
8830  * @params[in]F1AP_PDU_t  *f1apMsg)
8831  *
8832  * @return ROK     - success
8833  *         RFAILED - failure
8834  *
8835  * ****************************************************************/
8836
8837 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8838 {
8839    uint8_t ieIdx, arrIdx;
8840    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8841
8842    if(f1apMsg)
8843    {
8844       if(f1apMsg->choice.initiatingMessage)
8845       {
8846          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8847             choice.InitialULRRCMessageTransfer;
8848          if(initULRRCMsg->protocolIEs.list.array)
8849          {
8850             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8851             {
8852                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8853                {
8854                   case ProtocolIE_ID_id_NRCGI:
8855                   {
8856                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8857                      {
8858                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8859                         {
8860                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8861                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8862                         }
8863                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8864                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8865                      }
8866                      break;
8867                   }
8868                   case ProtocolIE_ID_id_RRCContainer:
8869                   {
8870                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8871                      {
8872                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8873                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8874                      }
8875                      break;
8876                   }
8877                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8878                   {
8879                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8880                      {
8881                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8882                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8883                      }
8884                      break;
8885                   }
8886                   default:
8887                      break;
8888                }
8889              }
8890              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8891              {
8892                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8893                 {
8894                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8895                       sizeof(InitialULRRCMessageTransferIEs_t));
8896                 }
8897              }
8898              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8899           }
8900          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8901       }
8902       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8903    }
8904    else
8905    {
8906       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8907       return RFAILED;
8908    }
8909    return ROK;
8910 }
8911
8912 /*******************************************************************
8913  *
8914  * @brief Builds and sends the InitialULRRCMessage 
8915  *
8916  * @details
8917  *
8918  *    Function : BuildAndSendInitialRrcMsgTransfer 
8919  *
8920  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
8921  *                   it to the CU through SCTP.
8922  *
8923  * @params[in] 
8924  *
8925  * @return ROK     - success
8926  *         RFAILED - failure
8927  *
8928  * ****************************************************************/
8929 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
8930       uint16_t rrcContSize, uint8_t *rrcContainer)
8931 {
8932    uint8_t   ret;
8933    uint8_t   elementCnt;
8934    uint8_t   ieIdx, cellIdx, ueIdx;
8935    DuUeCb    *duUeCb = NULLP;
8936    asn_enc_rval_t  encRetVal;
8937    F1AP_PDU_t  *f1apMsg = NULLP;
8938    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
8939    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8940
8941    while(true)
8942    {
8943       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
8944       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
8945       if(f1apMsg == NULLP)
8946       {
8947          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
8948          break;
8949       }
8950       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
8951       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8952       if(f1apMsg->choice.initiatingMessage == NULLP)
8953       {
8954          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
8955          break;
8956       }
8957       f1apMsg->choice.initiatingMessage->procedureCode =\
8958                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
8959       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
8960       f1apMsg->choice.initiatingMessage->value.present = \
8961                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
8962       initULRRCMsg =\
8963                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
8964       elementCnt = 5;
8965       initULRRCMsg->protocolIEs.list.count = elementCnt;
8966       initULRRCMsg->protocolIEs.list.size = \
8967                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
8968       /* Initialize the F1Setup members */
8969       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
8970       if(initULRRCMsg->protocolIEs.list.array == NULLP)
8971       {
8972          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
8973                RRCSetupRequestMessageTransferIEs failed");
8974          break;
8975       }
8976       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
8977       {
8978          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
8979                sizeof(InitialULRRCMessageTransferIEs_t));
8980          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
8981          {
8982             break;
8983          }
8984       }
8985       ieIdx = 0;
8986       /*GNB DU UE F1AP ID*/
8987       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8988                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
8989       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
8990       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8991                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
8992       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
8993
8994
8995       /*NRCGI*/
8996       ieIdx++;
8997       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8998                                                         ProtocolIE_ID_id_NRCGI;
8999       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9000       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9001                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9002
9003       ret =\
9004            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9005       if(ret!=ROK)
9006       {
9007          break;
9008       }
9009
9010       /*CRNTI*/
9011       ieIdx++;
9012       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9013                                                         ProtocolIE_ID_id_C_RNTI;
9014       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9015       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9016                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9017       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9018
9019       /*RRCContainer*/
9020       ieIdx++;
9021       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9022                                                         ProtocolIE_ID_id_RRCContainer;
9023       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9024       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9025                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9026
9027       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9028       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9029             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9030       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9031       {
9032          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9033          break;
9034       
9035       }
9036       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9037             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9038
9039
9040       /*DUtoCURRCContainer*/
9041       ieIdx++;
9042       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9043       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9044       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9045                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9046
9047       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9048       {
9049          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9050          {
9051             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9052                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9053             {
9054                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9055             }
9056          }
9057       }
9058
9059       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9060       if(ret != ROK)
9061       {
9062          break;
9063       }
9064
9065       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9066
9067       /* Encode the Intial UL RRC Message transfer as APER */
9068       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9069       encBufSize = 0;
9070       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9071       /* Encode results */
9072       if(encRetVal.encoded == ENCODE_FAIL)
9073       {
9074          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9075                structure (at %s)\n",encRetVal.failed_type ? \
9076                encRetVal.failed_type->name : "unknown");
9077          ret = RFAILED;
9078          break;
9079       }
9080       else
9081       {
9082
9083          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9084                Message transfer\n");
9085 #ifdef DEBUG_ASN_PRINT
9086          for(int i=0; i< encBufSize; i++)
9087          {
9088             printf("%x",encBuf[i]);
9089          }
9090 #endif
9091       }
9092       /* Sending  msg  */
9093       if(sendF1APMsg() != ROK)
9094       {
9095          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9096          ret = RFAILED;
9097          break;
9098       }
9099       break;
9100    }
9101    freeInitUlRrcMsgTransfer(f1apMsg);
9102    return ret;
9103 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9104
9105 /*****  UE SETUP REQUEST *****/
9106
9107 /******************************************************************
9108 *
9109 * @brief Function to delete the RLC Lc cfg from UE APP DB
9110 *
9111 * @details
9112 *
9113 *  Function : freeRlcLcCfg
9114 *
9115 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9116 *
9117 *
9118  *****************************************************************/
9119
9120 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9121 {
9122    switch(lcCfg->rlcMode)
9123    {
9124       case RLC_AM :
9125          {
9126             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9127             break;
9128          }
9129       case RLC_UM_BI_DIRECTIONAL :
9130          {
9131             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9132             break;
9133          }
9134       case RLC_UM_UNI_DIRECTIONAL_UL :
9135          {
9136             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9137             break;
9138          }
9139       case RLC_UM_UNI_DIRECTIONAL_DL :
9140          {
9141             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9142             break;
9143          }
9144       default:
9145          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9146          break;
9147    }
9148    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9149 }
9150
9151 /*******************************************************************
9152  *
9153  * @brief Function to free MacLcCfg
9154  *
9155  * @details
9156  *
9157  *    Function : freeMacLcCfg
9158  *
9159  *    Functionality: Function to free MacLcCfg
9160  *
9161  * @params[in] LcCfg *lcCfg,
9162  * @return void
9163  *
9164  * ****************************************************************/
9165
9166 void freeMacLcCfg(LcCfg *lcCfg)
9167 {
9168     /* Deleting DRBQOS */
9169    if(lcCfg->drbQos)
9170    {
9171       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9172    }
9173    /* Deleting SNSSAI */
9174    if(lcCfg->snssai)
9175    {
9176       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9177    }
9178 }
9179 /*******************************************************************
9180  *
9181  * @brief Free UE NR Capability received in UE Context setup request
9182  *
9183  * @details
9184  *
9185  *    Function : freeAperDecodeUeNrCapability
9186  *
9187  *    Functionality:  
9188  *       Free UE NR Capability received in UE Context setup request
9189  *
9190  * @params[in] 
9191  * @return ROK     - success
9192  *         RFAILED - failure
9193  *
9194  * ****************************************************************/
9195 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9196 {
9197    uint8_t arrIdx =0;
9198    FeatureSets_t *featureSets =NULLP;
9199    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9200
9201    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9202    {
9203       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9204       {
9205          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9206             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9207       }
9208       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9209    }
9210
9211    if(ueNrCap->featureSets)
9212    {
9213       featureSets = ueNrCap->featureSets;
9214       if(featureSets->featureSetsDownlinkPerCC)
9215       {
9216          if(featureSets->featureSetsDownlinkPerCC->list.array)
9217          {
9218             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9219             {
9220                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9221                {
9222                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9223                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9224                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9225                }
9226             }
9227             free(featureSets->featureSetsDownlinkPerCC->list.array);
9228          }
9229          free(featureSets->featureSetsDownlinkPerCC);
9230       }
9231       if(featureSets->featureSetsUplinkPerCC)
9232       {
9233          if(featureSets->featureSetsUplinkPerCC->list.array)
9234          {
9235             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9236             {
9237                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9238                {
9239                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9240                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9241                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9242                }
9243             }
9244             free(featureSets->featureSetsUplinkPerCC->list.array);
9245          }
9246          free(featureSets->featureSetsUplinkPerCC);
9247       }
9248       free(ueNrCap->featureSets);
9249    }   
9250 }
9251
9252 /*******************************************************************
9253 *
9254 * @brief Function to free PdcchSearchSpcToAddModList
9255          where memory allocated by aper_decoder
9256 *
9257 * @details
9258 *
9259 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9260 *
9261 *    Functionality: Function to free PdcchSearchSpcToAddModList
9262 *
9263 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9264 * @return void
9265 *
9266 * ****************************************************************/
9267
9268 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9269 {
9270    uint8_t searchSpcArrIdx=0;
9271    uint8_t searchSpcArrIdx1=0;
9272    struct  SearchSpace *searchSpc=NULLP;
9273
9274
9275    if(searchSpcList->list.array)
9276    {
9277       if(searchSpcList->list.array[searchSpcArrIdx1])
9278       {
9279          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9280          if(searchSpc->controlResourceSetId)
9281          {
9282             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9283             {
9284                if(searchSpc->monitoringSymbolsWithinSlot)
9285                {
9286                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9287                   {
9288                      if(searchSpc->nrofCandidates)
9289                      {
9290                         if(searchSpc->searchSpaceType)
9291                         {
9292                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9293                            free(searchSpc->searchSpaceType);
9294                         }
9295                         free(searchSpc->nrofCandidates);
9296                      }
9297                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9298                   }
9299                   free(searchSpc->monitoringSymbolsWithinSlot);
9300                }
9301                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9302             }
9303             free(searchSpc->controlResourceSetId);
9304          }
9305       }
9306       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9307       {
9308          free(searchSpcList->list.array[searchSpcArrIdx]);
9309       }
9310       free(searchSpcList->list.array);
9311    }
9312 }
9313 /*******************************************************************
9314 *
9315 * @brief Function for free part for the memory allocated by aper_decoder
9316
9317 * @details
9318 *
9319 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9320 *
9321 *    Functionality: Function to free BWPDlDedPdcchConfig
9322 *
9323 * @params[in] 
9324 * @return void
9325 *
9326 * ****************************************************************/
9327
9328
9329 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9330 {
9331    uint8_t arrIdx1=0;
9332    uint8_t arrIdx2=0;
9333    struct PDCCH_Config *pdcchCfg=NULLP;
9334    struct ControlResourceSet *controlRSet=NULLP;
9335    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9336    
9337    if(dlBwp->pdcch_Config->choice.setup)
9338    {
9339       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9340       if(pdcchCfg->controlResourceSetToAddModList)
9341       {
9342          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9343          if(controlRSetList->list.array)
9344          {
9345             controlRSet = controlRSetList->list.array[arrIdx2];
9346             if(controlRSet)
9347             {
9348                if(controlRSet->frequencyDomainResources.buf)
9349                {
9350                   if(controlRSet->pdcch_DMRS_ScramblingID)
9351                   {
9352                      if(pdcchCfg->searchSpacesToAddModList)
9353                      {
9354                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9355                         free(pdcchCfg->searchSpacesToAddModList);
9356                      }
9357                      free(controlRSet->pdcch_DMRS_ScramblingID);
9358                   }
9359                   free(controlRSet->frequencyDomainResources.buf);
9360                }
9361             }
9362             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9363             {
9364                free(controlRSetList->list.array[arrIdx1]);
9365             }
9366             free(controlRSetList->list.array);
9367          }
9368          free(pdcchCfg->controlResourceSetToAddModList);
9369       }
9370       free(dlBwp->pdcch_Config->choice.setup);
9371    }
9372 }
9373 /*******************************************************************
9374 *
9375 * @brief Function to free PdschTimeDomAllocationList 
9376 *     where the memory allocated by aper_decoder
9377
9378 * @details
9379 *
9380 *    Function : freeAperDecodePdschTimeDomAllocationList
9381 *
9382 *    Functionality: Function to free PdschTimeDomAllocationList
9383 *
9384 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9385 * @return void
9386 *
9387 * ****************************************************************/
9388
9389
9390 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9391 {
9392    uint8_t arrIdx=0;
9393
9394    if(timeDomAllocList->choice.setup)
9395    {
9396       if(timeDomAllocList->choice.setup->list.array)
9397       {
9398          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9399          {
9400             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9401          }
9402          free(timeDomAllocList->choice.setup->list.array);
9403       }
9404       free(timeDomAllocList->choice.setup);
9405    }
9406 }
9407
9408 /*******************************************************************
9409 *
9410 * @brief Function to free BWPDlDedPdschConfig 
9411 *        where the memory allocated by aper_decoder
9412 *  
9413 * @details
9414 *
9415 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9416 *
9417 *    Functionality: Function to free BWPDlDedPdschConfig 
9418 *
9419 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9420 * @return void
9421 *
9422 * ****************************************************************/
9423
9424
9425 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9426 {
9427    struct PDSCH_Config *pdschCfg=NULLP;
9428    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9429    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9430    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9431
9432    if(dlBwp->pdsch_Config->choice.setup)
9433    {
9434       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9435       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9436       {
9437          if(pdschCfg->pdsch_TimeDomainAllocationList)
9438          {
9439             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9440             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9441             {
9442                prbBndlType=&pdschCfg->prb_BundlingType;
9443                free(prbBndlType->choice.staticBundling);
9444                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9445             }
9446             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9447             free(pdschCfg->pdsch_TimeDomainAllocationList);
9448          }
9449          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9450          if(dmrsDlCfg->choice.setup)
9451          {
9452             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9453             free(dmrsDlCfg->choice.setup);
9454          }
9455          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9456       }
9457       free(dlBwp->pdsch_Config->choice.setup);
9458    }
9459 }
9460 /*******************************************************************
9461 *
9462 * @brief Function to free PuschTimeDomAllocListCfg
9463                  where the memory allocated by aper_decoder
9464 *
9465 * @details
9466 *
9467 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9468 *
9469 *    Functionality: Function to free PuschTimeDomAllocListCfg
9470 *
9471 * @params[in] PUSCH_Config_t *puschCfg 
9472 * @return void
9473 *
9474 * ****************************************************************/
9475
9476
9477 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9478 {
9479    uint8_t arrIdx=0;
9480    uint8_t arrIdx1=0;
9481    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9482
9483    if(puschCfg->pusch_TimeDomainAllocationList)
9484    {
9485       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9486       if(timeDomAllocList_t->choice.setup)
9487       {
9488          if(timeDomAllocList_t->choice.setup->list.array)
9489          {
9490             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9491             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9492             {
9493                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9494             }
9495             free(timeDomAllocList_t->choice.setup->list.array);
9496          }
9497          free(timeDomAllocList_t->choice.setup);
9498       }
9499       free(puschCfg->transformPrecoder);
9500       free(puschCfg->pusch_TimeDomainAllocationList);
9501    }
9502 }
9503 /*******************************************************************
9504 *
9505 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9506 *
9507 * @details
9508 *
9509 *    Function : freeAperDecodeInitialUlBWPConfig 
9510 *
9511 *    Functionality: Function to free InitialUlBWPConfig
9512 *
9513 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9514 * @return void
9515 *
9516 * ****************************************************************/
9517
9518
9519 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9520 {
9521    uint8_t  rSetIdx =0;
9522    uint8_t  rsrcIdx =0;
9523    SRS_Config_t   *srsCfg = NULLP;
9524    PUSCH_Config_t *puschCfg = NULLP;
9525    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9526    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9527    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9528    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9529
9530    if(ulBwp->pusch_Config)
9531    {
9532       if(ulBwp->pusch_Config->choice.setup)
9533       {
9534          puschCfg=ulBwp->pusch_Config->choice.setup;
9535          if(puschCfg->dataScramblingIdentityPUSCH)
9536          {
9537             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9538             {
9539                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9540                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9541                if(dmrsUlCfg->choice.setup)
9542                {
9543                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9544                   {
9545                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9546                      {
9547                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9548                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9549                      }
9550                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9551                   }
9552                   free(dmrsUlCfg->choice.setup);
9553                }
9554                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9555             }
9556             free(puschCfg->dataScramblingIdentityPUSCH);
9557          }
9558          free(ulBwp->pusch_Config->choice.setup);
9559       }
9560       free(ulBwp->pusch_Config);
9561
9562       /* Free SRS-Config */
9563       if(ulBwp->srs_Config)
9564       {
9565          if(ulBwp->srs_Config->choice.setup)
9566          {
9567             srsCfg = ulBwp->srs_Config->choice.setup;
9568
9569             /* Free Resource Set to add/mod list */
9570             if(srsCfg->srs_ResourceSetToAddModList)
9571             {
9572                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9573                if(rsrcSetList->list.array)
9574                {
9575                   rSetIdx = 0;
9576
9577                   /* Free SRS resource Id list in this SRS resource set */
9578                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9579                   {
9580                      rsrcIdList =
9581                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9582
9583                      if(rsrcIdList->list.array)
9584                      {
9585                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9586                               rsrcIdx++)
9587                         {
9588                            free(rsrcIdList->list.array[rsrcIdx]);
9589                         }
9590                         free(rsrcIdList->list.array);
9591                      }
9592                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9593                   }
9594
9595                   /* Free resource type info for this SRS resource set */
9596
9597                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9598
9599                   /* Free memory for each resource set */
9600                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9601                   {
9602                      free(rsrcSetList->list.array[rSetIdx]);
9603                   }
9604                   free(rsrcSetList->list.array);
9605                }
9606                free(srsCfg->srs_ResourceSetToAddModList);
9607             }
9608
9609             /* Free resource to add/modd list */
9610             if(srsCfg->srs_ResourceToAddModList)
9611             {
9612                resourceList = srsCfg->srs_ResourceToAddModList;
9613                if(resourceList->list.array)
9614                {
9615                   rsrcIdx = 0;
9616
9617                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9618                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9619
9620                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9621                   {
9622                      free(resourceList->list.array[rsrcIdx]);
9623                   }
9624                   free(resourceList->list.array);
9625                }
9626                free(srsCfg->srs_ResourceToAddModList);
9627             }
9628
9629             free(ulBwp->srs_Config->choice.setup);
9630          }
9631          free(ulBwp->srs_Config);
9632       }
9633    }
9634 }
9635 /*******************************************************************
9636 *
9637 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9638 *
9639 * @details
9640 *
9641 *    Function : freeAperDecodeinitialUplinkBWPConfig
9642 *
9643 *    Functionality: Function to free initialUplinkBWPConfig
9644 *
9645 * @params[in] UplinkConfig_t *ulCfg 
9646 * @return void
9647 *
9648 * ****************************************************************/
9649
9650
9651 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9652 {
9653    BWP_UplinkDedicated_t *ulBwp=NULLP;
9654    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9655    
9656    if(ulCfg->initialUplinkBWP)
9657    {
9658       ulBwp=ulCfg->initialUplinkBWP;
9659       if(ulCfg->firstActiveUplinkBWP_Id)
9660       {
9661          if(ulCfg->pusch_ServingCellConfig)
9662          {
9663             puschCfg=ulCfg->pusch_ServingCellConfig;
9664             if(puschCfg->choice.setup)
9665             {
9666                if(puschCfg->choice.setup->ext1)
9667                {
9668                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9669                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9670                   free(puschCfg->choice.setup->ext1);
9671                }
9672                free(puschCfg->choice.setup);
9673             }
9674             free(ulCfg->pusch_ServingCellConfig);
9675          }
9676          free(ulCfg->firstActiveUplinkBWP_Id);
9677       }
9678       freeAperDecodeInitialUlBWPConfig(ulBwp);
9679       free(ulCfg->initialUplinkBWP);
9680    }
9681 }
9682
9683 /*******************************************************************
9684  *
9685  * @brief Function to free DuUeCfg
9686  *
9687  * @details
9688  *
9689  *    Function : freeDuUeCfg
9690  *
9691  *    Functionality: Function to free DuUeCfg
9692  *
9693  * @params[in] DuUeCfg *ueCfg
9694  * @return void
9695  *
9696  * ****************************************************************/
9697 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9698 {
9699    uint8_t lcIdx = 0;
9700    uint8_t arrIdx = 0;
9701    SpCellConfig_t *spCellCfg = NULLP;
9702    ServingCellConfig_t *srvCellCfg = NULLP;
9703    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9704    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9705    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9706    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9707    struct RLC_Config *rlcConfig = NULLP;
9708    struct LogicalChannelConfig *macLcConfig = NULLP;
9709    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9710    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9711    struct TAG_Config *tagConfig = NULLP;
9712    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9713    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9714    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9715    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9716   
9717    if(ueCfg->ueNrCapability)
9718    {
9719       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9720       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9721       ueCfg->ueNrCapability = NULLP;
9722    }
9723
9724    if(ueCfg->cellGrpCfg)
9725    {
9726       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9727       if(rlcBearerList)
9728       {
9729          if(rlcBearerList->list.array)
9730          {
9731             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9732             {
9733                if(rlcBearerList->list.array[arrIdx])
9734                {
9735                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9736                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9737
9738                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9739                   {
9740                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9741                   }
9742                   if(rlcConfig)
9743                   {
9744                      if(rlcConfig->choice.am)
9745                      {
9746                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9747                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9748                         free(rlcConfig->choice.am);
9749                      }
9750                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9751                   }
9752                   if(macLcConfig)
9753                   {
9754                      if(macLcConfig->ul_SpecificParameters)
9755                      {
9756                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9757                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9758                         free(macLcConfig->ul_SpecificParameters);
9759                      }
9760                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9761                   }
9762                   free(rlcBearerList->list.array[arrIdx]); 
9763                }
9764             }
9765             free(rlcBearerList->list.array);
9766          }
9767          free(cellGrpCfg->rlc_BearerToAddModList);
9768       }
9769
9770       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9771       if(macCellGrpCfg)
9772       {
9773          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9774          if(schedulingRequestConfig)
9775          {
9776             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9777             if(schReqList)
9778             {
9779                if(schReqList->list.array)
9780                {
9781                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9782                   {
9783                      if(schReqList->list.array[arrIdx])
9784                      {
9785                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9786                         free(schReqList->list.array[arrIdx]);
9787                      }
9788                   }
9789                   free(schReqList->list.array);
9790                }
9791                free(schedulingRequestConfig->schedulingRequestToAddModList);
9792             }
9793             free(macCellGrpCfg->schedulingRequestConfig);
9794          }
9795          if(macCellGrpCfg->bsr_Config)
9796          {
9797             free(macCellGrpCfg->bsr_Config);
9798          }
9799          tagConfig = macCellGrpCfg->tag_Config;
9800          if(tagConfig)
9801          {
9802             tagList = tagConfig->tag_ToAddModList;
9803             if(tagList)
9804             {
9805                if(tagList->list.array)
9806                {
9807                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9808                   {
9809                      free(tagList->list.array[arrIdx]);
9810                   }
9811                   free(tagList->list.array);
9812                }
9813                free(tagConfig->tag_ToAddModList);
9814             }
9815             free(tagConfig); 
9816          }
9817
9818          phrConfig = macCellGrpCfg->phr_Config;
9819          if(phrConfig)
9820          {
9821             free(phrConfig->choice.setup); 
9822             free(phrConfig); 
9823          }
9824
9825          free(macCellGrpCfg); 
9826       }
9827
9828       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9829       if(phyCellGrpCfg)
9830       {
9831          free(phyCellGrpCfg->p_NR_FR1);
9832          free(phyCellGrpCfg); 
9833       }
9834
9835       spCellCfg = cellGrpCfg->spCellConfig;
9836       if(spCellCfg)
9837       {
9838          if(spCellCfg->servCellIndex)
9839          {
9840             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9841             {
9842                if(spCellCfg->spCellConfigDedicated)
9843                {
9844                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9845                   if(srvCellCfg->initialDownlinkBWP)
9846                   {
9847                      dlBwp = srvCellCfg->initialDownlinkBWP;
9848                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9849                      {
9850                         if(srvCellCfg->defaultDownlinkBWP_Id)
9851                         {
9852                            if(srvCellCfg->uplinkConfig)
9853                            {
9854
9855                               if(srvCellCfg->pdsch_ServingCellConfig)
9856                               {
9857                                  pdschCfg=
9858                                     srvCellCfg->pdsch_ServingCellConfig;
9859                                  if(pdschCfg->choice.setup)
9860                                  {
9861
9862                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9863                                     free(pdschCfg->choice.setup);
9864                                  }
9865
9866                                  free(srvCellCfg->pdsch_ServingCellConfig);
9867                               }
9868
9869                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9870                               free(srvCellCfg->uplinkConfig);
9871                            }
9872                            free(srvCellCfg->defaultDownlinkBWP_Id);
9873                         }
9874
9875                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9876                      }
9877                      if(dlBwp->pdcch_Config)
9878                      {
9879                         if(dlBwp->pdsch_Config)
9880                         {
9881                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9882                            free(dlBwp->pdsch_Config);
9883                         }
9884                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9885                         free(dlBwp->pdcch_Config);
9886                      }
9887                      free(srvCellCfg->initialDownlinkBWP);
9888                   }
9889
9890                   free(spCellCfg->spCellConfigDedicated);
9891                }
9892                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9893             }
9894             free(spCellCfg->servCellIndex); 
9895          }
9896          free(spCellCfg);
9897       }
9898       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9899       ueCfg->cellGrpCfg = NULLP;
9900    }
9901
9902    if(ueCfg->ambrCfg)
9903    {
9904       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9905    }
9906
9907    if(actionType != UE_CTXT_CFG_QUERY)
9908    {
9909       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9910       {
9911          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9912       }
9913    }
9914
9915    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9916    {
9917       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
9918    }
9919
9920    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9921    {
9922       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9923    }
9924 }
9925
9926 /*******************************************************************
9927  *
9928  * @brief Function to free UecontextSetupDb
9929  *
9930  * @details
9931  *
9932  *    Function : freeF1UeDb
9933  *
9934  *    Functionality: Function to free UecontextSetupDb
9935  *
9936  * @params[in] UecontextSetupDb *
9937  * @return void
9938  *
9939  * ****************************************************************/
9940
9941 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9942 {
9943    
9944    if(f1UeDb->dlRrcMsg)
9945    {
9946       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9947       {
9948         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9949                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9950       }
9951       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9952    }
9953    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
9954    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9955    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9956 }
9957
9958 /*******************************************************************
9959  *
9960  * @brief Function to build Am cfg Info
9961  *
9962  * @details
9963  *
9964  *    Function : extractRlcAmCfg
9965  *
9966  *    Functionality: Function to build Am cfg Info
9967  *
9968  * @params[in] AmBearerCfg *
9969  *             void *
9970  *
9971  * @return ROK/RFAILED
9972  *
9973  * ****************************************************************/
9974
9975 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9976 {
9977    if(rlcAmCfg)
9978    {
9979       /* UL AM */
9980       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9981       {
9982          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9983          /*TODO: Check the timer value when sent by real CU */
9984          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9985          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9986       }
9987
9988       /* DL AM */
9989       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9990       {
9991          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9992          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9993          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9994          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9995          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9996       }
9997    }
9998 }
9999
10000 /*******************************************************************
10001  *
10002  * @brief Function to build Um Bi Info
10003  *
10004  * @details
10005  *
10006  *    Function : extractRlcUmBiCfg
10007  *
10008  *    Functionality: Function to build Um Bi Info
10009  *
10010  * @params[in] UmBiDirBearerCfg *
10011  *             void *
10012  *
10013  * @return ROK/RFAILED
10014  *
10015  * ****************************************************************/
10016
10017 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10018 {
10019    if(rlcBiCfg)
10020    {
10021       /* UL UM BI DIR Cfg */
10022       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10023       {
10024          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10025          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10026       }
10027
10028       /* DL UM BI DIR Cfg */
10029       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10030          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10031    }
10032 }
10033
10034 /*******************************************************************
10035  *
10036  * @brief Function to build Um Ul Info
10037  *
10038  * @details
10039  *
10040  *    Function : extractRlcUmUlCfg
10041  *
10042  *    Functionality: Function to build Um Ul Info
10043  *
10044  * @params[in] UmUniDirUlBearerCfg *
10045  *             void *
10046  *
10047  * @return ROK/RFAILED
10048  *
10049  * ****************************************************************/
10050
10051 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10052 {
10053    if(umUlCfg)
10054    {
10055       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10056       {
10057          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10058          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10059       }
10060    }
10061 }
10062
10063 /*******************************************************************
10064  *
10065  * @brief Function to build Um Uni Dl Info
10066  *
10067  * @details
10068  *
10069  *    Function : extractRlcUmDlCfg
10070  *
10071  *    Functionality: Function to build Um Uni Dl Info
10072  *
10073  * @params[in] UmUniDirDlBearerCfg *
10074  *             void *
10075  *
10076  * @return ROK/RFAILED
10077  *
10078  * ****************************************************************/
10079 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10080 {
10081    if(umDlCfg)
10082    {
10083       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10084          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10085    }
10086 }
10087
10088 /*******************************************************************
10089  *
10090  * @brief Function to extractRlcModeCfg
10091  *
10092  * @details
10093  *
10094  *    Function : extractRlcModeCfg
10095  *
10096  *    Functionality: Function to extractRlcModeCfg
10097  *
10098  * @params[in] RLC_Config_t *
10099  *             RlcBearerCfg *
10100  *             void  *    
10101  * @return ROK/RFAILED
10102  *
10103  * ****************************************************************/
10104 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10105 {
10106    if(lcCfg)
10107    {
10108       switch(rlcMode)
10109       {
10110          case RLC_AM :
10111             {
10112                if(lcCfg->choice.am)
10113                {
10114                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10115                   if(rlcDbCfg->u.amCfg)
10116                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10117                }
10118                break;
10119             }
10120          case RLC_UM_BI_DIRECTIONAL :
10121             {
10122                if(lcCfg->choice.um_Bi_Directional)
10123                {
10124                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10125                   if(rlcDbCfg->u.umBiDirCfg)
10126                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10127                }
10128                break;
10129             }
10130          case RLC_UM_UNI_DIRECTIONAL_UL :
10131             {
10132                if(lcCfg->choice.um_Uni_Directional_DL)
10133                {
10134                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10135                   if(rlcDbCfg->u.umUniDirUlCfg)
10136                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10137                }
10138                break;
10139             }
10140          case RLC_UM_UNI_DIRECTIONAL_DL :
10141             {
10142                if(lcCfg->choice.um_Uni_Directional_UL)
10143                {
10144                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10145                   if(rlcDbCfg->u.umUniDirDlCfg)
10146                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10147                }
10148                break;
10149             }
10150          default:
10151             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10152             break;
10153       }
10154    }
10155 }
10156
10157 /*******************************************************************
10158  *
10159  * @brief Function to extract extractUlLcCfg
10160  *
10161  * @details
10162  *
10163  *    Function : extractUlLcCfg
10164  *
10165  *    Functionality: Function to extract extractUlLcCfg
10166  *
10167  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10168  * @return void
10169  *
10170  * ****************************************************************/
10171
10172 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10173 {
10174    if(ulLcCfg)
10175    {
10176       if(ulLcCfg->ul_SpecificParameters)
10177       {
10178          f1UlLcCfg->priority = \
10179             ulLcCfg->ul_SpecificParameters->priority;
10180       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10181       {
10182          f1UlLcCfg->lcGroup = \
10183            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10184       }
10185       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10186       {
10187          f1UlLcCfg->schReqId = \
10188            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10189       }
10190       f1UlLcCfg->pbr = \
10191          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10192       f1UlLcCfg->bsd = \
10193          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10194       }
10195    }
10196 }
10197
10198 /*******************************************************************
10199 *
10200 * @brief Function to extract Snssai Cfg Info from CU
10201 *
10202 * @details
10203 *
10204 *    Function : extractDrbSnssaiCfg
10205 *
10206 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10207 *
10208 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10209 * @return ROK/RFAILED
10210 *
10211 * ****************************************************************/
10212
10213 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10214 {
10215    if(!(*snssaiToBeShared))
10216    {
10217       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10218       if(snssaiToBeShared == NULLP)
10219       {
10220          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10221          return RFAILED;
10222       }
10223    }
10224    if(RecvSnssai)
10225    {
10226       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10227       if(RecvSnssai->sD)
10228       {
10229          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10230       }
10231       else
10232       {
10233          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10234          return RFAILED;
10235       }
10236    }
10237    return ROK;
10238 }
10239
10240 /*******************************************************************
10241  *
10242  * @brief Function to procRlcLcCfg
10243  *
10244  * @details
10245  *
10246  *    Function : procRlcLcCfg
10247  *
10248  *    Functionality: Function to procRlcLcCfg
10249  *
10250  * @params[in] rbId, lcId, rbType, rlcMod
10251  *             RLC_Config_t *, RlcBearerCfg * , 
10252  * @return void
10253  *
10254  * ****************************************************************/
10255
10256 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10257    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10258 {
10259    DRB_Information_t *drbInfo;
10260
10261    lcCfg->rlcBearerCfg.rbId   = rbId;
10262    lcCfg->configType = configType;
10263
10264    if(rbType == RB_TYPE_SRB)
10265    {
10266       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10267       lcCfg->rlcBearerCfg.lcId   = rbId;
10268       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10269       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10270    }
10271    else if(rbType == RB_TYPE_DRB)
10272    {
10273       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10274       lcCfg->rlcBearerCfg.lcId   = lcId;
10275       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10276       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10277    }
10278    if(f1RlcCfg) /* rlc mode config recived */
10279    {
10280       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10281    }
10282    if(qoSInformation != NULLP)
10283    {
10284       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10285       {
10286          if(qoSInformation->choice.choice_extension->value.present ==\
10287                QoSInformation_ExtIEs__value_PR_DRB_Information)
10288          {
10289             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10290             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10291             {
10292                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10293                return;
10294             }
10295          }
10296       }
10297    }
10298 }
10299
10300 /*******************************************************************
10301  *
10302  * @brief Fills DrbQos Info received by CU
10303  *
10304  * @details
10305  *
10306  *    Function : extractQosInfo
10307  *
10308  *    Functionality: Fills DrbQos Info received  by CU
10309  *
10310  * @params[in] DrbQosInfo *qosToAdd, 
10311  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10312  * @return void
10313  *
10314  * ****************************************************************/
10315
10316 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10317 {
10318    uint8_t qosCntIdx = 0;
10319    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10320
10321    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10322    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10323                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10324    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10325    {
10326       qosToAdd->u.nonDyn5Qi.avgWindow = \
10327                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10328    }
10329
10330    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10331    {
10332       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10333                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10334    }
10335
10336    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10337    {
10338       qosToAdd->u.nonDyn5Qi.priorLevel = \
10339                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10340    }
10341    qosToAdd->ngRanRetPri.priorityLevel = \
10342                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10343    qosToAdd->ngRanRetPri.preEmptionCap = \
10344                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10345    qosToAdd->ngRanRetPri.preEmptionVul = \
10346                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10347    if(qosFlowCfg->gBR_QoS_Flow_Information)
10348    {
10349       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10350             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10351             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10352       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10353             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10354             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10355       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10356             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10357             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10358       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10359             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10360             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10361    }
10362    /*Extracting PDU_SESSION_ID*/
10363    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10364    if(qosIeExt)
10365    {
10366       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10367       {
10368          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10369                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10370          {
10371             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10372             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10373          }
10374       }  
10375    }
10376    qosToAdd->ulPduSessAggMaxBitRate = 0;
10377 }
10378
10379 /*******************************************************************
10380  *
10381  * @brief Function to extract GTP Tunnel Info from CU
10382  *
10383  * @details
10384  *
10385  *    Function : extractUpTnlInfo
10386  *
10387  *    Functionality: Function to extract GTP Tunnel Info from CU
10388  *
10389  * @params[in] F1AP message
10390  * @return ROK/RFAILED
10391  *
10392  * ****************************************************************/
10393
10394 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10395    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10396 {
10397    uint8_t tnlIdx;
10398    uint32_t ipv4_du = 0;
10399    GTPTunnel_t *gtpTunnel = NULLP;
10400
10401    upTnlInfo->drbId = drbId; 
10402    upTnlInfo->configType = configType;
10403 #ifdef O1_ENABLE
10404    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10405 #else
10406    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10407 #endif
10408
10409    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10410    {
10411       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10412       {
10413          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10414          {
10415             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10416             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10417             if(upTnlInfo->tnlCfg1 == NULLP)
10418             {
10419                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10420                return RFAILED;
10421             }
10422             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10423             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10424             if(gtpTunnel->gTP_TEID.size > 0)
10425             {
10426                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10427             }
10428          }
10429          break;
10430       }
10431    }
10432    return ROK;
10433 }
10434
10435 /*******************************************************************
10436 *
10437 * @brief Function to extract Drb Qos Cfg Info from CU
10438 *
10439 * @details
10440 *
10441 *    Function : extractDrbQosCfg 
10442 *
10443 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10444 *
10445 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10446 * @return ROK/RFAILED
10447 *
10448 * ****************************************************************/
10449
10450 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10451 {
10452    if(!macLcToAdd->drbQos)
10453    {
10454       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10455       if(macLcToAdd->drbQos == NULLP)
10456       {
10457          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10458          return RFAILED;
10459       }
10460
10461    }
10462    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10463    {
10464       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10465       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10466    }
10467    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10468    {
10469       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10470       return RFAILED;
10471    }
10472    return ROK;
10473 }
10474 /*******************************************************************
10475  *
10476  * @brief Function to extract DRB info received from CU
10477  *
10478  * @details
10479  *
10480  *    Function : extractDrbCfg
10481  *
10482  *    Functionality: Function to extract DRB info received from CU
10483  *
10484  * @params[in] F1AP message
10485  * @return void
10486  *
10487  * ****************************************************************/
10488 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10489 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10490 {
10491    DRB_Information_t *drbInfo = NULLP;
10492
10493    if(drbItem != NULLP)
10494    {
10495       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10496       {
10497          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10498          return RFAILED;
10499       }
10500       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10501       {
10502          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10503          {
10504             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10505             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10506             {
10507                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10508                return RFAILED;
10509             }
10510          }
10511       }
10512    }
10513    else if(drbSetupModItem != NULLP)
10514    {
10515       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10516       upTnlInfo) != ROK)
10517       {
10518          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10519          return RFAILED;
10520       }
10521       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10522       {
10523          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10524          QoSInformation_ExtIEs__value_PR_DRB_Information)
10525          {
10526             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10527             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10528             {
10529                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10530                return RFAILED;
10531             }
10532
10533          }
10534       }
10535    }
10536    else if(drbModItem != NULLP)
10537    {
10538       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10539       upTnlInfo) != ROK)
10540       {
10541          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10542          return RFAILED;
10543       }
10544       if(drbModItem->qoSInformation != NULLP)
10545       {
10546          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10547          {
10548             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10549                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10550             {
10551                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10552                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10553                {
10554                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10555                   return RFAILED;
10556                }
10557
10558             }
10559          }
10560       }
10561    }
10562    return ROK;
10563 }
10564
10565 /*******************************************************************
10566  *
10567  * @brief Function to extract RB info received from CU
10568  *
10569  * @details
10570  *
10571  *    Function : extractMacRbCfg
10572  *
10573  *    Functionality: Function to extract RB info received from CU
10574  *
10575  * @params[in] F1AP message
10576  * @return ROK/RFAILED
10577  *
10578  * ****************************************************************/
10579
10580 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10581 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10582 {
10583    if(drbCfg != NULLP)
10584    {
10585       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10586       {
10587          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10588          return RFAILED;
10589       }
10590    }
10591    else if(drbSetupModCfg != NULLP)
10592    { 
10593       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10594       {
10595          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10596          return RFAILED;
10597       }
10598    }
10599    else if(drbModCfg != NULLP)
10600    { 
10601       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10602       {
10603          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10604          return RFAILED;
10605       }
10606    }
10607    else
10608    {
10609       lcCfg->lcConfig.drbQos = NULLP;
10610       lcCfg->lcConfig.snssai = NULLP;
10611       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10612          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10613       else
10614          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10615
10616    }
10617    if(ulLcCfg)
10618    {
10619       lcCfg->lcConfig.ulLcCfgPres = true;
10620       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10621    }
10622    else
10623       lcCfg->lcConfig.ulLcCfgPres = false;
10624    return ROK;
10625 }
10626
10627 /*******************************************************************
10628  *
10629  * @brief Function processing LC config info received from CU
10630  *
10631  * @details
10632  *
10633  *    Function : procMacLcCfg
10634  *
10635  *    Functionality: Function processing LC config info received from CU
10636  *
10637  * @params[in] F1AP message
10638  * @return ROK/RFAILED
10639  *
10640  * ****************************************************************/
10641
10642 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10643 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10644 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10645 {
10646    uint8_t ret = ROK;
10647
10648    lcCfg->lcConfig.lcId = lcId;
10649    lcCfg->configType = configType;
10650    if(rbType == RB_TYPE_SRB)
10651    {
10652       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10653    }
10654    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10655    {
10656       if(drbItem != NULL)
10657         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10658       else if(drbSetupModItem != NULL)
10659         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10660       else if(drbModItem != NULL)
10661         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10662    }
10663    return ret;
10664 }
10665
10666 /*******************************************************************
10667  *
10668  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10669  *
10670  * @details
10671  *
10672  *    Function : extractRlcCfgToAddMod
10673  *
10674  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10675  *
10676  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10677  *             DuUeCfg Pointer
10678  * @return ROK/RFAILED
10679  *
10680  * ****************************************************************/
10681
10682 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10683 {
10684   uint8_t idx, rbId, lcId, rlcMode, rbType;
10685   RLC_Config_t *f1RlcCfg = NULLP;
10686   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10687
10688   for(idx = 0; idx < lcCfg->list.count; idx++)
10689   {
10690      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10691      if(lcCfg->list.array[idx]->servedRadioBearer)
10692      {
10693         /* RadioBearer for SRB/DRB */
10694         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10695         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10696         {
10697            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10698            rbType = RB_TYPE_SRB;
10699         }
10700         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10701         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10702         {
10703            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10704            rbType = RB_TYPE_DRB;
10705         }
10706         else
10707         {
10708            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10709            return RFAILED;
10710         }
10711         /* MAC UL LC Config */
10712         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10713         {
10714            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10715         }
10716      }
10717      else
10718      {
10719         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10720         return RFAILED;
10721      }
10722      /* RLC Mode Config */
10723      if(lcCfg->list.array[idx]->rlc_Config)
10724      {
10725         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10726         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10727      }
10728      
10729      /* Filling RLC/MAC Config*/
10730      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10731      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10732      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10733      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10734      {
10735         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10736         return RFAILED;
10737      }
10738      (ueCfgDb->numRlcLcs)++;
10739      (ueCfgDb->numMacLcs)++;
10740      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10741         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10742   }
10743   //TODO: To send the failure cause in UeContextSetupRsp 
10744   return ROK;
10745 }
10746
10747 /*******************************************************************
10748  *
10749  * @brief DeAlloc pdsch serv cell config info
10750  *
10751  * @details
10752  *
10753  *    Function : freeMacPdschServCellInfo
10754  *
10755  *    Functionality: DeAlloc pdsch serv cell config info
10756  *
10757  * @params[in] PdschServCellCfg pointer
10758  * @return void
10759  *
10760  * ****************************************************************/
10761
10762 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10763 {
10764    if(pdsch->xOverhead)
10765    {
10766       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10767    }
10768    if(pdsch->codeBlkGrpFlushInd)
10769    {
10770       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10771    }
10772    if(pdsch->maxCodeBlkGrpPerTb)
10773    {
10774       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10775    }
10776    if(pdsch->maxMimoLayers)
10777    {
10778       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10779    }
10780 }
10781
10782 /*******************************************************************
10783  *
10784  * @brief Free Serving cell Info
10785  *
10786  * @details
10787  *
10788  *    Function : freeMacServingCellInfo
10789  *
10790  *    Functionality: Free Serving cell Info
10791  *
10792  * @params[in] ServCellCfgInfo *srvCellCfg
10793  * @return void
10794  *
10795  * ****************************************************************/
10796 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10797 {
10798    uint8_t timeDomRsrcIdx;
10799
10800    if(srvCellCfg->initDlBwp.pdschPresent)
10801    {
10802       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10803       {
10804          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10805             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10806       }
10807    }
10808
10809    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10810    if(srvCellCfg->bwpInactivityTmr)
10811    {
10812       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10813    }
10814
10815    if(srvCellCfg->initUlBwp.pucchPresent)
10816    {
10817       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10818    }
10819 }
10820
10821 /*******************************************************************
10822  *
10823  * @brief Free cell Grp Cfg Info
10824  *
10825  * @details
10826  *
10827  *    Function : freeUeRecfgCellGrpInfo
10828  *
10829  *    Functionality: Free cell Grp Cfg Info
10830  *
10831  * @params[in] DuMacUeCfg*  duUeCfg
10832  * @return void
10833  *
10834  * ****************************************************************/
10835
10836 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10837 {
10838    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10839 }
10840
10841 /*******************************************************************
10842  *
10843  * @brief Fills Reconfig SchReqReConfig
10844  *
10845  * @details
10846  *
10847  *    Function : extractSchReqReConfig
10848  *
10849  *    Functionality: Fills Reconfig SchReqReConfig
10850  *
10851  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10852  *             SchedReqCfg*  macSchedReq
10853  * @return void
10854  *
10855  * ****************************************************************/
10856 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10857 {
10858    uint8_t schReqIdx = 0;
10859    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10860    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10861
10862    if(cuSchedReq->schedulingRequestToAddModList)
10863    {
10864       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10865       if(schReqListToAdd->list.count)
10866       {
10867          macSchedReq->addModListCount = schReqListToAdd->list.count;
10868          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10869          {
10870             macSchedReq->addModList[schReqIdx].schedReqId = \
10871                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10872             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10873                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10874             macSchedReq->addModList[schReqIdx].srTransMax    =\
10875                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10876          }
10877       }
10878    }
10879    /* Scheduling Req To release */
10880    if(cuSchedReq->schedulingRequestToReleaseList)
10881    {
10882       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10883       if(schReqListToRel->list.count)
10884       {
10885          macSchedReq->relListCount = schReqListToRel->list.count;
10886          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10887          {
10888             macSchedReq->relList[schReqIdx] = \
10889                *schReqListToRel->list.array[schReqIdx];
10890          }
10891       }
10892    }
10893 }
10894
10895 /*******************************************************************
10896  *
10897  * @brief Fills TagReconfig
10898  *
10899  * @details
10900  *
10901  *    Function : extractTagReconfig
10902  *
10903  *    Functionality: Fills extractTagReconfig
10904  *
10905  * @params[in] TAG_Config_t *cuTagCfg
10906  *             TagCfg *macTagCfg
10907  * @return void
10908  *
10909  * ****************************************************************/
10910
10911 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10912 {
10913   uint8_t tagIdx = 0;
10914   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10915   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10916
10917   /* Tag config to AddMod */
10918   if(cuTagCfg->tag_ToAddModList)
10919   {
10920      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10921      if(tagListToAddMod->list.count)
10922      {
10923         macTagCfg->addModListCount = tagListToAddMod->list.count;
10924         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10925         {
10926            macTagCfg->addModList[tagIdx].tagId =\
10927               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10928            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10929
10930               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10931         }
10932      }
10933   }
10934   /* Tag config to release */
10935   if(cuTagCfg->tag_ToReleaseList)
10936   {
10937      tagListToRel = cuTagCfg->tag_ToReleaseList;
10938      if(tagListToRel->list.count)
10939      {
10940         macTagCfg->relListCount = tagListToRel->list.count;
10941         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10942         {
10943            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10944         }
10945      }
10946   }
10947 }
10948
10949 /*******************************************************************
10950  *
10951  * @brief Fills PdcchCfg received by CU
10952  *
10953  * @details
10954  *
10955  *    Function : extractPdcchCfg
10956  *
10957  *    Functionality: Fills PdcchCfg received  by CU
10958  *
10959  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10960  *             PdcchConfig *duPdcchCfg
10961  * @return void
10962  *
10963  * ****************************************************************/
10964
10965 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10966 {
10967    uint8_t cRsetIdx = 0;
10968    uint8_t srchSpcIdx = 0;
10969
10970    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10971    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10972    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10973    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10974
10975
10976    /* Control Resource Set To Add/Mod List */
10977    if(cuPdcchCfg->controlResourceSetToAddModList)
10978    {
10979       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10980       if(cRsetToAddModList->list.count)
10981       {
10982          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10983          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10984          {
10985             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10986                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10987             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10988                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10989             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10990                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10991                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10992
10993             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10994                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10995
10996             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10997                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10998             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10999             {
11000                //TODO: handle the case for Interleaved
11001             }
11002             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11003                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11004             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11005             {
11006                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11007                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11008             }
11009          }
11010       }
11011    }
11012    /* Control Resource Set To Release List */
11013    if(cuPdcchCfg->controlResourceSetToReleaseList)
11014    {
11015       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11016       if(cRsetToRelList->list.count)
11017       {
11018          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11019          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11020          {
11021             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11022          }
11023       }
11024    }
11025
11026    /* Search space To Add/Mod List */
11027    if(cuPdcchCfg->searchSpacesToAddModList)
11028    {
11029       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11030       if(srchSpcToAddModList->list.count)
11031       {
11032          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11033          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11034          {
11035             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11036                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11037             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11038                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11039             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11040             {
11041                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11042                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11043             }
11044             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11045             {
11046                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11047                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11048             }
11049             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11050             {
11051                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11052                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11053                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11054                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11055                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11056                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11057
11058                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11059                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11060
11061                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11062                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11063             }
11064             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11065             {
11066                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11067                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11068                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11069                {
11070                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11071                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11072                }
11073
11074             }
11075          }
11076       }
11077    }
11078    /* Search space To Rel List */
11079    if(cuPdcchCfg->searchSpacesToReleaseList)
11080    {
11081       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11082       if(srchSpcToRelList->list.count)
11083       {
11084          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11085          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11086          {
11087             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11088                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11089          }
11090       }
11091    }
11092 }
11093
11094 /*******************************************************************
11095  *
11096  * @brief Fills PdschCfg received by CU
11097  *
11098  * @details
11099  *
11100  *    Function : extractPdschCfg
11101  *
11102  *    Functionality: Fills PdschCfg received  by CU
11103  *
11104  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11105  *                   which we have stored in F1UeContextSetupDb,
11106  *             PdschConfig *macPdschCfg = Used to Store the information which
11107  *                   needs to send in other layer, as well as this can be the variable
11108  *                   which stores the information in DuCb,
11109  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11110  *                   information to other layer else it will have stored pdsch 
11111  *                   configuration in copyOfmacUeCfg.
11112  * @return void
11113  *
11114  * ****************************************************************/
11115
11116 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11117 {
11118    uint8_t timeDomIdx;
11119    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11120
11121    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11122    {
11123       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11124             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11125       {
11126          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11127          {
11128             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11129                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11130          }
11131       }
11132    }
11133    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11134    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11135    {
11136       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11137       if(timeDomAlloc->present ==\
11138             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11139       {
11140          if(timeDomAlloc->choice.setup)
11141          {
11142             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11143             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11144             {
11145                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11146                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11147                {
11148                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11149                   {
11150                      if(storedPdschCfg)
11151                      {
11152                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11153                         {
11154                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11155                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11156                         }
11157                         else
11158                         {
11159                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11160                         }
11161                      }
11162                      else
11163                      {
11164                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11165                      }
11166                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11167                      {
11168                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11169                         return;
11170                      }
11171                   }
11172                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11173                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11174                }
11175                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11176                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11177                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11178                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11179             }
11180          }
11181       }
11182    }
11183    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11184    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11185       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11186    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11187    {
11188       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11189       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11190       {
11191          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11192          {
11193             macPdschCfg->bundlingInfo.StaticBundling.size = \
11194                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11195          }
11196       }
11197    }
11198    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11199    {
11200       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11201    }
11202
11203 }
11204
11205 /*******************************************************************
11206  *
11207  * @brief Fills PdschServingCellCfg received by CU
11208  *
11209  * @details
11210  *
11211  *    Function : extractPdschServingCellCfg
11212  *
11213  *    Functionality: Fills PdschCfg received  by CU
11214  *
11215  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11216  *             PdschServCellCfg *macUePdschSrvCellCfg
11217  * @return ROK/RFAILED
11218  *
11219  * ****************************************************************/
11220
11221 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11222 {
11223    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11224    {
11225       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11226       {
11227          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11228          {
11229             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11230                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11231          }
11232          else
11233          {
11234             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11235             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11236             {
11237                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11238                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11239             }
11240             else
11241             {
11242                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11243                return RFAILED;
11244             }
11245          }
11246          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11247          {
11248             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11249                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11250          }
11251          else
11252          {
11253             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11254             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11255             {
11256                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11257                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11258             }
11259             else
11260             {
11261                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11262                return RFAILED;
11263             }
11264          }
11265       }
11266    }
11267    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11268    {
11269       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11270    }
11271    if(cuPdschSrvCellCfg->ext1)
11272    {
11273       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11274       {
11275         if(macUePdschSrvCellCfg->maxMimoLayers)
11276         {
11277            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11278         }
11279         else
11280         {
11281            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11282            if(macUePdschSrvCellCfg->maxMimoLayers)
11283            {
11284               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11285            }
11286            else
11287            {
11288               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11289               return RFAILED;
11290            }
11291         }
11292       }
11293    }
11294    if(cuPdschSrvCellCfg->xOverhead)
11295    {
11296       if(macUePdschSrvCellCfg->xOverhead)
11297       {
11298          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11299       }
11300       else
11301       {
11302          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11303          if(macUePdschSrvCellCfg->xOverhead)
11304          {
11305             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11306          }
11307          else
11308          {
11309             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11310             return RFAILED;
11311          }
11312       }
11313    }
11314    return ROK;
11315 }
11316
11317 /*******************************************************************
11318  *
11319  * @brief Fills PuschCfg received by CU
11320  *
11321  * @details
11322  *
11323  *    Function : extractPuschCfg
11324  *
11325  *    Functionality: Fills PuschCfg received  by CU
11326  *
11327  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11328  *             PuschCfg *macPuschCfg
11329  * @return void
11330  *
11331  * ****************************************************************/
11332
11333 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11334 {
11335    uint8_t timeDomIdx = 0;
11336    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11337    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11338
11339    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11340    {
11341       if(cuPuschCfg->choice.setup)
11342       {
11343          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11344          {
11345              macPuschCfg->dataScramblingId = \
11346                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11347          }
11348          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11349          {
11350             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11351             {
11352                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11353                {
11354                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11355                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11356                   {
11357                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11358                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11359                   }
11360                   if(dmrsUlCfg->transformPrecodingDisabled)
11361                   {
11362                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11363                      {
11364                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11365                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11366                      }
11367                   }
11368                }
11369             }
11370          }
11371          /*Res Alloc Type for UL */
11372          if(cuPuschCfg->choice.setup->resourceAllocation)
11373          {
11374             macPuschCfg->resourceAllocType = \
11375                cuPuschCfg->choice.setup->resourceAllocation;
11376          }
11377          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11378          {
11379             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11380             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11381             {
11382                if(timeDomAllocList->choice.setup)
11383                {
11384                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11385                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11386                   {
11387                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11388                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11389                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11390                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11391                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11392                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11393                   }
11394                }
11395             }
11396          }
11397          if(cuPuschCfg->choice.setup->transformPrecoder)
11398             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11399       }
11400    }
11401 }
11402
11403 /*******************************************************************
11404  *
11405  * @brief Function to fill pucch Power Control
11406  *
11407  * @details
11408  *
11409  *    Function : extractPucchPowerControl
11410  *
11411  *    Functionality: Function to fill pucch Power Control
11412  *
11413  * @params[in] PucchPowerControl *pwrCtrl,
11414  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11415  * @return void
11416  *
11417  * ****************************************************************/
11418
11419 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11420 {
11421    uint8_t arrIdx;
11422
11423    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11424       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11425    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11426       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11427    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11428       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11429    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11430       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11431    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11432       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11433    if(cuPwrCtrlCfg->p0_Set)
11434    {
11435       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11436       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11437       {
11438          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11439             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11440          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11441             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11442       }
11443    }
11444    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11445    {
11446       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11447       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11448       {
11449          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11450             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11451       }
11452    }
11453 }
11454  
11455  /*******************************************************************
11456  *
11457  * @brief Function to extractResrcSetToAddModList sent by CU
11458  *
11459  * @details
11460  *
11461  *    Function : extractResrcSetToAddModList
11462  *
11463  *    Functionality: Fucntion to extractResrcSetToAddModList
11464  *
11465  * @params[in] PucchResrcSetCfg pointer,
11466  *             struct PUCCH_Config__resourceSetToAddModList pointer
11467  * @return void
11468  *
11469  * ****************************************************************/
11470
11471 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11472 {
11473    uint8_t arrIdx, rsrcListIdx;
11474
11475    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11476    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11477    {
11478       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11479          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11480       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11481          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11482       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11483       {
11484          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11485             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11486       }
11487
11488       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11489       {
11490          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11491             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11492       }
11493       else
11494       {
11495          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11496       }
11497    }
11498 }/* End of extractResrcSetToAddModList */
11499
11500 /*******************************************************************
11501  *
11502  * @brief Fills extractResrcToAddModList sent by CU
11503  *
11504  * @details
11505  *
11506  *    Function : extractResrcToAddModList
11507  *
11508  *    Functionality: Fills extractResrcToAddModList
11509  *
11510  * @params[in] PucchResrcCfg pointer,
11511  *             struct PUCCH_Config__resourceToAddModList pointer
11512  * @return ROk/RFAILED
11513  *
11514  * ****************************************************************/
11515
11516 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11517 {
11518    uint8_t arrIdx;
11519    
11520    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11521    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11522    {
11523       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11524         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11525       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11526         cuResrcList->list.array[arrIdx]->startingPRB;
11527       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11528       {
11529          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11530            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11531       }
11532       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11533       {
11534          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11535            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11536       }
11537       /* PUCCH RSRC FORMAT */
11538       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11539       {
11540          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11541          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11542          {
11543             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11544             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11545             {
11546                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11547                return RFAILED;
11548             }
11549             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11550                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11551             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11552                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11553             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11554                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11555          }
11556       }
11557       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11558       {
11559          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11560          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11561          {
11562             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11563             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11564             {
11565                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11566                return RFAILED;
11567             }
11568             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11569                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11570             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11571                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11572             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11573                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11574             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11575                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11576          }
11577       }
11578       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11579       {
11580          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11581          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11582          {
11583             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11584             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11585             {
11586                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11587                return RFAILED;
11588             }
11589             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11590                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11591             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11592                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11593             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11594                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11595          }
11596       }
11597       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11598       {
11599          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11600          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11601          {
11602             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11603             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11604             {
11605                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11606                return RFAILED;
11607             }
11608             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11609                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11610             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11611                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11612             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11613                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11614          }
11615       }
11616       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11617       {
11618          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11619          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11620          {
11621             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11622             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11623             {
11624                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11625                return RFAILED;
11626             }
11627             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11628                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11629             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11630                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11631             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11632                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11633             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11634                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11635          }
11636       }
11637    }
11638    return ROK;
11639
11640 }/* End of extractResrcToAddModList */
11641
11642 /*******************************************************************
11643  *
11644  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11645  *
11646  * @details
11647  *
11648  *    Function : fillPucchSchedReqPeriodAndOffset
11649  *
11650  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11651  *
11652  * @params[in] macPeriodicty,
11653  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11654  * @return void
11655  *
11656  * ****************************************************************/
11657
11658 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11659    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11660 {
11661    macPeriodicty = cuPeriodicty->present;
11662    switch(macPeriodicty)
11663    {
11664       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11665          {
11666             macOffset     = cuPeriodicty->choice.sym2;
11667             break;
11668          }
11669       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11670          {
11671             macOffset     = cuPeriodicty->choice.sym6or7;
11672             break;
11673          }
11674       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11675          {
11676             macOffset     = cuPeriodicty->choice.sl1;
11677             break;
11678          }
11679       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11680          {
11681             macOffset = cuPeriodicty->choice.sl2;
11682             break;
11683          }
11684       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11685          {
11686             macOffset = cuPeriodicty->choice.sl4;
11687             break;
11688          }
11689       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11690          {
11691             macOffset = cuPeriodicty->choice.sl5;
11692             break;
11693          }
11694       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11695          {
11696             macOffset = cuPeriodicty->choice.sl8;
11697             break;
11698          }
11699       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11700          {
11701             macOffset = cuPeriodicty->choice.sl10;
11702             break;
11703          }
11704       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11705          {
11706             macOffset = cuPeriodicty->choice.sl16;
11707             break;
11708          }
11709       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11710          {
11711             macOffset = cuPeriodicty->choice.sl20;
11712             break;
11713          }
11714       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11715          {
11716             macOffset = cuPeriodicty->choice.sl40;
11717             break;
11718          }
11719       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11720          {
11721             macOffset = cuPeriodicty->choice.sl80;
11722             break;
11723          }
11724       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11725          {
11726             macOffset = cuPeriodicty->choice.sl160;
11727             break;
11728          }
11729       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11730          {
11731             macOffset = cuPeriodicty->choice.sl320;
11732             break;
11733          }
11734       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11735          {
11736             macOffset = cuPeriodicty->choice.sl640;
11737             break;
11738          }
11739       default :
11740          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11741    }
11742 }
11743
11744 /*******************************************************************
11745  *
11746  * @brief Function to extractPucchFormatCfg sent by CU
11747  *
11748  * @details
11749  *
11750  *    Function : extractPucchFormatCfg
11751  *
11752  *    Functionality: Function to extractPucchFormatCfg
11753  *
11754  * @params[in] PucchFormatCfg pointer,
11755  *             PUCCH_FormatConfig_t pointer
11756  * @return void
11757  *
11758  * ****************************************************************/
11759
11760 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11761  {
11762     if(cuFormatCfg->interslotFrequencyHopping)
11763        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11764     if(cuFormatCfg->additionalDMRS)  
11765        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11766     if(cuFormatCfg->maxCodeRate)
11767        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11768     if(cuFormatCfg->nrofSlots)  
11769        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11770     if(cuFormatCfg->pi2BPSK)  
11771        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11772     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11773        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11774  }/* End of extractPucchFormatCfg */
11775
11776 /*******************************************************************
11777  *
11778  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11779  *
11780  * @details
11781  *
11782  *    Function : extractSchedReqCfgToAddMod
11783  *
11784  *    Functionality: Function to extractSchedReqCfgToAddMod
11785  *
11786  * @params[in] PucchSchedReqCfg pointer,
11787  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11788  * @return void
11789  *
11790  * ****************************************************************/
11791
11792 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11793 {
11794    uint8_t arrIdx;
11795
11796    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11797    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11798    {
11799       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11800          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11801       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11802          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11803       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11804       {
11805          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11806             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11807       }
11808       if(cuSchedReqList->list.array[arrIdx]->resource)
11809       {
11810          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11811             *cuSchedReqList->list.array[arrIdx]->resource;
11812       }
11813    }
11814
11815 }/* End of extractSchedReqCfgToAddMod */
11816
11817  /*******************************************************************
11818  *
11819  * @brief Fills PucchCfg received by CU
11820  *
11821  * @details
11822  *
11823  *    Function : extractPucchCfg
11824  *
11825  *    Functionality: Fills PucchCfg received  by CU
11826  *
11827  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11828  *                is send by CU, which we have stored in F1UeContextSetupDb,
11829  *             PucchCfg *macPucchCfg = Used to Store the information which
11830  *                needs to send in other layer, as well as this can be the variable
11831  *                which stores the information in DuCb,
11832  *             PucchCfg *storedPucchCfg = Null in case of sending the
11833  *                information to other layer else it will have Pucch Cfg which
11834  *                we have stored in copyOfmacUeCfg.
11835  * @return ROK/RFAILED
11836  *
11837  * ****************************************************************/
11838
11839 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11840 PucchCfg *storedPucchCfg)        
11841 {
11842    uint8_t arrIdx;
11843
11844    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11845    {
11846       if(cuPucchCfg->choice.setup)
11847       {
11848          /* Resource Set Cfg */ 
11849          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11850          {
11851             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11852             if(macPucchCfg->resrcSet == NULLP)
11853             {
11854                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11855                return RFAILED;
11856             }
11857             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11858             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11859          }
11860          
11861          /* Resource Cfg */ 
11862          if(cuPucchCfg->choice.setup->resourceToAddModList)
11863          {
11864             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11865             if(macPucchCfg->resrc == NULLP)
11866             {
11867                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11868                return RFAILED;
11869             }
11870             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11871             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11872          }
11873          
11874          /* Format 1 Cfg */ 
11875          if(cuPucchCfg->choice.setup->format1)
11876          {
11877             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11878             if(macPucchCfg->format1 == NULLP)
11879             {
11880                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11881                return RFAILED;
11882             }
11883             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11884             extractPucchFormatCfg(macPucchCfg->format1,\
11885                cuPucchCfg->choice.setup->format1->choice.setup);
11886          }
11887          
11888          /* Format 2 Cfg */
11889          if(cuPucchCfg->choice.setup->format2)
11890          {
11891             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11892             if(macPucchCfg->format2 == NULLP)
11893             {
11894                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11895                return RFAILED;
11896             }
11897             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11898             extractPucchFormatCfg(macPucchCfg->format2,\
11899                cuPucchCfg->choice.setup->format2->choice.setup);
11900          }
11901          
11902          /* Format 3 Cfg */
11903          if(cuPucchCfg->choice.setup->format3)
11904          {
11905             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11906             if(macPucchCfg->format3 == NULLP)
11907             {
11908                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11909                return RFAILED;
11910             }
11911             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11912             extractPucchFormatCfg(macPucchCfg->format3,\
11913                cuPucchCfg->choice.setup->format3->choice.setup);
11914          }
11915
11916          /* Format 4 Cfg */
11917          if(cuPucchCfg->choice.setup->format4)
11918          {
11919             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11920             if(macPucchCfg->format4 == NULLP)
11921             {
11922                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11923                return RFAILED;
11924             }
11925             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11926             extractPucchFormatCfg(macPucchCfg->format4,\
11927                cuPucchCfg->choice.setup->format4->choice.setup);
11928          }
11929
11930          /* Sched Req List */
11931          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11932          {
11933             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11934             if(macPucchCfg->schedReq == NULLP)
11935             {
11936                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11937                return RFAILED;
11938             }
11939             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11940             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11941             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11942          }
11943
11944          /*TODO: Add support for  Spatial Info */
11945
11946          /* MultiCsiCfg */
11947          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11948          {
11949             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11950             if(macPucchCfg->multiCsiCfg == NULLP)
11951             {
11952                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11953                return RFAILED;
11954             }
11955             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11956             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11957             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11958             {
11959                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11960                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11961             }
11962          }
11963
11964          /* Dl_DataToUL_ACK */ 
11965          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11966     {
11967        if(storedPucchCfg)
11968        {
11969           if(storedPucchCfg->dlDataToUlAck)
11970           {
11971              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11972           }
11973           else
11974           {
11975             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11976           }
11977        }
11978        else
11979        {
11980           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11981        }
11982        if(macPucchCfg->dlDataToUlAck == NULLP)
11983        {
11984           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11985           return RFAILED;
11986        }
11987        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11988        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11989        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11990        {
11991           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11992           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11993        }
11994          }
11995
11996          /* Power Control */
11997          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11998          {
11999             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12000             if(macPucchCfg->powerControl == NULLP)
12001             {
12002                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12003                return RFAILED;
12004             }
12005             extractPucchPowerControl(macPucchCfg->powerControl,\
12006                cuPucchCfg->choice.setup->pucch_PowerControl);
12007          }
12008       }
12009    }
12010    return ROK;
12011 }
12012
12013 /*******************************************************************
12014  *
12015  * @brief Fills ServingCellReconfig received by CU
12016  *
12017  * @details
12018  *
12019  *    Function : extractSpCellDedicatedCfg
12020  *
12021  *    Functionality: Fills ServingCellReconfig received  by CU
12022  *
12023  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12024  *                  CU, which we have stored in F1UeContextSetupDb,
12025  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12026  *                  which  needs to send in other layer, as well as this can be the
12027  *                  variable which stores the information in DuCb, 
12028  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12029  *                  information to other layer else it will have ServCellCfgInfo which
12030  *                  we have stored in copyOfmacUeCfg.
12031  * @return ROK/RFAILD
12032  *
12033  * ****************************************************************/
12034 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12035 ServCellRecfgInfo *storedSrvCellCfg)
12036 {
12037    uint8_t ret = ROK;
12038    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12039    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12040
12041    if(cuSrvCellCfg->initialDownlinkBWP)
12042    {
12043       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12044       if(dlBwp->pdcch_Config)
12045       {
12046          if(dlBwp->pdcch_Config->choice.setup)
12047          {
12048             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12049             if(storedSrvCellCfg)
12050             {
12051                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12052                {
12053                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12054                }
12055                else
12056                {
12057                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12058                }
12059             }
12060             else
12061             {
12062                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12063             }
12064          }
12065       }
12066       if(dlBwp->pdsch_Config)
12067       {
12068          if(dlBwp->pdsch_Config->choice.setup)
12069          {
12070             macSrvCellCfg->initDlBwp.pdschPresent = true;
12071             
12072             if(storedSrvCellCfg)
12073             {
12074                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12075                {
12076                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12077                }
12078                else
12079                {
12080                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12081                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12082                }
12083             }
12084             else
12085             {
12086                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12087             }
12088          }
12089       }
12090    }
12091    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12092       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12093    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12094       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12095    if(cuSrvCellCfg->bwp_InactivityTimer)
12096    {
12097       if(macSrvCellCfg->bwpInactivityTmr)
12098       {
12099          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12100       }
12101       else
12102       {
12103          macSrvCellCfg->bwpInactivityTmr = NULLP;
12104          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12105          if(macSrvCellCfg->bwpInactivityTmr)
12106          {
12107             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12108          }
12109          else
12110          {
12111             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12112             return RFAILED;
12113          }
12114       }
12115    }
12116    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12117    {
12118       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12119       {
12120          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12121          if(ret == RFAILED)
12122          {
12123             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12124             return RFAILED;
12125          }
12126       }
12127    }
12128    if(cuSrvCellCfg->uplinkConfig)
12129    {
12130       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12131       {
12132          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12133          if(ulBwp->pusch_Config)
12134          {
12135             macSrvCellCfg->initUlBwp.puschPresent = true;
12136             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12137          }
12138          if(ulBwp->pucch_Config)
12139          {
12140             macSrvCellCfg->initUlBwp.pucchPresent = true;
12141             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12142             if(storedSrvCellCfg)
12143             {
12144                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12145                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12146                else
12147                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12148                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12149             }
12150             else
12151             {
12152                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12153             }
12154          }
12155       }
12156       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12157          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12158    }
12159    return ret;
12160 }
12161
12162 #ifdef NR_DRX
12163
12164 /*******************************************************************
12165  *
12166  * @brief fill long cycle offset value of drx in UE structure
12167  *
12168  * @details
12169  *
12170  *    Function : fillLongCycleOffsetValueInUeDb
12171  *
12172  *    Functionality: fill long cycle offset value of drx in UE structure
12173  *
12174  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12175  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12176  *
12177  * @return ROK     - success
12178  *         RFAILED - failure
12179  *
12180  * ****************************************************************/
12181 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12182 {
12183
12184    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12185    switch(drx_LongCycleStartOffset->present)
12186    {
12187       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12188          {
12189             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12190             break;
12191          }
12192       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12193          {
12194             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12195             break;
12196          }
12197       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12198          {
12199             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12200             break;
12201          }
12202       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12203         {
12204             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12205             break;
12206          }
12207       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12208          {
12209             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12210             break;
12211          }
12212       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12213          {
12214             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12215             break;
12216          }
12217       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12218          {
12219             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12220             break;
12221          }
12222       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12223          {
12224             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12225             break;
12226          }
12227       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12228          {
12229             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12230             break;
12231          }
12232       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12233          {
12234             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12235             break;
12236          }
12237       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12238          {
12239             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12240             break;
12241          }
12242       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12243          {
12244             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12245             break;
12246          }
12247       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12248          {
12249             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12250             break;
12251          }
12252       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12253          {
12254             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12255             break;
12256          }
12257       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12258          {
12259             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12260             break;
12261          }
12262       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12263          {
12264             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12265             break;
12266          }
12267       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12268          {
12269             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12270             break;
12271          }
12272       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12273          {
12274             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12275             break;
12276          }
12277        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12278          {
12279             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12280             break;
12281          }
12282       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12283          {
12284             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12285             break;
12286          }
12287       default :
12288          break;
12289    }
12290 }
12291
12292 /*******************************************************************
12293  *
12294  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12295  *which recive from CU or storedDrxCfg which is already stored
12296  *
12297  * @details
12298  *
12299  *    Function : extractDrxConfiguration 
12300  *
12301  *    Functionality: Fills Reconfig Cell group Info received by CU
12302  *   
12303  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12304  *                       is send by CU, which we have stored in F1UeContextSetupDb
12305  *             DrxCfg * drxCfg  = Used to Store the information,
12306  *                      which needs to send in other layer, as well as this can be
12307  *                      the variable which stores the information in DuCb,
12308  *             DrxCfg *storedDrxCfg = Null in case of sending the
12309  *                      information to other layer else it will have the drx information 
12310  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12311  *
12312  * @return void
12313  *
12314  * ****************************************************************/
12315 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12316 {
12317    struct DRX_ConfigRrc *cuDrxConfig;
12318
12319    if(storedDrxCfg)
12320    {
12321       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12322    }
12323    else
12324    {
12325       if(cuMacCellGrpDrxConfig)
12326       {
12327          switch(cuMacCellGrpDrxConfig->present)
12328          {
12329             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12330                break;
12331
12332             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12333                {
12334                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12335                   if(cuDrxConfig)
12336                   {
12337                      switch(cuDrxConfig->drx_onDurationTimer.present)
12338                      {
12339                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12340                            break;
12341                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12342                            {
12343                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12344                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12345                               drx_onDurationTimer.choice.milliSeconds);
12346                               break;
12347                            }
12348                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12349                            {
12350                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12351                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12352                               break;
12353                            }
12354                      }
12355                   }
12356                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12357                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12358                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12359                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12360                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12361                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12362                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12363                   if(cuDrxConfig->shortDRX)
12364                   {
12365                      drxCfg->shortDrxPres=true;
12366                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12367                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12368                   }
12369                   else
12370                      drxCfg->shortDrxPres=false;
12371
12372                   break;
12373                }
12374
12375             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12376                break;
12377          }
12378       }
12379    }
12380 }
12381 #endif
12382
12383 /*******************************************************************
12384  *
12385  * @brief Fills Reconfig Cell group Info received by CU
12386  *
12387  * @details
12388  *
12389  *    Function : extractUeRecfgCellInfo
12390  *
12391  *    Functionality: Fills Reconfig Cell group Info received by CU
12392  *   
12393  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12394  *                       is send by CU, which we have stored in F1UeContextSetupDb
12395  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12396  *                      which needs to send in other layer, as well as this can be
12397  *                      the variable which stores the information in DuCb,
12398  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12399  *                      information to other layer else it will have copyOfmacUeCfg
12400  *                      which we have stored in F1UeContextSetupDb.
12401  *
12402  * @return ROK/RFAILED
12403  *
12404  * ****************************************************************/
12405 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12406 {
12407    uint8_t ret = ROK;
12408    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12409    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12410    SpCellConfig_t            *spcellCfg = NULLP;
12411    ServingCellConfig_t       *servCellCfg = NULLP;
12412
12413    if(cellGrp)
12414    {
12415       /* Fill MacCell Group Reconfig  */
12416       if(cellGrp->mac_CellGroupConfig)
12417       {
12418          macUeCfg->macCellGrpCfgPres = true;
12419          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12420
12421 #ifdef NR_DRX         
12422          if(macCellGroup->drx_ConfigRrc)
12423          {
12424             if(storedMacUeCfg)
12425             {
12426                if(!storedMacUeCfg->macCellGrpCfgPres) 
12427                {
12428                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12429                }
12430                else
12431                {
12432                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12433                }
12434             }
12435             else
12436             {
12437                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12438             }
12439          }
12440 #endif
12441
12442          if(macCellGroup->schedulingRequestConfig)
12443          {
12444             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12445          }
12446          if(macCellGroup->tag_Config)
12447          {
12448             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12449          }
12450          if(macCellGroup->bsr_Config)
12451          {
12452             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12453             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12454             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12455             {
12456                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12457                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12458             }
12459          }
12460          if(macCellGroup->phr_Config)
12461          {
12462             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12463             {
12464                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12465                if(macCellGroup->phr_Config->choice.setup)
12466                {
12467                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12468                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12469                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12470                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12471                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12472                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12473                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12474                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12475                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12476                   macCellGroup->phr_Config->choice.setup->dummy;
12477                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12478                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12479                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12480                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12481                }
12482             }
12483          }
12484       }
12485       /* Fill Physical Cell Group Reconfig */
12486       if(cellGrp->physicalCellGroupConfig)
12487       {
12488          macUeCfg->phyCellGrpCfgPres = true;
12489          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12490          if(phyCellGrpCfg->p_NR_FR1)
12491          {
12492             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12493                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12494          }
12495          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12496       }
12497       /* Fill SpCell Reconfig */
12498       if(cellGrp->spCellConfig)
12499       {
12500          macUeCfg->spCellCfgPres = true;
12501          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12502          if(spcellCfg->servCellIndex)
12503          {
12504             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12505          }
12506          /* Fill Serving cell Reconfig info */
12507          if(cellGrp->spCellConfig->spCellConfigDedicated)
12508          {
12509             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12510             if(storedMacUeCfg)
12511             {
12512                if(!storedMacUeCfg->spCellCfgPres)
12513                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12514                else
12515                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12516                         &storedMacUeCfg->spCellCfg.servCellCfg);
12517             }
12518             else
12519             {
12520                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12521             }
12522             if(ret == RFAILED)
12523             {
12524                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12525             }
12526          }
12527       }
12528    }
12529    return ret;
12530 }
12531 /*******************************************************************
12532 *
12533 * @brief free the memory allocated by decoder
12534 *
12535 * @details
12536 *
12537 *    Function : freeAperDecodeNrcgi 
12538 *
12539 *    Functionality: Free Nrcgi values
12540 *
12541 * @params[in] NRCGI_t *nrcgi
12542 * @return void
12543 *
12544 * ****************************************************************/
12545
12546
12547 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12548 {
12549     if(nrcgi->pLMN_Identity.buf != NULLP)
12550     {
12551        free(nrcgi->pLMN_Identity.buf);
12552     }
12553     if(nrcgi->nRCellIdentity.buf != NULLP)
12554     {
12555        free(nrcgi->nRCellIdentity.buf);
12556     }
12557 }
12558 /*******************************************************************
12559 *
12560 * @brief free the memory allocated by decoder
12561 *
12562 * @details
12563 *
12564 *    Function : freeAperDecodeCuToDuInfo 
12565 *
12566 *    Functionality:  Free Cu To Du Information
12567 *
12568 * @params[in] CUtoDURRCInformation_t *rrcMsg
12569 * @return void
12570 *
12571 * ****************************************************************/
12572
12573
12574 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12575 {
12576    uint8_t ieIdx =0;
12577    uint8_t arrIdx =0;
12578
12579    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12580    {
12581       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12582          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12583       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12584    }
12585
12586    if(rrcMsg->iE_Extensions)
12587    {
12588       if(rrcMsg->iE_Extensions->list.array)
12589       {
12590          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12591          {
12592             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12593             {
12594                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12595                {
12596                   case ProtocolIE_ID_id_CellGroupConfig:
12597                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12598                      {
12599                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12600                      }
12601                      break;
12602                   default:
12603                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12604                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12605                      break;
12606                }
12607             }
12608          }
12609          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12610          {
12611             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12612          }
12613          free(rrcMsg->iE_Extensions->list.array);
12614
12615       }
12616
12617       free(rrcMsg->iE_Extensions);
12618    }
12619 }
12620 /*******************************************************************
12621 *
12622 * @brief free the memory allocated by decoder
12623 *
12624 * @details 
12625 *
12626 *    Function : freeAperDecodeSplCellList
12627 *
12628 *    Functionality: Free Spl Cell List 
12629                     where memory allocated by aper_decoder
12630 *
12631 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12632 * @return void
12633 *
12634 * ****************************************************************/
12635
12636
12637 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12638 {
12639     uint8_t  cellIdx =0;
12640
12641     if(spCellLst->list.array != NULLP)
12642     {
12643        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12644        {
12645           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12646           {
12647              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12648           }
12649           if(spCellLst->list.array[cellIdx]!=NULLP)
12650           {
12651              free(spCellLst->list.array[cellIdx]);
12652           }
12653        }
12654        free(spCellLst->list.array);
12655     }
12656 }
12657 /*******************************************************************
12658 *
12659 * @brief free the memory allocated by decoder
12660 *
12661 * @details
12662 *
12663 *    Function : freeAperDecodeSRBSetup 
12664 *
12665 *    Functionality: added free part for the memory allocated by aper_decoder
12666 *
12667 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12668 * @return void
12669 *
12670 ****************************************************************/
12671
12672
12673 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12674 {
12675     uint8_t srbIdx =0;
12676     if(srbSet->list.array != NULLP)
12677     {
12678        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12679        {
12680           if(srbSet->list.array[srbIdx]!=NULLP)
12681           {
12682              free(srbSet->list.array[srbIdx]);
12683           }
12684        }
12685        free(srbSet->list.array);
12686     }
12687 }
12688
12689 /*******************************************************************
12690 *
12691 * @brief free the memory allocated by decoder
12692 *
12693 * @details
12694 *
12695 *    Function : freeAperDecodeULTnlInfo
12696 *
12697 *    Functionality: added free part for the memory allocated by aper_decoder
12698 *
12699 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12700 * @return void
12701 *
12702 * ****************************************************************/
12703
12704
12705 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12706 {
12707    uint8_t ulIdx=0;
12708    if(ulInfo->list.array != NULLP)
12709    {
12710       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12711       {
12712          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12713          {
12714             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12715             {
12716                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12717                      transportLayerAddress.buf != NULLP)
12718                {
12719                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12720                         !=NULLP)
12721                   {
12722                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12723                   }
12724                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12725                         transportLayerAddress.buf);
12726                }
12727                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12728             }
12729          }
12730          if(ulInfo->list.array[ulIdx]!=NULLP)
12731          {
12732             free(ulInfo->list.array[ulIdx]);
12733          }
12734       }
12735       free(ulInfo->list.array);
12736    }
12737 }
12738 /*******************************************************************
12739 *
12740 * @brief free the memory allocated by decoder
12741 *
12742 * @details
12743 *
12744 *    Function : freeAperDecodeDRBSetup  
12745 *
12746 *    Functionality: free DRBSetup which is allocated by decoder
12747 *
12748 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12749 * @return void
12750 *
12751 * ****************************************************************/
12752
12753 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12754 {
12755    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12756    uint8_t  flowIdx =0;
12757    uint8_t  drbIdx =0;
12758
12759    if(drbSet->list.array != NULLP)
12760    {
12761       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12762       {
12763          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12764          {
12765             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12766             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12767             {
12768                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12769                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12770                {
12771                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12772                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12773                   {
12774                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12775                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12776                      {
12777
12778                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12779                         {
12780
12781                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12782                            {
12783
12784                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12785                                     buf!=NULLP)
12786                               {
12787
12788                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12789                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12790                                  {
12791
12792                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12793                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12794                                     {
12795
12796                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12797                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12798                                        {
12799                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12800                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12801                                                 qoSFlowLevelQoSParameters.\
12802                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12803                                           {
12804                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12805                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12806                                                    qoSFlowLevelQoSParameters.\
12807                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12808                                              {
12809
12810                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12811                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12812                                                       qoSFlowLevelQoSParameters.\
12813                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12814                                                 {
12815
12816
12817                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12818                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12819                                                          qoSFlowLevelQoSParameters.\
12820                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12821                                                 }
12822
12823                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12824                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12825                                                       qoSFlowLevelQoSParameters.\
12826                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12827                                              }
12828
12829                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12830
12831                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12832                                                    qoSFlowLevelQoSParameters.\
12833                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12834                                           }
12835                                        }
12836                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12837                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12838                                        {
12839
12840                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12841                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12842                                        }
12843                                     }
12844
12845                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12846                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12847                                  }
12848
12849                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12850                                        DRB_Information.sNSSAI.sD->buf);
12851                               }
12852
12853                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12854                            }
12855
12856                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12857
12858                         }
12859
12860                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12861
12862                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12863                      }
12864
12865                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12866                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12867                   }
12868
12869                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12870                         qoS_Characteristics.choice.non_Dynamic_5QI);
12871                }
12872                free(drbSetItem->qoSInformation.choice.choice_extension);
12873             }
12874             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12875             if(drbSetItem->uLConfiguration)
12876             {
12877                free(drbSetItem->uLConfiguration);
12878             }
12879          }
12880          if(drbSet->list.array[drbIdx]!=NULLP)
12881          {
12882             free(drbSet->list.array[drbIdx]);
12883          }
12884       }
12885       free(drbSet->list.array);
12886    }
12887 }
12888
12889
12890 /*******************************************************************
12891  *
12892  * @brief builds Mac Cell Cfg
12893  *
12894  * @details
12895  *
12896  *    Function : procUeRecfgCellInfo
12897  *
12898  *    Functionality: builds Mac Cell Cfg
12899  *
12900  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12901  *                       needs to send in other layer, as well as this can be
12902  *                       the variable which stores the information in DuCb.
12903  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12904  *                       information to other layer else it will have copyOfmacUeCfg  
12905  *                       which we have stored in F1UeContextSetupDb
12906  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12907  *                        by CU, which we have stored in F1UeContextSetupDb 
12908  *
12909  * @return void 
12910  *
12911  * ****************************************************************/
12912 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12913 {
12914    uint8_t ret = ROK;
12915    CellGroupConfigRrc_t *cellGrp = NULLP;
12916
12917    if(cellInfo)
12918    {
12919       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12920       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12921       if(ret == RFAILED)
12922          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
12923    }
12924    if(ret == RFAILED)
12925    {
12926       freeUeRecfgCellGrpInfo(macUeCfgToSend);
12927    }
12928    return ret;
12929 }
12930
12931 /*******************************************************************
12932  *
12933  * @brief Filling modulation info in mac ue cfg
12934  *
12935  * @details
12936  *
12937  *    Function : duFillModulationDetails
12938  *
12939  *    Functionality: Filling modulation info in mac ue cfg
12940  *
12941  * @params[in] MAC UE Config to be updated
12942  *             Current UE configuration
12943  *             UE NR capability from CU
12944  * @return ROK     - success
12945  *         RFAILED - failure
12946  *
12947  * ****************************************************************/
12948 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
12949 {
12950    UE_NR_Capability_t *ueNrCap=NULLP;
12951
12952    if(!ueCap && oldUeCfg)
12953    {
12954       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12955       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12956    }
12957    else
12958    {
12959       ueNrCap = (UE_NR_Capability_t *)ueCap;
12960
12961       /* Filling DL modulation info */
12962       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12963          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12964          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12965       {
12966          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12967          {
12968             case ModulationOrder_qpsk:
12969                {
12970                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12971                   break;
12972                }
12973             case ModulationOrder_qam16:
12974                {
12975                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12976                   break;
12977                }
12978             case ModulationOrder_qam64:
12979                {
12980                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12981                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12982                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12983                   break;
12984                }
12985             case ModulationOrder_qam256:
12986                {
12987                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12988                   break;
12989                }
12990             default:
12991                {
12992                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12993                   if(oldUeCfg)
12994                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12995                   break;
12996                }
12997          }
12998       }
12999       else
13000       {
13001          if(oldUeCfg)
13002             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13003       }
13004
13005       /* Filling UL modulation info */
13006       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13007          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13008          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13009       {
13010          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13011          {
13012             case ModulationOrder_qpsk:
13013                {
13014                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13015                   break;
13016                }
13017             case ModulationOrder_qam16:
13018                {
13019                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13020                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13021                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13022                   break;
13023                }
13024             case ModulationOrder_qam64:
13025                {
13026                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13027                   break;
13028                }
13029             case ModulationOrder_qam256:
13030                {
13031                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13032                   break;
13033                }
13034             default:
13035                {
13036                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13037                   if(oldUeCfg)
13038                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13039                   break;
13040                }
13041          }
13042       }
13043       else
13044       {
13045          if(oldUeCfg)
13046             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13047       }
13048    }
13049 }
13050
13051 /*******************************************************************
13052  *
13053  * @brief Function to extract info from CU to DU RRC container extension
13054  *
13055  * @details
13056  *
13057  *    Function : extractCuToDuRrcInfoExt
13058  *
13059  *    Functionality: Function to extract info from CU to DU RRC container
13060  *    extension
13061  *
13062  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13063  *
13064  * @return ROK
13065  *         RFAILED
13066  *
13067  * ****************************************************************/
13068 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13069 {
13070    uint8_t ieIdx =0;
13071    uint16_t recvBufLen =0;
13072    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13073    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13074    asn_dec_rval_t rval; /* Decoder return value */
13075    memset(&rval, 0, sizeof(asn_dec_rval_t));
13076
13077    if(protocolIeExtn)
13078    {
13079       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13080       {
13081          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13082          switch(extIeInfo->id)
13083          {
13084             case ProtocolIE_ID_id_CellGroupConfig:
13085                {
13086                   /* decoding the CellGroup Buf received */
13087                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13088                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13089                   if(cellGrpCfg)
13090                   {
13091                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13092                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13093                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13094                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13095                      {
13096                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13097                         return RFAILED;
13098                      }
13099                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13100
13101                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13102                         return NULLP;
13103                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13104                   }
13105                   break;
13106                }
13107
13108             case ProtocolIE_ID_id_HandoverPreparationInformation:
13109                {
13110                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13111                   break;
13112                }
13113
13114             default:
13115                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13116                break;
13117          }
13118       }
13119    }
13120    return ROK;
13121 }
13122
13123 /*******************************************************************
13124  *
13125  * @brief Fills Srb List received by CU
13126  *
13127  * @details
13128  *
13129  *    Function : procSrbListToSetup
13130  *
13131  *    Functionality: Fills Srb List received  by CU
13132  *
13133  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13134  *             DuLcCfg pointer
13135  *             RlcBearerCfg pointer
13136  * @return void
13137  *
13138  * ****************************************************************/
13139 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13140 {
13141
13142    /* Filling RLC INFO */
13143    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13144
13145    /* Filling MAC INFO */
13146    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13147    { 
13148       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13149       return RFAILED;
13150    }
13151
13152    return ROK;
13153 }
13154
13155
13156
13157 /*******************************************************************
13158  *
13159  * @brief extract Srb List received by CU
13160  *
13161  * @details
13162  *
13163  *    Function : extractSrbListToSetup
13164  *
13165  *    Functionality: extract Srb List received by CU
13166  *                   for both MAC and RLC
13167  *
13168  * @params[in] SRBs_ToBeSetup_Item_t pointer
13169  *             DuUeCfg pointer
13170  * @return ROK/RFAIED
13171  *
13172  * ****************************************************************/
13173
13174 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13175 {
13176    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13177    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13178    DuLcCfg *macLcCtxt = NULLP;
13179    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13180
13181    if(srbCfg)
13182    {
13183       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13184       {
13185          macLcCtxt = NULL;
13186          rlcLcCtxt = NULL;
13187
13188          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13189          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13190          { 
13191             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13192             ret = RFAILED;
13193             break;
13194          }
13195          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13196          {
13197             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13198             ret = RFAILED;
13199             break;
13200          }
13201
13202          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13203          {
13204             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13205             {
13206                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13207                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13208                break;
13209             }
13210          }
13211          if(!macLcCtxt)
13212          {
13213             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13214             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13215             ueCfgDb->numMacLcs++;
13216          }
13217          if(!rlcLcCtxt)
13218          {
13219             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13220             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13221             ueCfgDb->numRlcLcs++;
13222          }
13223
13224          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13225
13226          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13227                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13228          if(ret == RFAILED)
13229          {
13230             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13231             break;
13232          }
13233       }
13234    }
13235    else
13236       ret = RFAILED;
13237
13238    return ret;
13239 }
13240
13241 /*******************************************************************
13242  *
13243  * @brief Fills Drb List received by CU
13244  *
13245  * @details
13246  *
13247  *    Function : procDrbListToSetupMod
13248  *
13249  *    Functionality: Fills Drb List received by CU
13250  *                   for both MAC and RLC
13251  *
13252  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13253  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13254  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13255  * @return void
13256  *
13257  * ****************************************************************/
13258
13259 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13260 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13261 {
13262    uint8_t cfgIdx = 0;
13263    RlcMode rlcModeInfo;
13264
13265    if(drbItem != NULLP)
13266    {
13267       /* Filling RLC INFO */
13268       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13269       qoSInformation);
13270
13271       /* Filling MAC INFO */
13272       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13273       { 
13274          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13275          return RFAILED;
13276       }
13277    }
13278    else if(drbSetupModItem != NULLP)
13279    {
13280       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13281       &drbSetupModItem->qoSInformation);
13282
13283       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13284       {
13285          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13286          return RFAILED;
13287       }
13288    }
13289    else if(drbModItem != NULLP)
13290    {
13291       /* Drb to Mod IEs doesnot have rlcMode to be modified
13292        * in ASN. Hence no change in RLC configurations */
13293       if(storedRlcUeCfg != NULLP)
13294       {
13295          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13296          {
13297             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13298             {
13299                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13300                break;
13301             }
13302          }
13303       }
13304
13305       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13306       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13307       {
13308          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13309          return RFAILED;
13310       }
13311    }
13312    return ROK;
13313 }
13314
13315 /*******************************************************************
13316  *
13317  * @brief extract Drb List received by CU
13318  *
13319  * @details
13320  *
13321  *    Function : extractDrbListToSetupMod
13322  *
13323  *    Functionality: extract Drb List received by CU
13324  *                   for both MAC and RLC
13325  *
13326  * @params[in] DRBs_ToBeSetup_Item_t pointer
13327  *             DuUeCfg pointer
13328  * @return ROK/RFAIED
13329  *
13330  * ****************************************************************/
13331
13332 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13333  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13334 {
13335    uint8_t ret = ROK;
13336    uint8_t drbIdx = 0, rlcLcIdx = 0;
13337    uint8_t drbId = 0, lcId = 0;
13338    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13339    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13340    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13341    DuLcCfg *macLcCtxt = NULLP;
13342    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13343
13344    ret = ROK;
13345    if(drbCount > 0)
13346    {
13347       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13348       {
13349          macLcCtxt = NULL;
13350          rlcLcCtxt = NULL;
13351
13352          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13353          { 
13354             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13355             ret = RFAILED;
13356             break;
13357          }
13358          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13359          {
13360             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13361             ret = RFAILED;
13362             break;
13363          }
13364
13365          if(drbModCfg != NULLP)
13366          {
13367             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13368             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13369          }
13370          else if(drbCfg != NULLP)
13371             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13372          else if(drbSetupModCfg != NULL)
13373          {
13374             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13375             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13376          }
13377
13378          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13379          {
13380             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13381                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13382             {
13383                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13384                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13385                break;
13386             }
13387          }
13388          if(!macLcCtxt)
13389          {
13390             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13391             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13392             ueCfgDb->numMacLcs++;
13393          }
13394          if(!rlcLcCtxt)
13395          {
13396             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13397             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13398             ueCfgDb->numRlcLcs++;
13399          }
13400
13401          if(drbModCfg != NULLP)
13402          {
13403             lcId = fetchLcId(drbId);
13404             if(lcId < MIN_DRB_LCID)
13405             {
13406                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13407                break;
13408             } 
13409             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13410             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13411             if(ret == RFAILED)
13412             {
13413                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13414                break;
13415             }
13416             ueCfgDb->numDrbModified++;
13417          }
13418          else
13419          {
13420             lcId = getDrbLcId(drbBitMap);
13421             if(lcId == RFAILED)
13422             {
13423                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13424                ret = RFAILED;
13425                break;
13426             }
13427             if(drbCfg != NULL)
13428             {
13429                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13430                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13431                if(ret == RFAILED)
13432                {
13433                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13434                   break;
13435                }
13436             }
13437             else if(drbSetupModCfg != NULL)
13438             {
13439                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13440                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13441                if(ret == RFAILED)
13442                {
13443                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13444                   break;
13445                }
13446                ueCfgDb->numDrbSetupMod++;
13447             }
13448          }
13449          ueCfgDb->numDrb++;
13450  
13451          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13452                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13453          if(ret == RFAILED)
13454          {
13455             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13456             break;
13457          }
13458       }
13459    }
13460    else
13461       ret = RFAILED;
13462
13463    return ret;
13464 }
13465
13466 /*******************************************************************
13467  *
13468  * @brief extract Drb List received from CU
13469  *
13470  * @details
13471  *
13472  *    Function : extractDrbListToRelease
13473  *
13474  *    Functionality: extract Drb List received from CU
13475  *                   for both MAC and RLC
13476  *
13477  * @params[in] DRBs_ToBeReleased_Item_t pointer
13478  *             DuUeCfg pointer
13479  * @return ROK/RFAIED
13480  *
13481  * ****************************************************************/
13482
13483 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13484 {
13485    uint8_t ret = ROK, teIdx = 0;
13486    uint8_t drbIdx = 0, rlcLcIdx = 0;
13487    uint8_t drbId = 0, lcId = 0;
13488    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13489    DuLcCfg *macLcCtxt = NULLP;
13490    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13491
13492    ret = ROK;
13493    if(drbCount > 0)
13494    {
13495       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13496       {
13497          macLcCtxt = NULL;
13498          rlcLcCtxt = NULL;
13499
13500          if(drbToRel != NULLP)
13501          {
13502             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13503             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13504          }
13505          else
13506          {
13507             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13508             return RFAILED;
13509          }
13510
13511          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13512          {
13513             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13514             {
13515                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13516                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13517                break;
13518             }
13519          }
13520
13521          if(!macLcCtxt)
13522          {
13523             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13524             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13525             ueCfgDb->numMacLcs++;
13526          }
13527          if(!rlcLcCtxt)
13528          {
13529             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13530             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13531             ueCfgDb->numRlcLcs++;
13532          }
13533          lcId = fetchLcId(drbId);
13534          if(lcId < MIN_DRB_LCID)
13535          {
13536             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13537             break;
13538          } 
13539
13540          /* Filling RLC INFO */
13541          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13542          /* Filling MAC INFO */
13543          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13544          { 
13545             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13546             return RFAILED;
13547          }
13548          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13549          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13550          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13551
13552          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13553          {
13554             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13555                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13556             {
13557                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13558                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13559                break;
13560             }
13561          }
13562
13563          ueCfgDb->numDrb++;
13564          if(ret == RFAILED)
13565          {
13566             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13567             break;
13568          }
13569
13570          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13571                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13572       }
13573    }
13574    else
13575       ret = RFAILED;
13576
13577    return ret;
13578 }
13579
13580 /*******************************************************************
13581  *
13582  * @brief Function to extract Dl RRC Msg received from CU
13583  *
13584  * @details
13585  *
13586  *    Function : extractDlRrcMsg
13587  *
13588  *    Functionality: Function to extract Dl RRC Msg received from CU
13589  *
13590  * @params[in] F1AP message
13591  * @return ROK     - success
13592  *         RFAILED - failure
13593  *
13594  * ****************************************************************/
13595
13596 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13597    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13598 {
13599    uint8_t ret = ROK;
13600    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13601    if(dlRrcMsg->rrcMsgSize > 0)
13602    {
13603       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13604       if(!dlRrcMsg->rrcMsgPdu)
13605       {
13606          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13607          ret = RFAILED;
13608       }
13609       else
13610       {
13611          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13612          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13613          dlRrcMsg->srbId = SRB1_LCID;
13614          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13615       }
13616    }
13617    return ret;
13618 }
13619
13620 /*******************************************************************
13621  *
13622  * @brief Extract UE capability info 
13623  *
13624  * @details
13625  *
13626  *    Function : extractUeCapability
13627  *
13628  *    Functionality: Extract UE capability info and stores in ue Cb
13629  *
13630  * @params[in] Octet string of UE capability RAT container list
13631  * @return ROK     - success
13632  *         RFAILED - failure
13633  *
13634  * ****************************************************************/
13635 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13636 {
13637    uint8_t  idx;
13638    uint16_t recvBufLen;
13639    asn_dec_rval_t rval;
13640    UE_NR_Capability_t  *ueNrCap = NULLP;
13641    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13642
13643    /* Decoding UE Capability RAT Container List */
13644    recvBufLen = ueCapablityListBuf->size;
13645    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13646    if(!ueCapRatContList)
13647    {
13648       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13649       return NULLP;
13650    }
13651    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13652    memset(&rval, 0, sizeof(asn_dec_rval_t));
13653    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13654           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13655    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13656    {
13657       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13658       return NULLP;
13659    }
13660    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13661
13662    /* Free encoded buffer after decoding */
13663
13664    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13665    {
13666       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13667       {
13668          /* Decoding UE NR Capability */
13669           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13670           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13671           if(!ueNrCap)
13672           {
13673              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13674              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13675              return NULLP;
13676           } 
13677           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13678           memset(&rval, 0, sizeof(asn_dec_rval_t));
13679           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13680                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13681           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13682           {
13683              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13684              return NULLP;
13685           }
13686           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13687           
13688           /* Free encoded buffer after decoding */
13689           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13690       }
13691       free(ueCapRatContList->list.array[idx]);
13692    }
13693
13694    /* Free Memory*/
13695    free(ueCapRatContList->list.array);
13696    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13697    return ueNrCap;
13698 }
13699  
13700 /*******************************************************************
13701 *
13702 * @brief free UE context setup request from CU
13703 *
13704 * @details
13705 *
13706 *    Function : freeAperDecodeF1UeContextSetupReq
13707 *
13708 *    Functionality: freeing part for the memory allocated by aper_decoder
13709 *
13710 * @params[in] F1AP message
13711 * @return ROK     - success
13712 *         RFAILED - failure
13713 *
13714 * ****************************************************************/
13715 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13716 {
13717    uint8_t ieIdx = 0;
13718
13719    if(ueSetReq->protocolIEs.list.array != NULLP)
13720    {
13721       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13722       {
13723          if(ueSetReq->protocolIEs.list.array[ieIdx])
13724          {
13725             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13726             {
13727                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13728                   break;
13729                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13730                   break;
13731                case ProtocolIE_ID_id_SpCell_ID:
13732                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13733                   break;
13734                case ProtocolIE_ID_id_ServCellIndex:
13735                   break;
13736                case ProtocolIE_ID_id_SpCellULConfigured:
13737                   break;
13738                case ProtocolIE_ID_id_CUtoDURRCInformation:
13739
13740                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13741                   break;
13742                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13743
13744                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13745                   break;
13746                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13747
13748                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13749                   break;
13750                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13751
13752                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13753                   break;
13754                case ProtocolIE_ID_id_RRCContainer:
13755                   {
13756
13757                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13758                      {
13759
13760                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13761                      }
13762                      break;
13763                   }
13764                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13765                   break;
13766                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13767                   {
13768                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13769                      {
13770                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13771                      }
13772                      break;
13773                   }
13774 #ifdef NR_DRX
13775                case ProtocolIE_ID_id_DRXCycle:
13776                   {
13777                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13778                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13779                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13780                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13781                      break;
13782                   }
13783 #endif             
13784                 default:
13785                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13786             } 
13787             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13788          }
13789       }
13790       free(ueSetReq->protocolIEs.list.array);
13791    }
13792 }
13793 /*******************************************************************
13794  *
13795  * @brief Process UE context setup request from CU
13796  *
13797  * @details
13798  *
13799  *    Function : procF1UeContextSetupReq
13800  *
13801  *    Functionality: Process UE context setup request from CU
13802  *
13803  * @params[in] F1AP message
13804  * @return ROK     - success
13805  *         RFAILED - failure
13806  *
13807  * ****************************************************************/
13808 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13809 {
13810    int8_t ueIdx = -1;
13811    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13812    //uint8_t servCellIdx = 0;
13813    bool ueCbFound = false, hoInProgress = false;
13814    uint16_t cellIdx=0;
13815    uint64_t nrCellId = 0;
13816    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13817    DuUeCb   *duUeCb = NULL;
13818    UEContextSetupRequest_t   *ueSetReq = NULL;
13819    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13820    CUtoDURRCInformation_t *rrcInfo = NULL;
13821 #ifdef NR_DRX
13822    DRXCycle_t *drxCycle;
13823 #endif
13824    ret = ROK;
13825
13826    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13827    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13828    {
13829       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13830       {
13831          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13832             {
13833                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13834                break;
13835             }
13836
13837          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13838             {
13839                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13840                break;
13841             }
13842
13843          case ProtocolIE_ID_id_SpCell_ID:
13844             {
13845                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13846
13847                GET_CELL_IDX(nrCellId, cellIdx);
13848                if(!duCb.actvCellLst[cellIdx])
13849                {
13850                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13851                   ret = RFAILED;
13852                }
13853                break;
13854             }
13855
13856          case ProtocolIE_ID_id_ServCellIndex:
13857             {
13858                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13859                break;
13860             }
13861
13862          case ProtocolIE_ID_id_SpCellULConfigured:
13863             {
13864                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13865                   UL, SUL or UL+SUL for the indicated cell for the UE */
13866                break;
13867             }
13868
13869          case ProtocolIE_ID_id_CUtoDURRCInformation:
13870             {
13871                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13872
13873                /* Search if UE context is present */
13874                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13875                {
13876                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13877                   {
13878                      ueCbFound = true;
13879                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13880                      break;
13881                   }
13882                }
13883
13884                /* Check if UE Handover scenario */
13885                if(rrcInfo->iE_Extensions)
13886                {
13887                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13888                   {
13889                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13890                      {
13891                         hoInProgress = true;
13892                         break;
13893                      }
13894                   }
13895                }
13896                
13897                /* If UE context is not present, but UE is in handover */
13898                if(!ueCbFound && hoInProgress)
13899                {
13900                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13901                   if(ueIdx != -1)
13902                      gnbDuUeF1apId = ueIdx +1;
13903                   else
13904                   {
13905                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13906                      ret = RFAILED;
13907                      break;
13908                   }
13909                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13910                   duUeCb->f1UeDb = NULL;
13911                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13912                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13913                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13914                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13915                }
13916
13917                if(duUeCb)
13918                {
13919                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13920                   if(duUeCb->f1UeDb)
13921                   {
13922                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13923                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13924                      duUeCb->f1UeDb->cellIdx = cellIdx;
13925                   }
13926                   else
13927                   {
13928                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13929                      ret = RFAILED;
13930                      break;
13931                   }
13932                }
13933                else
13934                {
13935                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13936                   ret = RFAILED;
13937                   break;
13938                }
13939                  
13940                /* Extract UE capability info */
13941                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13942                {
13943                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13944                }
13945
13946                /* Extract IE extension */
13947                if(rrcInfo->iE_Extensions)
13948                {
13949                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13950                   {
13951                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13952                      //TODO: Update the failure cause in ue context Setup Response
13953                      ret = RFAILED;
13954                   }
13955                }
13956                break;
13957             } 
13958
13959 #ifdef NR_DRX
13960          case ProtocolIE_ID_id_DRXCycle:
13961             {
13962                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
13963                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
13964                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
13965                if(drxCycle->shortDRXCycleLength)
13966                {
13967                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
13968                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
13969                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
13970                }
13971                if(drxCycle->shortDRXCycleTimer)
13972                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
13973
13974                break;
13975             }
13976
13977 #endif
13978          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13979             {
13980                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13981                         &duUeCb->f1UeDb->duUeCfg))
13982                {
13983                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13984                   //TODO: Update the failure cause in ue context Setup Response
13985                   ret = RFAILED;
13986                }
13987                break;
13988             }
13989
13990          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13991             {
13992                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13993
13994                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13995                {
13996                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13997                   //TODO: Update the failure cause in ue context Setup Response
13998                   ret = RFAILED;
13999                }
14000                break;
14001             }
14002          case ProtocolIE_ID_id_RRCContainer:
14003             {
14004                /* Filling Dl RRC Msg Info */
14005                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14006                if(!duUeCb->f1UeDb->dlRrcMsg)
14007                {
14008                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14009                   ret = RFAILED;
14010                }
14011                else
14012                {
14013                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14014                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14015                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14016                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14017                }          
14018                break;
14019             }
14020
14021          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14022             {
14023                if(duUeCb->f1UeDb->dlRrcMsg)
14024                {
14025                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14026                   {
14027                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14028                   }
14029                   else
14030                   {
14031                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14032                   }
14033                }
14034                break;
14035             }
14036
14037          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14038             {
14039                /* MaximumBitRate Uplink */
14040                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14041                if(bitRateSize > 0)
14042                {
14043                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14044                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14045                   {
14046                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14047                      ret = RFAILED;
14048                   }
14049                   else
14050                   {
14051                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14052                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14053                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14054                   }
14055                }
14056                else
14057                   ret = RFAILED;
14058                break;
14059             }
14060
14061          default:
14062             {
14063                break;
14064             }
14065       } /* End of switch */
14066
14067       /* In case of any failure in any IE */
14068       if(ret == RFAILED)
14069       {
14070          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14071          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14072          break;
14073       }
14074    } /* End of for loop of IEs */
14075
14076    if(ret == ROK)
14077       ret = duProcUeContextSetupRequest(duUeCb);
14078
14079    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14080    return ret;
14081
14082 }
14083 /*******************************************************************
14084  * @brief Free the memory allocated for Dl Tunnel Info
14085  *
14086  * @details
14087  *
14088  *    Function : freeDlTnlInfo
14089  *
14090  *    Functionality:
14091  *       Free the memory allocated for Dl Tunnel Info
14092  *
14093  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14094  * @return void
14095  *
14096  * ****************************************************************/
14097
14098 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14099 {
14100    uint8_t arrIdx = 0;
14101
14102    if(tnlInfo)
14103    {
14104       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14105       {
14106          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14107                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14108          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14109                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14110          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14111          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14112       }
14113       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14114    }
14115 }
14116
14117 /*******************************************************************
14118  * @brief Free the memory allocated for DRB setup List
14119  *
14120  * @details
14121  *
14122  *    Function : freeDrbSetupList
14123  *
14124  *    Functionality:
14125  *       Free the memory allocated for DRB setup list
14126  *
14127  * @params[in] DRBs_Setup_List_t *
14128  * @return void
14129  *
14130  * ****************************************************************/
14131 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14132 {
14133    uint8_t arrIdx = 0;
14134    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14135
14136    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14137    {
14138       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14139       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14140       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14141    }
14142    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14143 }
14144
14145 /*******************************************************************
14146  * @brief Free the memory allocated for UE Setup response
14147  *
14148  * @details
14149  *
14150  *    Function : FreeUeContextSetupRsp
14151  *
14152  *    Functionality:
14153  *       Free the memory allocated for UE Setup response
14154  *
14155  * @params[in] F1AP PDU for UE setup response
14156  * @return ROK     - success
14157  *         RFAILED - failure
14158  *
14159  * ****************************************************************/
14160 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14161 {
14162    uint8_t idx;
14163    UEContextSetupResponse_t *ueSetRsp = NULLP;
14164
14165    if(f1apMsg)
14166    {
14167       if(f1apMsg->choice.successfulOutcome)
14168       {
14169          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14170                     UEContextSetupResponse;
14171          if(ueSetRsp->protocolIEs.list.array)
14172          {
14173             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14174             {
14175                if(ueSetRsp->protocolIEs.list.array[idx])
14176                {
14177                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14178                   {
14179                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14180                         break;
14181                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14182                         break;
14183                      case ProtocolIE_ID_id_C_RNTI:
14184                         break;
14185                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14186                         {
14187                            CellGroupConfig_t *cellGrpCfg = NULLP;
14188                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14189                                          DUtoCURRCInformation.cellGroupConfig;
14190                            if(cellGrpCfg->buf != NULLP)
14191                            {
14192                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14193                               cellGrpCfg = NULLP;
14194                            }
14195                            break;
14196                         }
14197                      case ProtocolIE_ID_id_DRBs_Setup_List:
14198                         {
14199                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14200                            break;
14201                         }
14202                      default:
14203                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14204                               ueSetRsp->protocolIEs.list.array[idx]->id);
14205                         break;
14206                   }
14207                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14208                         sizeof(UEContextSetupResponseIEs_t));
14209                }
14210             }
14211             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14212                   ueSetRsp->protocolIEs.list.size);
14213          }
14214          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14215       }
14216       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14217    }
14218 }
14219
14220 /*******************************************************************
14221  *
14222  * @brief Builds Ue context Setup Rsp DU To CU Info
14223  *
14224  * @details
14225  *
14226  *    Function : EncodeUeCntxtDuToCuInfo
14227  *
14228  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14229  *
14230  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14231  *
14232  * @return ROK     - success
14233  *         RFAILED - failure
14234  *
14235  ******************************************************************/
14236
14237 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14238 {
14239    asn_enc_rval_t        encRetVal;
14240
14241    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14242    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14243    encBufSize = 0;
14244    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14245    /* Encode results */
14246    if(encRetVal.encoded == ENCODE_FAIL)
14247    {
14248       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14249             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14250       return RFAILED;
14251    }
14252    else
14253    {
14254       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14255 #ifdef DEBUG_ASN_PRINT
14256       for(int i=0; i< encBufSize; i++)
14257       {
14258          printf("%x",encBuf[i]);
14259       }
14260 #endif
14261    }
14262    duToCuCellGrp->size = encBufSize;
14263    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14264    if(!duToCuCellGrp->buf)
14265    {
14266       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14267    }
14268    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14269    return ROK;
14270 }
14271
14272 /*******************************************************************
14273  *
14274  * @brief Fills Dl Gtp tunnel Info
14275  *
14276  * @details
14277  *
14278  *    Function : fillGtpTunnelforDl
14279  *
14280  *    Functionality: Fills Dl Gtp tunnel Info
14281  *
14282  * @params[in] 
14283  *
14284  * @return ROK     - success
14285  *         RFAILED - failure
14286  *
14287  * ****************************************************************/
14288
14289 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14290 {
14291    uint8_t bufSize = 0;
14292
14293    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14294    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14295    if(gtpDl->transportLayerAddress.buf == NULLP)
14296    {
14297       return RFAILED;
14298    }
14299    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14300
14301    /*GTP TEID*/
14302    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14303    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14304    if(gtpDl->gTP_TEID.buf == NULLP)
14305    {
14306       return RFAILED;
14307    }
14308    bufSize = 3; /*forming an Octect String*/
14309    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14310
14311    return ROK;
14312 }
14313
14314 /*******************************************************************
14315  *
14316  * @brief Fills DL Tunnel Setup List
14317  *
14318  * @details
14319  *
14320  *    Function : fillDlTnlSetupList
14321  *
14322  *    Functionality: Fills the DL Tunnel Setup List
14323  *
14324  * @params[in] 
14325  *
14326  * @return ROK     - success
14327  *         RFAILED - failure
14328  *
14329  * ****************************************************************/
14330
14331 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14332 {
14333    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14334
14335    eleCount = 1;
14336    dlTnlInfo->list.count = eleCount; 
14337    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14338
14339    /* Initialize the DL Tnl Setup List Members */
14340    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14341    if(dlTnlInfo->list.array == NULLP)
14342    {
14343       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14344       ret = RFAILED;
14345    }
14346    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14347    {
14348       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14349       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14350       {
14351          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14352          return RFAILED;
14353       }
14354       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14355       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14356       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14357       {
14358          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14359          return RFAILED;
14360       }
14361       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14362                tnlCfg->tnlCfg1);
14363       if(ret != ROK)
14364          break;
14365    }
14366    return ret;
14367 }
14368
14369 /*******************************************************************
14370  *
14371  * @brief Fills the Drb Setup List for Ue Context Setup Response
14372  *
14373  * @details
14374  *
14375  *    Function : fillDrbSetupList
14376  *
14377  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14378  *
14379  * @params[in] 
14380  *
14381  * @return ROK     - success
14382  *         RFAILED - failure
14383  *
14384  * ****************************************************************/
14385 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14386 {
14387    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14388    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14389
14390    eleCount = ueCfg->numDrb;
14391    drbSetupList->list.count = eleCount;
14392    drbSetupList->list.size = \
14393         (eleCount * sizeof(DRBs_Setup_Item_t *));
14394
14395    /* Initialize the Drb Setup List Members */
14396    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14397    if(drbSetupList->list.array == NULLP)
14398    {
14399       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14400       ret = RFAILED;
14401    }
14402
14403    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14404    {
14405       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14406       if(drbSetupList->list.array[arrIdx] == NULLP)
14407       {
14408          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14409          return RFAILED;
14410       }
14411       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14412       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14413       drbItemIe->criticality = Criticality_reject;
14414       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14415       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14416       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14417           &ueCfg->upTnlInfo[arrIdx]);
14418       if(ret != ROK)
14419          break;
14420    }
14421    return ret;
14422 }
14423
14424 /*******************************************************************
14425  *
14426  * @brief Builds and sends the UE Setup Response
14427  *
14428  * @details
14429  *
14430  *    Function : BuildAndSendUeContextSetupRsp
14431  *
14432  *    Functionality: Constructs the UE Setup Response and sends
14433  *                   it to the DU through SCTP.
14434  *
14435  * @params[in] uint8_t cellId,uint8_t ueId
14436  *
14437  * @return ROK     - success
14438  *         RFAILED - failure
14439  *
14440  * ****************************************************************/
14441 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14442 {
14443    uint8_t   idx, ret, cellIdx, elementCnt;
14444    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14445    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14446    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14447    F1AP_PDU_t               *f1apMsg = NULLP;
14448    UEContextSetupResponse_t *ueSetRsp = NULLP;
14449    DuUeCb                   *ueCb = NULLP;
14450
14451    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14452
14453    while(true)
14454    {
14455       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14456       if(f1apMsg == NULLP)
14457       {
14458          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14459          ret = RFAILED;
14460          break;
14461       }
14462
14463       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14464       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14465             sizeof(SuccessfulOutcome_t));
14466       if(f1apMsg->choice.successfulOutcome == NULLP)
14467       {
14468          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14469          ret = RFAILED;
14470          break;
14471       }
14472
14473       f1apMsg->choice.successfulOutcome->procedureCode = \
14474                                                          ProcedureCode_id_UEContextSetup;
14475       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14476       f1apMsg->choice.successfulOutcome->value.present = \
14477                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14478
14479       ueSetRsp =
14480          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14481       elementCnt = 5;
14482       ueSetRsp->protocolIEs.list.count = elementCnt;
14483       ueSetRsp->protocolIEs.list.size = \
14484                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14485
14486       /* Initialize the UESetup members */
14487       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14488             ueSetRsp->protocolIEs.list.size);
14489       if(ueSetRsp->protocolIEs.list.array == NULLP)
14490       {
14491          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14492          ret = RFAILED;
14493          break;
14494       }
14495
14496       for(idx=0; idx<elementCnt; idx++)
14497       {
14498          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14499                sizeof(UEContextSetupResponseIEs_t));
14500          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14501          {
14502             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14503             ret = RFAILED;
14504             break;
14505          }
14506       }
14507       /* Fetching Ue Cb Info*/
14508       GET_CELL_IDX(cellId, cellIdx);
14509       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14510       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14511       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14512
14513       idx = 0;
14514       /*GNB CU UE F1AP ID*/
14515       ueSetRsp->protocolIEs.list.array[idx]->id = \
14516                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14517       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14518       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14519                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14520       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14521
14522       /*GNB DU UE F1AP ID*/
14523       idx++;
14524       ueSetRsp->protocolIEs.list.array[idx]->id = \
14525                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14526       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14527       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14528                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14529       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14530
14531
14532       /*DUtoCURRC Information */
14533       idx++;
14534       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14535                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14536       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14537       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14538                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14539       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14540
14541       /* CRNTI */
14542       idx++;
14543       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14544       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14545       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14546       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14547
14548
14549       /* Drb Setup List */
14550       idx++;
14551       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14552                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14553       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14554       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14555                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14556       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14557             &ueCb->f1UeDb->duUeCfg);
14558       if(ret == RFAILED)
14559       {
14560          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14561          freeF1UeDb(ueCb->f1UeDb);
14562          ueCb->f1UeDb = NULLP;
14563          break;
14564       }
14565
14566       /* Free UeContext Db created during Ue context Req */
14567       freeF1UeDb(ueCb->f1UeDb);
14568       ueCb->f1UeDb = NULLP;
14569
14570       /* TODO: To send Drb list */
14571       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14572
14573       /* Encode the UE context setup response type as APER */
14574       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14575       encBufSize = 0;
14576       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14577             encBuf);
14578       /* Encode results */
14579       if(encRetVal.encoded == ENCODE_FAIL)
14580       {
14581          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14582                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14583          ret = RFAILED;
14584          break;
14585       }
14586       else
14587       {
14588          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14589 #ifdef DEBUG_ASN_PRINT
14590          for(int i=0; i< encBufSize; i++)
14591          {
14592             printf("%x",encBuf[i]);
14593          }
14594 #endif
14595       }
14596
14597       /* Sending  msg  */
14598       if(sendF1APMsg()  != ROK)
14599       {
14600          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14601          ret = RFAILED;
14602          break;
14603       }
14604       break;
14605    }
14606    FreeUeContextSetupRsp(f1apMsg);
14607    return ret;
14608 }/* End of BuildAndSendUeContextSetupRsp */
14609
14610 /*******************************************************************
14611 *
14612 * @brief  Build And Send Ue Context Rsp 
14613 *
14614 * @details
14615 *
14616 *    Function : BuildAndSendUeCtxtRsp 
14617 *
14618 *    Functionality : Build And Send Ue Context Rsp
14619
14620 * @params[in]
14621 * @return sucess = ROK
14622 *         failure = RFAILED
14623 *
14624 * ****************************************************************/
14625 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14626 {
14627    uint8_t cellIdx = 0, actionType = 0; 
14628
14629    GET_CELL_IDX(cellId, cellIdx);
14630    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14631
14632    switch(actionType)
14633    {
14634       case UE_CTXT_SETUP:
14635          {
14636             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14637             {
14638                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14639                return RFAILED;
14640             }
14641             break;
14642          }
14643       case UE_CTXT_MOD:
14644          {
14645             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14646             {
14647                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14648                return RFAILED;
14649             }
14650             break;
14651          }
14652       default:
14653          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14654          break;
14655
14656    }
14657    return ROK;
14658 }
14659
14660 /*******************************************************************
14661  *
14662  * @brief deallocating the memory of  F1reset msg
14663  *
14664  * @details
14665  *
14666  *    Function : FreeF1ResetReq
14667  *
14668  *    Functionality :
14669  *         - freeing memory of F1reset request msg
14670  *
14671  * @params[in]
14672  * @return void
14673  *
14674  *
14675  * ****************************************************************/
14676 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14677 {
14678    uint8_t idx =0 ;
14679    Reset_t *f1ResetMsg;
14680
14681    if(f1apMsg)
14682    {
14683       if(f1apMsg->choice.initiatingMessage)
14684       {
14685          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14686
14687          if(f1ResetMsg->protocolIEs.list.array)
14688          {
14689             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14690             {
14691                if(f1ResetMsg->protocolIEs.list.array[idx])
14692                {
14693                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14694                }
14695             }
14696             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14697          }
14698          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14699       }
14700       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14701    }
14702 }
14703 /*******************************************************************
14704  *
14705  * @brief Build and Send F1reset request 
14706  *
14707  * @details
14708  *
14709  *    Function : BuildAndSendF1ResetReq
14710  *
14711  *    Functionality:
14712  *         - Build and Send F1reset request msg
14713  *
14714  * @params[in]
14715  * @return ROK     - success
14716  *         RFAILED - failure
14717  *
14718  * ****************************************************************/
14719 uint8_t BuildAndSendF1ResetReq()
14720 {
14721    uint8_t          elementCnt=0;
14722    uint8_t          idx=0;
14723    uint8_t          ret= RFAILED;
14724    Reset_t          *f1ResetMsg = NULLP;
14725    F1AP_PDU_t       *f1apMsg = NULLP;
14726    asn_enc_rval_t   encRetVal;
14727    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14728    do
14729    {
14730       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14731       if(f1apMsg == NULLP)
14732       {
14733          break;
14734       }
14735       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14736       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14737       if(f1apMsg->choice.initiatingMessage == NULLP)
14738       {
14739          break;
14740       }
14741       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14742       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14743       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14744
14745       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14746
14747       elementCnt = 3;
14748       f1ResetMsg->protocolIEs.list.count = elementCnt;
14749       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14750
14751       /* Initialize the F1Setup members */
14752       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14753       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14754       {
14755          break;
14756       }
14757       for(idx=0; idx<elementCnt; idx++)
14758       {
14759          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14760          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14761          {
14762             break;
14763          }
14764       }
14765
14766       /*TransactionID*/
14767       idx=0;
14768       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14769       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14770       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14771       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14772
14773       /*Cause*/
14774       idx++;
14775       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14776       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14777       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14778       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14779       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14780
14781       /*Reset Type*/
14782       idx++;
14783       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14784       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14785       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14786       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14787       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14788
14789       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14790
14791       /* Encode the F1SetupRequest type as APER */
14792       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14793       encBufSize = 0;
14794       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14795             encBuf);
14796
14797       /* Encode results */
14798       if(encRetVal.encoded == ENCODE_FAIL)
14799       {
14800          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14801                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14802          break;
14803       }
14804       else
14805       {
14806          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14807 #ifdef DEBUG_ASN_PRINT
14808          for(idx=0; idx< encBufSize; idx++)
14809          {
14810             printf("%x",encBuf[idx]);
14811          }
14812 #endif
14813       }
14814
14815       if(sendF1APMsg() != ROK)
14816       {
14817          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14818          break;
14819       }
14820
14821       ret = ROK;
14822       break;
14823    }while(true);
14824
14825    FreeF1ResetReq(f1apMsg);
14826    return ret;
14827 }
14828 /*******************************************************************
14829  *
14830  * @brief Build And Send F1ResetAck
14831  *
14832  * @details
14833  *
14834  *    Function : BuildAndSendF1ResetAck
14835  *
14836  *    Functionality:
14837  *         - Build And Send  F1ResetRSP
14838  *
14839  * @return ROK     - success
14840  *         RFAILED - failure
14841  *
14842  * ****************************************************************/
14843 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14844 {
14845    uint8_t idx;
14846    ResetAcknowledge_t *f1ResetAck;
14847
14848    if(f1apMsg)
14849    {
14850       if(f1apMsg->choice.successfulOutcome)
14851       {
14852          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14853
14854          if(f1ResetAck->protocolIEs.list.array)
14855          {
14856             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14857             {
14858                if(f1ResetAck->protocolIEs.list.array[idx])
14859                {
14860                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14861                }
14862             }
14863             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14864          }
14865          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14866       }
14867       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14868    }
14869 }
14870
14871 /*******************************************************************
14872  *
14873  * @brief Build And Send F1ResetAck
14874  *
14875  * @details
14876  *
14877  *    Function : BuildAndSendF1ResetAck
14878  *
14879  *    Functionality:
14880  *         - Build And Send  F1ResetRSP
14881  *
14882  *  @params[in]
14883  * @return ROK     - success
14884  *         RFAILED - failure
14885  *
14886  * ****************************************************************/
14887 uint8_t BuildAndSendF1ResetAck()
14888 {
14889    uint8_t                idx = 0;
14890    uint8_t                elementCnt = 0;
14891    uint8_t                ret = RFAILED;
14892    F1AP_PDU_t             *f1apMsg = NULL;
14893    ResetAcknowledge_t     *f1ResetAck = NULLP;
14894    asn_enc_rval_t         encRetVal;
14895    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14896
14897    do{
14898       /* Allocate the memory for F1ResetRequest_t */
14899       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14900       if(f1apMsg == NULLP)
14901       {
14902          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14903          break;
14904       }
14905
14906       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14907
14908       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14909       if(f1apMsg->choice.successfulOutcome == NULLP)
14910       {
14911          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14912          break;
14913       }
14914       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14915       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14916       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14917
14918       elementCnt = 1;
14919
14920       f1ResetAck->protocolIEs.list.count = elementCnt;
14921       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14922
14923       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14924       if(f1ResetAck->protocolIEs.list.array == NULLP)
14925       {
14926          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14927          break;
14928       }
14929
14930       for(idx=0; idx<elementCnt; idx++)
14931       {
14932          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14933          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14934          {
14935             break;
14936          }
14937       }
14938       /*TransactionID*/
14939       idx = 0;
14940       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14941       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14942       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14943       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14944
14945       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14946
14947       /* Encode the F1SetupRequest type as UPER */
14948       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14949       encBufSize = 0;
14950       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14951
14952       /* Check encode results */
14953       if(encRetVal.encoded == ENCODE_FAIL)
14954       {
14955          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14956                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14957          break;
14958       }
14959       else
14960       {
14961          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14962 #ifdef DEBUG_ASN_PRINT
14963          for(int i=0; i< encBufSize; i++)
14964          {
14965             printf("%x",encBuf[i]);
14966          }
14967 #endif
14968       }
14969       /* Sending msg */
14970       if(sendF1APMsg() != ROK)
14971       {
14972          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14973          break;
14974       }
14975
14976       ret = ROK;
14977       break;
14978    }while(true);
14979
14980    FreeF1ResetAck(f1apMsg);
14981    return ret;
14982 }
14983 /******************************************************************
14984 *
14985 * @brief free F1 reset msg allocated by aper_decoder 
14986 *
14987 * @details
14988 *
14989 *    Function : freeAperDecodeF1ResetMsg 
14990 *
14991 *    Functionality: free F1 reset msg allocated by aper_decoder 
14992 *
14993 * @params[in] Reset_t *f1ResetMsg 
14994 * @return void 
14995 *
14996 * ****************************************************************/
14997
14998 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14999 {
15000    uint8_t ieIdx =0;
15001    if(f1ResetMsg->protocolIEs.list.array)
15002    {
15003       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15004       {
15005          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15006          {
15007             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15008          }
15009       }
15010       free(f1ResetMsg->protocolIEs.list.array);
15011    }
15012 }
15013
15014 /******************************************************************
15015  *
15016  * @brief Processes DL RRC Message Transfer  sent by CU
15017  *
15018  * @details
15019  *
15020  *    Function : procF1ResetReq
15021  *
15022  *    Functionality: Processes DL RRC Message Transfer sent by CU
15023  *
15024  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15025  * @return ROK     - success
15026  *         RFAILED - failure
15027  *
15028  * ****************************************************************/
15029 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15030 {
15031    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15032    uint8_t       ieIdx = 0;
15033    uint8_t        ret = ROK;
15034    Reset_t       *f1ResetMsg = NULLP;
15035
15036    DU_LOG("\nINFO   -->  Processing F1 reset request");
15037    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15038
15039    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15040    {
15041       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15042       {
15043          case ProtocolIE_ID_id_TransactionID:
15044             break;
15045
15046          case ProtocolIE_ID_id_Cause:
15047             break;
15048
15049          case ProtocolIE_ID_id_ResetType:
15050             {
15051                break;
15052             }
15053
15054          default:
15055             break;
15056       }
15057    }
15058    ret = BuildAndSendF1ResetAck();
15059    DU_LOG("\nINFO   -->  UE release is not supported for now");
15060
15061    freeAperDecodeF1ResetMsg(f1ResetMsg);
15062
15063    return ret;
15064 }
15065
15066 /*******************************************************************
15067  *
15068  * @brief free the RRC delivery report
15069  *
15070  * @details
15071  *
15072  *    Function : freeRrcDeliveryReport
15073  *
15074  *    Functionality: free the RRC delivery report
15075  *
15076  * @params[in]
15077  * @return ROK     - success
15078  *         RFAILED - failure
15079  *
15080  * ****************************************************************/
15081 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15082 {
15083    uint8_t idx=0;
15084    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15085
15086    if(f1apMsg)
15087    {
15088       if(f1apMsg->choice.initiatingMessage)
15089       {
15090          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15091          if(rrcDeliveryReport->protocolIEs.list.array)
15092          {
15093             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15094                   idx++)
15095             {
15096                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15097                {
15098                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15099                         sizeof(RRCDeliveryReportIEs_t));
15100                }   
15101             }
15102             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15103                   rrcDeliveryReport->protocolIEs.list.size);
15104          }
15105          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15106       }
15107       DU_FREE(f1apMsg,
15108             sizeof(F1AP_PDU_t));
15109    }
15110 }
15111
15112 /*******************************************************************
15113 *
15114 * @brief Builds and sends the RRC delivery report
15115 *
15116 * @details
15117 *
15118 *    Function : BuildAndSendRrcDeliveryReport
15119 *
15120 *    Functionality: Builds and sends the RRC delivery report
15121 *
15122 * @params[in]
15123 *
15124 * @return ROK     - success
15125 *         RFAILED - failure
15126 *
15127 * ****************************************************************/
15128 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15129    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15130 {
15131    uint8_t             ret = RFAILED;
15132    uint8_t             idx    = 0;
15133    uint8_t             idx1   = 0;
15134    uint8_t             elementCnt = 0;
15135    F1AP_PDU_t          *f1apMsg = NULLP;
15136    asn_enc_rval_t      encRetVal;  
15137    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15138
15139    do{
15140
15141       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15142       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15143       if(f1apMsg == NULLP)
15144       {
15145          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15146          break;
15147       }
15148       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15149       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15150       if(f1apMsg->choice.initiatingMessage == NULLP)
15151       {
15152          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15153          break;
15154       }
15155       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15156       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15157       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15158
15159       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15160       elementCnt = 4;
15161       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15162       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15163
15164       /* Initialize the F1Setup members */
15165       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15166       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15167       {
15168          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15169          break;
15170       }
15171       for(idx =0 ;idx <elementCnt; idx++)
15172       {
15173          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15174          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15175          {
15176             break;
15177          }
15178       }
15179
15180       idx1 = 0;
15181
15182       /*GNB CU UE F1AP ID*/
15183       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15184       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15185       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15186       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15187
15188       /*GNB DU UE F1AP ID*/
15189       idx1++;
15190       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15191       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15192       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15193       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15194
15195       /*RRC delivery status*/
15196       idx1++;
15197       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15198       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15199       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15200       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15201       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15202       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15203       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15204
15205       /* SRB ID */ 
15206       idx1++;
15207       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15208       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15209       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15210       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15211
15212       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15213
15214       /* Encode the RRC DELIVERY REPORT type as APER */
15215       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15216       encBufSize = 0;
15217       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15218             encBuf);
15219
15220       /* Encode results */
15221       if(encRetVal.encoded == ENCODE_FAIL)
15222       {
15223          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15224                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15225          break;
15226       }
15227       else
15228       {
15229          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15230 #ifdef DEBUG_ASN_PRINT
15231          for(idx=0; idx< encBufSize; idx++)
15232          {
15233             printf("%x",encBuf[idx]);
15234          }
15235 #endif
15236       }
15237
15238       /* Sending msg */
15239       if(sendF1APMsg() != ROK)
15240       {
15241          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15242          break;
15243       }
15244       ret = ROK;
15245       break;
15246
15247    }while(true);
15248
15249    freeRrcDeliveryReport(f1apMsg);
15250    return ret;
15251 }
15252
15253 /*******************************************************************
15254  *
15255  * @brief Processes cells to be activated
15256  *
15257  * @details
15258  *
15259  *    Function : extractCellsToBeActivated
15260  *
15261  *    Functionality:
15262  *      - Processes cells to be activated list received in F1SetupRsp
15263  *
15264  * @params[in] void
15265  * @return ROK     - success
15266  *         RFAILED - failure
15267  *
15268  * ****************************************************************/
15269
15270 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15271 {
15272    uint8_t  ret = ROK;
15273    uint16_t idx, pci = 0;
15274    uint64_t nci;
15275    Cells_to_be_Activated_List_Item_t cell;
15276
15277    for(idx=0; idx<cellsToActivate.list.count; idx++)
15278    {
15279       nci = 0;
15280       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15281       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15282
15283       if(cell.nRPCI)
15284       {
15285          pci = *cell.nRPCI;
15286       }
15287       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15288    }
15289    return ret;
15290 }
15291 /******************************************************************
15292 *
15293 * @brief Processes F1 Setup Response allocated by aper_decoder 
15294 *
15295 * @details
15296 *
15297 *    Function : freeF1SetupRsp 
15298 *
15299 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15300 *
15301 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15302 * @return void 
15303 *
15304 * ****************************************************************/
15305
15306 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15307 {
15308    uint8_t ieIdx =0;
15309    uint8_t arrIdx =0;
15310    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15311    RRC_Version_t      *rrcVer =NULLP;
15312
15313    if(f1SetRspMsg->protocolIEs.list.array)
15314    {
15315       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15316       {
15317          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15318          {
15319             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15320             {
15321                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15322                   {
15323                      cellToActivate =
15324                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15325                      if(cellToActivate->list.array)
15326                      {
15327                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15328                         {
15329                            if(cellToActivate->list.array[arrIdx])
15330                            {
15331
15332                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15333                               pLMN_Identity.buf)
15334                               {
15335                                  if(cellToActivate->list.array[0]->value.choice.\
15336                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15337                                  {
15338                                     free(cellToActivate->list.array[0]->value.choice.\
15339                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15340                                  }
15341
15342                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15343                                        nRCGI.pLMN_Identity.buf);
15344                               }
15345                               free(cellToActivate->list.array[arrIdx]);
15346                            }
15347                         }
15348                         free(cellToActivate->list.array);
15349                      }
15350                      break;
15351                   }
15352                case ProtocolIE_ID_id_TransactionID:
15353                   {
15354                      break;
15355                   }
15356                case ProtocolIE_ID_id_gNB_CU_Name:
15357                   {
15358                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15359                      break;
15360                   }
15361                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15362                   {
15363                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15364                      if(rrcVer->latest_RRC_Version.buf)
15365                      {
15366                         if(rrcVer->iE_Extensions)
15367                         {
15368                            if(rrcVer->iE_Extensions->list.array)
15369                            {
15370                               if(rrcVer->iE_Extensions->list.array[0])
15371                               {
15372                                  if(rrcVer->iE_Extensions->list.\
15373                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15374                                  {
15375                                     free(rrcVer->iE_Extensions->list.\
15376                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15377                                  }
15378                                  free(rrcVer->iE_Extensions->list.array[0]);
15379                               }
15380                               free(rrcVer->iE_Extensions->list.array);
15381                            }
15382                            free(rrcVer->iE_Extensions);
15383                         }
15384                         free(rrcVer->latest_RRC_Version.buf);
15385                      }
15386                      break;
15387
15388                   }
15389                default:
15390                   {
15391                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15392                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15393                   }
15394             }
15395             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15396          }
15397       }
15398       free(f1SetRspMsg->protocolIEs.list.array);
15399    }
15400 }
15401 /******************************************************************
15402  *
15403  * @brief Processes F1 Setup Response sent by CU
15404  *
15405  * @details
15406  *
15407  *    Function : procF1SetupRsp
15408  *
15409  *    Functionality: Processes F1 Setup Response sent by CU
15410  *
15411  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15412  * @return ROK     - success
15413  *         RFAILED - failure
15414  *
15415  * ****************************************************************/
15416 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15417 {
15418    uint8_t ret = ROK;
15419    uint16_t idx =0;
15420    F1SetupResponse_t *f1SetRspMsg = NULLP;
15421    GNB_CU_Name_t     *cuName = NULLP;
15422    F1SetupRsp  f1SetRspDb;
15423    RRC_Version_t      *rrcVer =NULLP;
15424    
15425    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15426
15427    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15428    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15429
15430    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15431    {
15432       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15433       {
15434          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15435             {
15436                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15437                      value.choice.Cells_to_be_Activated_List);
15438                break;
15439             }
15440          case ProtocolIE_ID_id_TransactionID:
15441             {
15442                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15443                                     value.choice.TransactionID;
15444                break;
15445             }
15446          case ProtocolIE_ID_id_gNB_CU_Name:
15447             {
15448                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15449                         value.choice.GNB_CU_Name;
15450                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15451                break;
15452             }
15453          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15454             {
15455                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15456                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15457                      (const char*)rrcVer->latest_RRC_Version.buf);
15458                break;
15459             }
15460          default:
15461             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15462                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15463       }
15464    }
15465    
15466    duProcF1SetupRsp();
15467    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15468
15469    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15470    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15471    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15472    {
15473       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15474       return RFAILED;
15475    }
15476    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15477
15478    if(BuildAndSendE2SetupReq() != ROK)
15479    {
15480       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15481       return RFAILED;
15482    }
15483    return ret;
15484 }
15485 /*******************************************************************
15486 *
15487 * @brief free GNB DU config update ack
15488 *
15489 * @details
15490 *
15491 *    Function : freeAperDecodeGnbDuAck 
15492 *
15493 *    Functionality: Processes GNB DU config update ack And
15494 *                     added free part for the memory allocated by aper_decoder
15495 *
15496 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15497 * @return ROK     - success
15498 *         RFAILED - failure
15499 *
15500 * ****************************************************************/
15501
15502 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15503 {
15504    uint8_t ieIdx = 0;
15505
15506    if(gnbDuAck->protocolIEs.list.array)
15507    {
15508       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15509       {
15510          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15511          {
15512             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15513          }
15514       }
15515       free(gnbDuAck->protocolIEs.list.array);
15516    }
15517 }
15518
15519 /*******************************************************************
15520 *
15521 * @brief Building  result of gnb-du config update ack output
15522 *
15523 * @details
15524 *
15525 *    Function : duProcGnbDuCfgUpdAckMsg 
15526 *
15527 *    Functionality: 
15528 *        Building output of gnb-du config update ack 
15529 *
15530 * @params[in] transId
15531 * @return void
15532 *
15533 * ****************************************************************/
15534
15535 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15536 {
15537    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15538    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15539    uint16_t cellIdx =0, crnti=0;
15540    uint64_t cellId =0;
15541    CmLList *f1apPduNode = NULLP;
15542    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15543    F1AP_PDU_t *f1apMsgPdu = NULLP;
15544    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15545    BIT_STRING_t *cellIdentity=NULLP;
15546    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15547    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15548    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15549
15550    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15551    f1apPduNode = searchFromReservedF1apPduList(transId);
15552    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15553    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15554
15555    if(f1apMsgPdu)
15556    {
15557       if(f1apMsgPdu->choice.initiatingMessage)
15558       {
15559          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15560          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15561          {
15562             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15563             {
15564                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15565                   {
15566                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15567                                      Served_Cells_To_Delete_List;
15568                      if(cellsToDelete->list.array)
15569                      {
15570                         if(cellsToDelete->list.array[arrIdx])
15571                         {
15572                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15573                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15574                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15575                            {
15576                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15577                               bitStringToInt(cellIdentity, &cellId);
15578
15579                               GET_CELL_IDX(cellId, cellIdx);
15580                               if(duCb.actvCellLst[cellIdx] != NULLP)
15581                               {
15582                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15583                               }
15584                            }
15585                         }
15586                      }
15587
15588                      if(duCb.actvCellLst[cellIdx] != NULLP)
15589                      {
15590                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15591                         {
15592                            ret = duSendCellDeletReq(cellId);
15593                            if(ret == RFAILED)
15594                            {
15595                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15596                               request for cellId[%lu]", cellId);
15597                            }
15598                         }
15599                         else
15600                         {
15601                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15602                            while(totalActiveUe)
15603                            {
15604                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15605                               {
15606                                  ueIdx++;
15607                                  continue;
15608                               }
15609
15610                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15611                               GET_UE_ID(crnti,ueId);
15612                               /* Sending Ue Context release request only for maximum supporting UEs */
15613                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15614                               if(ret == RFAILED)
15615                               {
15616                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15617                                  request for cellId[%lu]", cellId);
15618                               }
15619                               ueIdx++;
15620                               totalActiveUe--;
15621                            }
15622                         }
15623                      }
15624                      else
15625                      {
15626                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15627                         ret = RFAILED;
15628                      }
15629                      break;
15630                   }
15631
15632                default:
15633                   break;
15634             }
15635          }
15636       }
15637    }
15638    
15639    FreeDUConfigUpdate(f1apMsgPdu);
15640    deleteFromReservedF1apPduList(f1apPduNode);
15641    return ret;
15642 }
15643
15644 /*******************************************************************
15645 *
15646 * @brief Processes GNB DU config update ack
15647 *
15648 * @details
15649 *
15650 *    Function : procF1GNBDUCfgUpdAck
15651 *
15652 *    Functionality: added free part for the memory allocated by aper_decoder
15653 *
15654 * @params[in] F1AP_PDU_t *f1apMsg 
15655 * @return void 
15656 *
15657 * ****************************************************************/
15658 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15659 {
15660    uint8_t ieIdx=0,transId=0;
15661    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15662
15663    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15664    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15665
15666    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15667    {
15668       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15669       {
15670          case ProtocolIE_ID_id_TransactionID:
15671             {
15672                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15673                break;
15674             }
15675          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15676             {
15677                break;
15678             }
15679          default :
15680             {
15681                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15682                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15683                break;
15684             }
15685       }
15686    }
15687    
15688    duProcGnbDuCfgUpdAckMsg(transId);
15689     
15690 #if 0
15691    /* presently we are not supporting F1 Reset from DU to CU , we are only
15692     * supporting F1 Reset from CU to DU */
15693
15694    if(BuildAndSendF1ResetReq() != ROK)
15695    {
15696       return RFAILED;
15697    }
15698 #endif
15699
15700    freeAperDecodeGnbDuAck(gnbDuAck);
15701    return ROK;
15702 }
15703 /******************************************************************
15704 *
15705 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15706 *
15707 * @details
15708 *
15709 *    Function : freeAperDecodef1DlRrcMsg 
15710 *
15711 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15712 *
15713 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15714 * @return ROK     - success
15715 *         RFAILED - failure
15716 *
15717 * ****************************************************************/
15718
15719 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15720 {
15721    uint8_t ieIdx =0;
15722    RRCContainer_t *rrcContainer = NULLP;
15723
15724    if(f1DlRrcMsg->protocolIEs.list.array)
15725    {
15726       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15727       {
15728          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15729          {
15730             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15731             {
15732                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15733                   break;
15734                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15735                   break;
15736                case ProtocolIE_ID_id_SRBID:
15737                   break;
15738                case ProtocolIE_ID_id_RRCContainer:
15739                   {
15740                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15741                      free(rrcContainer->buf);
15742                   }
15743                case ProtocolIE_ID_id_ExecuteDuplication:
15744                   break;
15745                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15746                   break;
15747                   break;
15748             }
15749             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15750          }
15751       }
15752       free(f1DlRrcMsg->protocolIEs.list.array);
15753    }
15754 }
15755 /******************************************************************
15756  *
15757  * @brief Processes DL RRC Message Transfer  sent by CU
15758  *
15759  * @details
15760  *
15761  *    Function : procF1DlRrcMsgTrans
15762  *
15763  *    Functionality: Processes DL RRC Message Transfer sent by CU
15764  *
15765  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15766  * @return ROK     - success
15767  *         RFAILED - failure
15768  *
15769  * ****************************************************************/
15770 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15771 {
15772    uint8_t  idx, ret;
15773    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15774    F1DlRrcMsg dlMsg;
15775    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15776
15777    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15778    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15779
15780    ret = ROK;
15781
15782    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15783    {
15784       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15785       {
15786          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15787             {
15788                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15789                break;
15790             }
15791          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15792             {
15793                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15794                break;
15795             }
15796          case ProtocolIE_ID_id_SRBID:
15797             {
15798                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15799                break;
15800             }
15801          case ProtocolIE_ID_id_ExecuteDuplication:
15802             dlMsg.execDup = true;
15803             break;
15804
15805          case ProtocolIE_ID_id_RRCContainer:
15806             {
15807                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15808                {
15809              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15810              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15811              if(dlMsg.rrcMsgPdu)
15812              {
15813                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15814                       dlMsg.rrcMsgSize);
15815              }
15816              else
15817              {
15818                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15819                 return RFAILED;
15820              }
15821           }
15822           else
15823           {
15824              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15825                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15826              return RFAILED;
15827           }
15828           break;
15829        }
15830     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15831        {
15832           dlMsg.deliveryStatRpt = true;
15833           break;
15834        }
15835     default:
15836        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15837              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15838       }
15839    }
15840
15841    ret = duProcDlRrcMsg(&dlMsg);
15842
15843    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15844    return ret;
15845 }
15846 /*******************************************************************
15847  *
15848 * @brief Builds the DRB to be Setup Mod list
15849 *
15850 * @details
15851 *
15852 *    Function : 
15853 *
15854 *    Functionality: Constructs the DRB to be Setup Mod list
15855 *
15856 * @params[in] DRBs_SetupMod_List_t *drbSet
15857 *
15858 * @return ROK     - success
15859 *         RFAILED - failure
15860 *
15861 * ****************************************************************/
15862 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15863 {
15864    uint8_t srbIdx = 0;
15865    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15866
15867    srbList->list.count = ueCfg->numRlcLcs;
15868    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15869
15870    DU_ALLOC(srbList->list.array, srbList->list.size);
15871    if(srbList->list.array == NULLP)
15872    {
15873       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15874       return RFAILED;
15875    }
15876
15877    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15878    {
15879       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15880       if(srbList->list.array[srbIdx] == NULLP)
15881       {
15882          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15883          return RFAILED;
15884       }
15885    } 
15886
15887    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15888    {
15889       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15890       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15891       srbItemIe->criticality = Criticality_reject;
15892       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15893       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15894       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15895    }
15896    return ROK;
15897 }
15898
15899 /*******************************************************************
15900  *
15901 * @brief Builds the DRB to be Setup Mod list
15902 *
15903 * @details
15904 *
15905 *    Function : 
15906 *
15907 *    Functionality: Constructs the DRB to be Setup Mod list
15908 *
15909 * @params[in] DRBs_SetupMod_List_t *drbSet
15910 *
15911 * @return ROK     - success
15912 *         RFAILED - failure
15913 *
15914 * ****************************************************************/
15915
15916 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15917 {
15918    uint8_t arrIdx =0;
15919    uint8_t drbCnt =0;
15920    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15921
15922    drbCnt = ueCfg->numDrbSetupMod;
15923
15924    drbSet->list.count = drbCnt;
15925    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15926    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15927    if(drbSet->list.array == NULLP)
15928    {
15929       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15930       return  RFAILED;
15931    }
15932    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15933    {
15934       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15935       if(drbSet->list.array[arrIdx] == NULLP)
15936       {
15937               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15938               return  RFAILED;
15939       }
15940
15941       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15942       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15943       drbItemIe->criticality = Criticality_reject;
15944       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15945       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15946       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15947       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15948       {
15949          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15950          return RFAILED;
15951       }
15952       
15953    }
15954
15955    return ROK;
15956 }
15957 /*******************************************************************
15958 * @brief Free the memory allocated for DRB setup List
15959 *
15960 * @details
15961 *
15962 *    Function : FreeDrbSetupModList 
15963 *
15964 *    Functionality:
15965 *       Free the memory allocated for DRB setup list
15966 *
15967 * @params[in] DRBs_Setup_List_t *
15968 * @return void
15969 *
15970 * ****************************************************************/
15971 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15972 {
15973    uint8_t arrIdx = 0;
15974    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15975
15976    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15977    {
15978       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15979       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15980       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15981    }
15982    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15983 }
15984
15985 /*******************************************************************
15986 *
15987 * @brief Builds the DRB to be Mod list
15988 *
15989 * @details
15990 *
15991 *    Function : 
15992 *
15993 *    Functionality: Constructs the DRB to be Mod list
15994 *
15995 * @params[in] DRBs_Modified_List_t *drbModList
15996 *
15997 * @return ROK     - success
15998 *         RFAILED - failure
15999 *
16000 * ****************************************************************/
16001
16002 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16003 {
16004    uint8_t arrIdx =0, drbIdx = 0;
16005    uint8_t drbCnt =0;
16006    struct DRBs_Modified_ItemIEs *drbItemIe;
16007
16008    drbCnt = ueCfg->numDrbModified;
16009
16010    drbModList->list.count = drbCnt;
16011    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16012    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16013    if(drbModList->list.array == NULLP)
16014    {
16015       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16016       return  RFAILED;
16017    }
16018
16019    drbIdx = 0;
16020    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16021    {
16022       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16023       {
16024          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16025          if(drbModList->list.array[drbIdx] == NULLP)
16026          {
16027             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16028             return  RFAILED;
16029          }
16030
16031          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16032          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16033          drbItemIe->criticality = Criticality_reject;
16034          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16035          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16036          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16037                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16038          {
16039             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16040             return RFAILED;
16041          }
16042          drbIdx++;
16043       } 
16044    }
16045
16046    return ROK;
16047 }
16048
16049 /*******************************************************************
16050 * @brief Free the memory allocated for DRB Mod List
16051 *
16052 * @details
16053 *
16054 *    Function : FreeDrbModList 
16055 *
16056 *    Functionality:
16057 *       Free the memory allocated for DRB modified list
16058 *
16059 * @params[in] DRBs_Modified_List_t *
16060 * @return void
16061 *
16062 * ****************************************************************/
16063 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16064 {
16065    uint8_t arrIdx = 0;
16066    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16067
16068    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16069    {
16070       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16071       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16072       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16073    }
16074    DU_FREE(drbModList->list.array, drbModList->list.size);
16075 }
16076
16077 /*******************************************************************
16078 * @brief Free the memory allocated for SRB setup List
16079 *
16080 * @details
16081 *
16082 *    Function : FreeSrbSetupModList 
16083 *
16084 *    Functionality:
16085 *       Free the memory allocated for SRB setup list
16086 *
16087 * @params[in] SRBs_Setup_List_t *
16088 * @return void
16089 *
16090 * ****************************************************************/
16091 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16092 {
16093    uint8_t srbIdx = 0;
16094    
16095    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16096       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16097    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16098 }
16099
16100 /*******************************************************************
16101 * @brief Free the memory allocated for UE Context Mod Response
16102 *
16103 * @details
16104 *
16105 *    Function : FreeUeContextModResp 
16106 *
16107 *    Functionality:
16108 *       Free the memory allocated for UE Context Mod Response
16109 *
16110 * @params[in] F1AP_PDU_t *f1apMsg
16111 * @return void
16112 *
16113 * ****************************************************************/
16114
16115 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16116 {
16117    uint8_t ieIdx;
16118    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16119    if(f1apMsg)
16120    {
16121       if(f1apMsg->choice.successfulOutcome)
16122       {
16123          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16124          if(ueContextModifyRes->protocolIEs.list.array)
16125          {
16126             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16127             {
16128                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16129                {
16130                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16131                   {
16132                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16133                         break;
16134                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16135                         break;
16136                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16137                         {
16138                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16139                             value.choice.DRBs_SetupMod_List));
16140                             break;
16141                         }
16142                      case ProtocolIE_ID_id_DRBs_Modified_List:
16143                         {
16144                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16145                             value.choice.DRBs_Modified_List));
16146                             break;
16147                         }
16148                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16149                         {
16150                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16151                               SRBs_SetupMod_List));
16152                            break; 
16153                         }
16154                   }
16155                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16156                }
16157
16158             }
16159             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16160          }
16161          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16162       }
16163       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16164    }
16165 }
16166
16167 /*****************************************************************i
16168 *
16169 * @brief Creating the ue context modifcation response and sending
16170 *
16171 * @details
16172 *
16173 *    Function : BuildAndSendUeContextModRsp 
16174 *
16175 *    Functionality:
16176 *         - Creating the ue context modifcation response 
16177 *
16178 * @params[in] uint8_t cellId,uint8_t ueId
16179 * @return ROK     - success
16180 *         RFAILED - failure
16181 *
16182 * ****************************************************************/
16183 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16184 {
16185    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16186    uint8_t   elementCnt = 0;
16187    uint8_t   ret = RFAILED;
16188    F1AP_PDU_t *f1apMsg = NULLP;
16189    asn_enc_rval_t  encRetVal;
16190    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16191
16192    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16193
16194    while(true)
16195    {
16196       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16197       if(f1apMsg == NULLP)
16198       {
16199          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16200          break;
16201       }
16202
16203       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16204
16205       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16206       if(f1apMsg->choice.successfulOutcome == NULLP)
16207       {
16208          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16209          break;
16210       }
16211       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16212       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16213       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16214
16215       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16216   
16217       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16218       {
16219          elementCnt = 2;
16220          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16221             elementCnt++;
16222          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16223             elementCnt++; 
16224       }
16225       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16226       {
16227          elementCnt = 5;
16228       }
16229       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16230          elementCnt = 2;
16231       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16232       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16233
16234       /* Initialize the UE context modification members */
16235       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16236       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16237       {
16238          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16239          break;
16240       }
16241
16242       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16243       {
16244          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16245          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16246          {
16247             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16248             break;
16249          }
16250       }
16251
16252       ieIdx=0;
16253       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16254       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16255       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16256       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16257       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16258
16259       ieIdx++;
16260       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16261       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16262       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16263       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16264       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16265
16266       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16267       {
16268          ieIdx++;
16269          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16270          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16271          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16272          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16273          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16274       }
16275
16276       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16277            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16278       { 
16279          ieIdx++;
16280          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16281          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16282          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16283                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16284          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16285          {
16286             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16287             {
16288                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16289                {
16290                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16291                }
16292             }
16293          }
16294          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16295                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16296          if(ret != ROK)
16297          {
16298             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16299             break;
16300          }
16301       }
16302
16303       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16304       { 
16305          ieIdx++;
16306          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16307          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16308          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16309                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16310          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16311                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16312          if(ret != ROK)
16313          {
16314             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16315             break;
16316          }
16317       }
16318
16319       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16320       {
16321          ieIdx++;
16322          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16323          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16324          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16325                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16326          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16327          {
16328             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16329             {
16330                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16331                      sizeof(DuRlcBearerCfg));
16332             }
16333          }
16334          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16335                &ueCb->f1UeDb->duUeCfg);
16336          if(ret != ROK)
16337          {
16338             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16339             break;
16340          }
16341       }
16342
16343       freeF1UeDb(ueCb->f1UeDb);
16344       ueCb->f1UeDb = NULLP;
16345
16346       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16347
16348       /* Encode the F1SetupRequest type as APER */
16349       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16350       encBufSize = 0;
16351       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16352
16353       /* Encode results */
16354       if(encRetVal.encoded == ENCODE_FAIL)
16355       {
16356          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16357                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16358          ret = RFAILED;
16359          break;
16360       }
16361       else
16362       {
16363          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16364 #ifdef DEBUG_ASN_PRINT
16365          for(int i=0; i< encBufSize; i++)
16366          {
16367             printf("%x",encBuf[i]);
16368          }
16369 #endif
16370       }
16371
16372       /* Sending  msg  */
16373       if(sendF1APMsg() != ROK && (ret == ROK))
16374       {
16375          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16376          ret = RFAILED;
16377          break;
16378       }
16379
16380       ret = ROK;
16381       break;
16382    }
16383    FreeUeContextModResp(f1apMsg);
16384    return ret;
16385 }
16386
16387 /*******************************************************************
16388  *
16389  * @brief Deallocating the memory allocated by the aper decoder
16390  *          for QOSInfo
16391  *
16392  * @details
16393  *
16394  *    Function : freeAperDecodeQosInfo
16395  *
16396  *    Functionality:  Deallocating the memory allocated for QOSInfo
16397  *
16398  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16399  *
16400  * @return void
16401  *
16402  * ****************************************************************/
16403
16404 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16405 {
16406    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16407    {
16408       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16409       {
16410          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16411          {
16412             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16413          }
16414          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16415       }
16416       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16417    }
16418 }
16419 /*******************************************************************
16420  *
16421  * @brief Deallocating the memory allocated by the aper decoder
16422  *          for UlTnlInfoforDrb
16423  *
16424  * @details
16425  *
16426  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16427  *
16428  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16429  *
16430  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16431  *
16432  * @return void
16433  *
16434  * ****************************************************************/
16435 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16436 {
16437    uint8_t arrIdx =0;
16438
16439    if(ulInfo->list.array)
16440    {
16441       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16442       {
16443          if(ulInfo->list.array[arrIdx])
16444          {
16445             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16446             {
16447                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16448                {
16449                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16450                   {
16451                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16452                            gTP_TEID.buf);
16453                   }
16454                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16455                         transportLayerAddress.buf);
16456                }
16457                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16458             }
16459             free(ulInfo->list.array[arrIdx]);
16460          }
16461       }
16462       free(ulInfo->list.array);
16463    }
16464 }
16465
16466 /*******************************************************************
16467  *
16468  * @brief Deallocating the memory allocated by the aper decoder
16469  *          for DrbSetupModItem  
16470  *
16471  * @details
16472  *
16473  *    Function : freeAperDecodeDrbSetupModItem 
16474  *
16475  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16476  *
16477  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16478  *
16479  * @return void
16480  *
16481  * ****************************************************************/
16482
16483 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16484 {
16485    uint8_t arrIdx =0;
16486    SNSSAI_t *snssai =NULLP;
16487    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16488
16489    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16490    switch(drbItem->qoSInformation.present)
16491    {
16492       case QoSInformation_PR_NOTHING:
16493          break;
16494       case QoSInformation_PR_eUTRANQoS:
16495          {
16496             if(drbItem->qoSInformation.choice.eUTRANQoS)
16497             {
16498                free(drbItem->qoSInformation.choice.eUTRANQoS);
16499             }
16500             break;
16501          }
16502       case QoSInformation_PR_choice_extension:
16503          {
16504             if(drbItem->qoSInformation.choice.choice_extension)
16505             {
16506                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16507                      DRB_Information.dRB_QoS);
16508                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16509                if(snssai->sST.buf)
16510                {
16511                   free(snssai->sST.buf);
16512                }
16513                if(snssai->sD)
16514                {
16515                   if(snssai->sD->buf)
16516                   {
16517                      free(snssai->sD->buf);
16518                   }
16519                   free(snssai->sD);
16520                }
16521
16522                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16523                          DRB_Information.flows_Mapped_To_DRB_List;
16524                if(flowMap->list.array)
16525                {
16526                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16527                   {
16528                      if(flowMap->list.array[arrIdx] )
16529                      {
16530                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16531                         free(flowMap->list.array[arrIdx]);
16532                      }
16533                   }
16534                   free(flowMap->list.array);
16535                }
16536
16537                free(drbItem->qoSInformation.choice.choice_extension);
16538             }
16539             break;
16540          }
16541
16542    }
16543    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16544    if(drbItem->uLConfiguration)
16545    {
16546       free(drbItem->uLConfiguration);
16547    }
16548 }
16549
16550 /*******************************************************************
16551  *
16552  * @brief Deallocating the memory allocated by the aper decoder
16553  *          for DrbToBeSetupModList
16554  *
16555  * @details
16556  *
16557  *    Function : freeAperDecodeDrbToBeSetupModList
16558  *
16559  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16560  *
16561  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16562  *
16563  * @return void
16564  *
16565  * ****************************************************************/
16566
16567 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16568 {
16569    uint8_t arrIdx =0;
16570    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16571
16572    if(drbSet->list.array)
16573    {
16574       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16575       {
16576          if(drbSet->list.array[arrIdx] != NULLP)
16577          {
16578             if(arrIdx == 0)
16579             {
16580                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16581                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16582             }
16583             free(drbSet->list.array[arrIdx]);
16584          }
16585       }
16586       free(drbSet->list.array);
16587    }
16588
16589 }
16590
16591 /*******************************************************************
16592  *
16593  * @brief Deallocating the memory allocated by the aper decoder
16594  *          for DrbSetupModItem  
16595  *
16596  * @details
16597  *
16598  *    Function : freeAperDecodeDrbModifiedItem 
16599  *
16600  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16601  *
16602  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16603  *
16604  * @return void
16605  *
16606  * ****************************************************************/
16607
16608 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16609 {
16610    uint8_t arrIdx =0;
16611    SNSSAI_t *snssai =NULLP;
16612    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16613
16614    if(drbItem->qoSInformation != NULLP)
16615    {
16616       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16617       switch(drbItem->qoSInformation->present)
16618       {
16619          case QoSInformation_PR_NOTHING:
16620             break;
16621          case QoSInformation_PR_eUTRANQoS:
16622             {
16623                if(drbItem->qoSInformation->choice.eUTRANQoS)
16624                {
16625                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16626                }
16627                break;
16628             }
16629          case QoSInformation_PR_choice_extension:
16630             {
16631                if(drbItem->qoSInformation->choice.choice_extension)
16632                {
16633                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16634                         DRB_Information.dRB_QoS);
16635                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16636                   if(snssai->sST.buf)
16637                   {
16638                      free(snssai->sST.buf);
16639                   }
16640                   if(snssai->sD)
16641                   {
16642                      if(snssai->sD->buf)
16643                      {
16644                         free(snssai->sD->buf);
16645                      }
16646                      free(snssai->sD);
16647                   }
16648
16649                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16650                             DRB_Information.flows_Mapped_To_DRB_List;
16651                   if(flowMap->list.array)
16652                   {
16653                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16654                      {
16655                         if(flowMap->list.array[arrIdx] )
16656                         {
16657                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16658                            free(flowMap->list.array[arrIdx]);
16659                         }
16660                      }
16661                      free(flowMap->list.array);
16662                   }
16663
16664                   free(drbItem->qoSInformation->choice.choice_extension);
16665                }
16666                break;
16667             }
16668       }
16669       free(drbItem->qoSInformation);
16670    }
16671    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16672    if(drbItem->uLConfiguration)
16673    {
16674       free(drbItem->uLConfiguration);
16675    }
16676 }
16677
16678 /*******************************************************************
16679  *
16680  * @brief Deallocating the memory allocated by the aper decoder
16681  *          for DrbToBeSetupModList
16682  *
16683  * @details
16684  *
16685  *    Function : freeAperDecodeDrbToBeModifiedList
16686  *
16687  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16688  *
16689  * @params[in] DRBs_ToBeModified_List_t *drbSet
16690  *
16691  * @return void
16692  *
16693  * ****************************************************************/
16694
16695 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16696 {
16697    uint8_t arrIdx =0;
16698    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16699
16700    if(drbSet->list.array)
16701    {
16702       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16703       {
16704          if(drbSet->list.array[arrIdx] != NULLP)
16705          {
16706             if(arrIdx == 0)
16707             {
16708                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16709                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16710             }
16711             free(drbSet->list.array[arrIdx]);
16712          }
16713       }
16714       free(drbSet->list.array);
16715    }
16716
16717 }
16718
16719 /*******************************************************************
16720  *
16721  * @brief Deallocating the memory allocated by the aper decoder
16722  *          for DrbToBeSetupModList
16723  *
16724  * @details
16725  *
16726  *    Function : freeAperDecodeDrbToBeReleasedList
16727  *
16728  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16729  *
16730  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16731  *
16732  * @return void
16733  *
16734  * ****************************************************************/
16735
16736 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16737 {
16738    uint8_t arrIdx =0;
16739
16740    if(drbSet->list.array)
16741    {
16742       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16743       {
16744          if(drbSet->list.array[arrIdx] != NULLP)
16745          {
16746             free(drbSet->list.array[arrIdx]);
16747          }
16748       }
16749       free(drbSet->list.array);
16750    }
16751
16752 }
16753 /*******************************************************************
16754  *
16755  * @brief Deallocating the memory allocated by the aper decoder
16756  *          for UeContextModificationReqMsg
16757  *
16758  * @details
16759  *
16760  *    Function : freeAperDecodeUeContextModificationReqMsg
16761  *
16762  *    Functionality:  Deallocating memory allocated for
16763  *                  UeContextModificationReqMsg
16764  *
16765  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16766  *
16767  * @return void
16768  *
16769  * ****************************************************************/
16770 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16771 {
16772    uint8_t arrIdx, ieId;
16773
16774    if(ueContextModifyReq->protocolIEs.list.array)
16775    {
16776       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16777       {
16778          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16779          {
16780             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16781             switch(ieId)
16782             {
16783                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16784                   break;
16785                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16786                   break;
16787                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16788                   {
16789                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16790                            value.choice.DRBs_ToBeSetupMod_List);
16791                      break;
16792                   }
16793                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16794                   {
16795                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16796                            value.choice.DRBs_ToBeModified_List);
16797                      break;
16798                   }
16799                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16800                   {
16801                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16802                            value.choice.DRBs_ToBeReleased_List);
16803                      break;
16804                   }
16805                case ProtocolIE_ID_id_TransmissionActionIndicator:
16806                   break;
16807                case ProtocolIE_ID_id_RRCContainer:
16808                   {
16809                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16810                   }
16811             }
16812             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16813          }
16814       }
16815       free(ueContextModifyReq->protocolIEs.list.array);
16816    }
16817 }
16818 /*******************************************************************
16819  *
16820  * @brief processing the F1 UeContextModificationReq
16821  *
16822  * @details
16823  *
16824  *    Function : procF1UeContextModificationReq
16825  *
16826  *    Functionality:  processing the F1 UeContextModificationReq
16827  *
16828  * @params[in] F1AP_PDU_t *f1apMsg
16829  *
16830  * @return
16831  * ****************************************************************/
16832 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16833 {
16834    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16835    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16836    DuUeCb   *duUeCb = NULLP;
16837    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16838    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16839    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16840    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16841
16842    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16843    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16844    {
16845       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16846       {
16847          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16848             {
16849                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16850                break;
16851             }
16852          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16853             {
16854                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16855                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16856                {
16857                   if(duCb.actvCellLst[cellIdx])
16858                   {
16859                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16860                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16861                      {
16862                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16863                         if(duUeCb->f1UeDb == NULLP)
16864                         {
16865                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16866                            duUeCb->f1UeDb->cellIdx = cellIdx;
16867                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16868                         }
16869                         break;
16870                      }
16871                   }
16872                }
16873                if(duUeCb == NULLP)
16874                {
16875                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16876                   ret = RFAILED;
16877                }
16878                break;
16879             }
16880
16881          case ProtocolIE_ID_id_RRCContainer:
16882             {
16883                /* Filling Dl RRC Msg Info */
16884                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16885                if(!duUeCb->f1UeDb->dlRrcMsg)
16886                {
16887                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16888                         Memory allocation failed ");
16889                   ret = RFAILED;
16890                }
16891                else
16892                {
16893                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16894                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16895                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16896                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16897                         value.choice.RRCContainer);
16898                }
16899
16900                break;
16901             }
16902
16903          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16904          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16905          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16906             {
16907                if(duUeCb->f1UeDb)
16908                {
16909                   /*DRBs to be Added*/
16910                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
16911                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
16912                   {
16913                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16914                                       choice.DRBs_ToBeSetupMod_List;
16915
16916                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
16917                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
16918                      {
16919                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
16920                         ret = RFAILED;
16921                      }
16922                   }
16923
16924                   /*DRBs to be Modified*/
16925                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
16926                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
16927
16928                   {
16929                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16930                                       choice.DRBs_ToBeModified_List;
16931                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
16932                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
16933                      {
16934                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
16935                         ret = RFAILED;
16936                      }
16937                   }
16938                   /*DRBs to be Released*/
16939                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
16940                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
16941
16942                   {
16943                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16944                                       choice.DRBs_ToBeReleased_List;
16945                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
16946                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
16947                      {
16948                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
16949                         ret = RFAILED;
16950                      }
16951                   }
16952                }
16953                break;
16954             }
16955
16956          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
16957             {
16958                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
16959                if(duUeCb->f1UeDb)
16960                {
16961                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
16962                }
16963                break;
16964             }
16965
16966          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
16967             {
16968                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
16969                   RRCReconfigurationCompleteIndicator_true)
16970                {
16971                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
16972                }
16973                break;
16974             }
16975          case ProtocolIE_ID_id_TransmissionActionIndicator:
16976             {
16977                if(duUeCb->f1UeDb)
16978                {
16979                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
16980                   {
16981                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
16982                   }
16983                   else 
16984                   {
16985                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
16986                   }
16987                }
16988                break;
16989             }
16990
16991          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
16992             {
16993                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
16994                {
16995                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
16996                }
16997                break;
16998             }
16999 #ifdef NR_DRX
17000          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17001             {
17002                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17003                break;
17004             }
17005 #endif
17006               
17007       }
17008    }
17009
17010    if(ret != RFAILED) 
17011    {
17012       ret = duProcUeContextModReq(duUeCb);
17013    }
17014    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17015    return ret; 
17016 }
17017
17018 /*****************************************************************i
17019 *
17020 * @brief Free memory allocated for UE Context Release Request
17021 *
17022 * @details
17023 *
17024 *    Function : FreeUeContextReleaseReq
17025 *
17026 *    Functionality:
17027 *         - Free memory allocated for UE Context Release Request
17028 *
17029 * @params[in] F1AP_PDU_t *f1apMsg
17030 * @return void 
17031 *
17032 * *************************************************************/
17033 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17034 {
17035    uint8_t ieIdx;
17036    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17037    
17038    if(f1apMsg)
17039    {
17040       if(f1apMsg->choice.initiatingMessage)
17041       {
17042          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17043          if(ueReleaseReq->protocolIEs.list.array)
17044          {
17045             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17046             {
17047                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17048             }
17049             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17050          }
17051          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17052       }
17053       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17054    }
17055
17056 }
17057 /*****************************************************************i
17058 *
17059 * @brief Build and Send UE Context Release Request  
17060 *
17061 * @details
17062 *
17063 *    Function : BuildAndSendUeContextReleaseReq
17064 *
17065 *    Functionality:
17066 *         - Build and Send UE Context Release Request 
17067 *
17068 * @params[in]
17069 * @return ROK     - success
17070 *         RFAILED - failure
17071 *
17072 * *************************************************************/
17073 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17074 {
17075    bool memAllocFail = false;
17076    uint8_t ieIdx =0;
17077    uint8_t ret = RFAILED;
17078    uint16_t cellIdx =0;
17079    uint16_t crnti = 0;
17080    uint8_t  elementCnt = 0;
17081    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17082    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17083    asn_enc_rval_t encRetVal; 
17084    F1AP_PDU_t *f1apMsg = NULLP;
17085    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17086
17087    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17088    do
17089    {
17090       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17091       if(f1apMsg == NULLP)
17092       {
17093          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17094          break;
17095       }
17096
17097       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17098       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17099       if(f1apMsg->choice.initiatingMessage == NULLP)
17100       {
17101          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17102          initiatingMessage");   
17103          break;
17104       }
17105       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17106       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17107       f1apMsg->choice.initiatingMessage->value.present = \
17108       InitiatingMessage__value_PR_UEContextReleaseRequest;
17109
17110       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17111
17112       elementCnt = 2;
17113
17114       ueReleaseReq->protocolIEs.list.count = elementCnt;
17115       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17116
17117       /* Initialize the F1Setup members */
17118       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17119       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17120       {
17121          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17122          break;
17123       }
17124       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17125       {
17126          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17127                sizeof(UEContextReleaseRequest_t));
17128          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17129          {
17130             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17131             memAllocFail = true;  
17132             break;
17133          }
17134       }
17135       if(memAllocFail == true)
17136          break;
17137
17138       /* Fetching Ue Cb Info*/
17139       GET_CELL_IDX(cellId, cellIdx);
17140       if(duCb.actvCellLst[cellIdx] == NULLP)
17141       {
17142          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17143          break;
17144       }
17145       else
17146       {
17147          GET_CRNTI(crnti, ueId);
17148          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17149          {
17150             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17151             break;
17152          }
17153          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17154          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17155       }
17156
17157       ieIdx=0; 
17158       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17159       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17160       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17161       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17162       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17163       
17164       ieIdx++;
17165       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17166       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17167       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17168       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17169       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17170       
17171       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17172
17173       /* Encode the F1SetupRequest type as APER */
17174       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17175       encBufSize = 0;
17176       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17177       /* Encode results */
17178       if(encRetVal.encoded == ENCODE_FAIL)
17179       {
17180          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17181                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17182          break;
17183       }
17184       else
17185       {
17186          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17187 #ifdef DEBUG_ASN_PRINT
17188          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17189          {
17190             printf("%x",encBuf[ieIdx]);
17191          }
17192 #endif
17193       }
17194
17195       /* Sending msg */
17196       if(sendF1APMsg() != ROK)
17197       {
17198          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17199          break;
17200       }
17201       ret = ROK;
17202       break;
17203    }while(true);
17204
17205    FreeUeContextReleaseReq(f1apMsg);
17206    return ret;
17207 }
17208 /*****************************************************************i
17209  *
17210  * @brief Free memory allocated for UE Context Release Complete
17211  *
17212  * @details
17213  *
17214  *    Function : FreeUeContextReleaseComplete
17215  *
17216  *    Functionality:
17217  *         - Free memory allocated for UE Context Release Complete
17218  *
17219  * @params[in] F1AP_PDU_t *f1apMsg
17220  * @return void
17221  *
17222  * *************************************************************/
17223 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17224 {
17225    uint8_t ieIdx;
17226    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17227
17228    if(f1apMsg)
17229    {
17230       if(f1apMsg->choice.successfulOutcome)
17231       {
17232          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17233          if(ueReleaseComplete->protocolIEs.list.array)
17234          {
17235             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17236             {
17237                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17238             }
17239             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17240          }
17241          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17242       }
17243       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17244    }
17245
17246 }
17247 /*****************************************************************i
17248  *
17249  * @brief Build and Send UE Context Release Complete
17250  *
17251  * @details
17252  *
17253  *    Function : BuildAndSendUeContextReleaseComplete
17254  *
17255  *    Functionality:
17256  *         - Build and Send UE Context Release Complete
17257  *
17258  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17259  * @return ROK     - success
17260  *         RFAILED - failure
17261  *
17262  * *************************************************************/
17263 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17264 {
17265    bool memAllocFail = false;
17266    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17267    asn_enc_rval_t encRetVal;
17268    F1AP_PDU_t *f1apMsg = NULLP;
17269    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17270
17271    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17272    do
17273    {
17274       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17275       if(f1apMsg == NULLP)
17276       {
17277          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17278          break;
17279       }
17280
17281       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17282       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17283       if(f1apMsg->choice.successfulOutcome == NULLP)
17284       {
17285          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17286                successfulOutcome");
17287          break;
17288       }
17289       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17290       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17291       f1apMsg->choice.successfulOutcome->value.present = \
17292       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17293
17294       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17295
17296       elementCnt = 2;
17297       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17298       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17299
17300       /* Initialize the UE Release Complete members */
17301       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17302       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17303       {
17304          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17305          break;
17306       }
17307       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17308       {
17309          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17310                sizeof(UEContextReleaseComplete_t));
17311          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17312          {
17313             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17314             elements");
17315             memAllocFail = true;
17316             break;
17317          }
17318       }
17319       if(memAllocFail == true)
17320          break;
17321
17322
17323       ieIdx=0;
17324       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17325       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17326       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17327       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17328       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17329
17330       ieIdx++;
17331       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17332       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17333       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17334       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17335       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17336
17337       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17338
17339       /* Encode the F1SetupComplete type as APER */
17340       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17341       encBufSize = 0;
17342       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17343       /* Encode results */
17344       if(encRetVal.encoded == ENCODE_FAIL)
17345       {
17346          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17347                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17348          break;
17349       }
17350       else
17351       {
17352          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17353 #ifdef DEBUG_ASN_PRINT
17354          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17355          {
17356             printf("%x",encBuf[ieIdx]);
17357          }
17358 #endif
17359       }
17360
17361       /* Sending msg */
17362       if(sendF1APMsg() != ROK)
17363       {
17364          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17365          break;
17366       }
17367       ret = ROK;
17368       break;
17369    }while(true);
17370    
17371    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17372          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17373    {
17374       ret = duSendCellDeletReq(cellId);
17375       if(ret != ROK)
17376       {
17377          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17378                Delete req for CellId");
17379       }
17380    }
17381    FreeUeContextReleaseComplete(f1apMsg);
17382    return ret;
17383
17384 }
17385
17386 /*******************************************************************
17387 *
17388 * @brief added free part for the memory allocated by aper_decoder 
17389 *
17390 * @details
17391 *
17392 *    Function : freeAperDecodeUeContextReleaseCommand 
17393 *
17394 *    Functionality: added free part for the memory allocated by aper_decoder
17395 *
17396 * @params[in] F1AP_PDU_t *f1apMsg
17397 * @return void
17398 *
17399 * ****************************************************************/
17400 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17401 {
17402    uint8_t ieIdx=0;
17403    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17404
17405    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17406    
17407    if(ueContextReleaseCommand->protocolIEs.list.array)
17408    {
17409       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17410       {
17411          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17412          {
17413             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17414             {
17415                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17416                   break;
17417                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17418                   break;
17419                case ProtocolIE_ID_id_Cause:
17420                   break;
17421                case ProtocolIE_ID_id_RRCContainer:
17422                {
17423                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17424                   {
17425                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17426                   }
17427                   break;
17428                }
17429                default :
17430                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17431                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17432                   break;
17433             }
17434          }
17435          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17436       }
17437       free(ueContextReleaseCommand->protocolIEs.list.array);
17438    }
17439 }
17440 /*******************************************************************
17441 *
17442 * @brief processing of UE Context Release Command
17443 *
17444 * @details
17445 *
17446 *    Function : procF1UeContextReleaseCommand 
17447 *
17448 *    Functionality: processing of UE Context Release Command
17449 *
17450 * @params[in] F1AP_PDU_t *f1apMsg
17451 * @return void
17452 *
17453 * ****************************************************************/
17454 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17455 {
17456    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17457    uint16_t cellIdx =0, cellId = 0;
17458    bool ueIdxFound = false;
17459    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17460    DuUeCb   *duUeCb = NULLP;
17461    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17462
17463    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17464
17465    if(ueContextReleaseCommand->protocolIEs.list.array)
17466    {
17467       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17468       {
17469          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17470          {
17471             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17472             {
17473                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17474                   {
17475                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17476                                     value.choice.GNB_CU_UE_F1AP_ID;
17477                      break;
17478                   }
17479
17480                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17481                   {
17482                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17483                                      value.choice.GNB_DU_UE_F1AP_ID;
17484                      break;
17485                   }
17486
17487                case ProtocolIE_ID_id_Cause:
17488                   {
17489                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17490                      {
17491                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17492                         {
17493                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17494                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17495                            {
17496                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17497                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17498                               ueIdxFound = true;
17499                               break;
17500                            }
17501                         }
17502                         if(ueIdxFound == true)
17503                         {
17504                            break;
17505                         }
17506                      }
17507                      
17508                      if(!ueIdxFound)
17509                      {
17510                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17511                         ret = RFAILED;
17512                      }
17513                      break;
17514                   }
17515
17516                case ProtocolIE_ID_id_RRCContainer:
17517                   {
17518                      if(ueIdxFound == true)  
17519                      {
17520                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17521                         if(duUeCb->f1UeDb)
17522                         {
17523                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17524                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17525                            duUeCb->f1UeDb->cellIdx = cellIdx;
17526                            /* Filling Dl RRC Msg Info */
17527                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17528                            if(!duUeCb->f1UeDb->dlRrcMsg)
17529                            {
17530                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17531                                     Memory allocation failed ");
17532                               ret = RFAILED;
17533                            }
17534                            else
17535                            {
17536                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17537                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17538                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17539                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17540                                     value.choice.RRCContainer);
17541                            }
17542
17543                         }
17544                         else
17545                         {
17546                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17547                                  Memory allocation failed ");
17548                            ret = RFAILED;
17549
17550                         }
17551                      }
17552                      break;
17553                   }
17554                default :
17555                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17556                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17557                   break;
17558             }
17559          }
17560       }
17561    }
17562    if(ret != RFAILED)
17563    {
17564       duProcUeContextReleaseCommand(cellId, duUeCb);
17565    }
17566    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17567    return ret;
17568 }
17569
17570 /**************************************************************
17571  *
17572  * @brief free the memory allocated by aper decoder for paging
17573  *
17574  * @details
17575  *
17576  *    Function : freeAperDecodePagingMsg
17577  *
17578  *    Functionality:
17579  *         - free the memory allocated by aper decoder for
17580  *         the paging f1ap msg
17581  *
17582  * @params[in] Paging_t   *paging
17583  * @return ROK     - success
17584  *         RFAILED - failure
17585  *
17586  ****************************************************************/
17587 void freeAperDecodePagingMsg(Paging_t   *paging)
17588 {
17589    uint8_t ieIdx, cellIdx;
17590    PagingCell_ItemIEs_t *pagingCellItemIes;
17591    PagingCell_Item_t *pagingCellItem;
17592    PagingCell_list_t  *pagingCelllist;
17593
17594    if(paging)
17595    {
17596       if(paging->protocolIEs.list.array)
17597       {
17598          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17599          {
17600             if(paging->protocolIEs.list.array[ieIdx])
17601             {
17602                switch(paging->protocolIEs.list.array[ieIdx]->id)
17603                {
17604                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17605                      {
17606                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17607                         break;
17608                      }
17609                   case ProtocolIE_ID_id_PagingIdentity:
17610                      {
17611                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17612                         {
17613                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17614                            {
17615                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17616                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17617                               {
17618                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17619                               }
17620                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17621                            }
17622                         }
17623                         break;
17624                      }
17625                   case ProtocolIE_ID_id_PagingCell_List:
17626                      {
17627                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17628                         if(pagingCelllist->list.array)
17629                         {
17630                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17631                            {
17632                               if(pagingCelllist->list.array[cellIdx])
17633                               {
17634                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17635                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17636                                  {
17637                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17638                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17639                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17640                                  }
17641                                  free(pagingCelllist->list.array[cellIdx]);
17642                               }
17643                            }
17644                            free(pagingCelllist->list.array);
17645                         }
17646                         break;
17647                      }
17648                }
17649                free(paging->protocolIEs.list.array[ieIdx]);
17650             }
17651          }
17652          free(paging->protocolIEs.list.array);
17653
17654       }
17655    }
17656 }
17657
17658 /**************************************************************
17659  *
17660  * @brief processing the paging f1ap msg received from CU 
17661  *
17662  * @details
17663  *
17664  *    Function : procPagingMsg
17665  *
17666  *    Functionality:
17667  *         - processing the paging f1ap msg received from CU
17668  *
17669  * @params[in] F1AP_PDU_t *f1apMsg
17670  * @return ROK     - success
17671  *         RFAILED - failure
17672  *
17673  *
17674  ****************************************************************/
17675 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17676 {
17677    uint8_t ieIdx = 0, cellListIdx = 0;
17678    uint64_t cellId = 0;
17679    Paging_t   *paging = NULLP;
17680    PagingCell_list_t  *pagingCelllist = NULLP;
17681    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17682    PagingCell_Item_t *pagingCellItem = NULLP;
17683    DuPagingMsg *tmpPagingParam = NULLP;
17684
17685    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17686    if(paging)
17687    {
17688       if(paging->protocolIEs.list.array)
17689       {
17690          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17691          if(tmpPagingParam == NULLP)
17692          {
17693             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17694             freeAperDecodePagingMsg(paging);
17695             return RFAILED;
17696          }
17697          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17698          {
17699             if(paging->protocolIEs.list.array[ieIdx])
17700             {
17701                switch(paging->protocolIEs.list.array[ieIdx]->id)
17702                {
17703                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17704                      {
17705                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17706                                          &tmpPagingParam->pagUeId);
17707                         break;
17708                      }
17709
17710                   case ProtocolIE_ID_id_PagingIdentity:
17711                      {
17712                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17713                         {
17714                            case PagingIdentity_PR_cNUEPagingIdentity: 
17715                               {
17716                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17717                                  {
17718                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17719                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17720
17721                                  }
17722                                  break;
17723                               }
17724                             case PagingIdentity_PR_rANUEPagingIdentity:
17725                                {
17726                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17727                                   break;
17728                                }
17729                             default:
17730                                {
17731                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17732                                   continue;
17733                                }
17734                         }
17735                      }
17736
17737                   case ProtocolIE_ID_id_PagingDRX:
17738                      {
17739                         tmpPagingParam->pagingDrxPres = TRUE;
17740                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17741                         break;
17742                      }
17743
17744                   case ProtocolIE_ID_id_PagingPriority:
17745                      {
17746                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17747                         break;
17748                      }
17749
17750                   case ProtocolIE_ID_id_PagingCell_List:
17751                      {
17752                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17753                         if(pagingCelllist->list.array)
17754                         {
17755                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17756                            {
17757                               if(pagingCelllist->list.array[cellListIdx])
17758                               {
17759                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17760                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17761                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17762                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17763                                  {
17764                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17765                                     continue;
17766                                  }
17767                               }
17768                            }
17769                         }
17770                         break;
17771                      }
17772                    default:
17773                      {
17774                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17775                          break;
17776                      }
17777                }
17778             }
17779          }
17780       }
17781    }
17782    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17783    freeAperDecodePagingMsg(paging);
17784   
17785    return ROK;
17786 }
17787
17788 /**************************************************************
17789  *
17790  * @brief Handles received F1AP message and sends back response  
17791  *
17792  * @details
17793  *
17794  *    Function : F1APMsgHdlr
17795  *
17796  *    Functionality:
17797  *         - Decodes received F1AP control message
17798  *         - Prepares response message, encodes and sends to SCTP
17799  *
17800  * @params[in] 
17801  * @return ROK     - success
17802  *         RFAILED - failure
17803  *
17804  * ****************************************************************/
17805 void F1APMsgHdlr(Buffer *mBuf)
17806 {
17807    int i =0;
17808    char *recvBuf =NULLP;
17809    MsgLen copyCnt =0;
17810    MsgLen recvBufLen =0;
17811    F1AP_PDU_t *f1apMsg =NULLP;
17812    asn_dec_rval_t rval; /* Decoder return value */
17813    F1AP_PDU_t f1apasnmsg ;
17814    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17815    ODU_PRINT_MSG(mBuf, 0,0);
17816
17817    /* Copy mBuf into char array to decode it */
17818    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17819    DU_ALLOC(recvBuf, (Size)recvBufLen);
17820
17821    if(recvBuf == NULLP)
17822    {
17823       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17824       return;
17825    }
17826    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17827    {
17828       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17829       return;
17830    }
17831
17832 #ifdef DEBUG_ASN_PRINT
17833    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17834    for(i=0; i< recvBufLen; i++)
17835    {
17836       printf("%x",recvBuf[i]);
17837    }
17838 #endif
17839
17840    /* Decoding flat buffer into F1AP messsage */
17841    f1apMsg = &f1apasnmsg;
17842    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17843
17844    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17845
17846    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17847    {
17848       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17849       return;
17850    }
17851    printf("\n");
17852    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17853
17854    switch(f1apMsg->present)
17855    {
17856       case F1AP_PDU_PR_successfulOutcome:
17857          {
17858             switch(f1apMsg->choice.successfulOutcome->value.present)
17859             {
17860                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17861                   {
17862                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17863                      break;
17864                   }
17865                case SuccessfulOutcome__value_PR_F1SetupResponse:
17866                   {                             
17867 #ifndef ODU_TEST_STUB
17868                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17869 #endif
17870                      break;
17871                   }
17872
17873                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17874                   {
17875                      procF1GNBDUCfgUpdAck(f1apMsg);
17876                      break;
17877                   }
17878
17879                default:
17880                   {
17881                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17882                            f1apMsg->choice.successfulOutcome->value.present);
17883                      return;
17884                   }
17885             }/* End of switch(successfulOutcome) */
17886             free(f1apMsg->choice.successfulOutcome);
17887             break;
17888          }
17889       case F1AP_PDU_PR_initiatingMessage:
17890          {
17891             switch(f1apMsg->choice.initiatingMessage->value.present)
17892             {
17893                case InitiatingMessage__value_PR_Reset:
17894                   {
17895                      procF1ResetReq(f1apMsg);
17896                      break;
17897                   }
17898                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17899                   {
17900                      procF1DlRrcMsgTrans(f1apMsg);
17901                      break;
17902                   }
17903                case InitiatingMessage__value_PR_UEContextSetupRequest:
17904                   {
17905                      procF1UeContextSetupReq(f1apMsg);
17906                      break;
17907                   }
17908                case InitiatingMessage__value_PR_UEContextModificationRequest:
17909                   {
17910                      procF1UeContextModificationReq(f1apMsg);
17911                      break;
17912                   }
17913                case InitiatingMessage__value_PR_UEContextReleaseCommand:
17914                   {
17915                       procF1UeContextReleaseCommand(f1apMsg);
17916                       break;
17917                   }
17918                case InitiatingMessage__value_PR_Paging:
17919                   {
17920                      procPagingMsg(f1apMsg);
17921                      break;
17922                   }
17923                default:
17924                   {
17925                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
17926                            f1apMsg->choice.initiatingMessage->value.present);
17927                      return;
17928                   }
17929             }/* End of switch(initiatingMessage) */
17930             free(f1apMsg->choice.initiatingMessage);
17931             break;
17932          }
17933
17934       default:
17935          {
17936             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
17937             return;
17938          }
17939          free(f1apMsg);
17940
17941    }/* End of switch(f1apMsg->present) */
17942    
17943    DU_FREE(recvBuf, (Size)recvBufLen);
17944 } /* End of F1APMsgHdlr */
17945
17946 /**********************************************************************
17947   End of file
17948  **********************************************************************/