[Epic-ID: ODUHIGH-488][Task-ID: ODUHIGH-501] Ue Create and Rsp correction in DUAPP...
[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
180 #ifdef O1_ENABLE
181 #include "CmInterface.h"
182 extern StartupConfig g_cfg;
183 #endif
184
185 DuCfgParams duCfgParam;
186
187 /******************************************************************
188  *
189  * @brief Function to fetch lcId based on DRB Id
190  *
191  * @details
192  *
193  *    Function : fetchLcId
194  *
195  *    @params[in] drbId
196  *
197  *    Functionality: Function to fetch lcId based on DRB Id
198  *
199  * Returns: lcId - SUCCESS
200  *          RFAILED - FAILURE
201  *****************************************************************/
202
203 uint8_t fetchLcId(uint8_t drbId)
204 {
205    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
206
207    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
208    {
209       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
210       {
211          if(duCb.actvCellLst[cellIdx] != NULLP)
212          {
213             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
214             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
215             {
216                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
217                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
218                {
219                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
220                   return lcId;
221                }
222             }
223          }
224       }
225    }
226    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
227    return RFAILED;
228 }
229
230 /*******************************************************************
231 *
232 * @brief Adding F1AP pdu to reserved pdu list
233 *
234 * @details
235 *
236 *    Function : addToReservedF1apPduList 
237 *
238 *    Functionality: Adding F1AP pdu to reserved pdu list.
239 *     These pdu are awaiting aknowledgment from CU
240 *
241 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
242 *
243 * @return ROK - success
244 *         RFAILED - failure
245 *
246 * ****************************************************************/
247 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
248 {
249    CmLList         *node = NULLP;
250    ReservedF1apPduInfo *pduInfo = NULLP;
251    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
252    if(pduInfo)
253    {
254       DU_ALLOC(node, sizeof(CmLList));
255       if(node)
256       {
257          pduInfo->transId = transId;
258          pduInfo->f1apMsg = (void*) f1apPdu;
259
260          node->node = (PTR)pduInfo;
261          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
262       }
263    }
264 }
265
266 /*******************************************************************
267 *
268 * @brief searching for F1AP pdu from ReservedF1apPduList 
269 *
270 * @details
271 *
272 *    Function : searchFromReservedF1apPduList 
273 *
274 *    Functionality: searching for F1AP pdu information
275 *
276 * @params[in] uint8_t transId
277 *
278 * @return pointer to F1AP_PDU_t
279 *
280 * ****************************************************************/
281
282 CmLList *searchFromReservedF1apPduList(uint8_t transId)
283 {
284    CmLList         *node;
285    ReservedF1apPduInfo *f1apPdu;
286    if(duCb.reservedF1apPduList.count)
287    {
288       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
289       while(node)
290       {
291          f1apPdu = (ReservedF1apPduInfo*)node->node;
292          if(f1apPdu->transId == transId)
293          {
294             return node;
295          }
296          node = node->next;
297       }
298    }
299    return NULL;
300 }
301
302 /*******************************************************************
303 *
304 * @brief deleting F1AP pdu information from ReservedF1apPduList
305 *
306 * @details
307 *
308 *    Function : deleteFromReservedF1apPduList 
309 *
310 *    Functionality: deleting pdu information from ReservedF1apPduList
311 *
312 * @params[in] CmLList *node 
313 *
314 * @return void 
315 *
316 * ****************************************************************/
317
318 void deleteFromReservedF1apPduList(CmLList *node)
319 {
320    ReservedF1apPduInfo *f1apPdu;
321
322    if(node != NULL)
323    {
324       f1apPdu = (ReservedF1apPduInfo *)node->node;
325       cmLListDelFrm(&duCb.reservedF1apPduList, node);
326       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
327       DU_FREE(node, sizeof(CmLList));
328       node = NULL;
329    }
330 }
331
332 /*******************************************************************
333  *
334  * @brief Builds Uplink Info for NR 
335  *
336  * @details
337  *
338  *    Function : BuildULNRInfo
339  *
340  *    Functionality: Building NR Uplink Info
341  *
342  * @params[in] NRFreqInfo_t *ulnrfreq
343  * @return ROK     - success
344  *         RFAILED - failure
345  *
346  * ****************************************************************/
347 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
348 {
349    uint8_t idx=0;
350    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
351                        fdd.ulNrFreqInfo.nrArfcn;
352    ulnrfreq->freqBandListNr.list.count = 1;
353    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
354    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
355    if(ulnrfreq->freqBandListNr.list.array == NULLP)
356    {
357       return RFAILED;
358    }
359    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
360    {
361       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
362       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
363       {
364          return RFAILED;
365       }
366    }
367    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
368                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
369                                                                  freqBand[0].nrFreqBand;
370    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
371    return ROK;
372 }
373 /*******************************************************************
374  *
375  * @brief Builds Downlink NR Info 
376  *
377  * @details
378  *
379  *    Function : BuildDLNRInfo
380  *
381  *    Functionality: Building Downlink NR Info
382  *    
383  * @params[in] NRFreqInfo_t *dlnrfreq
384  * @return ROK     - success
385  *         RFAILED - failure
386  *
387  * ****************************************************************/
388 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
389 {
390    uint8_t idx=0;
391    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
392                        fdd.dlNrFreqInfo.nrArfcn;
393    dlnrfreq->freqBandListNr.list.count = 1;
394    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
395    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
396    if(dlnrfreq->freqBandListNr.list.array == NULLP)
397    {
398       return RFAILED;   
399    }
400    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
401    {
402       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
403       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
404       {
405          return RFAILED;
406       }
407    }   
408    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
409                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
410                                                                  freqBand[0].nrFreqBand;
411    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
412
413    return ROK;
414 }
415
416 /*******************************************************************
417  *
418  * @brief Builds Nrcgi 
419  *
420  * @details
421  *
422  *    Function : BuildNrcgi
423  *
424  *    Functionality: Building the PLMN ID and NR Cell id
425  *
426  * @params[in] NRCGI_t *nrcgi
427  * @return ROK     - success
428  *         RFAILED - failure
429  *
430  * ****************************************************************/
431 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
432 {
433    uint8_t ret;
434    uint8_t byteSize = 5;
435    /* Allocate Buffer Memory */
436    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
437    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
438    if(nrcgi->pLMN_Identity.buf == NULLP)
439    {
440       return RFAILED;
441    }
442    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
443          nrcgi->pLMN_Identity.buf); // Building PLMN function
444    if(ret != ROK)
445    {
446       return RFAILED;
447    }
448    /*nrCellIdentity*/
449    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
450    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
451    if(nrcgi->nRCellIdentity.buf == NULLP)
452    {
453       return RFAILED;
454    }
455    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
456
457    return ROK;
458 }
459 /*******************************************************************
460  *
461  * @brief Builds FiveGStac 
462  *
463  * @details
464  *
465  *    Function : BuildFiveGSTac
466  *
467  *    Functionality: Building the FiveGSTac
468  *
469  * @params[in] OCTET_STRING_t *fivegsTac
470  * @return ROK     - success
471  *         RFAILED - failure
472  *
473  * ****************************************************************/
474 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
475 {
476    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
477    if(servcell->fiveGS_TAC == NULLP)
478    {
479       return RFAILED;
480    }
481    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
482    DU_ALLOC(servcell->fiveGS_TAC->buf,\
483          sizeof(servcell->fiveGS_TAC->size));
484    if(servcell->fiveGS_TAC->buf == NULLP)
485    {
486       return RFAILED;
487    }
488    servcell->fiveGS_TAC->buf[0] = 0;
489    servcell->fiveGS_TAC->buf[1] = 0;
490    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
491    return ROK;  
492 }
493
494 /*******************************************************************
495  *
496  * @brief fill nr frequency information
497  *
498  * @details
499  *
500  *    Function : fillNrTddInfo 
501  *
502  *    Functionality: fill nr frequency information
503  *
504  * @params[in] NRFreqInfo_t freqInfo
505  * @return ROK     - success
506  *         RFAILED - failure
507  *
508  * ****************************************************************/
509 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
510 {
511    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
512    NRFreqInfo_t *freqInfo = NULLP;
513
514    if(tddInfo == NULLP)
515    {
516       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
517       return RFAILED;
518    }
519    
520    freqInfo = &tddInfo->nRFreqInfo;
521    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
522
523    freqInfo->freqBandListNr.list.count = elementCnt; 
524    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
525    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
526    if(!freqInfo->freqBandListNr.list.array)
527    {
528       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
529       return RFAILED;
530    }
531
532    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
533    {
534       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
535       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
536       {
537          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
538          return RFAILED;
539       }
540
541       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
542       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
543       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
544       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
545       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
546
547       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
548             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
549       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
550       {
551          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
552          return RFAILED;
553       }
554
555       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
556       {
557          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
558                sizeof(SupportedSULFreqBandItem_t));
559          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
560          {
561             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
562             return RFAILED;
563          }
564
565          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
566          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
567       }
568    }
569
570    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
571    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
572
573    return ROK;
574 }
575
576 /*******************************************************************
577  *
578  * @brief Builds NR Mode 
579  *
580  * @details
581  *
582  *    Function : BuildNrMode
583  *
584  *    Functionality: Building the NR Mode
585  *
586  * @params[in] NR_Mode_Info_t *fdd
587  * @return ROK     - success
588  *         RFAILED - failure
589  *
590  * ****************************************************************/
591 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
592 {
593    uint8_t BuildDLNRInforet=0;
594    uint8_t BuildULNRInforet=0; 
595    
596 #ifdef NR_TDD
597    mode->present = NR_Mode_Info_PR_tDD;
598 #else
599    mode->present = NR_Mode_Info_PR_fDD;
600 #endif   
601    
602    if(mode->present == NR_Mode_Info_PR_fDD)
603    {
604       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
605       if(mode->choice.fDD == NULLP)
606       {
607          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
608          return RFAILED;
609       }
610       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
611       if(BuildULNRInforet != ROK)
612       {
613          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
614          return RFAILED;    
615       }
616       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
617       if(BuildDLNRInforet != ROK)
618       {
619          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
620          return RFAILED;
621       }
622       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
623                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
624                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
625       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
626                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
627                                                           f1Mode.mode.fdd.ulTxBw.nrb;
628       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
629                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
630                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
631       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
632                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
633                                                           f1Mode.mode.fdd.dlTxBw.nrb;
634    }
635    else if(mode->present == NR_Mode_Info_PR_tDD) 
636    {
637       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
638       if(mode->choice.tDD == NULLP)
639       {
640          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
641          return RFAILED;
642       }
643
644       if(fillNrTddInfo(mode->choice.tDD) != ROK)
645       {
646          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
647          return RFAILED;
648       }
649
650    }
651
652    return ROK;
653 }
654 /*******************************************************************
655  *
656  * @brief Builds IE Extensions for Served PLMNs 
657  *
658  * @details
659  *
660  *    Function : BuildExtensions
661  *
662  *    Functionality: Building the IE Extensions
663  *
664  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
665  * @return ROK     - success
666  *         RFAILED - failure
667  *
668  * ****************************************************************/
669 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
670 {
671    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
672    uint8_t elementCnt=0, extensionCnt=0;
673
674    extensionCnt=IE_EXTENSION_LIST_COUNT;
675    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
676    if((*ieExtend) == NULLP)
677    {
678       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
679       return RFAILED;
680    }
681    (*ieExtend)->list.count = extensionCnt;
682    (*ieExtend)->list.size = \
683                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
684    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
685    if((*ieExtend)->list.array == NULLP)
686    {
687       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
688       return RFAILED;
689    }
690    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
691    {
692       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
693             sizeof(ServedPLMNs_ItemExtIEs_t));
694       if((*ieExtend)->list.array[plmnidx] == NULLP)
695       {
696          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
697          return RFAILED;
698       }
699    }
700    
701    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
702    idx = 0;
703    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
704    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
705    (*ieExtend)->list.array[idx]->extensionValue.present = \
706    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
707    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
708       list.count = elementCnt;
709    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
710       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
711       list.count * sizeof(SliceSupportItem_t *);
712
713    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
714          list.array, elementCnt * sizeof(SliceSupportItem_t *));
715    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
716          list.array == NULLP)
717    {
718       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
719       return RFAILED;
720    }
721
722    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
723    {
724       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
725             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
726       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
727             list.array[sliceLstIdx] == NULLP) 
728       {
729          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
730          return RFAILED;
731       }
732       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
733          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
734       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
735             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
736             extensionValue.choice.SliceSupportList.\
737             list.array[sliceLstIdx]->sNSSAI.sST.size);
738       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
739             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
740       {
741          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
742          return RFAILED;
743       }
744       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
745          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
746          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
747       
748       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
749             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
750       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
751             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
752       {
753          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
754          return RFAILED;
755       }
756       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
757          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
758       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
759             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
760             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
761       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
762             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
763       {
764          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
765          return RFAILED;
766       }
767       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
768       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
769       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
770       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
771    }
772    return ROK;
773 }
774 /*******************************************************************
775  *
776  * @brief Builds Served PLMN 
777  *
778  * @details
779  *
780  *    Function : BuildServedPlmn
781  *
782  *    Functionality: Building the Served PLMN
783  *
784  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
785  * @return ROK     - success
786  *         RFAILED - failure
787  *
788  * ****************************************************************/
789 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
790 {  
791    uint8_t  plmnidx;
792    uint8_t  servPlmnCnt=1;
793    uint8_t buildPlmnIdret=0;
794    uint8_t BuildExtensionsret=0;
795    srvplmn->list.count = servPlmnCnt;
796    srvplmn->list.size = \
797                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
798    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
799    if(srvplmn->list.array == NULLP)
800    {
801       return RFAILED;
802    }
803    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
804    {   
805       DU_ALLOC(srvplmn->list.array[plmnidx],\
806             sizeof(ServedPLMNs_Item_t));
807       if(srvplmn->list.array[plmnidx] == NULLP)
808       {
809          return RFAILED;
810       }  
811    }
812    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
813    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
814    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
815          srvplmn->list.array[0]->pLMN_Identity.buf);
816    if(buildPlmnIdret!= ROK)
817    {
818       return RFAILED;
819    }
820    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
821    if(BuildExtensionsret!= ROK)
822    {
823       return RFAILED;
824    }
825    return ROK;
826 }
827 /*******************************************************************
828  *
829  * @brief Builds Served Cell List
830  *
831  * @details
832  *
833  *    Function : BuildServedCellList
834  *
835  *    Functionality: Building Served Cell List
836  *
837  * @params[in] PLMNID plmn
838  * @return ROK     - success
839  *         RFAILED - failure
840  *
841  * ****************************************************************/
842
843 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
844 {
845    uint8_t  BuildNrcgiret=0;
846    uint8_t  BuildFiveGSTacret=0;
847    uint8_t  BuildServedPlmnret=0;
848    uint8_t  BuildNrModeret=0;
849    uint8_t  idx;
850    uint8_t  plmnidx;
851    uint8_t  plmnCnt=1;
852    GNB_DU_Served_Cells_Item_t *srvCellItem;
853    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
854    duServedCell->list.count = plmnCnt;
855
856    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
857    if(duServedCell->list.array == NULLP)
858    {
859       return RFAILED;
860    }
861    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
862    {
863       DU_ALLOC(duServedCell->list.array[plmnidx],\
864             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
865       if(duServedCell->list.array[plmnidx] == NULLP)
866       {
867          return RFAILED;
868       }
869    }
870    idx = 0;
871    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
872    duServedCell->list.array[idx]->criticality = Criticality_reject;
873    duServedCell->list.array[idx]->value.present = \
874                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
875    srvCellItem = \
876                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
877    /*nRCGI*/
878    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
879    if(BuildNrcgiret != ROK)
880    {
881       return RFAILED;
882    }
883    /*nRPCI*/
884    srvCellItem->served_Cell_Information.nRPCI = \
885                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
886
887    /*fiveGS_TAC*/
888    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
889    if(BuildFiveGSTacret != ROK)
890    {
891       return RFAILED;
892    }
893    /*Served PLMNs*/
894    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
895    if(BuildServedPlmnret !=ROK)
896    {
897       return RFAILED;
898    }
899    /*nR Mode Info with FDD*/
900    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
901    if(BuildNrModeret != ROK)
902    {
903       return RFAILED;
904    }
905    /*Measurement timing Config*/
906    srvCellItem->served_Cell_Information.measurementTimingConfiguration.\
907       size = sizeof(uint8_t);
908    DU_ALLOC(srvCellItem->served_Cell_Information.\
909          measurementTimingConfiguration.buf,srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
910    if(srvCellItem->served_Cell_Information.\
911          measurementTimingConfiguration.buf == NULLP)
912    {
913       return RFAILED;
914    }
915    srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf[0] = \
916                                                                                 duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
917
918    /* GNB DU System Information */
919    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
920          sizeof(GNB_DU_System_Information_t));
921    if(!srvCellItem->gNB_DU_System_Information)
922    {
923       return RFAILED;
924    }
925    /* MIB */
926    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
927    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
928          srvCellItem->gNB_DU_System_Information->mIB_message.size);
929    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
930    {
931       return RFAILED;
932    }
933    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
934                    srvCellItem->gNB_DU_System_Information->mIB_message.size);
935
936    /* SIB1 */
937    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
938                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
939
940    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
941          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
942    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
943    {
944       return RFAILED;
945    }
946    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
947    {
948       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
949                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
950    }
951    return ROK; 
952 }                                                                                                                  
953 /*******************************************************************
954  *
955  * @brief Builds RRC Version 
956  *
957  * @details
958  *
959  *    Function : BuildRrcVer
960  *
961  *    Functionality: Building RRC Version
962  *
963  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
964  * @return ROK     - success
965  *         RFAILED - failure
966  *
967  * ****************************************************************/
968 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
969 {
970    uint8_t rrcExt;
971    uint8_t rrcLatest;
972    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
973    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
974    if(rrcVer->latest_RRC_Version.buf == NULLP)
975    {
976       return RFAILED;
977    }
978    rrcVer->latest_RRC_Version.buf[0] = 0;
979    rrcVer->latest_RRC_Version.bits_unused = 5;
980    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
981    if(rrcVer->iE_Extensions == NULLP)
982    {  
983       return RFAILED;
984    }
985    rrcVer->iE_Extensions->list.count = 1;
986    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
987    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
988    if(rrcVer->iE_Extensions->list.array == NULLP)
989    {
990       return RFAILED;
991    }
992    rrcExt = 0;
993    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
994          sizeof(RRC_Version_ExtIEs_t));
995    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
996    {
997       return RFAILED;
998    }
999    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1000                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1001    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1002    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1003                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1004    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1005       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1006    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1007          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1008          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1009    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1010          .Latest_RRC_Version_Enhanced.buf == NULLP)
1011    {
1012       return RFAILED;
1013    }
1014    rrcLatest = 0;
1015    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1016       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1017    rrcLatest++;
1018    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1019       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1020    rrcLatest++;
1021    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1022       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1023    return ROK;
1024 }
1025 /*******************************************************************
1026  *
1027  * @brief Sends F1 msg over SCTP
1028  *
1029  * @details
1030  *
1031  *    Function : sendF1APMsg
1032  *
1033  *    Functionality: Sends F1 msg over SCTP
1034  *
1035  * @params[in] Region region
1036  *             Pool pool
1037  * @return ROK     - success
1038  *         RFAILED - failure
1039  *
1040  * ****************************************************************/
1041 uint8_t sendF1APMsg()
1042 {
1043    Buffer *mBuf = NULLP;
1044   
1045    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1046    {
1047       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1048       {
1049             ODU_PRINT_MSG(mBuf, 0,0);
1050
1051             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1052             {
1053                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1054                ODU_PUT_MSG_BUF(mBuf);
1055                return RFAILED;
1056             }
1057       }
1058       else
1059       {
1060          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1061          ODU_PUT_MSG_BUF(mBuf);
1062          return RFAILED;
1063       }
1064       ODU_PUT_MSG_BUF(mBuf);
1065    }
1066    else
1067    {
1068       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1069       return RFAILED;
1070    }
1071    return ROK; 
1072 } /* sendF1APMsg */
1073
1074 /*******************************************************************
1075  *
1076  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1077  *
1078  * @details
1079  *
1080  *    Function :  FreeRrcVer
1081  *
1082  *    Functionality: deallocating the memory of function BuildRrcVer
1083  *
1084  * @params[in] RRC_Version_t *rrcVer
1085  * 
1086  * @return void
1087  *
1088  *****************************************************************/
1089 void FreeRrcVer(RRC_Version_t *rrcVer)
1090 {
1091    if(rrcVer->latest_RRC_Version.buf != NULLP)
1092    {
1093       if(rrcVer->iE_Extensions != NULLP)
1094       {
1095          if(rrcVer->iE_Extensions->list.array != NULLP)
1096          {
1097             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1098             {
1099                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1100                      != NULLP)
1101                {
1102                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1103                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1104                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1105                }
1106                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1107             }
1108             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1109          }
1110          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1111       }
1112       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1113    }
1114 }
1115
1116 /*******************************************************************
1117  *
1118  * @brief Deallocating memory of TDD NrFreqInfo 
1119  *
1120  * @details
1121  *
1122  *    Function : freeTddNrFreqInfo 
1123  *
1124  *    Functionality: freeTddNrFreqInfo 
1125  *
1126  * @params[in]  F1AP_PDU_t *f1apDuCfg
1127  *
1128  * @return ROK     - void
1129  *
1130  * ****************************************************************/
1131 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1132 {
1133    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1134
1135    if(freqInfo->freqBandListNr.list.array)
1136    {
1137       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1138       {
1139          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1140          {
1141             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1142             {
1143                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1144                {
1145                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1146                         sizeof(SupportedSULFreqBandItem_t));
1147                }
1148                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1149                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1150
1151             }
1152             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1153          }
1154       }
1155       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1156    }
1157 }
1158
1159 /*******************************************************************
1160  *
1161  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1162  *
1163  * @details
1164  *
1165  *    Function : freeFddNrFreqInfo 
1166  *
1167  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1168  *
1169  * @params[in]  
1170  *
1171  * @return ROK     - void
1172  *
1173  * ****************************************************************/
1174 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1175 {
1176    uint8_t arrIdx =0;
1177
1178    if(fDD != NULLP)
1179    {
1180       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1181       {
1182          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1183                array[arrIdx], sizeof(FreqBandNrItem_t));
1184          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1185                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1186       }
1187
1188       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1189       {
1190          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1191                array[arrIdx], sizeof(FreqBandNrItem_t));
1192          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1193                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1194       }
1195       DU_FREE(fDD,sizeof(FDD_Info_t));
1196    }
1197 }
1198
1199 /*******************************************************************
1200  *
1201  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1202  *
1203  * @details
1204  *
1205  *    Function :  FreeServedCellList
1206  *
1207  *    Functionality:  deallocating the memory of function BuildServedCellList
1208
1209  *
1210  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1211  *
1212  * @return void
1213  *
1214  * ****************************************************************/
1215 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1216 {
1217    uint8_t   plmnCnt= 1;
1218    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1219    uint8_t  plmnIdx=0, sliceIdx=0;
1220    GNB_DU_Served_Cells_Item_t *srvCellItem;
1221    ServedPLMNs_Item_t  *servedPlmnItem;
1222    SliceSupportItem_t  *sliceSupportItem;
1223
1224    if(duServedCell->list.array!=NULLP)
1225    {
1226       if(duServedCell->list.array[0]!=NULLP)
1227       {
1228          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1229
1230          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1231                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1232          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1233                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1234
1235          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1236          {
1237             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1238                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1239             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1240          }
1241
1242          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1243          {
1244             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1245             {
1246                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1247                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1248
1249                if(servedPlmnItem->iE_Extensions != NULLP)
1250                {
1251                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1252                   {
1253                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1254                      {
1255                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1256                               SliceSupportList.list.array != NULLP)
1257                         {
1258                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1259                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1260                            {
1261                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1262                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1263                               {
1264                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1265                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1266
1267                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1268
1269                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1270                                  {
1271                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1272                                           sliceSupportItem->sNSSAI.sD->size);
1273                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1274                                  }
1275
1276                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1277                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1278                               }
1279                            }
1280                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1281                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1282                                  extensionValue.choice.SliceSupportList.list.size);
1283                         }
1284                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1285                               sizeof(ServedPLMNs_ItemExtIEs_t));
1286                      }
1287                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1288                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1289                   }
1290                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1291                }
1292                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1293                      sizeof(ServedPLMNs_Item_t));
1294             }
1295             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1296                   sizeof(ServedPLMNs_Item_t *));
1297          }
1298
1299          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1300          {
1301             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1302          }
1303          else   
1304          {
1305             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1306             {
1307                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1308                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1309             }
1310          }
1311          
1312          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1313                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1314
1315          if(srvCellItem->gNB_DU_System_Information != NULLP)
1316          {
1317             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1318             {
1319                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1320                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1321             }
1322
1323             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1324             { 
1325                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1326                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1327             }
1328
1329             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1330          }
1331
1332          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1333       }
1334       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1335    }
1336 }
1337
1338 /*******************************************************************
1339  *
1340  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1341  *
1342  * @details
1343  *
1344  *    Function :  FreeF1SetupReq
1345  *
1346  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1347  *
1348  * @params[in] F1AP_PDU_t *f1apMsg
1349  *
1350  * @return void
1351  *
1352  * ****************************************************************/
1353 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1354 {
1355    uint8_t ieIdx, ieIdx2;
1356    F1SetupRequest_t *f1SetupReq=NULLP;
1357
1358    if(f1apMsg != NULLP)
1359    {
1360       if(f1apMsg->choice.initiatingMessage != NULLP)
1361       {
1362          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1363          if(f1SetupReq->protocolIEs.list.array != NULLP)
1364          {
1365             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1366             {
1367                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1368                {
1369                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1370                   {
1371                      case ProtocolIE_ID_id_TransactionID:
1372                         break;
1373                      case ProtocolIE_ID_id_gNB_DU_ID:
1374                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1375                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1376                         break;
1377                      case ProtocolIE_ID_id_gNB_DU_Name:
1378                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1379                               strlen((char *)duCfgParam.duName));
1380                         break;
1381                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1382                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1383                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1384                         break;
1385                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1386                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1387                         break;
1388                      default:
1389                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1390                         break;
1391                   }
1392                }
1393             }
1394             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1395             {
1396                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1397             }
1398             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1399                   f1SetupReq->protocolIEs.list.size);
1400          }
1401          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1402       }
1403       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1404    }
1405 }
1406 /*******************************************************************
1407  *
1408  * @brief Builds and Send the F1SetupRequest
1409  *
1410  * @details
1411  *
1412  *    Function : BuildAndSendF1SetupReq
1413  *
1414  * Functionality:Fills the F1SetupRequest
1415  *
1416  * @return ROK     - success
1417  *         RFAILED - failure
1418  *
1419  ******************************************************************/
1420 uint8_t BuildAndSendF1SetupReq()
1421 {
1422    uint8_t   ret, ieIdx, elementCnt;
1423    F1AP_PDU_t                 *f1apMsg = NULLP;
1424    F1SetupRequest_t           *f1SetupReq=NULLP;
1425    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1426    RRC_Version_t              *rrcVer=NULLP;
1427    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1428    ret= RFAILED;
1429
1430    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1431    do
1432    {
1433       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1434       if(f1apMsg == NULLP)
1435       {
1436          break;
1437       }
1438       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1439       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1440       if(f1apMsg->choice.initiatingMessage == NULLP)
1441       {
1442          break;
1443       }
1444       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1445       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1446       f1apMsg->choice.initiatingMessage->value.present = \
1447                                                          InitiatingMessage__value_PR_F1SetupRequest;
1448
1449       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1450
1451       elementCnt = 4;
1452
1453       f1SetupReq->protocolIEs.list.count = elementCnt;
1454       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t );
1455
1456       /* Initialize the F1Setup members */
1457       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1458       if(f1SetupReq->protocolIEs.list.array == NULLP)
1459       {
1460          break;
1461       }
1462       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1463       {
1464          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1465                sizeof(F1SetupRequestIEs_t));
1466          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1467          {
1468             break;
1469          }
1470       }
1471
1472       ieIdx = 0;
1473       /*TransactionID*/
1474       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1475       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1476       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1477                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1478       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1479                                                                               TRANS_ID;
1480
1481       /*DU ID*/
1482       ieIdx++;
1483       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1484       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1485       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1486                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1487       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1488                                                                               sizeof(uint8_t);
1489
1490       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1491             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1492       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1493             NULLP)
1494       {
1495          break;
1496       }
1497
1498       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1499                                                                                 duCfgParam.duId;
1500 #if 0
1501       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1502        * However this string is decoded successfully on online decoders.
1503        * Since this is an optional IE and the value received in it are not
1504        * used as of now, eliminating this IE for now to avoid wireshark error.
1505        */
1506       /*DU Name*/
1507       if(duCfgParam.duName != NULL)
1508       {
1509          ieIdx++;
1510          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1511          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1512          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1513          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1514          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1515                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1516          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1517          {
1518             break;
1519          }
1520          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1521                (char*)&duCfgParam.duName);
1522       }
1523 #endif
1524
1525       /*Served Cell list */
1526       ieIdx++;
1527       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1528                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1529       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1530       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1531                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1532       duServedCell = &f1SetupReq->protocolIEs.list.\
1533                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1534       if(BuildServedCellList(duServedCell))
1535       {
1536          break;
1537       }
1538
1539
1540       /*RRC Version*/
1541       ieIdx++;
1542       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1543                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1544       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1545       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1546                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1547       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1548       if(BuildRrcVer(rrcVer))
1549       {
1550          break;
1551       }
1552
1553       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1554
1555       /* Encode the F1SetupRequest type as APER */
1556       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1557       encBufSize = 0;
1558       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1559             encBuf);
1560
1561       /* Encode results */
1562       if(encRetVal.encoded == ENCODE_FAIL)
1563       {
1564          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1565                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1566          break;
1567       }
1568       else
1569       {
1570          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1571 #ifdef DEBUG_ASN_PRINT
1572          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1573          {
1574             printf("%x",encBuf[ieIdx]);
1575          }
1576 #endif
1577
1578          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1579          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1580          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1581          {
1582             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1583             return RFAILED;
1584          }
1585          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1586       }
1587
1588       /* Sending msg */
1589       if(sendF1APMsg() != ROK)
1590       {
1591          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1592          break;
1593       }
1594
1595       ret=ROK;
1596       break;
1597    }while(true);
1598
1599    FreeF1SetupReq(f1apMsg);
1600
1601    return ret;
1602 }/* End of BuildAndSendF1SetupReq */
1603
1604 /*******************************************************************
1605  *
1606  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1607  *
1608  * @details
1609  *
1610  *    Function : freeCellsToModifyItem 
1611  *
1612  *    Functionality: Deallocating memory of variables allocated in
1613  *                    BuildAndSendDUConfigUpdate function
1614  *
1615  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1616  *
1617  * @return ROK     - void
1618  *
1619  * ****************************************************************/
1620
1621 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1622 {
1623    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1624    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1625    SliceSupportItem_t *sliceSupportItem = NULLP;
1626
1627    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1628    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1629
1630    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1631            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1632    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1633          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1634
1635    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1636    {
1637       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1638       {
1639          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1640
1641          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1642
1643          if(servedPlmnItem->iE_Extensions != NULLP)
1644          {
1645             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1646             {
1647                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1648                {
1649                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1650                         list.array != NULLP)
1651                   {
1652                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1653                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1654                      {
1655                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1656                               list.array[sliceLstIdx] != NULLP)
1657                         {
1658
1659                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1660                                               SliceSupportList.list.array[sliceLstIdx];
1661
1662                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1663                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1664                            {
1665                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1666                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1667                            }
1668                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1669                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1670                         }
1671                      }
1672                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1673                            choice.SliceSupportList.list.array,\
1674                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1675                            extensionValue.choice.SliceSupportList.list.size);
1676                   }
1677                }
1678                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1679                {
1680                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1681                }
1682                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1683             }
1684             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1685          }
1686       }
1687       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1688       {
1689          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1690       }
1691       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1692          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1693    }
1694    
1695    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1696    {
1697       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1698    }  
1699    else
1700    {
1701       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1702       {
1703          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1704          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1705       }
1706    }
1707    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1708       modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1709 }
1710
1711 /*******************************************************************
1712  *
1713  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1714  *
1715  * @details
1716  *
1717  *    Function : FreeDUConfigUpdate
1718  *
1719  *    Functionality: Deallocating memory of variables allocated in
1720  *                    BuildAndSendDUConfigUpdate function
1721  *
1722  * @params[in]  F1AP_PDU_t *f1apDuCfg
1723  *
1724  * @return ROK     - void
1725  *
1726  * ****************************************************************/
1727 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1728 {
1729    uint8_t  ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1730    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1731    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1732    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1733    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1734    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1735
1736    if(f1apDuCfg != NULLP)
1737    {
1738       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1739       {
1740          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1741                        value.choice.GNBDUConfigurationUpdate;
1742          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1743          {
1744             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1745             {
1746                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1747                {
1748                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1749                   {
1750                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1751                         {
1752                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1753                                            value.choice.Served_Cells_To_Modify_List;
1754                            if(cellsToModify->list.array != NULLP)
1755                            {
1756                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1757                               {
1758                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1759                                  {
1760                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1761                                           Served_Cells_To_Modify_Item);
1762                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1763                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1764                                  }
1765                               }
1766                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1767                            }
1768                            break;
1769                         }
1770                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1771                         {
1772                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1773                                            value.choice.Served_Cells_To_Delete_List;
1774                            if(cellsToDelete->list.array != NULLP)
1775                            {
1776                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1777                               {
1778                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1779                                  {
1780                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1781                                           cellsToDelete->list.array[cellDeleteIdx]);
1782                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1783                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1784                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1785                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1786                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1787                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1788                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1789                                  }
1790                               }
1791                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1792                            }
1793
1794                            break;
1795                         }
1796                      case ProtocolIE_ID_id_gNB_DU_ID:
1797                         {
1798                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1799                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1800                            break;
1801                         }
1802                   }
1803                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1804                         sizeof(GNBDUConfigurationUpdateIEs_t));
1805                }
1806             }
1807             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
1808          }
1809          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
1810       }
1811       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
1812    }
1813 }
1814
1815 /*******************************************************************
1816  *
1817  * @brief Fills Served Plmns required in ServCellInfo IE
1818  *
1819  * @details
1820  *
1821  *    Function : fillServedPlmns
1822  *
1823  *    Functionality: Fills Served Plmns required in ServCellInfo IE
1824  *
1825  * @params[in] Pointer to ServedPLMNs_List_t *
1826  *
1827  * @return ROK     - success
1828  *         RFAILED - failure
1829  *
1830  *****************************************************************/
1831
1832 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
1833 {
1834    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
1835
1836    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
1837    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
1838          array[arrayIdx]->pLMN_Identity.size);
1839    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
1840    {
1841       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1842       return RFAILED;
1843    }
1844    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
1845          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
1846    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1847    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
1848    {
1849       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1850       return RFAILED;
1851    }
1852
1853    ieListCnt=1;
1854    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
1855    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
1856    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
1857          iE_Extensions->list.size);
1858    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
1859    {
1860       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1861       return RFAILED;
1862    }
1863    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
1864    {
1865       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
1866             sizeof(ServedPLMNs_ItemExtIEs_t));
1867       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
1868       {
1869          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1870          return RFAILED;
1871       }
1872    }
1873    
1874    ieIdx = 0;
1875    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
1876    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
1877    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
1878    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
1879    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
1880    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1881       list.count = elementCnt;
1882    servedPlmn->list.array[arrayIdx]->\
1883       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1884       list.size = elementCnt * sizeof(SliceSupportItem_t *);
1885    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1886          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1887          list.array,servedPlmn->list.array[arrayIdx]->\
1888          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
1889    if(servedPlmn->list.array[arrayIdx]->\
1890          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1891          list.array == NULLP)
1892    {
1893       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1894       return RFAILED;
1895    }
1896
1897    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
1898    {
1899       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1900       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1901       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
1902       if(servedPlmn->list.array[arrayIdx]->\
1903       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1904       list.array[sliceLstIdx] == NULLP)
1905       {   
1906          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1907          return RFAILED;
1908       }
1909       
1910       servedPlmn->list.array[arrayIdx]->\
1911       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1912       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
1913       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1914       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1915       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
1916       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
1917       sNSSAI.sST.size);
1918       
1919       if(servedPlmn->list.array[arrayIdx]->\
1920       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1921       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
1922       {
1923          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1924          return RFAILED;
1925       }
1926       servedPlmn->list.array[arrayIdx]->\
1927       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1928       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1929       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
1930
1931       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1932       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1933       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
1934       if(servedPlmn->list.array[arrayIdx]->\
1935       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1936       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
1937       {
1938          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1939          return RFAILED;
1940       }
1941       servedPlmn->list.array[arrayIdx]->\
1942       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1943       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
1944       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1945       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1946       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
1947       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1948       list.array[sliceLstIdx]->sNSSAI.sD->size);
1949       if(servedPlmn->list.array[arrayIdx]->\
1950       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1951       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
1952       {
1953          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1954          return RFAILED;
1955       }
1956       memcpy(servedPlmn->list.array[arrayIdx]->\
1957       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1958       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1959       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
1960       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1961       list.array[sliceLstIdx]->sNSSAI.sD->size);
1962    }
1963    return ROK;
1964 }
1965
1966 /*******************************************************************
1967  *
1968  * @brief Fills Nr Fdd Info required in ServCellInfo IE
1969  *
1970  * @details
1971  *
1972  *    Function : fillNrFddInfo
1973  *
1974  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
1975  *
1976  * @params[in] FDD_Info_t *fDD
1977  *
1978  * @return ROK     - success
1979  *         RFAILED - failure
1980  *
1981  *****************************************************************/
1982
1983 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
1984 {
1985    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
1986       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
1987    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
1988    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
1989    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1990          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1991    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1992    {
1993       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1994       return RFAILED;
1995    }
1996
1997    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
1998       sizeof(FreqBandNrItem_t));
1999    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2000    {
2001       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2002       return RFAILED;
2003    }
2004    
2005    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2006       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2007       freqBand[0].nrFreqBand;
2008    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2009    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2010       dlNrFreqInfo.nrArfcn;
2011    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2012    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2013    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2014    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2015    {
2016       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2017       return RFAILED;
2018    }
2019    
2020    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2021    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2022    {
2023       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2024       return RFAILED;
2025    }
2026
2027    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2028       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2029       freqBand[0].nrFreqBand;
2030    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2031    
2032    /*Transmission Bandwidth*/
2033    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2034       f1Mode.mode.fdd.ulTxBw.nrScs;
2035    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2036       f1Mode.mode.fdd.ulTxBw.nrb;
2037    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2038       f1Mode.mode.fdd.dlTxBw.nrScs;
2039    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2040       f1Mode.mode.fdd.dlTxBw.nrb;
2041
2042    return ROK;
2043 }
2044
2045 /*******************************************************************
2046  *
2047  * @brief Fills ServCellInfo IE
2048  *
2049  * @details
2050  *
2051  *    Function : fillServedCellInfo
2052  *
2053  *    Functionality: Fills ServCellInfo
2054  *
2055  * @params[in] Pointer to Served_Cell_Information_t *
2056  *
2057  * @return ROK     - success
2058  *         RFAILED - failure
2059  *
2060  *****************************************************************/
2061
2062 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2063 {
2064    uint8_t ieIdx, ieListCnt;
2065
2066    /*nRCGI*/
2067    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2068    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2069          srvCellInfo->nRCGI.pLMN_Identity.size);
2070    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2071    {
2072       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2073       return RFAILED;
2074    }
2075    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2076          srvCellInfo->nRCGI.pLMN_Identity.buf);
2077    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2078    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2079          srvCellInfo->nRCGI.nRCellIdentity.size);
2080    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2081    {   
2082       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2083       return RFAILED;
2084    }
2085    
2086    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2087    /*nRPCI*/
2088    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2089
2090    /*servedPLMNs*/
2091    ieListCnt = 1;
2092    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2093    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2094    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2095    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2096    {
2097       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2098       return RFAILED;
2099    }
2100    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2101    {
2102       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2103       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2104       {
2105          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2106          return RFAILED;
2107       }
2108    }
2109    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2110    {
2111       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2112       return RFAILED;
2113    }
2114
2115 #ifndef NR_TDD
2116    /*nR Mode Info with FDD*/
2117    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2118    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2119    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2120    {
2121       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2122       return RFAILED;
2123    }
2124    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2125    {
2126        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2127       return RFAILED;
2128    }
2129 #else
2130    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2131    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2132    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2133    {
2134       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2135       return RFAILED;
2136    }
2137    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2138    {
2139       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2140       return RFAILED;
2141    }
2142 #endif
2143
2144    /*Measurement timing Config*/
2145    srvCellInfo->measurementTimingConfiguration.size = sizeof(uint8_t);
2146    DU_ALLOC(srvCellInfo->measurementTimingConfiguration.\
2147          buf,srvCellInfo->measurementTimingConfiguration.size);
2148    if(srvCellInfo->measurementTimingConfiguration.buf == NULLP)
2149    {
2150       return RFAILED;
2151    }
2152    srvCellInfo->measurementTimingConfiguration.\
2153          buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
2154
2155    return ROK;
2156 }
2157
2158 /*******************************************************************
2159  *
2160  * @brief Fills ServCellToModItem IE
2161  *
2162  * @details
2163  *
2164  *    Function : fillServCellToModItem
2165  *
2166  *    Functionality: Fills ServCellToModItem IE
2167  *
2168  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2169  *
2170  * @return ROK     - success
2171  *         RFAILED - failure
2172  *
2173  *****************************************************************/
2174
2175 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2176 {
2177    /*pLMN_Identity*/
2178    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2179    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2180    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2181    {
2182       return RFAILED;
2183    }
2184    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2185          modifyItem->oldNRCGI.pLMN_Identity.buf);
2186
2187    /*nRCellIdentity*/
2188    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2189    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2190          modifyItem->oldNRCGI.nRCellIdentity.size);
2191    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2192    {
2193       return RFAILED;
2194    }
2195    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2196
2197    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2198       return RFAILED;
2199    else
2200       return ROK;
2201 }
2202
2203 /*******************************************************************
2204  *
2205  * @brief Builds ServCellToModList
2206  *
2207  * @details
2208  *
2209  *    Function : buildServCellToModList
2210  *
2211  *    Functionality: Builds the serv cell to Mod List
2212  *
2213  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2214  *
2215  * @return ROK     - success
2216  *         RFAILED - failure
2217  *
2218  *****************************************************************/
2219
2220 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2221 {
2222    uint8_t ieListCnt, ieIdx;
2223    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2224
2225    ieListCnt = 1;
2226    cellsToModify->list.count = ieListCnt;
2227    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2228    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2229    if(cellsToModify->list.array == NULLP)
2230    {
2231       return RFAILED;
2232    }
2233    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2234    {
2235       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2236       if(cellsToModify->list.array[ieIdx] == NULLP)
2237       {
2238          return RFAILED;
2239       }
2240    }
2241    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2242    cellsToModify->list.array[0]->criticality = Criticality_reject;
2243    cellsToModify->list.array[0]->value.present =\
2244       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2245    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2246
2247    if(fillServCellToModItem(modifyItem))
2248       return RFAILED;
2249    else
2250       return ROK;
2251 }
2252 /*******************************************************************
2253  *
2254  * @brief filling the DeleteItemList
2255  *
2256  * @details
2257  *
2258  *    Function : fillCellToDeleteItem 
2259  *
2260  *    Functionality: Filling the DeleteItemIe 
2261  *
2262  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2263  *
2264  * @return ROK     - success
2265  *         RFAILED - failure
2266  *
2267  *****************************************************************/
2268 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2269 {
2270    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2271    
2272    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2273    deleteItemIe->criticality = Criticality_reject;
2274    deleteItemIe->value.present =\
2275    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2276    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2277
2278    /*pLMN_Identity*/
2279    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2280    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2281    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2282    {
2283       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2284       return RFAILED;
2285    }
2286    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2287          deleteItem->oldNRCGI.pLMN_Identity.buf);
2288
2289    /*nRCellIdentity*/
2290    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2291    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2292          deleteItem->oldNRCGI.nRCellIdentity.size);
2293    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2294    {
2295       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2296       return RFAILED;
2297    }
2298    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2299    return ROK;
2300
2301 /*******************************************************************
2302  *
2303  * @brief Builds ServCellToDeleteList
2304  *
2305  * @details
2306  *
2307  *    Function : buildServCellToDeleteList
2308  *
2309  *    Functionality: Builds the serv cell to delete List
2310  *
2311  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2312  *
2313  * @return ROK     - success
2314  *         RFAILED - failure
2315  *
2316  *****************************************************************/
2317  
2318 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2319 {
2320    uint8_t ieListCnt, arrIdx;
2321    
2322    ieListCnt = 1;
2323    cellsToDelete->list.count = ieListCnt;
2324    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2325    
2326    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2327    if(cellsToDelete->list.array == NULLP)
2328    {
2329       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2330       return RFAILED;
2331    }
2332    
2333    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2334    {
2335       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2336       if(cellsToDelete->list.array[arrIdx] == NULLP)
2337       {
2338          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2339          return RFAILED;
2340       }
2341    }
2342    
2343    arrIdx=0;
2344    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2345    {
2346       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2347       return RFAILED;
2348    }
2349    return ROK;
2350 }
2351
2352 /*******************************************************************
2353  *
2354  * @brief Builds and sends the DUConfigUpdate
2355  *
2356  * @details
2357  *
2358  *    Function : BuildAndSendDUConfigUpdate
2359  *
2360  *    Functionality: Constructs the DU Update message and sends
2361  *                   it to the CU through SCTP.
2362  *
2363  * @params[in] void **buf,Buffer to which encoded pattern is written into
2364  * @params[in] int *size,size of buffer
2365  *
2366  * @return ROK     - success
2367  *         RFAILED - failure
2368  *
2369  * ****************************************************************/
2370 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2371 {
2372    uint8_t ret =0, ieIdx=0, elementCnt=0;
2373    bool memAlloctionFailure = false;
2374    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2375    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2376    asn_enc_rval_t encRetVal;     /* Encoder return value */
2377    
2378    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2379    ret= RFAILED;
2380
2381    while(true)
2382    {
2383       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2384       /* Allocate the memory for F1DuCfg */
2385       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2386       if(f1apDuCfg == NULLP)
2387       {
2388          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2389          break;
2390       }
2391
2392       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2393       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2394       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2395       {
2396          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2397          break;
2398       }
2399
2400       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2401                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2402       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2403       f1apDuCfg->choice.initiatingMessage->value.present = \
2404                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2405       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2406                     choice.GNBDUConfigurationUpdate;
2407       elementCnt = 3;
2408       duCfgUpdate->protocolIEs.list.count = elementCnt;
2409       duCfgUpdate->protocolIEs.list.size = \
2410                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2411
2412       /* Initialize the F1Setup members */
2413       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2414       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2415       {
2416          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2417          break;
2418       }
2419       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2420       {
2421          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2422          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2423          {
2424             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2425             memAlloctionFailure = true;
2426             break;
2427          }
2428       }
2429       
2430       if(memAlloctionFailure == true)
2431       {
2432          break;
2433       }
2434       /*TransactionID*/
2435       ieIdx = 0;
2436       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2437       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2438       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2439       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2440       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2441       
2442       ieIdx++;
2443       if(servCellAction == SERV_CELL_TO_MODIFY)
2444       {
2445          /*Served Cell to Modify */
2446          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2447          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2448          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2449          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2450          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2451          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2452                   Served_Cells_To_Modify_List))
2453          {
2454             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2455             break;
2456          }
2457       }
2458       else
2459       {
2460          /*Served Cell to Delete */ 
2461          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2462          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2463          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2464          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2465          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2466          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2467          Served_Cells_To_Delete_List)!=ROK)
2468          {
2469             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2470             break;
2471          }
2472          
2473       }
2474       // NOTE :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2475       /*GNB DU ID */
2476       ieIdx++;
2477       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2478       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2479       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2480       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2481       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2482       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2483             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2484       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2485       {
2486          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2487          break;
2488       }
2489       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2490
2491       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2492
2493       /* Encode the DU Config Update type as APER */
2494       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2495       encBufSize = 0;
2496       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2497
2498       /* Checking encode results */
2499       if(encRetVal.encoded == ENCODE_FAIL)
2500       {
2501          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2502                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2503          break;
2504       }
2505       else
2506       {
2507          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2508 #ifdef DEBUG_ASN_PRINT
2509          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2510          {
2511             printf("%x",encBuf[ieIdx]);
2512          }
2513 #endif
2514       }
2515       /* Sending msg */
2516       if(sendF1APMsg() != ROK)
2517       {
2518          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2519          break;
2520       }
2521
2522       ret = ROK;
2523       break;
2524    }
2525   
2526    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2527    return ret;
2528 }
2529
2530
2531 /*******************************************************************
2532  *
2533  * @brief free the ULRRCMessageTransfer
2534  *
2535  * @details
2536  *
2537  *    Function : FreeULRRCMessageTransfer
2538  *
2539  *    Functionality: Deallocating the memory of variable allocated in
2540  *                      FreeULRRCMessageTransfer
2541  *
2542  * @params[in]
2543  *
2544  * @return ROK     - void
2545  *
2546  ******************************************************************/
2547 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2548 {
2549    uint8_t idx1;
2550    ULRRCMessageTransfer_t  *ulRRCMsg;
2551
2552    if(f1apMsg != NULLP)
2553    { 
2554       if(f1apMsg->choice.initiatingMessage != NULLP)
2555       {
2556          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2557          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2558          {
2559             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2560             {
2561                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2562                {
2563                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2564                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2565                   {
2566                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2567                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2568                   }
2569                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2570                }
2571             }
2572             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2573          }
2574          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2575       }
2576       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2577    }
2578 }
2579 /*******************************************************************
2580  *
2581  * @brief Builds and sends the ULRRCMessageTransfer 
2582  *
2583  * @details
2584  *
2585  *    Function : BuildAndSendULRRCMessageTransfer
2586  *
2587  *    Functionality: Constructs the UL RRC Message Transfer and sends
2588  *                   it to the CU through SCTP.
2589  *
2590  * @params[in] 
2591  *
2592  * @return ROK     - success
2593  *         RFAILED - failure
2594  *
2595  * ****************************************************************/
2596 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2597       uint16_t msgLen, uint8_t *rrcMsg)
2598 {
2599    uint8_t                 elementCnt=0, idx1=0, idx=0;
2600    uint8_t                 ret = RFAILED;
2601    F1AP_PDU_t              *f1apMsg = NULLP;
2602    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2603    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2604    
2605    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2606
2607    while(true)
2608    {
2609       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2610
2611       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2612       if(f1apMsg == NULLP)
2613       {
2614          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2615          break;
2616       }
2617       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2618       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2619       if(f1apMsg->choice.initiatingMessage == NULLP)
2620       {
2621          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2622          break;
2623       }
2624       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2625       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2626       f1apMsg->choice.initiatingMessage->value.present = \
2627                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2628       ulRRCMsg =
2629          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2630       elementCnt = 4;
2631       ulRRCMsg->protocolIEs.list.count = elementCnt;
2632       ulRRCMsg->protocolIEs.list.size = \
2633                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2634
2635       /* Initialize the F1Setup members */
2636       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2637       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2638       {
2639          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2640          break;
2641       }
2642       for(idx=0; idx<elementCnt; idx++)
2643       {
2644          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2645          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2646          {
2647             break;
2648          }
2649       }
2650
2651       idx1 = 0;
2652
2653       /*GNB CU UE F1AP ID*/
2654       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2655       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2656       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2657                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2658       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2659
2660       /*GNB DU UE F1AP ID*/
2661       idx1++;
2662       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2663       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2664       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2665                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2666       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2667
2668       /*SRBID*/
2669       idx1++;
2670       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2671       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2672       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2673                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2674       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2675
2676       /*RRCContainer*/
2677       idx1++;
2678       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2679       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2680       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2681                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2682       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2683       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2684             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2685       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2686       {
2687          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2688          break;
2689       }
2690       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2691       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2692             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2693
2694       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2695
2696       /* Encode the F1SetupRequest type as APER */
2697       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2698       encBufSize = 0;
2699       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2700             encBuf);
2701       /* Encode results */
2702       if(encRetVal.encoded == ENCODE_FAIL)
2703       {
2704          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2705                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2706          break;
2707       }
2708       else
2709       {
2710          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2711 #ifdef DEBUG_ASN_PRINT
2712          for(int i=0; i< encBufSize; i++)
2713          {
2714             printf("%x",encBuf[i]);
2715          }
2716 #endif
2717       }
2718
2719       /* Sending  msg  */
2720       if(sendF1APMsg()  !=      ROK)
2721       {
2722          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2723          break;
2724       }
2725       ret = ROK;
2726       break;
2727    }
2728    FreeULRRCMessageTransfer(f1apMsg);
2729
2730    return ret;
2731 }/* End of BuildAndSendULRRCMessageTransfer*/
2732
2733 /*******************************************************************
2734  *
2735  * @brief Builds tag config 
2736  *
2737  * @details
2738  *
2739  *    Function : BuildTagConfig 
2740  *
2741  *    Functionality: Builds tag config in MacCellGroupConfig
2742  *
2743  * @params[in] TAG_Config *tag_Config
2744  *
2745  * @return ROK     - success
2746  *         RFAILED - failure
2747  *
2748  * ****************************************************************/
2749 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2750 {
2751    struct TAG_Config__tag_ToAddModList *tagList;
2752    uint8_t                     idx, elementCnt;
2753
2754    tagConfig->tag_ToReleaseList = NULLP;
2755    tagConfig->tag_ToAddModList = NULLP;
2756    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2757    if(!tagConfig->tag_ToAddModList)
2758    {
2759       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2760       return RFAILED;
2761    }
2762
2763    if(ueCb == NULLP)
2764       elementCnt = ODU_VALUE_ONE;
2765    else
2766       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2767
2768    tagList = tagConfig->tag_ToAddModList;
2769    tagList->list.count = elementCnt;
2770    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2771
2772    tagList->list.array = NULLP;
2773    DU_ALLOC(tagList->list.array, tagList->list.size);
2774    if(!tagList->list.array)
2775    {
2776       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2777       return RFAILED;
2778    }
2779
2780    for(idx=0; idx<tagList->list.count; idx++)
2781    {
2782       tagList->list.array[idx] = NULLP;
2783       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2784       if(!tagList->list.array[idx])
2785       {
2786          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2787          return RFAILED;
2788       }
2789    }
2790
2791    if(ueCb == NULLP)
2792    {
2793       idx = 0;
2794       tagList->list.array[idx]->tag_Id = TAG_ID;
2795       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2796    }
2797    else
2798    {
2799       for(idx=0; idx<tagList->list.count; idx++)
2800       {
2801          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2802          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2803       }
2804    }
2805
2806    return ROK;
2807 }
2808
2809 /*******************************************************************
2810  *
2811  * @brief Builds PHR Config 
2812  *
2813  * @details
2814  *
2815  *    Function : BuildPhrConfig
2816  *
2817  *    Functionality: Builds phrConfig in MacCellGroupConfig
2818  *
2819  * @params[in] PHR Config *
2820  *
2821  * @return ROK     - success
2822  *         RFAILED - failure
2823  *
2824  * ****************************************************************/
2825 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2826 {
2827
2828    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2829    phrConfig->choice.setup = NULLP;
2830    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
2831    if(!phrConfig->choice.setup)
2832    {
2833       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
2834       return RFAILED;
2835    }
2836
2837    if(ueCb == NULLP)
2838    {
2839       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
2840       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
2841       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
2842       phrConfig->choice.setup->multiplePHR              = false;
2843       phrConfig->choice.setup->dummy                    = false;
2844       phrConfig->choice.setup->phr_Type2OtherCell       = false;
2845       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
2846    }
2847    else
2848    {
2849       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
2850       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
2851       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
2852       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
2853       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
2854       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
2855       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
2856    }
2857
2858    return ROK;
2859 }
2860
2861 /*******************************************************************
2862  *
2863  * @brief Builds BSR Config 
2864  *
2865  * @details
2866  *
2867  *    Function : BuildBsrConfig
2868  *
2869  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
2870  *
2871  * @params[in] BSR_Config *bsrConfig
2872  *
2873  * @return ROK     - success
2874  *         RFAILED - failure
2875  *
2876  * ****************************************************************/
2877 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
2878 {
2879    if(ueCb == NULLP)
2880    {
2881       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
2882       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
2883       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2884    }
2885    else
2886    {
2887       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
2888       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
2889
2890       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2891       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
2892       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
2893       {
2894          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
2895          return RFAILED;
2896       }
2897       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
2898    }
2899
2900    return ROK;
2901 }
2902
2903 /*******************************************************************
2904  *
2905  * @brief Builds scheduling request config 
2906  *
2907  * @details
2908  *
2909  *    Function : BuildSchedulingReqConfig 
2910  *
2911  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
2912  *
2913  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
2914  *
2915  * @return ROK     - success
2916  *         RFAILED - failure
2917  *
2918  * ****************************************************************/
2919 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
2920 {
2921    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
2922    uint8_t                     idx, elementCnt;
2923
2924    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
2925    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
2926          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
2927    if(!schedulingRequestConfig->schedulingRequestToAddModList)
2928    {
2929       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2930       return RFAILED;
2931    }
2932
2933    if(ueCb == NULLP)
2934       elementCnt = ODU_VALUE_ONE;
2935    else
2936       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
2937
2938    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
2939    schReqList->list.count = elementCnt;
2940    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
2941
2942    schReqList->list.array = NULLP;
2943    DU_ALLOC(schReqList->list.array, schReqList->list.size);
2944    if(!schReqList->list.array)
2945    {
2946       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2947       return RFAILED;
2948    }
2949
2950    for(idx=0; idx<schReqList->list.count; idx++)
2951    {
2952       schReqList->list.array[idx] = NULLP;
2953       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
2954       if(!schReqList->list.array[idx])
2955       {
2956          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2957          return RFAILED;
2958       }
2959    }
2960
2961    if(ueCb == NULLP)
2962    {
2963       idx = 0;
2964       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
2965
2966       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2967       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2968       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2969       {
2970          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2971          return RFAILED;
2972       }
2973       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
2974       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
2975    }
2976    else
2977    {
2978       for(idx=0; idx<schReqList->list.count; idx++)
2979       {
2980          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
2981
2982          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2983          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2984          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2985          {
2986             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2987             return RFAILED;
2988          }
2989          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
2990          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
2991       }
2992    }
2993
2994    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
2995
2996    return ROK;
2997 }
2998
2999 /*******************************************************************
3000  *
3001  * @brief Builds RLC Configuration for AM mode
3002  *
3003  * @details
3004  *
3005  *    Function : BuildRlcConfigAm
3006  *
3007  *    Functionality: 
3008  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3009  *
3010  * @params[in] AmBearerCfg *amCfg
3011  *             RLC_Config_t  *rlcConfig
3012  *
3013  * @return ROK     - success
3014  *         RFAILED - failure
3015  *
3016  * ****************************************************************/
3017 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3018 {
3019    rlcConfig->choice.am = NULLP;
3020    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3021    if(!rlcConfig->choice.am)
3022    {
3023       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3024       return RFAILED;
3025    }
3026
3027    /* Fill AM UL configuration */
3028    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3029    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3030    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3031    {
3032       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3033       return RFAILED;
3034    }
3035
3036    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3037    if(amCfg == NULLP)
3038    {
3039       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3040       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3041       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3042       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3043       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3044    }
3045    else
3046    {
3047       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3048       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3049       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3050       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3051       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3052    }
3053
3054    /* Fill AM DL configuraion */
3055    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3056    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3057    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3058    {
3059       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3060       return RFAILED;
3061    }
3062
3063    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3064    if(amCfg == NULLP)
3065    {
3066       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3067       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3068       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3069    }
3070    else /* Fill AM configuration from DU database */
3071    {
3072       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3073       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3074       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3075    }
3076    return ROK;
3077 }
3078
3079 /*******************************************************************
3080  *
3081  * @brief Builds RLC Config for UM Bidirection
3082  *
3083  * @details
3084  *
3085  *    Function : BuildRlcConfig UmBiDir
3086  *
3087  *    Functionality: 
3088  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3089  *
3090  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3091  *             RLC_Config_t *rlcConfig
3092  *
3093  * @return ROK     - success
3094  *         RFAILED - failure
3095  *
3096  * ****************************************************************/
3097 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3098 {
3099    rlcConfig->choice.um_Bi_Directional = NULLP;
3100    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3101    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3102    {
3103       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3104       return RFAILED;
3105    }
3106
3107    /* Fill UM Bidirectional UL configuration */
3108    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3109    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3110    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3111    {
3112       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3113       return RFAILED;
3114    }
3115
3116    if(umBiDirCfg != NULLP)
3117    {
3118       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3119    }
3120
3121    /* Fill UM Bidirectional DL configuration */
3122    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3123    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3124    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3125    {
3126       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3127       return RFAILED;
3128    }
3129
3130    if(umBiDirCfg != NULLP)
3131    {
3132       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3133       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3134    }
3135
3136    return ROK;
3137 }
3138
3139 /*******************************************************************
3140  *
3141  * @brief Builds RLC Config for UM Uni directional UL
3142  *
3143  * @details
3144  *
3145  *    Function : BuildRlcConfigUmUniDirUl
3146  *
3147  *    Functionality: 
3148  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3149  *
3150  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3151  *             RLC_Config_t *rlcConfig
3152  *
3153  * @return ROK     - success
3154  *         RFAILED - failure
3155  *
3156  * ****************************************************************/
3157 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3158 {
3159    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3160    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3161    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3162    {
3163       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3164       return RFAILED;
3165    }
3166
3167    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3168    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3169    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3170    {
3171       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3172       return RFAILED;
3173    }
3174
3175    if(umUniDirDlCfg != NULLP)
3176    {
3177       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3178    }
3179
3180    return ROK;
3181 }
3182
3183 /*******************************************************************
3184  *
3185  * @brief Builds RLC Config for UM Uni directional DL
3186  *
3187  * @details
3188  *
3189  *    Function : BuildRlcConfigUmUniDirDl
3190  *
3191  *    Functionality: 
3192  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3193  *
3194  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3195  *             RLC_Config_t *rlcConfig
3196  *
3197  * @return ROK     - success
3198  *         RFAILED - failure
3199  *
3200  * ****************************************************************/
3201 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3202 {
3203    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3204    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3205    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3206    {
3207       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3208       return RFAILED;
3209    }
3210
3211    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3212    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3213    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3214    {
3215       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3216       return RFAILED;
3217    }
3218
3219    if(umUniDirUlCfg != NULLP)
3220    {
3221       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3222       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3223    }
3224
3225    return ROK;
3226 }
3227
3228 /*******************************************************************
3229  *
3230  * @brief Builds RLC Config
3231  *
3232  * @details
3233  *
3234  *    Function : BuildRlcConfig
3235  *
3236  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3237  *
3238  * @params[in] RLC_Config_t *rlcConfig
3239  *
3240  * @return ROK     - success
3241  *         RFAILED - failure
3242  *
3243  * ****************************************************************/
3244 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3245 {
3246    
3247    /* Fill default values if rbCfg is NULL */
3248    if(rbCfg == NULLP)
3249    {
3250       rlcConfig->present = RLC_Config_PR_am;
3251       BuildRlcConfigAm(NULLP, rlcConfig);
3252    }
3253    /* If RbCfg is present, fill RLC configurations from DU Database */
3254    else
3255    {
3256       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3257       switch(rlcConfig->present)
3258       {
3259          case RLC_Config_PR_am:
3260             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3261             break;
3262          case RLC_Config_PR_um_Bi_Directional:
3263             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3264             break;
3265          case RLC_Config_PR_um_Uni_Directional_UL:
3266             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3267             break;
3268          case RLC_Config_PR_um_Uni_Directional_DL:
3269             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3270             break;
3271          case RLC_Config_PR_NOTHING:
3272          default:
3273             break;
3274       }
3275    }
3276
3277    return ROK;
3278 }
3279
3280 /*******************************************************************
3281  *
3282  * @brief Builds MAC LC Config
3283  *
3284  * @details
3285  *
3286  *    Function : BuildMacLCConfig 
3287  *
3288  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3289  *
3290  * @params[in] struct LogicalChannelConfig macLcConfig
3291  *
3292  * @return ROK     - success
3293  *         RFAILED - failure
3294  *
3295  * ****************************************************************/
3296 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3297 {
3298    macLcConfig->ul_SpecificParameters = NULLP;
3299    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3300    if(!macLcConfig->ul_SpecificParameters)
3301    {
3302       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3303       return RFAILED;
3304    }
3305
3306    if(lcCfgDb == NULLP)
3307    {
3308       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3309       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3310       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3311    }
3312    else
3313    {
3314       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3315       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3316       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3317    }
3318
3319    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3320    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3321    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3322    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3323
3324    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3325    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3326    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3327    {
3328       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3329       return RFAILED;
3330    }
3331
3332    if(lcCfgDb == NULLP)
3333       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3334    else
3335       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3336
3337    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3338    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3339    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3340    {
3341       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3342       return RFAILED;
3343    }
3344
3345    if(lcCfgDb == NULLP)
3346       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3347    else
3348       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3349
3350    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3351    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3352    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3353
3354    return ROK;
3355 }
3356
3357 /*******************************************************************
3358  *
3359  * @brief Builds RLC Bearer to Add/Mod list
3360  *
3361  * @details
3362  *
3363  *    Function :BuildRlcBearerToAddModList 
3364  *
3365  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3366  *
3367  * @params[in] rlc_BearerToAddModList
3368  *
3369  * @return ROK     - success
3370  *         RFAILED - failure
3371  *
3372  * ****************************************************************/
3373 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3374 {
3375    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3376
3377    if(ueCb == NULLP)
3378       elementCnt = 1;
3379    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3380       elementCnt = ueCb->duRlcUeCfg.numLcs;
3381    else
3382    {
3383       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3384       {
3385          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3386             elementCnt++;
3387       }
3388    }
3389    rlcBearerList->list.count = elementCnt;
3390    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3391
3392    rlcBearerList->list.array = NULLP;
3393    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3394    if(!rlcBearerList->list.array)
3395    {
3396       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3397       return RFAILED;
3398    }
3399
3400    for(idx=0; idx<rlcBearerList->list.count; idx++)
3401    {
3402       rlcBearerList->list.array[idx] = NULLP;
3403       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3404       if(!rlcBearerList->list.array[idx])
3405       {
3406          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3407          return RFAILED;
3408       }
3409    }
3410
3411    if(ueCb == NULLP)
3412    {
3413       idx=0;
3414       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3415       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3416       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3417       {     
3418          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3419          return RFAILED;
3420       }     
3421       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3422       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3423       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3424
3425       /* Fill RLC related Configurations for this Radio Bearer */
3426       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3427       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3428       if(!rlcBearerList->list.array[idx]->rlc_Config)
3429       {
3430          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3431          return RFAILED;
3432       }
3433       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3434       {
3435          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3436          return RFAILED;
3437       }
3438
3439       /* Fill MAC related configurations for this Radio Bearer */
3440       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3441       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3442       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3443       {
3444          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3445          return RFAILED;
3446       }
3447       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3448       {
3449          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3450          return RFAILED;
3451       }
3452    }
3453    else
3454    {
3455       idx=0;
3456       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3457       {
3458          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3459             continue;
3460
3461          /* Fill Logical channel identity */
3462          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3463
3464          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3465          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3466          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3467          {
3468             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3469             return RFAILED;
3470          }
3471          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3472                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3473          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3474          {
3475             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3476                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3477                break;
3478             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3479                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3480                break;
3481             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3482             default:
3483                break;
3484          }
3485          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3486
3487          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3488
3489          /* Fill RLC related Configurations for this Radio Bearer */
3490          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3491          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3492          if(!rlcBearerList->list.array[idx]->rlc_Config)
3493          {
3494             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3495             return RFAILED;
3496          }
3497          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3498          {
3499             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3500             return RFAILED;
3501          }
3502
3503          /* Fill MAC related configurations for this Radio Bearer */
3504          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3505          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3506          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3507          {
3508             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3509             return RFAILED;
3510          }
3511          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3512          {
3513             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3514             {
3515                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3516                {
3517                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3518                   return RFAILED;
3519                }
3520                break;
3521             }
3522          }
3523
3524          idx++;
3525       }
3526    }
3527    return ROK;
3528 }
3529
3530 /*******************************************************************
3531  *
3532  * @brief Build Control resource set to add/modify list 
3533  *
3534  * @details
3535  *
3536  *    Function : BuildControlRSetToAddModList
3537  *
3538  *    Functionality: Build Control resource set to add/modify list
3539  *
3540  * @params[in] 
3541  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3542  *
3543  * @return ROK     - success
3544  *         RFAILED - failure
3545  *
3546  * ****************************************************************/
3547 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3548 {
3549    uint8_t idx;
3550    uint8_t elementCnt;
3551    uint8_t numBytes, bitsUnused;
3552    struct ControlResourceSet *controlRSet;
3553    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3554    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3555
3556    if(pdcchCfg == NULLP)
3557       elementCnt = 1;
3558    else
3559       elementCnt = pdcchCfg->numCRsetToAddMod;
3560
3561    controlRSetList->list.count = elementCnt;
3562    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3563
3564    controlRSetList->list.array = NULLP;
3565    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3566    if(!controlRSetList->list.array)
3567    {
3568       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3569       return RFAILED;
3570    }
3571
3572    for(idx = 0; idx < elementCnt; idx++)
3573    {
3574       controlRSetList->list.array[idx] = NULLP;
3575       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3576       if(!controlRSetList->list.array[idx])
3577       {
3578          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3579          return RFAILED;
3580       }
3581    }
3582
3583    for(idx = 0; idx < elementCnt; idx++)
3584    {
3585       controlRSet = controlRSetList->list.array[idx];
3586
3587       if(pdcchCfg == NULLP)
3588          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3589       else
3590          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3591
3592       /* size 6 bytes
3593        * 3 LSBs unsued
3594        * Bit string stored ff0000000000
3595        */
3596       numBytes = 6;
3597       bitsUnused = 3;
3598       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3599
3600       controlRSet->frequencyDomainResources.buf = NULLP;
3601       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3602       if(!controlRSet->frequencyDomainResources.buf)
3603       {
3604          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3605          return RFAILED;
3606       }
3607
3608       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3609
3610       if(pdcchCfg == NULLP)
3611       {
3612          coreset0EndPrb = CORESET0_END_PRB;
3613          coreset1StartPrb = coreset0EndPrb + 6;
3614          coreset1NumPrb = CORESET1_NUM_PRB;
3615          /* calculate the PRBs */
3616          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3617          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3618          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3619
3620          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3621          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3622          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3623       }
3624       else
3625       {
3626          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3627          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3628          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3629          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3630          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3631       }
3632       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3633       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3634       controlRSet->tci_PresentInDCI = NULLP;
3635
3636 #if 0
3637       uint8_t tciStateIdx;
3638
3639       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3640             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3641       if(!controlRset->tci_StatesPDCCH_ToAddList)
3642       {
3643          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3644          return RFAILED;
3645       }
3646
3647       elementCnt = 1;
3648       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3649       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3650       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3651             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3652          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3653          {
3654             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3655             return RFAILED;
3656          }
3657
3658       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3659       {
3660          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3661          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3662          {
3663             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3664             return RFAILED;
3665          }
3666       }
3667
3668       tciStateIdx = 0;
3669       /* TODO */
3670       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3671
3672       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3673       if(!controlRset->tci_PresentInDCI)
3674       {
3675          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3676          return RFAILED;
3677       }
3678       /* TODO */
3679       *(controlRset->tci_PresentInDCI);
3680 #endif
3681
3682       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3683       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3684       if(!controlRSet->pdcch_DMRS_ScramblingID)
3685       {
3686          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3687          return RFAILED;
3688       }
3689       if(pdcchCfg == NULLP)
3690          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3691       else
3692          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3693    }
3694    return ROK;
3695 } /* End BuildControlRSetToAddModList */
3696
3697 /*******************************************************************
3698  *
3699  * @brief Build search space to add/modify list
3700  *
3701  * @details
3702  *
3703  *    Function : BuildSearchSpcToAddModList
3704  *
3705  *    Functionality: Build search space to add/modify list
3706  *
3707  * @params[in] 
3708  * @return ROK     - success
3709  *         RFAILED - failure
3710  *
3711  * ****************************************************************/
3712 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3713 {
3714    uint8_t idx;
3715    uint8_t numBytes;
3716    uint8_t byteIdx;
3717    uint8_t bitsUnused;
3718    uint8_t elementCnt;
3719    struct SearchSpace *searchSpc;
3720
3721    if(pdcchCfg == NULLP)
3722       elementCnt = 1;
3723    else
3724       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3725
3726    searchSpcList->list.count = elementCnt;
3727    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3728
3729    searchSpcList->list.array = NULLP;
3730    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3731    if(!searchSpcList->list.array)
3732    {
3733       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3734       return RFAILED;
3735    }
3736
3737    for(idx = 0; idx < elementCnt; idx++)
3738    {
3739       searchSpcList->list.array[idx] = NULLP;
3740       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3741       if(!searchSpcList->list.array[idx])
3742       {
3743          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3744          return RFAILED;
3745       }
3746    }
3747
3748    for(idx = 0; idx < elementCnt; idx++)
3749    {
3750       searchSpc = searchSpcList->list.array[idx];
3751
3752       if(pdcchCfg == NULLP)
3753          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3754       else
3755          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3756
3757       searchSpc->controlResourceSetId = NULLP;
3758       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3759       if(!searchSpc->controlResourceSetId)
3760       {
3761          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3762          return RFAILED;
3763       }
3764       if(pdcchCfg == NULLP)
3765          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3766       else
3767          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3768
3769       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3770       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3771       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3772       {
3773          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3774          return RFAILED;
3775       }
3776       if(pdcchCfg == NULLP)
3777          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3778       else
3779          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3780
3781       searchSpc->duration = NULLP;
3782       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3783       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3784       if(!searchSpc->monitoringSymbolsWithinSlot)
3785       {
3786          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3787          return RFAILED;
3788       }
3789
3790       /* Values taken from reference logs :
3791        * size 2 bytes
3792        * 2 LSBs unsued
3793        * Bit string stores 8000
3794        */
3795       numBytes = 2;
3796       bitsUnused = 2;
3797       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3798       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3799       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3800       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3801       {
3802          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3803          return RFAILED;
3804       }
3805       if(pdcchCfg == NULLP)
3806       {
3807          byteIdx = 0;
3808          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3809          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3810       }
3811       else
3812          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3813       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3814
3815       searchSpc->nrofCandidates = NULLP;
3816       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3817       if(!searchSpc->nrofCandidates)
3818       {
3819          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3820          return RFAILED;
3821       }
3822
3823       if(pdcchCfg == NULLP)
3824       {
3825          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3826          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3827          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3828          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3829          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
3830       }
3831       else
3832       {
3833          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
3834          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
3835          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
3836          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
3837          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
3838       }
3839
3840       searchSpc->searchSpaceType = NULLP;
3841       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
3842       if(!searchSpc->searchSpaceType)
3843       {
3844          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3845          return RFAILED;
3846       }
3847       if(pdcchCfg == NULLP)
3848          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
3849       else
3850          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
3851
3852       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
3853       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
3854       if(!searchSpc->searchSpaceType->choice.ue_Specific)
3855       {
3856          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3857          return RFAILED;
3858       }  
3859       if(pdcchCfg == NULLP)
3860          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
3861       else
3862          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
3863    }
3864    return ROK;
3865 }/* End BuildSearchSpcToAddModList */
3866
3867 /*******************************************************************
3868  *
3869  * @brief Builds BWP DL dedicated PDCCH config
3870  *
3871  * @details
3872  *
3873  *    Function : BuildBWPDlDedPdcchCfg
3874  *
3875  *    Functionality: Builds BWP DL dedicated PDCCH config
3876  *
3877  * @params[in] struct PDCCH_Config *pdcchCfg
3878  *
3879  * @return ROK     - success
3880  *         RFAILED - failure
3881  *
3882  * ****************************************************************/
3883 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
3884 {
3885    pdcchCfg->controlResourceSetToAddModList = NULLP;
3886    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
3887    if(!pdcchCfg->controlResourceSetToAddModList)
3888    {
3889       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3890       return RFAILED;
3891    }
3892
3893    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
3894    {
3895       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
3896       return RFAILED;
3897    }
3898
3899    pdcchCfg->controlResourceSetToReleaseList = NULLP;
3900
3901    pdcchCfg->searchSpacesToAddModList = NULLP;
3902    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
3903    if(!pdcchCfg->searchSpacesToAddModList)
3904    {
3905       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3906       return RFAILED;
3907    }
3908
3909    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
3910    {
3911       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
3912       return RFAILED;
3913    }
3914
3915    pdcchCfg->searchSpacesToReleaseList = NULLP;
3916    pdcchCfg->downlinkPreemption = NULLP;
3917    pdcchCfg->tpc_PUSCH = NULLP;
3918    pdcchCfg->tpc_PUCCH = NULLP;
3919    pdcchCfg->tpc_SRS = NULLP;
3920
3921    return ROK;
3922 }
3923
3924 /*******************************************************************
3925  *
3926  * @brief Builds DMRS DL PDSCH Mapping type A
3927  *
3928  * @details
3929  *
3930  *    Function : BuildDMRSDLPdschMapTypeA
3931  *
3932  *    Functionality: Builds DMRS DL PDSCH Mapping type A
3933  *
3934  * @params[in]
3935  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
3936  * @return ROK     - success
3937  *         RFAILED - failure
3938  *
3939  * ****************************************************************/
3940 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
3941 {
3942    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
3943    dmrsDlCfg->choice.setup = NULLP;
3944    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
3945    if(!dmrsDlCfg->choice.setup)
3946    {
3947       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3948       return RFAILED;
3949    }
3950
3951    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
3952    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
3953    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
3954    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
3955    {
3956       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3957       return RFAILED;
3958    }
3959    if(pdschCfg == NULLP)
3960       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
3961    else
3962       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
3963
3964    dmrsDlCfg->choice.setup->maxLength = NULLP;
3965    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
3966    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
3967    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
3968
3969    return ROK;
3970 }
3971
3972 /*******************************************************************
3973  *
3974  * @brief Builds TCI states to add/modify list
3975  *
3976  * @details
3977  *
3978  *    Function : BuildTCIStatesToAddModList
3979  *
3980  *    Functionality:Builds TCI states to add/modify list
3981  *
3982  * @params[in] 
3983  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
3984  *
3985  * @return ROK     - success
3986  *         RFAILED - failure
3987  *
3988  * ****************************************************************/
3989 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
3990 {
3991    return ROK;
3992 }
3993
3994 /*******************************************************************
3995  *
3996  * @brief Builds PDSCH time domain allocation list
3997  *
3998  * @details
3999  *
4000  *    Function : BuildPdschTimeDomAllocList
4001  *
4002  *    Functionality: Builds PDSCH time domain allocation list
4003  *
4004  * @params[in] 
4005  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4006  *
4007  * @return ROK     - success
4008  *         RFAILED - failure
4009  *
4010  * ****************************************************************/
4011 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4012 {
4013    uint8_t idx;
4014    uint8_t elementCnt;
4015    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4016
4017    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4018
4019    timeDomAllocList->choice.setup = NULLP;
4020    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4021    if(!timeDomAllocList->choice.setup)
4022    {
4023       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4024       return RFAILED;
4025    }
4026
4027 if(pdschCfg == NULLP)
4028    elementCnt = 2;
4029 else
4030 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4031    timeDomAllocList->choice.setup->list.count = elementCnt;
4032    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4033
4034    timeDomAllocList->choice.setup->list.array = NULLP;
4035    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4036    if(!timeDomAllocList->choice.setup->list.array)
4037    {
4038       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4039       return RFAILED;
4040    }
4041
4042    for(idx = 0; idx < elementCnt; idx++)
4043    {
4044       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4045       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4046             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4047       if(!timeDomAllocList->choice.setup->list.array[idx])
4048       {
4049          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4050          return RFAILED;
4051       }
4052    }
4053
4054    if(pdschCfg == NULLP)
4055    {
4056       idx = 0;
4057       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4058       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4059       if(!timeDomAlloc->k0)
4060       {
4061          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4062          return RFAILED;
4063       }
4064       *(timeDomAlloc->k0) = 0;
4065       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4066       timeDomAlloc->startSymbolAndLength = \
4067                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4068
4069       idx++;
4070       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4071       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4072       if(!timeDomAlloc->k0)
4073       {
4074          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4075          return RFAILED;
4076       }
4077       *(timeDomAlloc->k0) = 1;
4078       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4079       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4080    }
4081    else
4082    {
4083       for(idx = 0; idx < elementCnt; idx++)
4084       {
4085          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4086          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4087          {
4088             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4089             if(!timeDomAlloc->k0)
4090             {
4091                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4092                return RFAILED;
4093             }
4094             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4095          }
4096          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4097          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4098       }
4099    }
4100
4101    return ROK;
4102 }
4103
4104 /*******************************************************************
4105  *
4106  * @brief Builds PDSCH PRB Bundling type
4107  *
4108  * @details
4109  *
4110  *    Function : BuildPdschPrbBundlingType
4111  *
4112  *    Functionality: Builds PDSCH PRB Bundling type
4113  *
4114  * @params[in] 
4115  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4116  *
4117  * @return ROK     - success
4118  *         RFAILED - failure
4119  *
4120  * ****************************************************************/
4121 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4122 {
4123    if(pdschCfg == NULLP)
4124       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4125    else
4126       prbBndlType->present = pdschCfg->bundlingType;
4127
4128    prbBndlType->choice.staticBundling = NULLP;
4129    DU_ALLOC(prbBndlType->choice.staticBundling, \
4130          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4131    if(!prbBndlType->choice.staticBundling)
4132    {
4133       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4134       return RFAILED;
4135    }
4136    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4137
4138    return ROK;
4139 }
4140
4141 /*******************************************************************
4142  *
4143  * @brief Builds BWP DL dedicated PDSCH config 
4144  *
4145  * @details
4146  *
4147  *    Function : BuildBWPDlDedPdschCfg
4148  *
4149  *    Functionality: Builds BWP DL dedicated PDSCH config
4150  *
4151  * @params[in] struct PDSCH_Config *pdschCfg
4152  *
4153  * @return ROK     - success
4154  *         RFAILED - failure
4155  *
4156  * ****************************************************************/
4157 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4158 {
4159    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4160
4161    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4162    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4163    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4164    {
4165       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4166       return RFAILED;
4167    }
4168
4169    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4170    {
4171       return RFAILED;
4172    }
4173
4174    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4175    pdschCfg->tci_StatesToAddModList = NULLP;
4176    pdschCfg->tci_StatesToReleaseList = NULLP;
4177    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4178 #if 0
4179    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4180    if(!pdschCfg->tci_StatesToAddModList)
4181    {
4182       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4183       return RFAILED;
4184    }
4185    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4186    {
4187       return RFAILED;
4188    }
4189 #endif
4190
4191 if(pdschCfgDb == NULLP)
4192    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4193 else
4194 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4195
4196    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4197    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4198    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4199    {
4200       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4201       return RFAILED;
4202    }
4203    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4204    {
4205       return RFAILED;
4206    }
4207
4208    pdschCfg->pdsch_AggregationFactor = NULLP;
4209    pdschCfg->rateMatchPatternToAddModList = NULLP;
4210    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4211    pdschCfg->rateMatchPatternGroup1 = NULLP;
4212    pdschCfg->rateMatchPatternGroup2 = NULLP;
4213    if(pdschCfgDb == NULLP)
4214       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4215    else
4216       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4217    pdschCfg->mcs_Table = NULLP;
4218
4219    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4220    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4221    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4222    {
4223       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4224       return RFAILED;
4225    }
4226    if(pdschCfgDb == NULLP)
4227       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4228    else
4229       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4230
4231    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4232    {
4233       return RFAILED;
4234    }
4235
4236    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4237    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4238    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4239    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4240    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4241    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4242    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4243
4244    return ROK;
4245 }
4246
4247 /*******************************************************************
4248  *
4249  * @brief Builds intitial DL BWP
4250  * @details
4251  *
4252  *    Function : BuildInitialDlBWP 
4253  *
4254  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4255  *
4256  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4257  *
4258  * @return ROK     - success
4259  *         RFAILED - failure
4260  *
4261  * ****************************************************************/
4262 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4263 {
4264    PdcchConfig *pdcchCfg = NULLP;
4265    PdschConfig *pdschCfg = NULLP;
4266
4267    if(initiDlBwp)
4268    {
4269       if(initiDlBwp->pdcchPresent)
4270          pdcchCfg = &initiDlBwp->pdcchCfg;
4271       if(initiDlBwp->pdschPresent)
4272          pdschCfg = &initiDlBwp->pdschCfg;
4273    }
4274
4275    dlBwp->pdcch_Config = NULLP;
4276    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4277    if(!dlBwp->pdcch_Config)
4278    {
4279       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4280       return RFAILED;
4281    }
4282    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4283
4284    dlBwp->pdcch_Config->choice.setup = NULLP;
4285    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4286    if(!dlBwp->pdcch_Config->choice.setup)
4287    {
4288       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4289       return RFAILED;
4290    }
4291    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4292    {
4293       return RFAILED;
4294    }
4295
4296    dlBwp->pdsch_Config = NULLP;
4297    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4298    if(!dlBwp->pdsch_Config)
4299    {
4300       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4301       return RFAILED;
4302    }
4303    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4304
4305    dlBwp->pdsch_Config->choice.setup = NULLP;
4306    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4307    if(!dlBwp->pdsch_Config->choice.setup)
4308    {
4309       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4310       return RFAILED;
4311    }
4312
4313    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4314    {
4315       return RFAILED;
4316    }
4317
4318    dlBwp->sps_Config = NULLP;
4319    dlBwp->radioLinkMonitoringConfig = NULLP; 
4320    return ROK;
4321 }
4322
4323 /*******************************************************************
4324  *
4325  * @brief Builds DMRS UL Pusch Mapping type A
4326  *
4327  * @details
4328  *
4329  *    Function : BuildDMRSULPuschMapTypeA
4330  *
4331  *    Functionality: Builds DMRS UL Pusch Mapping type A
4332  *
4333  * @params[in] 
4334  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4335  * @return ROK     - success
4336  *         RFAILED - failure
4337  *
4338  * ****************************************************************/
4339 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4340 {
4341    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4342    dmrsUlCfg->choice.setup= NULLP;
4343    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4344    if(!dmrsUlCfg->choice.setup)
4345    {
4346       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4347       return RFAILED;
4348    }
4349
4350    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4351    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4352    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4353    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4354    {
4355       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4356       return RFAILED;
4357    }
4358    if(ulDmrsCfgDb == NULLP)
4359       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4360    else
4361       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4362
4363    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4364    dmrsUlCfg->choice.setup->maxLength = NULLP;
4365    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4366    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4367    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4368    {
4369       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4370       return RFAILED;
4371    }
4372
4373    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4374    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4375          sizeof(long));
4376    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4377    {
4378       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4379       return RFAILED;
4380    }
4381    if(ulDmrsCfgDb == NULLP)
4382       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4383    else
4384       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4385
4386    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4387    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4388    return ROK;
4389 }
4390
4391 /*******************************************************************
4392  *
4393  * @brief Build PUSCH time domain allocation list
4394  *
4395  * @details
4396  *
4397  *    Function : BuildPuschTimeDomAllocList
4398  *
4399  *    Functionality: Build PUSCH time domain allocation list
4400  *
4401  * @params[in] 
4402  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4403  *
4404  * @return ROK     - success
4405  *         RFAILED - failure
4406  *
4407  * ****************************************************************/
4408 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4409 {
4410    uint8_t idx;
4411    uint8_t elementCnt;
4412    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4413
4414    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4415    timeDomAllocList->choice.setup = NULLP;
4416    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4417    if(!timeDomAllocList->choice.setup)
4418    {
4419       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4420       return RFAILED;
4421    }
4422
4423    if(puschCfgDb == NULLP)
4424       elementCnt = 2;
4425    else
4426       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4427
4428    timeDomAllocList->choice.setup->list.count = elementCnt;
4429    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4430    timeDomAllocList->choice.setup->list.array = NULLP;
4431    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4432    if(!timeDomAllocList->choice.setup->list.array)
4433    {
4434       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4435       return RFAILED;
4436    }
4437
4438    for(idx = 0; idx < elementCnt; idx++)
4439    {
4440       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4441       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4442       if(!timeDomAllocList->choice.setup->list.array[idx])
4443       {
4444          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4445          return RFAILED;
4446       }
4447    }
4448
4449    for(idx = 0; idx < elementCnt; idx++)
4450    {
4451       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4452       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4453       if(!timeDomAlloc->k2)
4454       {
4455          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4456          return RFAILED;
4457       }
4458       if(puschCfgDb == NULLP)
4459       {
4460          if(idx == 0)
4461             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4462          else if(idx == 1)
4463             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4464
4465          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4466          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4467       }
4468       else
4469       {
4470          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4471          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4472          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4473       }
4474    }
4475
4476    return ROK;
4477 }
4478
4479 /*******************************************************************
4480  *
4481  * @brief Builds BWP UL dedicated PUSCH Config
4482  *
4483  * @details
4484  *
4485  *    Function : BuildBWPUlDedPuschCfg
4486  *
4487  *    Functionality:
4488  *      Builds BWP UL dedicated PUSCH Config
4489  *
4490  * @params[in] : PUSCH_Config_t *puschCfg
4491  *    
4492  * @return ROK     - success
4493  *         RFAILED - failure
4494  *
4495  * ****************************************************************/
4496 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4497 {
4498    DmrsUlCfg *ulDmrsCfg = NULLP;
4499    
4500    if(puschCfgDb)
4501       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4502
4503    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4504    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4505    if(!puschCfg->dataScramblingIdentityPUSCH)
4506    {
4507       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4508       return RFAILED;
4509    }
4510    if(puschCfgDb == NULLP)
4511       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4512    else
4513       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4514
4515    puschCfg->txConfig = NULLP;
4516    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4517    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4518    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4519    {
4520       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4521       return RFAILED;
4522    }
4523
4524    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4525    {
4526       return RFAILED;
4527    }
4528
4529    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4530    puschCfg->pusch_PowerControl = NULLP;
4531    puschCfg->frequencyHopping = NULLP;
4532    puschCfg->frequencyHoppingOffsetLists = NULLP;
4533
4534    if(puschCfgDb == NULLP)
4535       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4536    else
4537       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4538
4539    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4540    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4541    if(!puschCfg->pusch_TimeDomainAllocationList)
4542    {
4543       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4544       return RFAILED;
4545    }
4546
4547    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4548    {
4549       return RFAILED;
4550    }
4551
4552    puschCfg->pusch_AggregationFactor = NULLP;
4553    puschCfg->mcs_Table = NULLP;
4554    puschCfg->mcs_TableTransformPrecoder = NULLP;
4555    puschCfg->transformPrecoder = NULLP;
4556    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4557    if(!puschCfg->transformPrecoder)
4558    {
4559       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4560       return RFAILED;
4561    }
4562    if(puschCfgDb == NULLP)
4563       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4564    else
4565       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4566
4567    puschCfg->codebookSubset = NULLP;
4568    puschCfg->maxRank = NULLP;
4569    puschCfg->rbg_Size = NULLP;
4570    puschCfg->uci_OnPUSCH = NULLP;
4571    puschCfg->tp_pi2BPSK = NULLP;
4572
4573    return ROK;
4574 }
4575
4576 /*******************************************************************
4577  *
4578  * @brief Builds PUCCH resource set add/modify list
4579  *
4580  * @details
4581  *
4582  *    Function : BuildPucchRsrcSetAddModList
4583  *
4584  *    Functionality:
4585  *      Builds PUCCH resource set add/modify list
4586  *
4587  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4588  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4589  *
4590  * @return ROK     - success
4591  *         RFAILED - failure
4592  *
4593  * ****************************************************************/
4594 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4595    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4596 {
4597    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4598    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4599
4600    if(rsrcSetCfgDb == NULLP)
4601       elementCnt = 1;
4602    else
4603       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4604
4605    resourceSetToAddModList->list.count = elementCnt;
4606    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4607    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4608    if(resourceSetToAddModList->list.array == NULLP)
4609    {
4610       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4611       return RFAILED;
4612    }
4613    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4614    {
4615       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4616       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4617       {
4618          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4619          return RFAILED;
4620       }
4621    }
4622
4623    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4624    {
4625       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4626
4627       /* Resource set Id */
4628       if(rsrcSetCfgDb == NULLP)
4629          rsrcSet->pucch_ResourceSetId = 1;
4630       else
4631          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4632  
4633       /* Resource list of a resource set */
4634       if(rsrcSetCfgDb == NULLP)
4635          elementCnt = 1;
4636       else
4637          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4638       rsrcSet->resourceList.list.count = elementCnt;
4639       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4640       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4641       if(rsrcSet->resourceList.list.array == NULLP)
4642       {
4643          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4644          return RFAILED;
4645       }
4646
4647       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4648       {
4649          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4650          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4651          {
4652             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4653             return RFAILED;
4654          }
4655       }
4656       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4657       {
4658          if(rsrcSetCfgDb == NULLP)
4659             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4660          else
4661             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4662       }
4663
4664       /* Max payload size (minus 1) in a Resource set */
4665       rsrcSet->maxPayloadMinus1 = NULLP;
4666       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4667       {
4668          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4669          if(rsrcSet->maxPayloadMinus1 == NULLP)
4670          {
4671             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4672             return RFAILED;
4673          }
4674          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4675       }
4676    }
4677    return ROK;
4678 }
4679
4680 /*******************************************************************
4681  *
4682  * @brief Builds PUCCH resource add/modify list
4683  *
4684  * @details
4685  *
4686  *    Function : BuildPucchRsrcAdddModList
4687  *
4688  *    Functionality:
4689  *      Builds PUCCH resource add/modify list
4690  *
4691  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4692  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4693  *
4694  * @return ROK     - success
4695  *         RFAILED - failure
4696  *
4697  * ****************************************************************/
4698 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4699 {
4700    uint8_t elementCnt = 0, rsrcIdx = 0;
4701    PUCCH_Resource_t *rsrc = NULLP;
4702
4703    if(rsrcCfgDb == NULLP)
4704       elementCnt = 1;
4705    else
4706       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4707    resourceToAddModList->list.count = elementCnt;
4708    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4709    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4710    if(resourceToAddModList->list.array == NULLP)
4711    {
4712       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4713       return RFAILED;
4714    }
4715    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4716    {
4717       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4718       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4719       {
4720          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4721          return RFAILED;
4722       }
4723    }
4724
4725    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4726    {
4727       rsrc = resourceToAddModList->list.array[rsrcIdx];
4728
4729       if(rsrcCfgDb == NULLP)
4730       {
4731          rsrc->pucch_ResourceId = 1;
4732          rsrc->startingPRB = 0;
4733          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4734          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4735          if(rsrc->format.choice.format1 == NULLP)
4736          {
4737             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4738             return RFAILED;
4739          }  
4740          rsrc->format.choice.format1->initialCyclicShift = 0;
4741          rsrc->format.choice.format1->nrofSymbols = 4;
4742          rsrc->format.choice.format1->startingSymbolIndex = 0;
4743          rsrc->format.choice.format1->timeDomainOCC = 0;
4744       }
4745       else
4746       {
4747          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4748          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4749          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4750          {
4751             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4752             if(rsrc->intraSlotFrequencyHopping == NULLP)
4753             {
4754                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4755                return RFAILED;
4756             }
4757             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4758          }
4759          else
4760             rsrc->intraSlotFrequencyHopping = NULLP;
4761
4762          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4763          {
4764             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4765             if(rsrc->secondHopPRB == NULLP)
4766             {
4767                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4768                return RFAILED;
4769             }
4770             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4771          }
4772          else
4773             rsrc->secondHopPRB = NULLP;
4774          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4775
4776          switch(rsrc->format.present)
4777          {
4778             case PUCCH_Resource__format_PR_NOTHING:
4779                break;
4780             case PUCCH_Resource__format_PR_format0:
4781                {
4782                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4783                   if(rsrc->format.choice.format0 == NULLP)
4784                   {
4785                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4786                      return RFAILED;
4787                   }
4788                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4789                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4790                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4791                   break;
4792                }
4793
4794             case PUCCH_Resource__format_PR_format1:
4795                {
4796                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4797                   if(rsrc->format.choice.format1 == NULLP)
4798                   {
4799                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4800                      return RFAILED;
4801                   }  
4802                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4803                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4804                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4805                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4806                   break;
4807                }
4808
4809             case PUCCH_Resource__format_PR_format2:
4810                {
4811                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4812                   if(rsrc->format.choice.format2 == NULLP)
4813                   {
4814                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4815                      return RFAILED;
4816                   } 
4817                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4818                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4819                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4820                   break;
4821                }
4822
4823             case PUCCH_Resource__format_PR_format3:
4824                {
4825                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4826                   if(rsrc->format.choice.format3 == NULLP)
4827                   {
4828                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4829                      return RFAILED;
4830                   }
4831                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
4832                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
4833                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
4834                   break;
4835                }
4836
4837             case PUCCH_Resource__format_PR_format4:
4838                {
4839                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
4840                   if(rsrc->format.choice.format4 == NULLP)
4841                   {
4842                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4843                      return RFAILED;
4844                   }
4845                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
4846                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
4847                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
4848                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
4849                   break;
4850                }
4851          }
4852       }
4853    }
4854    return ROK;
4855 }
4856
4857 /*******************************************************************
4858  *
4859  * @brief Builds PUCCH format  config
4860  *
4861  * @details
4862  *
4863  *    Function : BuildPucchFormat
4864  *
4865  *    Functionality: Builds PUCCH format  config
4866  *
4867  * @params[in] : PucchFormatCfg *formatDb
4868  *               PUCCH_FormatConfig_t *format
4869  *
4870  * @return ROK     - success
4871  *         RFAILED - failure
4872  *
4873  * ****************************************************************/
4874 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
4875 {
4876    /* Inter Slot Fequency hopping */
4877    format->interslotFrequencyHopping = NULLP;
4878    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
4879    {
4880       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
4881       if(format->interslotFrequencyHopping)
4882       {
4883          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4884          return RFAILED;
4885       }
4886       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
4887    }
4888
4889    /* Additional DMRS */
4890    format->additionalDMRS = NULLP;
4891    if((formatDb != NULLP) && (formatDb->addDmrs == true))
4892    {
4893       DU_ALLOC(format->additionalDMRS, sizeof(long));
4894       if(format->additionalDMRS)
4895       {
4896          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4897          return RFAILED;
4898       }
4899       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
4900    }
4901
4902     /* Maximum code rate */
4903    format->maxCodeRate = NULLP;
4904    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
4905    {
4906       DU_ALLOC(format->maxCodeRate, sizeof(long));
4907       if(format->maxCodeRate)
4908       {
4909          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4910          return RFAILED;
4911       }  
4912       *(format->maxCodeRate) = formatDb->maxCodeRate;
4913    }
4914  
4915    /* Number of slots */
4916    format->nrofSlots = NULLP;
4917    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
4918    {
4919       DU_ALLOC(format->nrofSlots, sizeof(long));
4920       if(format->nrofSlots == NULLP)
4921       {
4922          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4923          return RFAILED;
4924       }
4925       if(formatDb == NULLP)
4926          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
4927       else
4928          *(format->nrofSlots) = formatDb->numSlots;
4929    }
4930
4931    /* Pi2BPSK*/
4932    format->pi2BPSK = NULLP;
4933    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
4934    {
4935       DU_ALLOC(format->pi2BPSK, sizeof(long));
4936       if(format->pi2BPSK)
4937       {     
4938          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4939          return RFAILED;
4940       }     
4941       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
4942    }
4943
4944    /* Simultaneous HARQ ACK and CSI */
4945    format->simultaneousHARQ_ACK_CSI = NULLP;
4946    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
4947    {
4948       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
4949       if(format->simultaneousHARQ_ACK_CSI)
4950       {     
4951          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4952          return RFAILED;
4953       }     
4954       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
4955    }
4956
4957    return ROK;
4958 }
4959
4960
4961 /*******************************************************************
4962  *
4963  * @brief Builds PUCCH scheduling request list
4964  *
4965  * @details
4966  *
4967  *    Function : BuildPucchSchReqAddModList
4968  *
4969  *    Functionality:
4970  *      Builds PUCCH scheduling request list
4971  *
4972  * @params[in] : PucchSchedReqCfg *schReqDb
4973  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
4974  *
4975  * @return ROK     - success
4976  *         RFAILED - failure
4977  *
4978  * ****************************************************************/
4979 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
4980    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
4981 {
4982    uint8_t elementCnt = 0, schReqIdx = 0;
4983    SchedulingRequestResourceConfig_t *schReqRsrc;
4984
4985    elementCnt = schReqDb->schedAddModListCount;
4986    schReqRsrcToAddModList->list.count = elementCnt;
4987    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
4988
4989    schReqRsrcToAddModList->list.array = NULLP;
4990    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
4991    if(schReqRsrcToAddModList->list.array == NULLP)
4992    {
4993       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4994       return RFAILED;
4995    }
4996
4997    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4998    {
4999       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5000       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5001       {
5002          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5003          return RFAILED;
5004       }
5005    }
5006
5007    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5008    {
5009       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5010       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5011       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5012
5013       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5014       {
5015          schReqRsrc->periodicityAndOffset = NULLP;
5016          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5017          if(schReqRsrc->periodicityAndOffset == NULLP)
5018          {
5019             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5020             return RFAILED;
5021          }
5022
5023          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5024          switch(schReqRsrc->periodicityAndOffset->present)
5025          {
5026             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5027                break;
5028             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5029                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5030                break;
5031             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5032                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5033                break;
5034             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5035                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5036                break;
5037             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5038                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5039                break;
5040             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5041                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5042                break;
5043             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5044                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5045                break;
5046             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5047                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5048                break;
5049             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5050                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5051                break;
5052             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5053                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5054                break;
5055             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5056                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5057                break;
5058             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5059                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5060                break;
5061             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5062                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5063                break;
5064             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5065                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5066                break;
5067             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5068                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5069                break;
5070             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5071                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5072                break;
5073          }
5074       }
5075
5076       if(schReqDb->schedAddModList[schReqIdx].resrc)
5077       {
5078          schReqRsrc->resource = NULLP;
5079          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5080          if(schReqRsrc->resource == NULLP)
5081          {
5082             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5083             return RFAILED;
5084          }
5085          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5086
5087       }
5088    }
5089    return ROK;
5090 }
5091
5092 /*******************************************************************
5093  *
5094  * @brief Builds PUCCH multi csi resource list
5095  *
5096  * @details
5097  *
5098  *    Function : BuildPucchMultiCsiRsrcList
5099  *
5100  *    Functionality:
5101  *      Builds PUCCH multi csi resource list
5102  *
5103  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5104  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5105  *
5106  * @return ROK     - success
5107  *         RFAILED - failure
5108  *
5109  * ****************************************************************/
5110 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5111 {
5112    uint8_t elementCnt = 0, rsrcIdx = 0;
5113
5114    elementCnt = multiCsiDb->multiCsiResrcListCount;
5115    multiCsiRsrcList->list.count = elementCnt;
5116    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5117    multiCsiRsrcList->list.array = NULLP;
5118    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5119    if(multiCsiRsrcList->list.array == NULLP)
5120    {
5121       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5122       return RFAILED;
5123    }
5124
5125    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5126    {
5127       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5128       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5129       {
5130          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5131          return RFAILED;
5132       }
5133    }
5134
5135    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5136    {
5137       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5138    }
5139    return ROK;
5140 }
5141
5142 /*******************************************************************
5143  *
5144  * @brief Builds DL data -to- Ul Ack list
5145  *
5146  * @details
5147  *
5148  *    Function : BuildDlDataToUlAckList
5149  *
5150  *    Functionality: Builds DL data -to- Ul Ack list
5151  *
5152  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5153  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5154  *
5155  * @return ROK     - success
5156  *         RFAILED - failure
5157  *
5158  * ****************************************************************/
5159 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5160 {
5161    uint8_t elementCnt = 0, arrIdx = 0;
5162
5163    if(dlDataToUlAckDb == NULLP)
5164       elementCnt = 2;
5165    else
5166       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5167
5168    dlDataToUlACKList->list.count = elementCnt;
5169    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5170    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5171    if(dlDataToUlACKList->list.array == NULLP)
5172    {
5173       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5174       return RFAILED;
5175    }   
5176
5177    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5178    {
5179       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5180       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5181       {
5182          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5183          return RFAILED;
5184       }   
5185    }
5186
5187    if(dlDataToUlAckDb == NULLP)
5188    {
5189       arrIdx = 0;
5190       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5191       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5192    }
5193    else
5194    {
5195       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5196       {
5197          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5198       }
5199    }
5200    return ROK;
5201 }
5202
5203 /*******************************************************************
5204  *
5205  * @brief Builds BWP UL dedicated PUCCH Config
5206  *
5207  * @details
5208  *
5209  *    Function : BuildBWPUlDedPucchCfg
5210  *
5211  *    Functionality:
5212  *      Builds BWP UL dedicated PUCCH Config
5213  *
5214  * @params[in] : PUCCH_Config_t *pucchCfg
5215  *
5216  * @return ROK     - success
5217  *         RFAILED - failure
5218  *
5219  * ****************************************************************/
5220 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5221 {
5222    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5223    PucchResrcCfg *rsrcCfgDb = NULLP;
5224    PucchFormatCfg *format1Db = NULLP;
5225    PucchFormatCfg *format2Db = NULLP;
5226    PucchFormatCfg *format3Db = NULLP;
5227    PucchFormatCfg *format4Db = NULLP;
5228    PucchSchedReqCfg *schReqDb = NULLP;   
5229    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5230    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5231
5232    if(pucchCfgDb)
5233    {
5234       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5235       rsrcCfgDb = pucchCfgDb->resrc;
5236       format1Db = pucchCfgDb->format1;
5237       format2Db = pucchCfgDb->format2;
5238       format3Db = pucchCfgDb->format3;
5239       format4Db = pucchCfgDb->format4;
5240       schReqDb = pucchCfgDb->schedReq;
5241       multiCsiDb = pucchCfgDb->multiCsiCfg;
5242       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5243    }
5244
5245    /* RESOURCE SET */
5246    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5247    if(pucchCfg->resourceSetToAddModList == NULL)
5248    {
5249       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5250       return RFAILED;
5251    }
5252
5253    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5254    {
5255       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5256       return RFAILED;
5257    }
5258
5259    /* PUCCH RESOURCE */
5260    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5261    if(pucchCfg->resourceToAddModList == NULLP)
5262    {
5263       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5264       return RFAILED;
5265    }
5266
5267    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5268    {
5269       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5270       return RFAILED;
5271    }
5272
5273    /* PUCCH Format 1 */
5274    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5275    if(pucchCfg->format1 == NULLP)
5276    {
5277       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5278       return RFAILED;
5279    }
5280    
5281    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5282    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5283    if(pucchCfg->format1->choice.setup == NULLP)
5284    {
5285       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5286       return RFAILED;
5287    }
5288
5289    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5290    {
5291       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5292       return RFAILED;
5293    }
5294
5295    /* PUCCH Format 2 */
5296    if(format2Db)
5297    {
5298       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5299       if(pucchCfg->format2 == NULLP)
5300       {
5301          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5302          return RFAILED;
5303       }
5304
5305       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5306       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5307       if(pucchCfg->format2->choice.setup == NULLP)
5308       {
5309          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5310          return RFAILED;
5311       }
5312
5313       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5314       {
5315          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5316          return RFAILED;
5317       }
5318    }
5319
5320    /* PUCCH Format 3 */
5321    if(format3Db)
5322    {
5323       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5324       if(pucchCfg->format3 == NULLP)
5325       {
5326          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5327          return RFAILED;
5328       }
5329
5330       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5331       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5332       if(pucchCfg->format3->choice.setup == NULLP)
5333       {
5334          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5335          return RFAILED;
5336       }
5337
5338       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5339       {
5340          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5341          return RFAILED;
5342       }
5343    }
5344
5345    /* PUCCH Format 4 */
5346    if(format4Db)
5347    {
5348       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5349       if(pucchCfg->format4 == NULLP)
5350       {
5351          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5352          return RFAILED;
5353       }
5354
5355       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5356       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5357       if(pucchCfg->format4->choice.setup == NULLP)
5358       {
5359          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5360          return RFAILED;
5361       }
5362
5363       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5364       {
5365          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5366          return RFAILED;
5367       }
5368    }
5369
5370    /* Scheduling Request */
5371    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5372    {
5373       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5374       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5375       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5376       {
5377          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5378          return RFAILED;
5379       }
5380
5381       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5382       {
5383          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5384          return RFAILED;
5385       }
5386    }
5387
5388    /* Multi CSI */
5389    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5390    {
5391       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5392       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5393       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5394       {
5395          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5396          return RFAILED;
5397       }
5398
5399       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5400       {
5401          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5402          return RFAILED;
5403       }
5404    }
5405
5406    /* DL DATA TO UL ACK */
5407    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5408    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5409    {
5410       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5411       return RFAILED;
5412    }
5413
5414    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5415    {
5416       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5417       return RFAILED;
5418    }
5419    
5420    /* TODO : spatial relation info add/mod list and power control*/
5421
5422    return ROK;
5423 }
5424
5425 /*******************************************************************
5426  *
5427  * @brief Fills SRS resource to add/modify list 
5428  *
5429  * @details
5430  *
5431  *    Function : BuildSrsRsrcAddModList
5432  *
5433  *    Functionality: Fills SRS resource to add/modify list
5434  *
5435  * @params[in] 
5436  * @return ROK     - success
5437  *         RFAILED - failure
5438  *
5439  * ****************************************************************/
5440 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5441 {
5442    uint8_t   elementCnt;
5443    uint8_t   rsrcIdx;
5444
5445    elementCnt = 1;
5446    resourceList->list.count = elementCnt;
5447    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5448    resourceList->list.array = NULLP;
5449    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5450    if(!resourceList->list.array)
5451    {
5452       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5453       return RFAILED;
5454    }
5455
5456    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5457    {
5458       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5459       if(!resourceList->list.array[rsrcIdx])
5460       {
5461          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5462          return RFAILED;
5463       }
5464    }
5465
5466    rsrcIdx = 0;
5467    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5468    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5469    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5470
5471    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5472    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5473          sizeof(struct SRS_Resource__transmissionComb__n2));
5474    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5475    {
5476       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5477       return RFAILED;
5478    }
5479    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5480       = SRS_COMB_OFFSET_N2;
5481    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5482       = SRS_CYCLIC_SHIFT_N2;
5483
5484    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5485                                                                       PUSCH_START_SYMBOL;
5486    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5487                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5488    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5489                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5490
5491    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5492    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5493    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5494    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5495    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5496    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5497                                                                SRS_Resource__groupOrSequenceHopping_neither;
5498
5499    /* Setting resource type to aperiodic for intergration purposes */
5500    resourceList->list.array[rsrcIdx]->resourceType.present = \
5501                                                              SRS_Resource__resourceType_PR_aperiodic;
5502    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5503    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5504          sizeof(struct SRS_Resource__resourceType__aperiodic));
5505    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5506    {
5507       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5508       return RFAILED;
5509    }
5510
5511    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5512
5513    return ROK;
5514 }
5515
5516 /*******************************************************************
5517  *
5518  * @brief Build SRS resource set Add/mod list
5519  *
5520  * @details
5521  *
5522  *    Function : BuildSrsRsrcSetAddModList
5523  *
5524  *    Functionality: Build SRS resource set Add/mod list
5525  *
5526  * @params[in] 
5527  * @return ROK     - success
5528  *         RFAILED - failure
5529  *
5530  * ****************************************************************/
5531    uint8_t BuildSrsRsrcSetAddModList
5532 (
5533  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5534  )
5535 {
5536    uint8_t  elementCnt;
5537    uint8_t  rSetIdx;
5538    uint8_t  rsrcIdx;
5539    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5540
5541    elementCnt = 1;
5542    rsrcSetList->list.count = elementCnt;
5543    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5544    rsrcSetList->list.array = NULLP;
5545    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5546    if(!rsrcSetList->list.array)
5547    {
5548       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5549       return RFAILED;
5550    }
5551
5552    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5553    {
5554       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5555       if(!rsrcSetList->list.array[rSetIdx])
5556       {
5557          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5558          return RFAILED;
5559       }
5560    }
5561
5562    rSetIdx = 0;
5563    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5564
5565    /* Fill Resource Id list in resource set */
5566    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5567    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5568          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5569    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5570    {
5571       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5572       return RFAILED;
5573    }
5574
5575    elementCnt = 1;
5576    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5577    rsrcIdList->list.count = elementCnt;
5578    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5579    rsrcIdList->list.array = NULLP;
5580    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5581    if(!rsrcIdList->list.array)
5582    {
5583       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5584       return RFAILED;
5585    }
5586
5587    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5588    {
5589       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5590       if(!rsrcIdList->list.array[rsrcIdx])
5591       {
5592          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5593          return RFAILED;
5594       }
5595    }
5596
5597    rsrcIdx = 0;
5598    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5599
5600    /* Fill resource type */
5601    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5602                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5603
5604    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5605    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5606          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5607    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5608    {
5609       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5610       return RFAILED;
5611    }
5612    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5613       = APERIODIC_SRS_RESRC_TRIGGER;
5614
5615    /* TODO : Fill values for below IEs as expected by Viavi */
5616    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5617    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5618
5619
5620    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5621    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5622    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5623    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5624    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5625
5626    return ROK;
5627 }
5628
5629 /*******************************************************************
5630  *
5631  * @brief Builds BWP UL dedicated SRS Config
5632  *
5633  * @details
5634  *
5635  *    Function : BuildBWPUlDedSrsCfg
5636  *
5637  *    Functionality: Builds BWP UL dedicated SRS Config
5638  *
5639  * @params[in] SRS Config 
5640  * @return ROK     - success
5641  *         RFAILED - failure
5642  *
5643  * ****************************************************************/
5644 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5645 {
5646    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5647    srsCfg->srs_ResourceSetToAddModList = NULLP;
5648    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5649          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5650    if(!srsCfg->srs_ResourceSetToAddModList)
5651    {
5652       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5653       return RFAILED;
5654    }
5655    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5656    {
5657       return RFAILED;
5658    }
5659
5660    srsCfg->srs_ResourceToReleaseList = NULLP;
5661
5662    /* Resource to Add/Modify list */
5663    srsCfg->srs_ResourceToAddModList = NULLP;
5664    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5665          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5666    if(!srsCfg->srs_ResourceToAddModList)
5667    {
5668       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5669       return RFAILED;
5670    }
5671
5672    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5673    {
5674       return RFAILED;
5675    }
5676    srsCfg->tpc_Accumulation = NULLP;
5677
5678    return ROK;
5679 }
5680
5681
5682
5683 /*******************************************************************
5684  *
5685  * @brief Builds Pusch Serving cell Config
5686  *
5687  * @details
5688  *
5689  *    Function : BuildPuschSrvCellCfg
5690  *
5691  *    Functionality: Builds Pusch Serving cell Config
5692  *
5693  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5694  *
5695  * @return ROK     - success
5696  *         RFAILED - failure
5697  *
5698  * ****************************************************************/
5699 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5700 {
5701    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5702    puschCfg->choice.setup = NULLP;
5703    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5704    if(!puschCfg->choice.setup)
5705    {
5706       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5707       return RFAILED;
5708    }
5709
5710    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5711    puschCfg->choice.setup->rateMatching = NULLP;
5712    puschCfg->choice.setup->xOverhead = NULLP;
5713    puschCfg->choice.setup->ext1 = NULLP;
5714
5715    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5716    if(!puschCfg->choice.setup->ext1)
5717    {
5718       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5719       return RFAILED;
5720    }
5721
5722    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5723    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5724    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5725    {
5726       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5727       return RFAILED;
5728    }
5729    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5730
5731    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5732    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5733    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5734    {
5735       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5736       return RFAILED;
5737    }
5738    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5739
5740    return ROK;
5741 }
5742
5743 /*******************************************************************
5744  *
5745  * @brief Builds inital UL BWP
5746  *
5747  * @details
5748  *
5749  *    Function : BuildInitialUlBWP
5750  *
5751  *    Functionality: Builds initial UL BWP
5752  *
5753  * @params[in] BWP_UplinkDedicated_t *ulBwp
5754  * @return ROK     - success
5755  *         RFAILED - failure
5756  *
5757  * ****************************************************************/
5758 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5759 {
5760    PucchCfg *pucchCfg = NULLP;
5761    PuschCfg *puschCfg = NULLP;
5762
5763    if(initUlBwp)
5764    {
5765       if(initUlBwp->pucchPresent)
5766          pucchCfg = &initUlBwp->pucchCfg;
5767       if(initUlBwp->puschPresent)
5768          puschCfg = &initUlBwp->puschCfg;
5769    }
5770
5771    ulBwp->pucch_Config = NULLP;
5772    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5773    if(!ulBwp->pucch_Config)
5774    {
5775       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5776       return RFAILED;
5777    }
5778
5779    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5780    ulBwp->pucch_Config->choice.setup = NULLP;
5781    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5782    if(!ulBwp->pucch_Config->choice.setup)
5783    {
5784       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5785       return RFAILED;
5786    }
5787
5788    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5789    {
5790       return RFAILED;
5791    }
5792
5793    /* Fill BWP UL dedicated PUSCH config */
5794    ulBwp->pusch_Config = NULLP;
5795    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5796    if(!ulBwp->pusch_Config)
5797    {
5798       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5799       return RFAILED;
5800    }
5801
5802    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5803    ulBwp->pusch_Config->choice.setup = NULLP;
5804    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5805    if(!ulBwp->pusch_Config->choice.setup)
5806    {
5807       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5808       return RFAILED;
5809    }
5810
5811    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5812    {
5813       return RFAILED;
5814    }
5815
5816    ulBwp->configuredGrantConfig = NULLP;
5817
5818    /* Fill BPW UL dedicated SRS config */
5819    ulBwp->srs_Config = NULLP;
5820    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5821    if(!ulBwp->srs_Config)
5822    {
5823       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5824       return RFAILED;
5825    }
5826
5827    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5828    ulBwp->srs_Config->choice.setup = NULLP;
5829    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
5830    if(!ulBwp->srs_Config->choice.setup)
5831    {
5832       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5833       return RFAILED;
5834    }
5835
5836    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
5837    {
5838       return RFAILED;   
5839    }
5840
5841    ulBwp->beamFailureRecoveryConfig = NULLP;
5842
5843    return ROK;
5844 }
5845
5846 /*******************************************************************
5847  *
5848  * @brief Builds UL config
5849  * @details
5850  *
5851  *    Function : BuildUlCfg 
5852  *
5853  *    Functionality: Builds UL config in spCellCfgDed
5854  *
5855  * @params[in] UplinkConfig_t *ulCfg
5856  *
5857  * @return ROK     - success
5858  *         RFAILED - failure
5859  *
5860  * ****************************************************************/
5861 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
5862 {
5863    InitialUlBwp *initUlBwp = NULLP;
5864
5865    if(servCellRecfg)
5866    {
5867       initUlBwp = &servCellRecfg->initUlBwp;
5868    }
5869
5870    ulCfg->initialUplinkBWP = NULLP;
5871    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
5872    if(!ulCfg->initialUplinkBWP)
5873    {
5874       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5875       return RFAILED;
5876    }
5877
5878    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
5879    {
5880       return RFAILED;
5881    }
5882
5883    ulCfg->uplinkBWP_ToReleaseList = NULLP;
5884    ulCfg->uplinkBWP_ToAddModList = NULLP;
5885    ulCfg->firstActiveUplinkBWP_Id = NULLP;
5886    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
5887    if(!ulCfg->firstActiveUplinkBWP_Id)
5888    {
5889       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5890       return RFAILED;
5891    }
5892    if(servCellRecfg == NULLP)
5893       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
5894    else
5895       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
5896
5897    ulCfg->pusch_ServingCellConfig = NULLP;
5898    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
5899    if(!ulCfg->pusch_ServingCellConfig)
5900    {
5901       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5902       return RFAILED;
5903    }
5904
5905    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
5906    {
5907       return RFAILED;
5908    }
5909
5910    ulCfg->carrierSwitching = NULLP;
5911    ulCfg->ext1 = NULLP;
5912    return ROK;
5913 }
5914
5915 /*******************************************************************
5916  *
5917  * @brief Builds PDSCH serving cell config
5918  * @details
5919  *
5920  *    Function : BuildPdschSrvCellCfg
5921  *
5922  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
5923  *
5924  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
5925  *
5926  * @return ROK     - success
5927  *         RFAILED - failure
5928  *
5929  * ****************************************************************/
5930 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
5931 {
5932    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
5933    pdschCfg->choice.setup = NULLP;
5934    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
5935    if(!pdschCfg->choice.setup)
5936    {
5937       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5938       return RFAILED;
5939    }
5940
5941    /* Code Block Group Transmission */
5942    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5943    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
5944    {
5945       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
5946       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
5947       {
5948          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5949          return RFAILED;
5950       }
5951
5952       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
5953       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
5954       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
5955       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
5956       {
5957          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5958          return RFAILED;
5959       }
5960
5961       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
5962          *(pdschServCellDb->maxCodeBlkGrpPerTb);
5963       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
5964          *(pdschServCellDb->codeBlkGrpFlushInd);
5965    }
5966
5967    /* xOverhead */
5968    pdschCfg->choice.setup->xOverhead = NULLP;
5969    if(pdschServCellDb && pdschServCellDb->xOverhead)
5970    {
5971       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
5972       if(pdschCfg->choice.setup->xOverhead == NULLP)
5973       {
5974          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5975          return RFAILED;
5976       }
5977       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
5978    }
5979
5980    /* Number of HARQ processes */
5981    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
5982    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
5983    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
5984    {
5985       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5986       return RFAILED;
5987    }
5988
5989    if(pdschServCellDb == NULLP)
5990    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
5991    else
5992    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
5993
5994    pdschCfg->choice.setup->pucch_Cell = NULLP;
5995
5996    /* Extension */
5997    pdschCfg->choice.setup->ext1 = NULLP;
5998    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
5999    {
6000       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6001       if(pdschCfg->choice.setup->ext1 == NULLP)
6002       {
6003          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6004          return RFAILED;
6005       }
6006
6007       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6008       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6009       {
6010          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6011          return RFAILED;
6012       }
6013       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6014    }
6015
6016    return ROK;
6017 }
6018
6019 /*******************************************************************
6020  *
6021  * @brief Builds CSI Meas config
6022  * @details
6023  *
6024  *    Function : BuildCsiMeasCfg 
6025  *
6026  *    Functionality: Builds CSI Meas config in spCellCfgDed
6027  *
6028  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6029  *
6030  * @return ROK     - success
6031  *         RFAILED - failure
6032  *
6033  * ****************************************************************/
6034 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6035 {
6036
6037    return ROK;
6038 }
6039
6040 /*******************************************************************
6041  *
6042  * @brief Builds DL BWP to add/modify list
6043  * @details
6044  *
6045  *    Function : BuildDlBwpToAddModList
6046  *
6047  *    Functionality: Builds DL BWP to add/modify list
6048  *
6049  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6050  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6051  *
6052  * @return ROK     - success
6053  *         RFAILED - failure
6054  *
6055  * ****************************************************************/ 
6056 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6057 {
6058    uint8_t elementCnt, idx;
6059
6060    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6061    dlBwpAddModList->list.count = elementCnt;
6062    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6063    dlBwpAddModList->list.array = NULLP;
6064    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6065    if(dlBwpAddModList->list.array == NULLP)
6066    {
6067       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6068       return RFAILED;
6069    }
6070
6071    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6072    {
6073       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6074       if(dlBwpAddModList->list.array[idx] == NULLP)
6075       {
6076          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6077          return RFAILED;
6078       }
6079    }
6080
6081    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6082    {
6083       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6084       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6085       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6086    }
6087    return ROK;
6088 }
6089
6090 /*******************************************************************
6091  *
6092  * @brief Builds Spcell config dedicated
6093  * @details
6094  *
6095  *    Function : BuildSpCellCfgDed
6096  *
6097  *    Functionality: Builds sp cell config dedicated in spCellCfg
6098  *
6099  * @params[in] ServingCellConfig_t srvCellCfg
6100  *
6101  * @return ROK     - success
6102  *         RFAILED - failure
6103  *
6104  * ****************************************************************/
6105 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6106 {
6107    ServCellRecfgInfo *servCellRecfg = NULLP;
6108    InitialDlBwp *initDlBwp = NULLP;
6109    PdschServCellCfg *pdschServCellDb = NULLP;
6110
6111    if(ueCb)
6112    {
6113       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6114       initDlBwp = &servCellRecfg->initDlBwp;
6115       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6116    }
6117
6118    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6119
6120    srvCellCfg->initialDownlinkBWP = NULLP;
6121    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6122    if(!srvCellCfg->initialDownlinkBWP)
6123    {
6124       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6125       return RFAILED;
6126    }
6127
6128    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6129    {
6130       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6131       return RFAILED;
6132    }
6133
6134    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6135
6136    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6137    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6138    {
6139       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6140       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6141       {
6142          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6143          return RFAILED;
6144       }
6145
6146       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6147       {
6148          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6149          return RFAILED;
6150       }
6151    }
6152
6153    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6154    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6155    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6156    {
6157       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6158       return RFAILED;
6159    }
6160    if(ueCb == NULLP)
6161       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6162    else
6163       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6164
6165    srvCellCfg->bwp_InactivityTimer = NULLP;
6166
6167    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6168    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6169    if(!srvCellCfg->defaultDownlinkBWP_Id)
6170    {
6171       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6172       return RFAILED;
6173    }
6174    if(ueCb == NULLP)
6175       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6176    else
6177       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6178
6179    srvCellCfg->uplinkConfig = NULLP;
6180    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6181    if(!srvCellCfg->uplinkConfig)
6182    {
6183       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6184       return RFAILED;
6185    }
6186
6187    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6188    {
6189       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6190       return RFAILED;
6191    }
6192    srvCellCfg->supplementaryUplink = NULLP;
6193    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6194
6195    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6196    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6197    if(!srvCellCfg->pdsch_ServingCellConfig)
6198    {
6199       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6200       return RFAILED;
6201    }
6202
6203    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6204    {
6205       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6206       return RFAILED;
6207    }
6208
6209    srvCellCfg->csi_MeasConfig = NULLP;
6210 #if 0
6211    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6212       if(!srvCellCfg->csi_MeasConfig)
6213       {
6214          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6215          return RFAILED;
6216       }
6217
6218    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6219    {
6220       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6221       return RFAILED;
6222    }
6223 #endif
6224    srvCellCfg->sCellDeactivationTimer = NULLP;
6225    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6226    srvCellCfg->tag_Id = TAG_ID;
6227    srvCellCfg->dummy = NULLP;
6228    srvCellCfg->pathlossReferenceLinking = NULLP;
6229    srvCellCfg->servingCellMO = NULLP;
6230    srvCellCfg->ext1 = NULLP;
6231
6232    return ROK;
6233 }
6234
6235 /*******************************************************************
6236  *
6237  * @brief Fills SCS specific carrier list in DL frequency info
6238  *
6239  * @details
6240  *
6241  *    Function : BuildScsSpecificCarrierListDl
6242  *
6243  *    Functionality: Fills SCS specific carrier list in DL frequency info
6244  *
6245  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6246  *
6247  * @return ROK     - success
6248  *         RFAILED - failure
6249  *
6250  * ****************************************************************/
6251 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6252 {
6253    uint8_t elementCnt = 0, listIdx = 0;
6254    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6255
6256    elementCnt = ODU_VALUE_ONE;
6257    scsCarrierList->list.count = elementCnt;
6258    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6259
6260    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6261    if(!scsCarrierList->list.array)
6262    {
6263       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6264          in BuildScsSpecificCarrierListDl()");
6265       return RFAILED;
6266    }
6267
6268    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6269    {
6270       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6271       if(!scsCarrierList->list.array[listIdx])
6272       {    
6273          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6274             element in BuildScsSpecificCarrierListDl()");
6275          return RFAILED;
6276       }    
6277    }
6278
6279    listIdx = 0;
6280    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6281    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6282    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6283
6284    return ROK;
6285 }
6286
6287 /*******************************************************************
6288  *
6289  * @brief Fills DL frequency info in DL config common
6290  *
6291  * @details
6292  *
6293  *    Function : BuildFreqInfoDl
6294  *
6295  *    Functionality: Fills DL frequency info in DL config common
6296  *
6297  * @params[in] Pointer to DownlinkConfigCommon_t
6298  *
6299  * @return ROK     - success
6300  *         RFAILED - failure
6301  *
6302  * ****************************************************************/
6303 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6304 {
6305    uint8_t freqBandIdx = 0, elementCnt = 0;
6306    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6307
6308    /* TODO : Fill SSB Absolute Frequency */
6309    /*
6310       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6311       if(!frequencyInfoDL->absoluteFrequencySSB)
6312       {
6313       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6314       return RFAILED;
6315       }
6316       frequencyInfoDL->absoluteFrequencySSB = ?;
6317       */
6318
6319    /* NR Multi Frequency Band List */
6320    elementCnt = ODU_VALUE_ONE;
6321    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6322    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6323
6324    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6325    if(!frequencyInfoDL->frequencyBandList.list.array)
6326    {
6327       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6328       return RFAILED;
6329    }
6330
6331    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6332    {
6333       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6334       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6335       {
6336          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6337          return RFAILED;
6338       }
6339    }
6340
6341    freqBandIdx = 0;
6342    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6343
6344    /* TODO : Absolute Frequency to Point A */
6345    //frequencyInfoDL->absoluteFrequencyPointA
6346
6347    /* Subcarrier Spacing specifc carrier List */
6348    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6349    {
6350       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6351       return RFAILED;
6352    }
6353
6354    return ROK;
6355
6356 }
6357
6358 /*******************************************************************
6359  *
6360  * @brief Fills DL config common in Serving cell config common
6361  *
6362  * @details
6363  *
6364  *    Function : BuildDlConfigCommon
6365  *
6366  *    Functionality: Fills DL config common in Serving cell config common
6367  *
6368  * @params[in] Pointer to DownlinkConfigCommon_t
6369  *
6370  * @return ROK     - success
6371  *         RFAILED - failure
6372  *
6373  * ****************************************************************/
6374 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6375 {
6376    /* DL Frequency Info */
6377    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6378    if(!dlCfgCommon->frequencyInfoDL)
6379    {
6380       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6381       return RFAILED;
6382    }
6383    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6384    {
6385       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6386       return RFAILED;
6387    }
6388
6389    /* DL BWP config common */
6390    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6391    if(!dlCfgCommon->initialDownlinkBWP)
6392    {
6393       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6394       return RFAILED;
6395    }
6396    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6397    {
6398       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6399       return RFAILED;
6400    }
6401
6402    return ROK;
6403 }
6404
6405 /*******************************************************************
6406  *
6407  * @brief Fills SCS specific carrier list in UL frequency Info
6408  *
6409  * @details
6410  *
6411  *    Function : BuildScsSpecificCarrierListUl
6412  *
6413  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6414  *
6415  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6416  *
6417  * @return ROK     - success
6418  *         RFAILED - failure
6419  *
6420  * ****************************************************************/
6421 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6422 {
6423    uint8_t elementCnt = 0, listIdx = 0; 
6424    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
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 : SCS Specific Carrier list memory allocation failed");
6434       return RFAILED;
6435    }
6436
6437    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6438    {
6439       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6440       if(!scsCarrierList->list.array[listIdx])
6441       {    
6442          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6443          return RFAILED;
6444       }    
6445    }
6446    listIdx = 0; 
6447    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6448    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6449    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6450
6451    return ROK;
6452 }
6453
6454 /*******************************************************************
6455  *
6456  * @brief Fills frequency info in UL config common
6457  *
6458  * @details
6459  *
6460  *    Function : BuildFreqInfoUl
6461  *
6462  *    Functionality: Fills frequency info in UL config common
6463  *
6464  * @params[in] Pointer to FrequencyInfoUL_t
6465  *
6466  * @return ROK     - success
6467  *         RFAILED - failure
6468  *
6469  * ****************************************************************/
6470 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6471 {
6472    uint8_t elementCnt = 0, listIdx= 0;
6473    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6474
6475    /* NR Multi Frequency Band List */
6476    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6477    if(!frequencyInfoUL->frequencyBandList)
6478    {
6479       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6480       return RFAILED;
6481    }
6482
6483    elementCnt = ODU_VALUE_ONE;
6484    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6485    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6486
6487    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6488    if(!frequencyInfoUL->frequencyBandList->list.array)
6489    {
6490       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6491       return RFAILED;
6492    }
6493
6494    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6495    {
6496       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6497       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6498       {
6499          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6500          return RFAILED;
6501       }
6502    }
6503
6504    listIdx = 0;
6505    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6506
6507    /* TODO : Fill Absolute frequency point A */
6508    /*
6509       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6510       if(!frequencyInfoUL->absoluteFrequencyPointA)
6511       {
6512       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6513       return RFAILED;
6514       }
6515     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6516     */
6517
6518    /* Subcarrier Spacing specifc carrier */
6519    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6520    {
6521       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6522       return RFAILED;
6523    }
6524
6525    /* P-MAX */
6526    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6527    if(!frequencyInfoUL->p_Max)
6528    {
6529       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6530       return RFAILED;
6531    }
6532    *frequencyInfoUL->p_Max = ulCfg.pMax;
6533
6534    return ROK;
6535 }
6536
6537 /*******************************************************************
6538  *
6539  * @brief Fills UL config common in Serving cell config common
6540  *
6541  * @details
6542  *
6543  *    Function : BuildUlConfigCommon
6544  *
6545  *    Functionality: Fills UL config common in Serving cell config common
6546  *
6547  * @params[in] Pointer to UplinkConfigCommon_t
6548  *
6549  * @return ROK     - success
6550  *         RFAILED - failure
6551  *
6552  * ****************************************************************/
6553 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6554 {
6555    /* UL Frequency Info */
6556    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6557    if(!ulCfgCommon->frequencyInfoUL)
6558    {
6559       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6560       return RFAILED;
6561    }
6562
6563    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6564    {
6565       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6566       return RFAILED;
6567    }
6568
6569    /* UL BWP common */
6570    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6571    if(!ulCfgCommon->initialUplinkBWP)
6572    {
6573       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6574       return RFAILED;
6575    }
6576
6577    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6578    {
6579       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6580       return RFAILED;
6581    }
6582
6583    /* Time Alignment timer */
6584    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6585
6586    return ROK;
6587 }
6588
6589 /*******************************************************************
6590  *
6591  * @brief Fills SSB position in burst in SP cell config common
6592  *
6593  * @details
6594  *
6595  *    Function : BuildSsbPosInBurst
6596  *
6597  *    Functionality: 
6598  *       Fills SSB position in burst in SP cell config common
6599  *
6600  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6601  *
6602  * @return ROK     - success
6603  *         RFAILED - failure
6604  *
6605  * ****************************************************************/
6606 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6607 {
6608    uint8_t bitStringSizeInBytes = 0;
6609
6610    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6611
6612    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6613    bitStringSizeInBytes = 1;
6614    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6615
6616    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6617    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6618    {
6619       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6620       return RFAILED;
6621    }
6622
6623    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6624                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6625    {
6626       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6627       return RFAILED;
6628    }
6629
6630    return ROK;
6631 }
6632
6633 /*******************************************************************
6634  *
6635  * @brief Fills SP cell config common in Reconfig with Sync
6636  *
6637  * @details
6638  *
6639  *    Function : BuildSpCellConfigCommon
6640  *
6641  *    Functionality: Fills SP cell config common in Reconfig with Sync
6642  *
6643  * @params[in] Pointer to ServingCellConfigCommon_t
6644  *
6645  * @return ROK     - success
6646  *         RFAILED - failure
6647  *
6648  * ****************************************************************/
6649 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6650 {
6651    /* Physical Cell Identity */
6652    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6653    if(!spCellConfigCommon->physCellId)
6654    {
6655       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6656       return RFAILED;
6657    } 
6658    *(spCellConfigCommon->physCellId) = NR_PCI;
6659
6660    /* Downlink Config Common */
6661    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6662    if(!spCellConfigCommon->downlinkConfigCommon)
6663    {
6664       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6665       return RFAILED;
6666    }
6667    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6668    {
6669       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6670       return RFAILED;
6671    }
6672
6673    /* Uplinlink Config Common */
6674    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6675    if(!spCellConfigCommon->uplinkConfigCommon)
6676    {
6677       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6678       return RFAILED;
6679    }
6680    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6681    {
6682       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6683       return RFAILED;
6684    }
6685
6686    /* Timing Advance offset */
6687    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6688    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6689    {
6690       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6691       return RFAILED;
6692    }
6693    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6694
6695    /* SSB Position In Burst */
6696    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6697    if(!spCellConfigCommon->ssb_PositionsInBurst)
6698    {
6699       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6700       return RFAILED;
6701    }
6702    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6703    {
6704       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6705       return RFAILED;
6706    }
6707
6708    /* SSB Periodicity in Serving cell */
6709    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6710    if(!spCellConfigCommon->ssb_periodicityServingCell)
6711    {
6712       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6713          BuildSpCellConfigCommon()");
6714       return RFAILED;
6715    }
6716    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6717       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6718
6719    /* DMRS Type A position */
6720    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6721
6722    /* SSB subcarrier spacing */
6723    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6724    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6725    {
6726       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6727       return RFAILED;
6728    }
6729    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6730
6731    /* TDD UL-DL configuration common */
6732    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6733    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6734    {
6735       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6736       return RFAILED;
6737    }
6738    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6739    {
6740       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6741       return RFAILED;
6742    }
6743
6744    /* SS PBCH Block Power */
6745    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6746
6747    return ROK;
6748 }
6749
6750 /*******************************************************************
6751  *
6752  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
6753  *
6754  * @details
6755  *
6756  *    Function : BuildRecfgWithSync
6757  *
6758  *    Functionality: 
6759  *       Fills dedicated RACH configuration in Reconfiguration with sync
6760  *
6761  * @params[in] DU UE CB
6762  *             Pointer to Rach config dedicated struct
6763  *
6764  * @return ROK     - success
6765  *         RFAILED - failure
6766  *
6767  * ****************************************************************/
6768 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
6769 {
6770    uint8_t elementCnt = 0, listIdx = 0;
6771    CFRA_t *cfra = NULLP;
6772    struct CFRA__resources__ssb *ssbResource = NULLP;
6773    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
6774
6775    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
6776
6777    /* Uplink */
6778    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
6779    if(!rachCfgDed->choice.uplink)
6780    {
6781       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
6782       return RFAILED;
6783    }
6784
6785    /* CFRA : Contention free Random Access */
6786    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
6787    if(!rachCfgDed->choice.uplink->cfra)
6788    {
6789       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
6790       return RFAILED;
6791    }
6792    cfra = rachCfgDed->choice.uplink->cfra;
6793
6794    /* CFRA occassions */
6795    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
6796    if(!cfra->occasions)
6797    {
6798       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
6799       return RFAILED;
6800    }
6801
6802    /* CFRA occassions : RACH generic configuration */
6803    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
6804    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
6805    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
6806    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
6807    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
6808    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
6809    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
6810    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
6811
6812    /* CFRA occassions : SSB per RACH occasion */
6813    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
6814    if(!cfra->occasions->ssb_perRACH_Occasion)
6815    {
6816       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
6817       return RFAILED;
6818    }
6819    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
6820
6821    /* CFRA resource */
6822    cfra->resources.present = CFRA__resources_PR_ssb;
6823
6824    /* CFRA resource : SSB */
6825    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
6826    if(!cfra->resources.choice.ssb)
6827    {
6828       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
6829       return RFAILED;
6830    }
6831    ssbResource = cfra->resources.choice.ssb;
6832
6833    /* CFRA SSB resource list */
6834    elementCnt = ueCb->cfraResource.numSsb;
6835    ssbResource->ssb_ResourceList.list.count = elementCnt;
6836    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
6837
6838    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
6839    if(!ssbResource->ssb_ResourceList.list.array)
6840    {
6841       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
6842       return RFAILED;
6843    }
6844
6845    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6846    {
6847       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
6848       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
6849       {
6850          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
6851          return RFAILED;
6852       }
6853       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
6854       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
6855    }
6856
6857    return ROK;
6858 }
6859
6860 /*******************************************************************
6861  *
6862  * @brief Fills reconfiguration with sync in SP cell config
6863  *
6864  * @details
6865  *
6866  *    Function : BuildRecfgWithSync
6867  *
6868  *    Functionality: Fills reconfiguration with sync in SP cell config
6869  *
6870  * @params[in] DU UE CB
6871  *             Pointer to ReconfigurationWithSync_t
6872  *
6873  * @return ROK     - success
6874  *         RFAILED - failure
6875  *
6876  * ****************************************************************/
6877 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
6878 {
6879    /* SP Cell Config Common */  
6880    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
6881    if(!recfgWithSync->spCellConfigCommon)
6882    {
6883       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
6884       return RFAILED;
6885    }
6886
6887    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
6888    {
6889       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
6890       return RFAILED;
6891    }
6892
6893    /* New UE Identity */
6894    recfgWithSync->newUE_Identity = ueCb->crnti;
6895
6896    /* T304 timer */
6897    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
6898
6899    /* RACH configuration dedicated */
6900    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
6901    if(!recfgWithSync->rach_ConfigDedicated)
6902    {
6903       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
6904       return RFAILED;
6905    }
6906
6907    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
6908    {
6909       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
6910       return RFAILED;
6911    }
6912
6913    return ROK;
6914 }
6915
6916 /*******************************************************************
6917  *
6918  * @brief Builds Spcell config 
6919  *
6920  * @details
6921  *
6922  *    Function : BuildSpCellCfg 
6923  *
6924  *    Functionality: Builds sp cell config in DuToCuRrcContainer
6925  *
6926  * @params[in] SpCellConfig_t spCellCfg
6927  *
6928  * @return ROK     - success
6929  *         RFAILED - failure
6930  *
6931  * ****************************************************************/
6932 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
6933 {
6934    spCellCfg->servCellIndex = NULLP;
6935    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
6936    if(!spCellCfg->servCellIndex)
6937    {
6938       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6939       return RFAILED;
6940    }
6941
6942    if(ueCb == NULLP)
6943       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
6944    else
6945       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
6946
6947    spCellCfg->reconfigurationWithSync = NULLP;
6948    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
6949    {
6950       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
6951       if(!spCellCfg->reconfigurationWithSync)
6952       {
6953          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6954          return RFAILED;
6955       }
6956
6957       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
6958       {
6959          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
6960          return RFAILED;
6961       }
6962    }
6963
6964    spCellCfg->rlf_TimersAndConstants = NULLP;
6965    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
6966
6967    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
6968    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
6969    {
6970       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6971       return RFAILED;
6972    }
6973    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
6974
6975    spCellCfg->spCellConfigDedicated = NULLP;
6976    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
6977    if(!spCellCfg->spCellConfigDedicated)
6978    {
6979       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6980       return RFAILED;
6981    }
6982    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
6983    {
6984       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
6985       return RFAILED;
6986    }
6987
6988    return ROK;
6989 }
6990
6991 /*******************************************************************
6992  *
6993  * @brief Builds Phy cell group config 
6994  *
6995  * @details
6996  *
6997  *    Function : BuildPhyCellGrpCfg 
6998  *
6999  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7000  *
7001  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7002  *
7003  * @return ROK     - success
7004  *         RFAILED - failure
7005  *
7006  * ****************************************************************/
7007 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7008 {
7009    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7010    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7011
7012    phyCellGrpCfg->p_NR_FR1 = NULLP;
7013    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7014    if(!phyCellGrpCfg->p_NR_FR1)
7015    {
7016       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7017       return RFAILED;
7018    }
7019
7020    if(ueCb == NULLP)
7021    {
7022       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7023       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7024    }
7025    else
7026    {
7027       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7028       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7029    }
7030
7031    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7032    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7033    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7034    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7035    phyCellGrpCfg->cs_RNTI = NULLP;
7036    phyCellGrpCfg->ext1 = NULLP;
7037    phyCellGrpCfg->ext2 = NULLP;
7038
7039    return ROK;
7040 }
7041 #ifdef NR_DRX
7042 /*******************************************************************
7043  *
7044  * @brief fill long cycle offset value of drx
7045  *
7046  * @details
7047  *
7048  *    Function : fillLongCycleOffsetValFromDuCb 
7049  *
7050  *    Functionality: fill long cycle offset value of drx
7051  *
7052  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7053  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7054  *
7055  * @return ROK     - success
7056  *         RFAILED - failure
7057  *
7058  * ****************************************************************/
7059 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7060 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7061 {
7062    
7063    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7064    switch(drx_LongCycleStartOffset->present)
7065    {
7066       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7067          {
7068             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7069             break;
7070          }
7071       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7072          {
7073             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7074             break;
7075          }
7076       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7077          {
7078             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7079             break;
7080          }
7081       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7082          {
7083             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7084             break;
7085          }
7086       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7087          {
7088             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7089             break;
7090          }
7091       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7092          {
7093             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7094             break;
7095          }
7096       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7097          {
7098             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7099             break;
7100          }
7101       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7102          {
7103             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7104             break;
7105          }
7106       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7107          {
7108             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7109             break;
7110          }
7111       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7112          {
7113             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7114             break;
7115          }
7116       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7117          {
7118             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7119             break;
7120          }
7121       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7122          {
7123             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7124             break;
7125          }
7126       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7127          {
7128             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7129             break;
7130          }
7131       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7132          {
7133             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7134             break;
7135          }
7136       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7137          {
7138             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7139             break;
7140          }
7141       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7142          {
7143             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7144             break;
7145          }
7146       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7147          {
7148             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7149             break;
7150          }
7151       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7152          {
7153             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7154             break;
7155          }
7156       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7157          {
7158             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7159             break;
7160          }
7161       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7162          {
7163             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7164             break;
7165          }
7166       default :
7167          break;
7168    }
7169 }
7170 /*******************************************************************
7171  *
7172  * @brief Builds drx config IE 
7173  *
7174  * @details
7175  *
7176  *    Function : BuildDrxConfigRrc 
7177  *
7178  *    Functionality: Build drx config in MacCellGrpCfg 
7179  *
7180  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7181  *
7182  * @return ROK     - success
7183  *         RFAILED - failure
7184  *
7185  * ****************************************************************/
7186 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7187 {
7188    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7189    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7190    if(!drxCfg->choice.setup)
7191    {
7192       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7193       return RFAILED;
7194    }
7195    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7196    {
7197       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7198       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7199       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7200    }
7201    else
7202    {
7203       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7204       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7205       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7206    }
7207    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7208    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7209    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7210    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7211    drxRetransmissionTimerDl);
7212    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7213    drxRetransmissionTimerUl);
7214    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7215    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7216    
7217    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7218    {
7219       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7220       if(drxCfg->choice.setup->shortDRX)
7221       {
7222          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7223          shortDrx.drxShortCycle);
7224          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7225       }
7226       else
7227       {
7228          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7229          return RFAILED;
7230       }
7231    }
7232    return ROK;
7233 }
7234 #endif
7235 /*******************************************************************
7236  *
7237  * @brief Builds Mac cell group config 
7238  *
7239  * @details
7240  *
7241  *    Function : BuildMacCellGrpCfg 
7242  *
7243  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7244  *
7245  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7246  *
7247  * @return ROK     - success
7248  *         RFAILED - failure
7249  *
7250  * ****************************************************************/
7251 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7252 {
7253    macCellGrpCfg->drx_ConfigRrc = NULLP;
7254 #ifdef NR_DRX   
7255    if(ueCb)
7256    {
7257       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7258       if(!macCellGrpCfg->drx_ConfigRrc)
7259       {
7260          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7261          return RFAILED;
7262       }
7263       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7264       {
7265          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7266          return RFAILED;
7267       }
7268    }
7269 #endif
7270    macCellGrpCfg->schedulingRequestConfig = NULLP;
7271    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7272    if(!macCellGrpCfg->schedulingRequestConfig)
7273    {
7274       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7275       return RFAILED;
7276    }
7277
7278    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7279    {
7280       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7281       return RFAILED;
7282    }
7283
7284    macCellGrpCfg->bsr_Config = NULLP;
7285    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7286    if(!macCellGrpCfg->bsr_Config)
7287    {
7288       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7289       return RFAILED;
7290    }
7291
7292    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7293    {
7294       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7295       return RFAILED;
7296    }
7297
7298    macCellGrpCfg->tag_Config = NULLP;
7299    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7300    if(!macCellGrpCfg->tag_Config)
7301    {
7302       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7303       return RFAILED;
7304    }
7305
7306    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7307    {
7308       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7309       return RFAILED;
7310    }
7311
7312    macCellGrpCfg->phr_Config = NULLP;
7313    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7314    if(!macCellGrpCfg->phr_Config)
7315    {
7316       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7317       return RFAILED;
7318    }
7319
7320    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7321    {
7322       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7323       return RFAILED;
7324    }
7325
7326    macCellGrpCfg->skipUplinkTxDynamic = false;
7327    macCellGrpCfg->ext1 = NULLP;
7328
7329    return ROK;
7330 }
7331 /*******************************************************************
7332  *
7333  * @brief Frees memeory allocated for SearchSpcToAddModList
7334  *
7335  * @details
7336  *
7337  *    Function : FreeSearchSpcToAddModList
7338  *
7339  *    Functionality: Deallocating memory of SearchSpcToAddModList
7340  *
7341  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7342  *
7343  * @return void
7344  *
7345  4221 * ****************************************************************/
7346 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7347 {
7348    uint8_t idx1=0;
7349    uint8_t idx2=0;
7350    struct  SearchSpace *searchSpc=NULLP;
7351
7352    if(searchSpcList->list.array)
7353    {
7354       if(searchSpcList->list.array[idx2])
7355       {
7356          searchSpc = searchSpcList->list.array[idx2];
7357          if(searchSpc->controlResourceSetId)
7358          {
7359             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7360             {
7361                if(searchSpc->monitoringSymbolsWithinSlot)
7362                {
7363                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7364                   {
7365                      if(searchSpc->nrofCandidates)
7366                      {
7367                         if(searchSpc->searchSpaceType)
7368                         {
7369                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7370                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7371                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7372                                     SearchSpace__searchSpaceType));
7373                         }
7374                         DU_FREE(searchSpc->nrofCandidates,
7375                               sizeof(struct SearchSpace__nrofCandidates));
7376                      }
7377                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7378                            searchSpc->monitoringSymbolsWithinSlot->size);
7379                   }
7380                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7381                         sizeof(BIT_STRING_t));
7382                }
7383                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7384                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7385             }
7386             DU_FREE(searchSpc->controlResourceSetId,
7387                   sizeof(ControlResourceSetId_t));
7388          }
7389       }
7390       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7391       {
7392          DU_FREE(searchSpcList->list.array[idx1],
7393                sizeof(struct SearchSpace));
7394       }
7395       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7396    }
7397 }
7398 /*******************************************************************
7399  *
7400  * @brief Frees memory allocated for PdschTimeDomAllocList
7401  *
7402  * @details
7403  *
7404  *    Function : FreePdschTimeDomAllocList
7405  *
7406  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7407  *
7408  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7409  *
7410  * @return void
7411  *
7412  * ****************************************************************/
7413 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7414 {
7415    uint8_t idx1=0;
7416
7417    if(timeDomAllocList->choice.setup)
7418    {
7419       if(timeDomAllocList->choice.setup->list.array)
7420       {
7421          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7422          {
7423             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7424             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7425                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7426          }
7427          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7428                timeDomAllocList->choice.setup->list.size);
7429       }
7430       DU_FREE(timeDomAllocList->choice.setup,\
7431             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7432    }
7433 }
7434 /*******************************************************************
7435  *
7436  * @brief Frees memory allocated for PuschTimeDomAllocList
7437  *
7438  *@details
7439  *
7440  *    Function : FreePuschTimeDomAllocList
7441  *
7442  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7443  *
7444  * @params[in] PUSCH_Config_t *puschCfg
7445  *
7446  * @return void
7447  *
7448  * ****************************************************************/
7449 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7450 {
7451    uint8_t rsrcListIdx=0;
7452    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7453
7454    if(puschCfg->pusch_TimeDomainAllocationList)
7455    {
7456       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7457       if(timeDomAllocList_t->choice.setup)
7458       {
7459          if(timeDomAllocList_t->choice.setup->list.array)
7460          {
7461             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7462             {
7463                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7464                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7465                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7466             }
7467             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7468                   timeDomAllocList_t->choice.setup->list.size);
7469          }
7470          DU_FREE(timeDomAllocList_t->choice.setup, \
7471                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7472       }
7473       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7474       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7475             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7476    }
7477
7478 }
7479
7480 /*******************************************************************
7481  *
7482  * @brief Frees memory allocated for Dedicated PUCCH config
7483  *
7484  * @details
7485  *
7486  *    Function : FreeBWPUlDedPucchCfg
7487  *
7488  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7489  *
7490  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7491  *
7492  * @return void
7493  *
7494  * ****************************************************************/
7495 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7496 {
7497    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7498    PUCCH_Config_t *pucchCfg = NULLP;
7499    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7500    PUCCH_Resource_t *rsrc = NULLP;
7501
7502    if(ulBwpPucchCfg)
7503    {
7504       if(ulBwpPucchCfg->choice.setup)
7505       {
7506          pucchCfg = ulBwpPucchCfg->choice.setup;
7507
7508          //Free resource set list
7509          if(pucchCfg->resourceSetToAddModList)
7510          {
7511             if(pucchCfg->resourceSetToAddModList->list.array)
7512             {
7513                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7514                {
7515                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7516                   if(rsrcSet->resourceList.list.array)
7517                   {
7518                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7519                      {
7520                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7521                      }
7522                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7523                   }
7524                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7525                }
7526                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7527             }
7528             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7529          }
7530
7531          //Free resource list
7532          if(pucchCfg->resourceToAddModList)
7533          {
7534             if(pucchCfg->resourceToAddModList->list.array)
7535             {
7536                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7537                {
7538                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7539                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7540                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7541                }
7542                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7543             }
7544             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7545          }
7546
7547          //PUCCH Format 1
7548          if(pucchCfg->format1)
7549          {
7550             if(pucchCfg->format1->choice.setup)
7551             {
7552                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7553                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7554             }
7555             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7556          }
7557          
7558          //DL DATA TO UL ACK
7559          if(pucchCfg->dl_DataToUL_ACK)
7560          {
7561             if(pucchCfg->dl_DataToUL_ACK->list.array)
7562             {
7563                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7564                {
7565                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7566                }
7567                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7568             }
7569             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7570          }
7571
7572          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7573       }
7574       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7575    }
7576 }
7577
7578 /*******************************************************************
7579  *
7580  * @brief Frees memory allocated for InitialUlBWP
7581  *
7582  * @details
7583  *
7584  *    Function : FreeInitialUlBWP
7585  *
7586  *    Functionality: Deallocating memory of InitialUlBWP
7587  *
7588  * @params[in] BWP_UplinkDedicated_t *ulBwp
7589  *
7590  * @return void
7591  *
7592  * ****************************************************************/
7593 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7594 {
7595    uint8_t  rSetIdx, rsrcIdx;
7596    SRS_Config_t   *srsCfg = NULLP;
7597    PUSCH_Config_t *puschCfg = NULLP;
7598    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7599    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7600    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7601    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7602
7603    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7604
7605    if(ulBwp->pusch_Config)
7606    {
7607       if(ulBwp->pusch_Config->choice.setup)
7608       {
7609          puschCfg=ulBwp->pusch_Config->choice.setup;
7610          if(puschCfg->dataScramblingIdentityPUSCH)
7611          {
7612             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7613             {
7614                FreePuschTimeDomAllocList(puschCfg);
7615                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7616                if(dmrsUlCfg->choice.setup)
7617                {
7618                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7619                   {
7620                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7621                      {
7622                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7623                               sizeof(long));
7624                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7625                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7626                      }
7627                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7628                            sizeof(long));
7629                   }
7630                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7631                }
7632                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7633                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7634             }
7635             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7636          }
7637          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7638       }
7639       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7640
7641       /* Free SRS-Config */
7642       if(ulBwp->srs_Config)
7643       {
7644          if(ulBwp->srs_Config->choice.setup)
7645          {
7646             srsCfg = ulBwp->srs_Config->choice.setup;
7647
7648             /* Free Resource Set to add/mod list */
7649             if(srsCfg->srs_ResourceSetToAddModList)
7650             {
7651                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7652                if(rsrcSetList->list.array)
7653                {
7654                   rSetIdx = 0;
7655
7656                   /* Free SRS resource Id list in this SRS resource set */
7657                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7658                   {
7659                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7660
7661                      if(rsrcIdList->list.array)
7662                      {
7663                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7664                         {
7665                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7666                         }
7667                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7668                      }
7669                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7670                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7671                   }
7672
7673                   /* Free resource type info for this SRS resource set */
7674                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7675                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7676
7677                   /* Free memory for each resource set */
7678                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7679                   {
7680                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7681                   }
7682                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7683                }
7684                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7685                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7686             }
7687
7688             /* Free resource to add/modd list */
7689             if(srsCfg->srs_ResourceToAddModList)
7690             {
7691                resourceList = srsCfg->srs_ResourceToAddModList;
7692                if(resourceList->list.array)
7693                {
7694                   rsrcIdx = 0;
7695                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7696                         sizeof(struct SRS_Resource__transmissionComb__n2));
7697                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7698                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7699
7700                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7701                   {
7702                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7703                   }
7704                   DU_FREE(resourceList->list.array, resourceList->list.size);
7705                }
7706                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7707                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7708             }
7709
7710             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7711          }
7712          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7713       }
7714    }
7715 }       
7716 /*******************************************************************
7717  *
7718  * @brief Frees memory allocated for initialUplinkBWP
7719  *
7720  * @details
7721  *
7722  *    Function : FreeinitialUplinkBWP
7723  *
7724  *    Functionality: Deallocating memory of initialUplinkBWP
7725  *
7726  * @params[in] UplinkConfig_t *ulCfg
7727  *
7728  * @return void
7729  *         
7730  *
7731  * ****************************************************************/
7732 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7733 {
7734    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7735    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7736
7737    if(ulCfg->initialUplinkBWP)
7738    {
7739       ulBwp=ulCfg->initialUplinkBWP;
7740       if(ulCfg->firstActiveUplinkBWP_Id)
7741       {
7742          if(ulCfg->pusch_ServingCellConfig)
7743          {
7744             puschCfg=ulCfg->pusch_ServingCellConfig;
7745             if(puschCfg->choice.setup)
7746             {
7747                if(puschCfg->choice.setup->ext1)
7748                {
7749                   DU_FREE(puschCfg->choice.setup->ext1->\
7750                         processingType2Enabled,sizeof(BOOLEAN_t));
7751                   DU_FREE(puschCfg->choice.setup->ext1->\
7752                         maxMIMO_Layers,sizeof(long));
7753                   DU_FREE(puschCfg->choice.setup->ext1, \
7754                         sizeof(struct PUSCH_ServingCellConfig__ext1));
7755                }
7756                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
7757             }
7758             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
7759          }
7760          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
7761       }
7762       FreeInitialUlBWP(ulBwp);
7763       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
7764    }
7765 }
7766 /*******************************************************************
7767  *
7768  * @brief Frees emmory allocated for BWPDlDedPdschCfg
7769  *
7770  * @details
7771  *
7772  *    Function : FreeBWPDlDedPdschCfg
7773  *
7774  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
7775  *
7776  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7777  *
7778  * @return void
7779  *
7780  *
7781  * ****************************************************************/
7782 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
7783 {
7784    struct PDSCH_Config *pdschCfg=NULLP;
7785    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7786    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7787    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7788
7789    if(dlBwp->pdsch_Config->choice.setup)
7790    {
7791       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7792       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7793       {
7794          if(pdschCfg->pdsch_TimeDomainAllocationList)
7795          {
7796             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7797             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7798             {
7799                prbBndlType=&pdschCfg->prb_BundlingType;
7800                DU_FREE(prbBndlType->choice.staticBundling,\
7801                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
7802                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
7803             }
7804             FreePdschTimeDomAllocList(timeDomAllocList);
7805             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
7806                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
7807          }
7808          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7809          if(dmrsDlCfg->choice.setup)
7810          {
7811             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
7812                   sizeof(long));
7813             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
7814          }
7815          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
7816                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
7817       }
7818       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
7819    }
7820 }
7821 /*******************************************************************
7822  *
7823  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
7824  *
7825  * @details
7826  *
7827  *    Function : FreeBWPDlDedPdcchCfg
7828  *
7829  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
7830  *
7831  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7832  *
7833  * @return void
7834  *         
7835  *
7836  * ****************************************************************/
7837 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
7838 {
7839    uint8_t idx1=0;
7840    uint8_t idx2=0;
7841    struct PDCCH_Config *pdcchCfg=NULLP;
7842    struct ControlResourceSet *controlRSet=NULLP;
7843    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
7844
7845    if(dlBwp->pdcch_Config->choice.setup)
7846    {
7847       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
7848       if(pdcchCfg->controlResourceSetToAddModList)
7849       {
7850          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
7851          if(controlRSetList->list.array)
7852          {
7853             controlRSet = controlRSetList->list.array[idx2];
7854             if(controlRSet)
7855             {
7856                if(controlRSet->frequencyDomainResources.buf)
7857                {
7858                   if(controlRSet->pdcch_DMRS_ScramblingID)
7859                   {
7860                      if(pdcchCfg->searchSpacesToAddModList)
7861                      {
7862                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
7863                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
7864                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
7865                      }
7866                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
7867                   }
7868                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
7869                         controlRSet->frequencyDomainResources.size);
7870                }
7871             }
7872             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
7873             {
7874                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
7875             }
7876             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
7877          }
7878          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
7879                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
7880       }
7881       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
7882    }
7883 }       
7884
7885 /*******************************************************************
7886  *
7887  * @brief Free SCS specific carrier list in DL frequency info
7888  *
7889  * @details
7890  *
7891  *    Function : FreeScsSpecificCarrierListDl
7892  *
7893  *    Functionality: Free SCS specific carrier list in DL frequency info
7894  *
7895  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
7896  *
7897  * @return void
7898  *
7899  * ****************************************************************/
7900 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
7901 {
7902    uint8_t listIdx = 0;
7903
7904    if(!scsCarrierList->list.array)
7905    {
7906       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7907       {
7908          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7909       }
7910       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7911    }
7912 }
7913
7914 /*******************************************************************
7915  *
7916  * @brief Free DL frequency info in DL config common
7917  *
7918  * @details
7919  *
7920  *    Function : FreeFreqInfoDl
7921  *
7922  *    Functionality: Free DL frequency info in DL config common
7923  *
7924  * @params[in] Pointer to DownlinkConfigCommon_t
7925  *
7926  * @return void
7927  *
7928  * ****************************************************************/
7929 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
7930 {
7931    uint8_t freqBandIdx = 0;
7932
7933    /* SSB Absolute Frequency */
7934    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
7935
7936    /* NR Multi Frequency Band List */
7937    if(frequencyInfoDL->frequencyBandList.list.array)
7938    {
7939       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
7940       {
7941          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
7942       }
7943       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
7944    }
7945
7946    /* Subcarrier Spacing specifc carrier List */
7947    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
7948 }
7949
7950 /*******************************************************************
7951  *
7952  * @brief Free DL config common in Serving cell config common
7953  *
7954  * @details
7955  *
7956  *    Function : FreeDlConfigCommon
7957  *
7958  *    Functionality: Free DL config common in Serving cell config common
7959  *
7960  * @params[in] Pointer to DownlinkConfigCommon_t
7961  *
7962  * @return void
7963  *
7964  * ****************************************************************/
7965 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
7966 {
7967    /* DL Frequency Info */
7968    if(dlCfgCommon->frequencyInfoDL)
7969    {
7970       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
7971       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
7972    }
7973
7974    /* DL BWP config common */
7975    if(dlCfgCommon->initialDownlinkBWP)
7976    {
7977       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
7978       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
7979    }
7980 }
7981
7982 /*******************************************************************
7983  *
7984  * @brief Free SCS specific carrier list in UL frequency Info
7985  *
7986  * @details
7987  *
7988  *    Function : FreeScsSpecificCarrierListUl
7989  *
7990  *    Functionality: Free SCS specific carrier list in UL frequency Info
7991  *
7992  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
7993  *
7994  * @return void
7995  *
7996  * ****************************************************************/
7997 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
7998 {
7999    uint8_t listIdx = 0;
8000
8001    if(scsCarrierList->list.array)
8002    {
8003       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8004       {
8005          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8006       }
8007       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8008    }
8009 }
8010
8011 /*******************************************************************
8012  *
8013  * @brief Free frequency info in UL config common
8014  *
8015  * @details
8016  *
8017  *    Function : FreeFreqInfoUl
8018  *
8019  *    Functionality: Free frequency info in UL config common
8020  *
8021  * @params[in] Pointer to FrequencyInfoUL_t
8022  *
8023  * @return void
8024  *
8025  * ****************************************************************/
8026 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8027 {
8028    uint8_t listIdx= 0;
8029
8030    /* NR Multi Frequency Band List */
8031    if(!frequencyInfoUL->frequencyBandList)
8032    {
8033       if(frequencyInfoUL->frequencyBandList->list.array)
8034       {
8035          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8036          {
8037             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8038          }
8039          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8040       }
8041       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8042    }
8043
8044    /* Absolute frequency point A */
8045    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8046
8047    /* Subcarrier Spacing specifc carrier */
8048    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8049
8050    /* P-MAX */
8051    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8052 }
8053
8054 /*******************************************************************
8055  *
8056  * @brief Free UL config common in Serving cell config common
8057  *
8058  * @details
8059  *
8060  *    Function : FreeUlConfigCommon
8061  *
8062  *    Functionality: Free UL config common in Serving cell config common
8063  *
8064  * @params[in] Pointer to UplinkConfigCommon_t
8065  *
8066  * @return void
8067  *
8068  * ****************************************************************/
8069 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8070 {
8071    /* UL Frequency Info */
8072    if(ulCfgCommon->frequencyInfoUL)
8073    {
8074       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8075       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8076    }
8077
8078    /* UL BWP common */
8079    if(ulCfgCommon->initialUplinkBWP)
8080    {
8081       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8082       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8083    }
8084 }
8085
8086 /*******************************************************************
8087  *
8088  * @brief Free SP cell config common in Reconfig with Sync
8089  *
8090  * @details
8091  *
8092  *    Function : FreeSpCellConfigCommon
8093  *
8094  *    Functionality: Free SP cell config common in Reconfig with Sync
8095  *
8096  * @params[in] Pointer to ServingCellConfigCommon_t
8097  *
8098  * @return void
8099  *
8100  * ****************************************************************/
8101 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8102 {
8103    /* Free Physical cell identity */
8104    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8105
8106    /* Free Downlink Config common */
8107    if(spCellConfigCommon->downlinkConfigCommon)
8108    {
8109       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8110       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8111    }
8112
8113    /* Free Uplink Config common */
8114    if(spCellConfigCommon->uplinkConfigCommon)
8115    {
8116       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8117       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8118    }
8119
8120    /* Free Timing Advance offset */
8121    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8122
8123    /* Free SSB Position in Burst */
8124    if(spCellConfigCommon->ssb_PositionsInBurst)
8125    {
8126       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8127          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8128       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8129    }
8130
8131    /* Free SSB Periodicity in Serving cell */
8132    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8133
8134    /* Free SSB subcarrier spacing */
8135    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8136
8137    /* TDD UL-DL configuration common */
8138    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8139 }
8140
8141 /*******************************************************************
8142  *
8143  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8144  *
8145  * @details
8146  *
8147  *    Function : FreeRecfgWithSync
8148  *
8149  *    Functionality:
8150  *       Free dedicated RACH configuration in Reconfiguration with sync
8151  *
8152  * @params[in] Pinter to Rach config dedicated struct
8153  *
8154  * @return void
8155  *
8156  * ****************************************************************/
8157 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8158 {
8159    uint8_t listIdx = 0;
8160    CFRA_t *cfra = NULLP;
8161    struct CFRA__resources__ssb *ssbResource = NULLP;
8162
8163    /* Uplink */
8164    if(rachCfgDed->choice.uplink)
8165    {
8166       /* CFRA : Contention free Random Access */
8167       if(rachCfgDed->choice.uplink->cfra)
8168       {
8169          cfra = rachCfgDed->choice.uplink->cfra;
8170
8171          /* CFRA occassions */
8172          if(cfra->occasions)
8173          {
8174             /* CFRA occassions : SSB per RACH occasion */
8175             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8176             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8177          }
8178
8179          /* CFRA resource */
8180          cfra->resources.present = CFRA__resources_PR_ssb;
8181
8182          /* CFRA resource : SSB */
8183          if(cfra->resources.choice.ssb)
8184          {
8185             ssbResource = cfra->resources.choice.ssb;
8186
8187             /* CFRA SSB resource list */
8188             if(ssbResource->ssb_ResourceList.list.array)
8189             {
8190                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8191                {
8192                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8193                }
8194                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8195             }
8196             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8197          }
8198          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8199       }
8200       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8201    }
8202 }
8203
8204 /*******************************************************************
8205  *
8206  * @brief Frees reconfiguration with sync in SP cell config
8207  *
8208  * @details
8209  *
8210  *    Function : FreeRecfgWithSync
8211  *
8212  *    Functionality: Fress reconfiguration with sync in SP cell config
8213  *
8214  * @params[in] Pointer to ReconfigurationWithSync_t
8215  *
8216  * @return void
8217  *
8218  * ****************************************************************/
8219 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8220 {
8221    /* Free SP Cell config common */
8222    if(recfgWithSync->spCellConfigCommon)
8223    {
8224       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8225       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8226    }
8227
8228    /* Free Dedicated RACH configuration */
8229    if(recfgWithSync->rach_ConfigDedicated)
8230    {
8231       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8232       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8233    }
8234 }
8235
8236 /*******************************************************************
8237  *
8238  * @brief Frees emmory allocated for DUToCURRCContainer 
8239  *
8240  * @details
8241  *
8242  *    Function : FreeMemDuToCuRrcCont
8243  *
8244  *    Functionality: Deallocating memory of DuToCuRrcContainer
8245  *
8246  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8247  *
8248  * @return ROK     - success
8249  *         RFAILED - failure
8250  *
8251  * ****************************************************************/
8252 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8253 {
8254    uint8_t idx=0;
8255    SpCellConfig_t *spCellCfg=NULLP;
8256    ServingCellConfig_t *srvCellCfg=NULLP;
8257    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8258    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8259    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8260    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8261    struct RLC_Config *rlcConfig=NULLP;
8262    struct LogicalChannelConfig *macLcConfig=NULLP;
8263    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8264    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8265    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8266    struct TAG_Config *tagConfig=NULLP;
8267    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8268    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8269    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8270
8271    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8272    if(rlcBearerList)
8273    {
8274       if(rlcBearerList->list.array)
8275       {
8276          for(idx=0; idx<rlcBearerList->list.count; idx++)
8277          {
8278             if(rlcBearerList->list.array[idx])
8279             {  
8280                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8281                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8282                if(rlcConfig)
8283                {
8284                   switch(rlcConfig->present)
8285                   {
8286                      case RLC_Config_PR_NOTHING:
8287                         break;
8288
8289                      case RLC_Config_PR_am:
8290                         {
8291                            if(rlcConfig->choice.am)
8292                            {
8293                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8294                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8295                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8296                            }
8297                            break;
8298                         }
8299                      case RLC_Config_PR_um_Bi_Directional:
8300                         {
8301                            if(rlcConfig->choice.um_Bi_Directional)
8302                            {
8303                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8304                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8305                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8306                            }
8307                            break;
8308                         }
8309                      case RLC_Config_PR_um_Uni_Directional_UL:
8310                         {
8311                            if(rlcConfig->choice.um_Uni_Directional_UL)
8312                            {
8313                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8314                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8315                            }
8316                            break;
8317                         }
8318                      case RLC_Config_PR_um_Uni_Directional_DL:
8319                         {
8320                            if(rlcConfig->choice.um_Uni_Directional_DL )
8321                            {
8322                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8323                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8324                            }
8325                            break;
8326                         }
8327                   }     
8328                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8329                }
8330                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8331                if(macLcConfig)
8332                {
8333                   if(macLcConfig->ul_SpecificParameters)
8334                   {
8335                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8336                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8337                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8338                   }
8339                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8340                }
8341                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8342             }   
8343          }
8344          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8345       }
8346       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8347    }
8348
8349    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8350    if(macCellGrpCfg)
8351    {
8352       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8353
8354       if(drxCfg)
8355       {
8356           switch(drxCfg->present)
8357           {
8358             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8359                break;
8360             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8361             {
8362                if(drxCfg->choice.setup)
8363                {
8364                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8365                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8366                }
8367             }
8368             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8369                break;
8370           }
8371           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8372       }
8373       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8374       if(schedulingRequestConfig)
8375       {
8376          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8377          if(schReqList)
8378          {
8379             if(schReqList->list.array)
8380             {
8381                for(idx=0;idx<schReqList->list.count; idx++)
8382                {
8383                   if(schReqList->list.array[idx])
8384                   {
8385                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8386                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8387                   }
8388                }
8389                DU_FREE(schReqList->list.array, schReqList->list.size);
8390             }
8391             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8392                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8393             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8394       }
8395       if(macCellGrpCfg->bsr_Config)
8396       {
8397          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8398          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8399       }
8400       tagConfig = macCellGrpCfg->tag_Config;
8401       if(tagConfig)
8402       {
8403          tagList = tagConfig->tag_ToAddModList;
8404          if(tagList)
8405          {
8406             if(tagList->list.array)
8407             {
8408                for(idx=0; idx<tagList->list.count; idx++)
8409                {
8410                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8411                }
8412                DU_FREE(tagList->list.array, tagList->list.size);
8413             }
8414             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8415          }
8416          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8417       }
8418
8419       phrConfig = macCellGrpCfg->phr_Config;
8420       if(phrConfig)
8421       {
8422          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8423          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8424       }
8425
8426       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8427    }
8428
8429    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8430    if(phyCellGrpCfg)
8431    {
8432       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8433       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8434    }
8435
8436    spCellCfg = cellGrpCfg->spCellConfig;
8437    if(spCellCfg)
8438    {
8439       /* Free serving cell index */
8440       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8441
8442       /* Free Reconfiguration with sync */
8443       if(spCellCfg->reconfigurationWithSync)
8444       {
8445          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8446          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8447       }
8448
8449       /* Free rlmInSyncOutOfSyncThreshold */
8450       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8451
8452       /* Free SP Cell config dedicated */
8453       if(spCellCfg->spCellConfigDedicated)
8454       {
8455          srvCellCfg = spCellCfg->spCellConfigDedicated;
8456
8457          /* Free TDD UL-DL config dedicated */
8458          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8459
8460          /* Free Initial Downlink BWP */
8461          if(srvCellCfg->initialDownlinkBWP)
8462          {
8463             dlBwp = srvCellCfg->initialDownlinkBWP;
8464
8465             /* Free DL BWP PDCCH Config */
8466             if(dlBwp->pdcch_Config)
8467             {
8468                FreeBWPDlDedPdcchCfg(dlBwp);
8469                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8470             }
8471
8472             /* Free DL BWP PDSCH config */
8473             if(dlBwp->pdsch_Config)
8474             {
8475                FreeBWPDlDedPdschCfg(dlBwp);
8476                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8477             }
8478             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8479          }
8480
8481          /* Free First Active Downlink BWP */
8482          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8483
8484          /* Free Default downlink BWP */
8485          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8486
8487          /* Free Uplink config */
8488          if(srvCellCfg->uplinkConfig)
8489          {
8490             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8491             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8492          }
8493
8494          /* Free PDSCH serving cell config */
8495          if(srvCellCfg->pdsch_ServingCellConfig)
8496          {
8497             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8498             if(pdschCfg->choice.setup)
8499             {
8500                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8501                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8502             }
8503             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8504          }
8505
8506          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8507       }
8508       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8509    }
8510    return ROK;
8511 }
8512
8513 /*******************************************************************
8514  *
8515  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8516  *
8517  * @details
8518  *
8519  *    Function : BuildCellGroupConfigRrc
8520  *
8521  *    Functionality: Builds and copied Cell group config buffer into 
8522  *       DuToCuRrcContainer
8523  *
8524  * @params[in] idx, index in F1AP msg
8525  *             DuToCuRRCContainer, DuToCuRRCContainer
8526  *
8527  * @return ROK     - success
8528  *         RFAILED - failure
8529  *
8530  * ****************************************************************/
8531 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8532 {
8533    uint8_t  ret = ROK;
8534    CellGroupConfigRrc_t  cellGrpCfg;
8535    asn_enc_rval_t        encRetVal;
8536    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8537    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8538
8539    while(true)
8540    {
8541       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8542
8543       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8544       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8545       if(!cellGrpCfg.rlc_BearerToAddModList)
8546       {
8547          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8548          ret = RFAILED;
8549          break;
8550       }
8551       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8552       {
8553          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8554          ret = RFAILED;
8555          break;
8556       }
8557
8558       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8559       cellGrpCfg.mac_CellGroupConfig = NULLP;
8560       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8561       if(!cellGrpCfg.mac_CellGroupConfig)
8562       {
8563          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8564          ret = RFAILED;
8565          break;
8566       }
8567       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8568       {
8569          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8570          ret = RFAILED;
8571          break;
8572       }
8573
8574       cellGrpCfg.physicalCellGroupConfig = NULLP;
8575       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8576       if(!cellGrpCfg.physicalCellGroupConfig)
8577       {
8578          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8579          ret = RFAILED;
8580          break;
8581       }
8582       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8583       {
8584          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8585          ret = RFAILED;
8586          break;
8587       }
8588
8589       cellGrpCfg.spCellConfig = NULLP;
8590       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8591       if(!cellGrpCfg.spCellConfig)
8592       {
8593          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8594          ret = RFAILED;
8595          break;
8596       }
8597       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8598       {
8599          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8600          ret = RFAILED;
8601          break;
8602       }
8603
8604       cellGrpCfg.sCellToAddModList = NULLP;
8605       cellGrpCfg.sCellToReleaseList = NULLP;
8606       cellGrpCfg.ext1 = NULLP;
8607
8608       /* encode cellGrpCfg into duToCuRrcContainer */
8609       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8610       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8611       encBufSize = 0;
8612       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8613       /* Encode results */
8614       if(encRetVal.encoded == ENCODE_FAIL)
8615       {
8616          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8617                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8618          ret = RFAILED;
8619          break;
8620       }
8621       else
8622       {
8623          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8624 #ifdef DEBUG_ASN_PRINT
8625          for(int i=0; i< encBufSize; i++)
8626          {
8627             printf("%x",encBuf[i]);
8628          }
8629 #endif
8630       }
8631
8632       duToCuRrcContainer->size = encBufSize;
8633       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8634       if(!duToCuRrcContainer->buf)
8635       {
8636          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8637          ret = RFAILED;
8638          break;
8639       }
8640       if(ret == ROK)
8641       {
8642          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8643       }
8644       break;
8645    }
8646    FreeMemDuToCuRrcCont(&cellGrpCfg);
8647    return ret;
8648 }
8649
8650 /*******************************************************************
8651  *
8652  * @brief Free memory allocated in InitialULRRCMessage
8653  *
8654  * @details
8655  *
8656  *    Function : freeInitUlRrcMsgTransfer
8657  *
8658  *    Functionality: Free memory allocated in InitialULRRCMessage
8659  *
8660  * @params[in]F1AP_PDU_t  *f1apMsg)
8661  *
8662  * @return ROK     - success
8663  *         RFAILED - failure
8664  *
8665  * ****************************************************************/
8666
8667 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8668 {
8669    uint8_t ieIdx, arrIdx;
8670    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8671
8672    if(f1apMsg)
8673    {
8674       if(f1apMsg->choice.initiatingMessage)
8675       {
8676          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8677             choice.InitialULRRCMessageTransfer;
8678          if(initULRRCMsg->protocolIEs.list.array)
8679          {
8680             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8681             {
8682                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8683                {
8684                   case ProtocolIE_ID_id_NRCGI:
8685                   {
8686                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8687                      {
8688                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8689                         {
8690                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8691                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8692                         }
8693                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8694                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8695                      }
8696                      break;
8697                   }
8698                   case ProtocolIE_ID_id_RRCContainer:
8699                   {
8700                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8701                      {
8702                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8703                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8704                      }
8705                      break;
8706                   }
8707                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8708                   {
8709                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8710                      {
8711                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8712                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8713                      }
8714                      break;
8715                   }
8716                   default:
8717                      break;
8718                }
8719              }
8720              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8721              {
8722                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8723                 {
8724                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8725                       sizeof(InitialULRRCMessageTransferIEs_t));
8726                 }
8727              }
8728              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8729           }
8730          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8731       }
8732       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8733    }
8734    else
8735    {
8736       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8737       return RFAILED;
8738    }
8739    return ROK;
8740 }
8741
8742 /*******************************************************************
8743  *
8744  * @brief Builds and sends the InitialULRRCMessage 
8745  *
8746  * @details
8747  *
8748  *    Function : BuildAndSendInitialRrcMsgTransfer 
8749  *
8750  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
8751  *                   it to the CU through SCTP.
8752  *
8753  * @params[in] 
8754  *
8755  * @return ROK     - success
8756  *         RFAILED - failure
8757  *
8758  * ****************************************************************/
8759 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
8760       uint16_t rrcContSize, uint8_t *rrcContainer)
8761 {
8762    uint8_t   ret;
8763    uint8_t   elementCnt;
8764    uint8_t   ieIdx, cellIdx, ueIdx;
8765    DuUeCb    *duUeCb = NULLP;
8766    asn_enc_rval_t  encRetVal;
8767    F1AP_PDU_t  *f1apMsg = NULLP;
8768    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
8769    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8770
8771    while(true)
8772    {
8773       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
8774       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
8775       if(f1apMsg == NULLP)
8776       {
8777          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
8778          break;
8779       }
8780       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
8781       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8782       if(f1apMsg->choice.initiatingMessage == NULLP)
8783       {
8784          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
8785          break;
8786       }
8787       f1apMsg->choice.initiatingMessage->procedureCode =\
8788                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
8789       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
8790       f1apMsg->choice.initiatingMessage->value.present = \
8791                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
8792       initULRRCMsg =\
8793                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
8794       elementCnt = 5;
8795       initULRRCMsg->protocolIEs.list.count = elementCnt;
8796       initULRRCMsg->protocolIEs.list.size = \
8797                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
8798       /* Initialize the F1Setup members */
8799       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
8800       if(initULRRCMsg->protocolIEs.list.array == NULLP)
8801       {
8802          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
8803                RRCSetupRequestMessageTransferIEs failed");
8804          break;
8805       }
8806       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
8807       {
8808          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
8809                sizeof(InitialULRRCMessageTransferIEs_t));
8810          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
8811          {
8812             break;
8813          }
8814       }
8815       ieIdx = 0;
8816       /*GNB DU UE F1AP ID*/
8817       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8818                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
8819       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
8820       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8821                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
8822       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
8823
8824
8825       /*NRCGI*/
8826       ieIdx++;
8827       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8828                                                         ProtocolIE_ID_id_NRCGI;
8829       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
8830       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8831                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
8832
8833       ret =\
8834            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
8835       if(ret!=ROK)
8836       {
8837          break;
8838       }
8839
8840       /*CRNTI*/
8841       ieIdx++;
8842       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8843                                                         ProtocolIE_ID_id_C_RNTI;
8844       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8845       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8846                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
8847       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
8848
8849       /*RRCContainer*/
8850       ieIdx++;
8851       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8852                                                         ProtocolIE_ID_id_RRCContainer;
8853       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8854       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8855                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
8856
8857       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
8858       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
8859             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
8860       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8861       {
8862          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
8863          break;
8864       
8865       }
8866       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
8867             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8868
8869
8870       /*DUtoCURRCContainer*/
8871       ieIdx++;
8872       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
8873       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8874       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8875                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
8876
8877       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
8878       {
8879          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
8880          {
8881             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
8882                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
8883             {
8884                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
8885             }
8886          }
8887       }
8888
8889       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
8890       if(ret != ROK)
8891       {
8892          break;
8893       }
8894
8895       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
8896
8897       /* Encode the Intial UL RRC Message transfer as APER */
8898       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8899       encBufSize = 0;
8900       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
8901       /* Encode results */
8902       if(encRetVal.encoded == ENCODE_FAIL)
8903       {
8904          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
8905                structure (at %s)\n",encRetVal.failed_type ? \
8906                encRetVal.failed_type->name : "unknown");
8907          ret = RFAILED;
8908          break;
8909       }
8910       else
8911       {
8912
8913          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
8914                Message transfer\n");
8915 #ifdef DEBUG_ASN_PRINT
8916          for(int i=0; i< encBufSize; i++)
8917          {
8918             printf("%x",encBuf[i]);
8919          }
8920 #endif
8921       }
8922       /* Sending  msg  */
8923       if(sendF1APMsg() != ROK)
8924       {
8925          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
8926          ret = RFAILED;
8927          break;
8928       }
8929       break;
8930    }
8931    freeInitUlRrcMsgTransfer(f1apMsg);
8932    return ret;
8933 }/* End of BuildAndSendInitialRrcMsgTransfer*/
8934
8935 /*****  UE SETUP REQUEST *****/
8936
8937 /******************************************************************
8938 *
8939 * @brief Function to delete the RLC Lc cfg from UE APP DB
8940 *
8941 * @details
8942 *
8943 *  Function : freeRlcLcCfg
8944 *
8945 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
8946 *
8947 *
8948  *****************************************************************/
8949
8950 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
8951 {
8952    switch(lcCfg->rlcMode)
8953    {
8954       case RLC_AM :
8955          {
8956             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
8957             break;
8958          }
8959       case RLC_UM_BI_DIRECTIONAL :
8960          {
8961             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8962             break;
8963          }
8964       case RLC_UM_UNI_DIRECTIONAL_UL :
8965          {
8966             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8967             break;
8968          }
8969       case RLC_UM_UNI_DIRECTIONAL_DL :
8970          {
8971             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8972             break;
8973          }
8974       default:
8975          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
8976          break;
8977    }
8978    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8979 }
8980
8981 /*******************************************************************
8982  *
8983  * @brief Function to free MacLcCfg
8984  *
8985  * @details
8986  *
8987  *    Function : freeMacLcCfg
8988  *
8989  *    Functionality: Function to free MacLcCfg
8990  *
8991  * @params[in] LcCfg *lcCfg,
8992  * @return void
8993  *
8994  * ****************************************************************/
8995
8996 void freeMacLcCfg(LcCfg *lcCfg)
8997 {
8998     /* Deleting DRBQOS */
8999    if(lcCfg->drbQos)
9000    {
9001       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9002    }
9003    /* Deleting SNSSAI */
9004    if(lcCfg->snssai)
9005    {
9006       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9007    }
9008 }
9009 /*******************************************************************
9010  *
9011  * @brief Free UE NR Capability received in UE Context setup request
9012  *
9013  * @details
9014  *
9015  *    Function : freeAperDecodeUeNrCapability
9016  *
9017  *    Functionality:  
9018  *       Free UE NR Capability received in UE Context setup request
9019  *
9020  * @params[in] 
9021  * @return ROK     - success
9022  *         RFAILED - failure
9023  *
9024  * ****************************************************************/
9025 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9026 {
9027    uint8_t arrIdx =0;
9028    FeatureSets_t *featureSets =NULLP;
9029    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9030
9031    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9032    {
9033       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9034       {
9035          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9036             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9037       }
9038       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9039    }
9040
9041    if(ueNrCap->featureSets)
9042    {
9043       featureSets = ueNrCap->featureSets;
9044       if(featureSets->featureSetsDownlinkPerCC)
9045       {
9046          if(featureSets->featureSetsDownlinkPerCC->list.array)
9047          {
9048             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9049             {
9050                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9051                {
9052                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9053                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9054                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9055                }
9056             }
9057             free(featureSets->featureSetsDownlinkPerCC->list.array);
9058          }
9059          free(featureSets->featureSetsDownlinkPerCC);
9060       }
9061       if(featureSets->featureSetsUplinkPerCC)
9062       {
9063          if(featureSets->featureSetsUplinkPerCC->list.array)
9064          {
9065             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9066             {
9067                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9068                {
9069                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9070                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9071                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9072                }
9073             }
9074             free(featureSets->featureSetsUplinkPerCC->list.array);
9075          }
9076          free(featureSets->featureSetsUplinkPerCC);
9077       }
9078       free(ueNrCap->featureSets);
9079    }   
9080 }
9081
9082 /*******************************************************************
9083 *
9084 * @brief Function to free PdcchSearchSpcToAddModList
9085          where memory allocated by aper_decoder
9086 *
9087 * @details
9088 *
9089 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9090 *
9091 *    Functionality: Function to free PdcchSearchSpcToAddModList
9092 *
9093 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9094 * @return void
9095 *
9096 * ****************************************************************/
9097
9098 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9099 {
9100    uint8_t searchSpcArrIdx=0;
9101    uint8_t searchSpcArrIdx1=0;
9102    struct  SearchSpace *searchSpc=NULLP;
9103
9104
9105    if(searchSpcList->list.array)
9106    {
9107       if(searchSpcList->list.array[searchSpcArrIdx1])
9108       {
9109          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9110          if(searchSpc->controlResourceSetId)
9111          {
9112             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9113             {
9114                if(searchSpc->monitoringSymbolsWithinSlot)
9115                {
9116                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9117                   {
9118                      if(searchSpc->nrofCandidates)
9119                      {
9120                         if(searchSpc->searchSpaceType)
9121                         {
9122                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9123                            free(searchSpc->searchSpaceType);
9124                         }
9125                         free(searchSpc->nrofCandidates);
9126                      }
9127                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9128                   }
9129                   free(searchSpc->monitoringSymbolsWithinSlot);
9130                }
9131                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9132             }
9133             free(searchSpc->controlResourceSetId);
9134          }
9135       }
9136       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9137       {
9138          free(searchSpcList->list.array[searchSpcArrIdx]);
9139       }
9140       free(searchSpcList->list.array);
9141    }
9142 }
9143 /*******************************************************************
9144 *
9145 * @brief Function for free part for the memory allocated by aper_decoder
9146
9147 * @details
9148 *
9149 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9150 *
9151 *    Functionality: Function to free BWPDlDedPdcchConfig
9152 *
9153 * @params[in] 
9154 * @return void
9155 *
9156 * ****************************************************************/
9157
9158
9159 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9160 {
9161    uint8_t arrIdx1=0;
9162    uint8_t arrIdx2=0;
9163    struct PDCCH_Config *pdcchCfg=NULLP;
9164    struct ControlResourceSet *controlRSet=NULLP;
9165    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9166    
9167    if(dlBwp->pdcch_Config->choice.setup)
9168    {
9169       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9170       if(pdcchCfg->controlResourceSetToAddModList)
9171       {
9172          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9173          if(controlRSetList->list.array)
9174          {
9175             controlRSet = controlRSetList->list.array[arrIdx2];
9176             if(controlRSet)
9177             {
9178                if(controlRSet->frequencyDomainResources.buf)
9179                {
9180                   if(controlRSet->pdcch_DMRS_ScramblingID)
9181                   {
9182                      if(pdcchCfg->searchSpacesToAddModList)
9183                      {
9184                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9185                         free(pdcchCfg->searchSpacesToAddModList);
9186                      }
9187                      free(controlRSet->pdcch_DMRS_ScramblingID);
9188                   }
9189                   free(controlRSet->frequencyDomainResources.buf);
9190                }
9191             }
9192             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9193             {
9194                free(controlRSetList->list.array[arrIdx1]);
9195             }
9196             free(controlRSetList->list.array);
9197          }
9198          free(pdcchCfg->controlResourceSetToAddModList);
9199       }
9200       free(dlBwp->pdcch_Config->choice.setup);
9201    }
9202 }
9203 /*******************************************************************
9204 *
9205 * @brief Function to free PdschTimeDomAllocationList 
9206 *     where the memory allocated by aper_decoder
9207
9208 * @details
9209 *
9210 *    Function : freeAperDecodePdschTimeDomAllocationList
9211 *
9212 *    Functionality: Function to free PdschTimeDomAllocationList
9213 *
9214 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9215 * @return void
9216 *
9217 * ****************************************************************/
9218
9219
9220 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9221 {
9222    uint8_t arrIdx=0;
9223
9224    if(timeDomAllocList->choice.setup)
9225    {
9226       if(timeDomAllocList->choice.setup->list.array)
9227       {
9228          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9229          {
9230             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9231          }
9232          free(timeDomAllocList->choice.setup->list.array);
9233       }
9234       free(timeDomAllocList->choice.setup);
9235    }
9236 }
9237
9238 /*******************************************************************
9239 *
9240 * @brief Function to free BWPDlDedPdschConfig 
9241 *        where the memory allocated by aper_decoder
9242 *  
9243 * @details
9244 *
9245 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9246 *
9247 *    Functionality: Function to free BWPDlDedPdschConfig 
9248 *
9249 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9250 * @return void
9251 *
9252 * ****************************************************************/
9253
9254
9255 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9256 {
9257    struct PDSCH_Config *pdschCfg=NULLP;
9258    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9259    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9260    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9261
9262    if(dlBwp->pdsch_Config->choice.setup)
9263    {
9264       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9265       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9266       {
9267          if(pdschCfg->pdsch_TimeDomainAllocationList)
9268          {
9269             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9270             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9271             {
9272                prbBndlType=&pdschCfg->prb_BundlingType;
9273                free(prbBndlType->choice.staticBundling);
9274                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9275             }
9276             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9277             free(pdschCfg->pdsch_TimeDomainAllocationList);
9278          }
9279          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9280          if(dmrsDlCfg->choice.setup)
9281          {
9282             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9283             free(dmrsDlCfg->choice.setup);
9284          }
9285          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9286       }
9287       free(dlBwp->pdsch_Config->choice.setup);
9288    }
9289 }
9290 /*******************************************************************
9291 *
9292 * @brief Function to free PuschTimeDomAllocListCfg
9293                  where the memory allocated by aper_decoder
9294 *
9295 * @details
9296 *
9297 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9298 *
9299 *    Functionality: Function to free PuschTimeDomAllocListCfg
9300 *
9301 * @params[in] PUSCH_Config_t *puschCfg 
9302 * @return void
9303 *
9304 * ****************************************************************/
9305
9306
9307 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9308 {
9309    uint8_t arrIdx=0;
9310    uint8_t arrIdx1=0;
9311    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9312
9313    if(puschCfg->pusch_TimeDomainAllocationList)
9314    {
9315       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9316       if(timeDomAllocList_t->choice.setup)
9317       {
9318          if(timeDomAllocList_t->choice.setup->list.array)
9319          {
9320             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9321             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9322             {
9323                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9324             }
9325             free(timeDomAllocList_t->choice.setup->list.array);
9326          }
9327          free(timeDomAllocList_t->choice.setup);
9328       }
9329       free(puschCfg->transformPrecoder);
9330       free(puschCfg->pusch_TimeDomainAllocationList);
9331    }
9332 }
9333 /*******************************************************************
9334 *
9335 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9336 *
9337 * @details
9338 *
9339 *    Function : freeAperDecodeInitialUlBWPConfig 
9340 *
9341 *    Functionality: Function to free InitialUlBWPConfig
9342 *
9343 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9344 * @return void
9345 *
9346 * ****************************************************************/
9347
9348
9349 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9350 {
9351    uint8_t  rSetIdx =0;
9352    uint8_t  rsrcIdx =0;
9353    SRS_Config_t   *srsCfg = NULLP;
9354    PUSCH_Config_t *puschCfg = NULLP;
9355    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9356    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9357    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9358    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9359
9360    if(ulBwp->pusch_Config)
9361    {
9362       if(ulBwp->pusch_Config->choice.setup)
9363       {
9364          puschCfg=ulBwp->pusch_Config->choice.setup;
9365          if(puschCfg->dataScramblingIdentityPUSCH)
9366          {
9367             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9368             {
9369                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9370                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9371                if(dmrsUlCfg->choice.setup)
9372                {
9373                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9374                   {
9375                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9376                      {
9377                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9378                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9379                      }
9380                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9381                   }
9382                   free(dmrsUlCfg->choice.setup);
9383                }
9384                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9385             }
9386             free(puschCfg->dataScramblingIdentityPUSCH);
9387          }
9388          free(ulBwp->pusch_Config->choice.setup);
9389       }
9390       free(ulBwp->pusch_Config);
9391
9392       /* Free SRS-Config */
9393       if(ulBwp->srs_Config)
9394       {
9395          if(ulBwp->srs_Config->choice.setup)
9396          {
9397             srsCfg = ulBwp->srs_Config->choice.setup;
9398
9399             /* Free Resource Set to add/mod list */
9400             if(srsCfg->srs_ResourceSetToAddModList)
9401             {
9402                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9403                if(rsrcSetList->list.array)
9404                {
9405                   rSetIdx = 0;
9406
9407                   /* Free SRS resource Id list in this SRS resource set */
9408                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9409                   {
9410                      rsrcIdList =
9411                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9412
9413                      if(rsrcIdList->list.array)
9414                      {
9415                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9416                               rsrcIdx++)
9417                         {
9418                            free(rsrcIdList->list.array[rsrcIdx]);
9419                         }
9420                         free(rsrcIdList->list.array);
9421                      }
9422                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9423                   }
9424
9425                   /* Free resource type info for this SRS resource set */
9426
9427                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9428
9429                   /* Free memory for each resource set */
9430                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9431                   {
9432                      free(rsrcSetList->list.array[rSetIdx]);
9433                   }
9434                   free(rsrcSetList->list.array);
9435                }
9436                free(srsCfg->srs_ResourceSetToAddModList);
9437             }
9438
9439             /* Free resource to add/modd list */
9440             if(srsCfg->srs_ResourceToAddModList)
9441             {
9442                resourceList = srsCfg->srs_ResourceToAddModList;
9443                if(resourceList->list.array)
9444                {
9445                   rsrcIdx = 0;
9446
9447                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9448                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9449
9450                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9451                   {
9452                      free(resourceList->list.array[rsrcIdx]);
9453                   }
9454                   free(resourceList->list.array);
9455                }
9456                free(srsCfg->srs_ResourceToAddModList);
9457             }
9458
9459             free(ulBwp->srs_Config->choice.setup);
9460          }
9461          free(ulBwp->srs_Config);
9462       }
9463    }
9464 }
9465 /*******************************************************************
9466 *
9467 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9468 *
9469 * @details
9470 *
9471 *    Function : freeAperDecodeinitialUplinkBWPConfig
9472 *
9473 *    Functionality: Function to free initialUplinkBWPConfig
9474 *
9475 * @params[in] UplinkConfig_t *ulCfg 
9476 * @return void
9477 *
9478 * ****************************************************************/
9479
9480
9481 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9482 {
9483    BWP_UplinkDedicated_t *ulBwp=NULLP;
9484    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9485    
9486    if(ulCfg->initialUplinkBWP)
9487    {
9488       ulBwp=ulCfg->initialUplinkBWP;
9489       if(ulCfg->firstActiveUplinkBWP_Id)
9490       {
9491          if(ulCfg->pusch_ServingCellConfig)
9492          {
9493             puschCfg=ulCfg->pusch_ServingCellConfig;
9494             if(puschCfg->choice.setup)
9495             {
9496                if(puschCfg->choice.setup->ext1)
9497                {
9498                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9499                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9500                   free(puschCfg->choice.setup->ext1);
9501                }
9502                free(puschCfg->choice.setup);
9503             }
9504             free(ulCfg->pusch_ServingCellConfig);
9505          }
9506          free(ulCfg->firstActiveUplinkBWP_Id);
9507       }
9508       freeAperDecodeInitialUlBWPConfig(ulBwp);
9509       free(ulCfg->initialUplinkBWP);
9510    }
9511 }
9512
9513 /*******************************************************************
9514  *
9515  * @brief Function to free DuUeCfg
9516  *
9517  * @details
9518  *
9519  *    Function : freeDuUeCfg
9520  *
9521  *    Functionality: Function to free DuUeCfg
9522  *
9523  * @params[in] DuUeCfg *ueCfg
9524  * @return void
9525  *
9526  * ****************************************************************/
9527 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9528 {
9529    uint8_t lcIdx = 0;
9530    uint8_t arrIdx = 0;
9531    SpCellConfig_t *spCellCfg = NULLP;
9532    ServingCellConfig_t *srvCellCfg = NULLP;
9533    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9534    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9535    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9536    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9537    struct RLC_Config *rlcConfig = NULLP;
9538    struct LogicalChannelConfig *macLcConfig = NULLP;
9539    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9540    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9541    struct TAG_Config *tagConfig = NULLP;
9542    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9543    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9544    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9545    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9546   
9547    if(ueCfg->ueNrCapability)
9548    {
9549       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9550       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9551       ueCfg->ueNrCapability = NULLP;
9552    }
9553
9554    if(ueCfg->cellGrpCfg)
9555    {
9556       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9557       if(rlcBearerList)
9558       {
9559          if(rlcBearerList->list.array)
9560          {
9561             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9562             {
9563                if(rlcBearerList->list.array[arrIdx])
9564                {
9565                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9566                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9567
9568                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9569                   {
9570                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9571                   }
9572                   if(rlcConfig)
9573                   {
9574                      if(rlcConfig->choice.am)
9575                      {
9576                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9577                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9578                         free(rlcConfig->choice.am);
9579                      }
9580                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9581                   }
9582                   if(macLcConfig)
9583                   {
9584                      if(macLcConfig->ul_SpecificParameters)
9585                      {
9586                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9587                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9588                         free(macLcConfig->ul_SpecificParameters);
9589                      }
9590                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9591                   }
9592                   free(rlcBearerList->list.array[arrIdx]); 
9593                }
9594             }
9595             free(rlcBearerList->list.array);
9596          }
9597          free(cellGrpCfg->rlc_BearerToAddModList);
9598       }
9599
9600       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9601       if(macCellGrpCfg)
9602       {
9603          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9604          if(schedulingRequestConfig)
9605          {
9606             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9607             if(schReqList)
9608             {
9609                if(schReqList->list.array)
9610                {
9611                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9612                   {
9613                      if(schReqList->list.array[arrIdx])
9614                      {
9615                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9616                         free(schReqList->list.array[arrIdx]);
9617                      }
9618                   }
9619                   free(schReqList->list.array);
9620                }
9621                free(schedulingRequestConfig->schedulingRequestToAddModList);
9622             }
9623             free(macCellGrpCfg->schedulingRequestConfig);
9624          }
9625          if(macCellGrpCfg->bsr_Config)
9626          {
9627             free(macCellGrpCfg->bsr_Config);
9628          }
9629          tagConfig = macCellGrpCfg->tag_Config;
9630          if(tagConfig)
9631          {
9632             tagList = tagConfig->tag_ToAddModList;
9633             if(tagList)
9634             {
9635                if(tagList->list.array)
9636                {
9637                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9638                   {
9639                      free(tagList->list.array[arrIdx]);
9640                   }
9641                   free(tagList->list.array);
9642                }
9643                free(tagConfig->tag_ToAddModList);
9644             }
9645             free(tagConfig); 
9646          }
9647
9648          phrConfig = macCellGrpCfg->phr_Config;
9649          if(phrConfig)
9650          {
9651             free(phrConfig->choice.setup); 
9652             free(phrConfig); 
9653          }
9654
9655          free(macCellGrpCfg); 
9656       }
9657
9658       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9659       if(phyCellGrpCfg)
9660       {
9661          free(phyCellGrpCfg->p_NR_FR1);
9662          free(phyCellGrpCfg); 
9663       }
9664
9665       spCellCfg = cellGrpCfg->spCellConfig;
9666       if(spCellCfg)
9667       {
9668          if(spCellCfg->servCellIndex)
9669          {
9670             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9671             {
9672                if(spCellCfg->spCellConfigDedicated)
9673                {
9674                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9675                   if(srvCellCfg->initialDownlinkBWP)
9676                   {
9677                      dlBwp = srvCellCfg->initialDownlinkBWP;
9678                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9679                      {
9680                         if(srvCellCfg->defaultDownlinkBWP_Id)
9681                         {
9682                            if(srvCellCfg->uplinkConfig)
9683                            {
9684
9685                               if(srvCellCfg->pdsch_ServingCellConfig)
9686                               {
9687                                  pdschCfg=
9688                                     srvCellCfg->pdsch_ServingCellConfig;
9689                                  if(pdschCfg->choice.setup)
9690                                  {
9691
9692                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9693                                     free(pdschCfg->choice.setup);
9694                                  }
9695
9696                                  free(srvCellCfg->pdsch_ServingCellConfig);
9697                               }
9698
9699                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9700                               free(srvCellCfg->uplinkConfig);
9701                            }
9702                            free(srvCellCfg->defaultDownlinkBWP_Id);
9703                         }
9704
9705                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9706                      }
9707                      if(dlBwp->pdcch_Config)
9708                      {
9709                         if(dlBwp->pdsch_Config)
9710                         {
9711                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9712                            free(dlBwp->pdsch_Config);
9713                         }
9714                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9715                         free(dlBwp->pdcch_Config);
9716                      }
9717                      free(srvCellCfg->initialDownlinkBWP);
9718                   }
9719
9720                   free(spCellCfg->spCellConfigDedicated);
9721                }
9722                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9723             }
9724             free(spCellCfg->servCellIndex); 
9725          }
9726          free(spCellCfg);
9727       }
9728       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9729       ueCfg->cellGrpCfg = NULLP;
9730    }
9731
9732    if(ueCfg->ambrCfg)
9733    {
9734       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9735    }
9736
9737    if(actionType != UE_CTXT_CFG_QUERY)
9738    {
9739       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9740       {
9741          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9742       }
9743    }
9744
9745    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9746    {
9747       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
9748    }
9749
9750    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9751    {
9752       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9753    }
9754 }
9755
9756 /*******************************************************************
9757  *
9758  * @brief Function to free UecontextSetupDb
9759  *
9760  * @details
9761  *
9762  *    Function : freeF1UeDb
9763  *
9764  *    Functionality: Function to free UecontextSetupDb
9765  *
9766  * @params[in] UecontextSetupDb *
9767  * @return void
9768  *
9769  * ****************************************************************/
9770
9771 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9772 {
9773    
9774    if(f1UeDb->dlRrcMsg)
9775    {
9776       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9777       {
9778         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9779                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9780       }
9781       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9782    }
9783    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
9784    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9785    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9786 }
9787
9788 /*******************************************************************
9789  *
9790  * @brief Function to build Am cfg Info
9791  *
9792  * @details
9793  *
9794  *    Function : extractRlcAmCfg
9795  *
9796  *    Functionality: Function to build Am cfg Info
9797  *
9798  * @params[in] AmBearerCfg *
9799  *             void *
9800  *
9801  * @return ROK/RFAILED
9802  *
9803  * ****************************************************************/
9804
9805 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9806 {
9807    if(rlcAmCfg)
9808    {
9809       /* UL AM */
9810       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9811       {
9812          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9813          /*TODO: Check the timer value when sent by real CU */
9814          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9815          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9816       }
9817
9818       /* DL AM */
9819       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9820       {
9821          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9822          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9823          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9824          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9825          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9826       }
9827    }
9828 }
9829
9830 /*******************************************************************
9831  *
9832  * @brief Function to build Um Bi Info
9833  *
9834  * @details
9835  *
9836  *    Function : extractRlcUmBiCfg
9837  *
9838  *    Functionality: Function to build Um Bi Info
9839  *
9840  * @params[in] UmBiDirBearerCfg *
9841  *             void *
9842  *
9843  * @return ROK/RFAILED
9844  *
9845  * ****************************************************************/
9846
9847 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
9848 {
9849    if(rlcBiCfg)
9850    {
9851       /* UL UM BI DIR Cfg */
9852       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
9853       {
9854          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
9855          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
9856       }
9857
9858       /* DL UM BI DIR Cfg */
9859       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
9860          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
9861    }
9862 }
9863
9864 /*******************************************************************
9865  *
9866  * @brief Function to build Um Ul Info
9867  *
9868  * @details
9869  *
9870  *    Function : extractRlcUmUlCfg
9871  *
9872  *    Functionality: Function to build Um Ul Info
9873  *
9874  * @params[in] UmUniDirUlBearerCfg *
9875  *             void *
9876  *
9877  * @return ROK/RFAILED
9878  *
9879  * ****************************************************************/
9880
9881 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
9882 {
9883    if(umUlCfg)
9884    {
9885       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
9886       {
9887          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
9888          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
9889       }
9890    }
9891 }
9892
9893 /*******************************************************************
9894  *
9895  * @brief Function to build Um Uni Dl Info
9896  *
9897  * @details
9898  *
9899  *    Function : extractRlcUmDlCfg
9900  *
9901  *    Functionality: Function to build Um Uni Dl Info
9902  *
9903  * @params[in] UmUniDirDlBearerCfg *
9904  *             void *
9905  *
9906  * @return ROK/RFAILED
9907  *
9908  * ****************************************************************/
9909 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
9910 {
9911    if(umDlCfg)
9912    {
9913       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
9914          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
9915    }
9916 }
9917
9918 /*******************************************************************
9919  *
9920  * @brief Function to extractRlcModeCfg
9921  *
9922  * @details
9923  *
9924  *    Function : extractRlcModeCfg
9925  *
9926  *    Functionality: Function to extractRlcModeCfg
9927  *
9928  * @params[in] RLC_Config_t *
9929  *             RlcBearerCfg *
9930  *             void  *    
9931  * @return ROK/RFAILED
9932  *
9933  * ****************************************************************/
9934 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
9935 {
9936    if(lcCfg)
9937    {
9938       switch(rlcMode)
9939       {
9940          case RLC_AM :
9941             {
9942                if(lcCfg->choice.am)
9943                {
9944                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
9945                   if(rlcDbCfg->u.amCfg)
9946                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
9947                }
9948                break;
9949             }
9950          case RLC_UM_BI_DIRECTIONAL :
9951             {
9952                if(lcCfg->choice.um_Bi_Directional)
9953                {
9954                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9955                   if(rlcDbCfg->u.umBiDirCfg)
9956                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
9957                }
9958                break;
9959             }
9960          case RLC_UM_UNI_DIRECTIONAL_UL :
9961             {
9962                if(lcCfg->choice.um_Uni_Directional_DL)
9963                {
9964                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9965                   if(rlcDbCfg->u.umUniDirUlCfg)
9966                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
9967                }
9968                break;
9969             }
9970          case RLC_UM_UNI_DIRECTIONAL_DL :
9971             {
9972                if(lcCfg->choice.um_Uni_Directional_UL)
9973                {
9974                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9975                   if(rlcDbCfg->u.umUniDirDlCfg)
9976                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
9977                }
9978                break;
9979             }
9980          default:
9981             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
9982             break;
9983       }
9984    }
9985 }
9986
9987 /*******************************************************************
9988  *
9989  * @brief Function to extract extractUlLcCfg
9990  *
9991  * @details
9992  *
9993  *    Function : extractUlLcCfg
9994  *
9995  *    Functionality: Function to extract extractUlLcCfg
9996  *
9997  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
9998  * @return void
9999  *
10000  * ****************************************************************/
10001
10002 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10003 {
10004    if(ulLcCfg)
10005    {
10006       if(ulLcCfg->ul_SpecificParameters)
10007       {
10008          f1UlLcCfg->priority = \
10009             ulLcCfg->ul_SpecificParameters->priority;
10010       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10011       {
10012          f1UlLcCfg->lcGroup = \
10013            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10014       }
10015       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10016       {
10017          f1UlLcCfg->schReqId = \
10018            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10019       }
10020       f1UlLcCfg->pbr = \
10021          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10022       f1UlLcCfg->bsd = \
10023          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10024       }
10025    }
10026 }
10027
10028 /*******************************************************************
10029 *
10030 * @brief Function to extract Snssai Cfg Info from CU
10031 *
10032 * @details
10033 *
10034 *    Function : extractDrbSnssaiCfg
10035 *
10036 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10037 *
10038 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10039 * @return ROK/RFAILED
10040 *
10041 * ****************************************************************/
10042
10043 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10044 {
10045    if(!(*snssaiToBeShared))
10046    {
10047       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10048       if(snssaiToBeShared == NULLP)
10049       {
10050          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10051          return RFAILED;
10052       }
10053    }
10054    if(RecvSnssai)
10055    {
10056       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10057       if(RecvSnssai->sD)
10058       {
10059          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10060       }
10061       else
10062       {
10063          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10064          return RFAILED;
10065       }
10066    }
10067    return ROK;
10068 }
10069
10070 /*******************************************************************
10071  *
10072  * @brief Function to procRlcLcCfg
10073  *
10074  * @details
10075  *
10076  *    Function : procRlcLcCfg
10077  *
10078  *    Functionality: Function to procRlcLcCfg
10079  *
10080  * @params[in] rbId, lcId, rbType, rlcMod
10081  *             RLC_Config_t *, RlcBearerCfg * , 
10082  * @return void
10083  *
10084  * ****************************************************************/
10085
10086 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10087    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10088 {
10089    DRB_Information_t *drbInfo;
10090
10091    lcCfg->rlcBearerCfg.rbId   = rbId;
10092    lcCfg->configType = configType;
10093
10094    if(rbType == RB_TYPE_SRB)
10095    {
10096       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10097       lcCfg->rlcBearerCfg.lcId   = rbId;
10098       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10099       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10100    }
10101    else if(rbType == RB_TYPE_DRB)
10102    {
10103       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10104       lcCfg->rlcBearerCfg.lcId   = lcId;
10105       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10106       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10107    }
10108    if(f1RlcCfg) /* rlc mode config recived */
10109    {
10110       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10111    }
10112    if(qoSInformation != NULLP)
10113    {
10114       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10115       {
10116          if(qoSInformation->choice.choice_extension->value.present ==\
10117                QoSInformation_ExtIEs__value_PR_DRB_Information)
10118          {
10119             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10120             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10121             {
10122                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10123                return;
10124             }
10125          }
10126       }
10127    }
10128 }
10129
10130 /*******************************************************************
10131  *
10132  * @brief Fills DrbQos Info received by CU
10133  *
10134  * @details
10135  *
10136  *    Function : extractQosInfo
10137  *
10138  *    Functionality: Fills DrbQos Info received  by CU
10139  *
10140  * @params[in] DrbQosInfo *qosToAdd, 
10141  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10142  * @return void
10143  *
10144  * ****************************************************************/
10145
10146 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10147 {
10148    uint8_t qosCntIdx = 0;
10149    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10150
10151    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10152    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10153                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10154    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10155    {
10156       qosToAdd->u.nonDyn5Qi.avgWindow = \
10157                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10158    }
10159
10160    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10161    {
10162       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10163                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10164    }
10165
10166    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10167    {
10168       qosToAdd->u.nonDyn5Qi.priorLevel = \
10169                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10170    }
10171    qosToAdd->ngRanRetPri.priorityLevel = \
10172                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10173    qosToAdd->ngRanRetPri.preEmptionCap = \
10174                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10175    qosToAdd->ngRanRetPri.preEmptionVul = \
10176                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10177    if(qosFlowCfg->gBR_QoS_Flow_Information)
10178    {
10179       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10180             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10181             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10182       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10183             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10184             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10185       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10186             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10187             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10188       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10189             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10190             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10191    }
10192    /*Extracting PDU_SESSION_ID*/
10193    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10194    if(qosIeExt)
10195    {
10196       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10197       {
10198          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10199                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10200          {
10201             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10202             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10203          }
10204       }  
10205    }
10206    qosToAdd->ulPduSessAggMaxBitRate = 0;
10207 }
10208
10209 /*******************************************************************
10210  *
10211  * @brief Function to extract GTP Tunnel Info from CU
10212  *
10213  * @details
10214  *
10215  *    Function : extractUpTnlInfo
10216  *
10217  *    Functionality: Function to extract GTP Tunnel Info from CU
10218  *
10219  * @params[in] F1AP message
10220  * @return ROK/RFAILED
10221  *
10222  * ****************************************************************/
10223
10224 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10225    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10226 {
10227    uint8_t tnlIdx;
10228    uint32_t ipv4_du = 0;
10229    GTPTunnel_t *gtpTunnel = NULLP;
10230
10231    upTnlInfo->drbId = drbId; 
10232    upTnlInfo->configType = configType;
10233 #ifdef O1_ENABLE
10234    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10235 #else
10236    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10237 #endif
10238
10239    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10240    {
10241       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10242       {
10243          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10244          {
10245             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10246             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10247             if(upTnlInfo->tnlCfg1 == NULLP)
10248             {
10249                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10250                return RFAILED;
10251             }
10252             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10253             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10254             if(gtpTunnel->gTP_TEID.size > 0)
10255             {
10256                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10257             }
10258          }
10259          break;
10260       }
10261    }
10262    return ROK;
10263 }
10264
10265 /*******************************************************************
10266 *
10267 * @brief Function to extract Drb Qos Cfg Info from CU
10268 *
10269 * @details
10270 *
10271 *    Function : extractDrbQosCfg 
10272 *
10273 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10274 *
10275 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10276 * @return ROK/RFAILED
10277 *
10278 * ****************************************************************/
10279
10280 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10281 {
10282    if(!macLcToAdd->drbQos)
10283    {
10284       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10285       if(macLcToAdd->drbQos == NULLP)
10286       {
10287          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10288          return RFAILED;
10289       }
10290
10291    }
10292    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10293    {
10294       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10295       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10296    }
10297    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10298    {
10299       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10300       return RFAILED;
10301    }
10302    return ROK;
10303 }
10304 /*******************************************************************
10305  *
10306  * @brief Function to extract DRB info received from CU
10307  *
10308  * @details
10309  *
10310  *    Function : extractDrbCfg
10311  *
10312  *    Functionality: Function to extract DRB info received from CU
10313  *
10314  * @params[in] F1AP message
10315  * @return void
10316  *
10317  * ****************************************************************/
10318 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10319 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10320 {
10321    DRB_Information_t *drbInfo = NULLP;
10322
10323    if(drbItem != NULLP)
10324    {
10325       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10326       {
10327          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10328          return RFAILED;
10329       }
10330       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10331       {
10332          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10333          {
10334             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10335             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10336             {
10337                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10338                return RFAILED;
10339             }
10340          }
10341       }
10342    }
10343    else if(drbSetupModItem != NULLP)
10344    {
10345       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10346       upTnlInfo) != ROK)
10347       {
10348          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10349          return RFAILED;
10350       }
10351       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10352       {
10353          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10354          QoSInformation_ExtIEs__value_PR_DRB_Information)
10355          {
10356             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10357             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10358             {
10359                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10360                return RFAILED;
10361             }
10362
10363          }
10364       }
10365    }
10366    else if(drbModItem != NULLP)
10367    {
10368       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10369       upTnlInfo) != ROK)
10370       {
10371          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10372          return RFAILED;
10373       }
10374       if(drbModItem->qoSInformation != NULLP)
10375       {
10376          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10377          {
10378             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10379                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10380             {
10381                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10382                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10383                {
10384                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10385                   return RFAILED;
10386                }
10387
10388             }
10389          }
10390       }
10391    }
10392    return ROK;
10393 }
10394
10395 /*******************************************************************
10396  *
10397  * @brief Function to extract RB info received from CU
10398  *
10399  * @details
10400  *
10401  *    Function : extractMacRbCfg
10402  *
10403  *    Functionality: Function to extract RB info received from CU
10404  *
10405  * @params[in] F1AP message
10406  * @return ROK/RFAILED
10407  *
10408  * ****************************************************************/
10409
10410 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10411 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10412 {
10413    if(drbCfg != NULLP)
10414    {
10415       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10416       {
10417          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10418          return RFAILED;
10419       }
10420    }
10421    else if(drbSetupModCfg != NULLP)
10422    { 
10423       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10424       {
10425          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10426          return RFAILED;
10427       }
10428    }
10429    else if(drbModCfg != NULLP)
10430    { 
10431       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10432       {
10433          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10434          return RFAILED;
10435       }
10436    }
10437    else
10438    {
10439       lcCfg->lcConfig.drbQos = NULLP;
10440       lcCfg->lcConfig.snssai = NULLP;
10441       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10442          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10443       else
10444          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10445
10446    }
10447    if(ulLcCfg)
10448    {
10449       lcCfg->lcConfig.ulLcCfgPres = true;
10450       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10451    }
10452    else
10453       lcCfg->lcConfig.ulLcCfgPres = false;
10454    return ROK;
10455 }
10456
10457 /*******************************************************************
10458  *
10459  * @brief Function processing LC config info received from CU
10460  *
10461  * @details
10462  *
10463  *    Function : procMacLcCfg
10464  *
10465  *    Functionality: Function processing LC config info received from CU
10466  *
10467  * @params[in] F1AP message
10468  * @return ROK/RFAILED
10469  *
10470  * ****************************************************************/
10471
10472 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10473 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10474 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10475 {
10476    uint8_t ret = ROK;
10477
10478    lcCfg->lcConfig.lcId = lcId;
10479    lcCfg->configType = configType;
10480    if(rbType == RB_TYPE_SRB)
10481    {
10482       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10483    }
10484    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10485    {
10486       if(drbItem != NULL)
10487         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10488       else if(drbSetupModItem != NULL)
10489         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10490       else if(drbModItem != NULL)
10491         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10492    }
10493    return ret;
10494 }
10495
10496 /*******************************************************************
10497  *
10498  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10499  *
10500  * @details
10501  *
10502  *    Function : extractRlcCfgToAddMod
10503  *
10504  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10505  *
10506  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10507  *             DuUeCfg Pointer
10508  * @return ROK/RFAILED
10509  *
10510  * ****************************************************************/
10511
10512 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10513 {
10514   uint8_t idx, rbId, lcId, rlcMode, rbType;
10515   RLC_Config_t *f1RlcCfg = NULLP;
10516   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10517
10518   for(idx = 0; idx < lcCfg->list.count; idx++)
10519   {
10520      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10521      if(lcCfg->list.array[idx]->servedRadioBearer)
10522      {
10523         /* RadioBearer for SRB/DRB */
10524         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10525         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10526         {
10527            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10528            rbType = RB_TYPE_SRB;
10529         }
10530         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10531         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10532         {
10533            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10534            rbType = RB_TYPE_DRB;
10535         }
10536         else
10537         {
10538            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10539            return RFAILED;
10540         }
10541         /* MAC UL LC Config */
10542         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10543         {
10544            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10545         }
10546      }
10547      else
10548      {
10549         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10550         return RFAILED;
10551      }
10552      /* RLC Mode Config */
10553      if(lcCfg->list.array[idx]->rlc_Config)
10554      {
10555         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10556         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10557      }
10558      
10559      /* Filling RLC/MAC Config*/
10560      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10561      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10562      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10563      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10564      {
10565         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10566         return RFAILED;
10567      }
10568      (ueCfgDb->numRlcLcs)++;
10569      (ueCfgDb->numMacLcs)++;
10570      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10571         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10572   }
10573   //TODO: To send the failure cause in UeContextSetupRsp 
10574   return ROK;
10575 }
10576
10577 /*******************************************************************
10578  *
10579  * @brief DeAlloc pdsch serv cell config info
10580  *
10581  * @details
10582  *
10583  *    Function : freeMacPdschServCellInfo
10584  *
10585  *    Functionality: DeAlloc pdsch serv cell config info
10586  *
10587  * @params[in] PdschServCellCfg pointer
10588  * @return void
10589  *
10590  * ****************************************************************/
10591
10592 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10593 {
10594    if(pdsch->xOverhead)
10595    {
10596       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10597    }
10598    if(pdsch->codeBlkGrpFlushInd)
10599    {
10600       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10601    }
10602    if(pdsch->maxCodeBlkGrpPerTb)
10603    {
10604       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10605    }
10606    if(pdsch->maxMimoLayers)
10607    {
10608       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10609    }
10610 }
10611
10612 /*******************************************************************
10613  *
10614  * @brief Free Serving cell Info
10615  *
10616  * @details
10617  *
10618  *    Function : freeMacServingCellInfo
10619  *
10620  *    Functionality: Free Serving cell Info
10621  *
10622  * @params[in] ServCellCfgInfo *srvCellCfg
10623  * @return void
10624  *
10625  * ****************************************************************/
10626 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10627 {
10628    uint8_t timeDomRsrcIdx;
10629
10630    if(srvCellCfg->initDlBwp.pdschPresent)
10631    {
10632       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10633       {
10634          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10635             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10636       }
10637    }
10638
10639    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10640    if(srvCellCfg->bwpInactivityTmr)
10641    {
10642       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10643    }
10644
10645    if(srvCellCfg->initUlBwp.pucchPresent)
10646    {
10647       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10648    }
10649 }
10650
10651 /*******************************************************************
10652  *
10653  * @brief Free cell Grp Cfg Info
10654  *
10655  * @details
10656  *
10657  *    Function : freeUeRecfgCellGrpInfo
10658  *
10659  *    Functionality: Free cell Grp Cfg Info
10660  *
10661  * @params[in] DuMacUeCfg*  duUeCfg
10662  * @return void
10663  *
10664  * ****************************************************************/
10665
10666 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10667 {
10668    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10669 }
10670
10671 /*******************************************************************
10672  *
10673  * @brief Fills Reconfig SchReqReConfig
10674  *
10675  * @details
10676  *
10677  *    Function : extractSchReqReConfig
10678  *
10679  *    Functionality: Fills Reconfig SchReqReConfig
10680  *
10681  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10682  *             SchedReqCfg*  macSchedReq
10683  * @return void
10684  *
10685  * ****************************************************************/
10686 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10687 {
10688    uint8_t schReqIdx = 0;
10689    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10690    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10691
10692    if(cuSchedReq->schedulingRequestToAddModList)
10693    {
10694       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10695       if(schReqListToAdd->list.count)
10696       {
10697          macSchedReq->addModListCount = schReqListToAdd->list.count;
10698          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10699          {
10700             macSchedReq->addModList[schReqIdx].schedReqId = \
10701                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10702             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10703                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10704             macSchedReq->addModList[schReqIdx].srTransMax    =\
10705                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10706          }
10707       }
10708    }
10709    /* Scheduling Req To release */
10710    if(cuSchedReq->schedulingRequestToReleaseList)
10711    {
10712       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10713       if(schReqListToRel->list.count)
10714       {
10715          macSchedReq->relListCount = schReqListToRel->list.count;
10716          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10717          {
10718             macSchedReq->relList[schReqIdx] = \
10719                *schReqListToRel->list.array[schReqIdx];
10720          }
10721       }
10722    }
10723 }
10724
10725 /*******************************************************************
10726  *
10727  * @brief Fills TagReconfig
10728  *
10729  * @details
10730  *
10731  *    Function : extractTagReconfig
10732  *
10733  *    Functionality: Fills extractTagReconfig
10734  *
10735  * @params[in] TAG_Config_t *cuTagCfg
10736  *             TagCfg *macTagCfg
10737  * @return void
10738  *
10739  * ****************************************************************/
10740
10741 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10742 {
10743   uint8_t tagIdx = 0;
10744   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10745   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10746
10747   /* Tag config to AddMod */
10748   if(cuTagCfg->tag_ToAddModList)
10749   {
10750      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10751      if(tagListToAddMod->list.count)
10752      {
10753         macTagCfg->addModListCount = tagListToAddMod->list.count;
10754         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10755         {
10756            macTagCfg->addModList[tagIdx].tagId =\
10757               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10758            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10759
10760               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10761         }
10762      }
10763   }
10764   /* Tag config to release */
10765   if(cuTagCfg->tag_ToReleaseList)
10766   {
10767      tagListToRel = cuTagCfg->tag_ToReleaseList;
10768      if(tagListToRel->list.count)
10769      {
10770         macTagCfg->relListCount = tagListToRel->list.count;
10771         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10772         {
10773            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10774         }
10775      }
10776   }
10777 }
10778
10779 /*******************************************************************
10780  *
10781  * @brief Fills PdcchCfg received by CU
10782  *
10783  * @details
10784  *
10785  *    Function : extractPdcchCfg
10786  *
10787  *    Functionality: Fills PdcchCfg received  by CU
10788  *
10789  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10790  *             PdcchConfig *duPdcchCfg
10791  * @return void
10792  *
10793  * ****************************************************************/
10794
10795 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10796 {
10797    uint8_t cRsetIdx = 0;
10798    uint8_t srchSpcIdx = 0;
10799
10800    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10801    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10802    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10803    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10804
10805
10806    /* Control Resource Set To Add/Mod List */
10807    if(cuPdcchCfg->controlResourceSetToAddModList)
10808    {
10809       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10810       if(cRsetToAddModList->list.count)
10811       {
10812          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10813          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10814          {
10815             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10816                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10817             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10818                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10819             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10820                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10821                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10822
10823             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10824                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10825
10826             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10827                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10828             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10829             {
10830                //TODO: handle the case for Interleaved
10831             }
10832             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
10833                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
10834             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
10835             {
10836                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
10837                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
10838             }
10839          }
10840       }
10841    }
10842    /* Control Resource Set To Release List */
10843    if(cuPdcchCfg->controlResourceSetToReleaseList)
10844    {
10845       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
10846       if(cRsetToRelList->list.count)
10847       {
10848          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
10849          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
10850          {
10851             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
10852          }
10853       }
10854    }
10855
10856    /* Search space To Add/Mod List */
10857    if(cuPdcchCfg->searchSpacesToAddModList)
10858    {
10859       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
10860       if(srchSpcToAddModList->list.count)
10861       {
10862          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
10863          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
10864          {
10865             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
10866                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
10867             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
10868                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
10869             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
10870             {
10871                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
10872                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
10873             }
10874             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
10875             {
10876                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
10877                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
10878             }
10879             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
10880             {
10881                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
10882                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
10883                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
10884                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
10885                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
10886                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
10887
10888                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
10889                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
10890
10891                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
10892                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
10893             }
10894             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
10895             {
10896                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
10897                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
10898                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
10899                {
10900                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
10901                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
10902                }
10903
10904             }
10905          }
10906       }
10907    }
10908    /* Search space To Rel List */
10909    if(cuPdcchCfg->searchSpacesToReleaseList)
10910    {
10911       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
10912       if(srchSpcToRelList->list.count)
10913       {
10914          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
10915          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
10916          {
10917             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
10918                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
10919          }
10920       }
10921    }
10922 }
10923
10924 /*******************************************************************
10925  *
10926  * @brief Fills PdschCfg received by CU
10927  *
10928  * @details
10929  *
10930  *    Function : extractPdschCfg
10931  *
10932  *    Functionality: Fills PdschCfg received  by CU
10933  *
10934  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
10935  *                   which we have stored in F1UeContextSetupDb,
10936  *             PdschConfig *macPdschCfg = Used to Store the information which
10937  *                   needs to send in other layer, as well as this can be the variable
10938  *                   which stores the information in DuCb,
10939  *             PdschConfig *storedPdschCfg =  Null in case of sending the
10940  *                   information to other layer else it will have stored pdsch 
10941  *                   configuration in copyOfmacUeCfg.
10942  * @return void
10943  *
10944  * ****************************************************************/
10945
10946 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
10947 {
10948    uint8_t timeDomIdx;
10949    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
10950
10951    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
10952    {
10953       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
10954             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
10955       {
10956          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
10957          {
10958             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
10959                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
10960          }
10961       }
10962    }
10963    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
10964    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
10965    {
10966       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
10967       if(timeDomAlloc->present ==\
10968             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
10969       {
10970          if(timeDomAlloc->choice.setup)
10971          {
10972             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
10973             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
10974             {
10975                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
10976                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
10977                {
10978                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
10979                   {
10980                      if(storedPdschCfg)
10981                      {
10982                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10983                         {
10984                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
10985                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
10986                         }
10987                         else
10988                         {
10989                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10990                         }
10991                      }
10992                      else
10993                      {
10994                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10995                      }
10996                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10997                      {
10998                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
10999                         return;
11000                      }
11001                   }
11002                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11003                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11004                }
11005                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11006                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11007                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11008                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11009             }
11010          }
11011       }
11012    }
11013    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11014    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11015       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11016    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11017    {
11018       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11019       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11020       {
11021          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11022          {
11023             macPdschCfg->bundlingInfo.StaticBundling.size = \
11024                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11025          }
11026       }
11027    }
11028    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11029    {
11030       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11031    }
11032
11033 }
11034
11035 /*******************************************************************
11036  *
11037  * @brief Fills PdschServingCellCfg received by CU
11038  *
11039  * @details
11040  *
11041  *    Function : extractPdschServingCellCfg
11042  *
11043  *    Functionality: Fills PdschCfg received  by CU
11044  *
11045  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11046  *             PdschServCellCfg *macUePdschSrvCellCfg
11047  * @return ROK/RFAILED
11048  *
11049  * ****************************************************************/
11050
11051 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11052 {
11053    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11054    {
11055       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11056       {
11057          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11058          {
11059             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11060                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11061          }
11062          else
11063          {
11064             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11065             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11066             {
11067                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11068                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11069             }
11070             else
11071             {
11072                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11073                return RFAILED;
11074             }
11075          }
11076          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11077          {
11078             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11079                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11080          }
11081          else
11082          {
11083             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11084             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11085             {
11086                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11087                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11088             }
11089             else
11090             {
11091                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11092                return RFAILED;
11093             }
11094          }
11095       }
11096    }
11097    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11098    {
11099       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11100    }
11101    if(cuPdschSrvCellCfg->ext1)
11102    {
11103       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11104       {
11105         if(macUePdschSrvCellCfg->maxMimoLayers)
11106         {
11107            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11108         }
11109         else
11110         {
11111            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11112            if(macUePdschSrvCellCfg->maxMimoLayers)
11113            {
11114               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11115            }
11116            else
11117            {
11118               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11119               return RFAILED;
11120            }
11121         }
11122       }
11123    }
11124    if(cuPdschSrvCellCfg->xOverhead)
11125    {
11126       if(macUePdschSrvCellCfg->xOverhead)
11127       {
11128          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11129       }
11130       else
11131       {
11132          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11133          if(macUePdschSrvCellCfg->xOverhead)
11134          {
11135             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11136          }
11137          else
11138          {
11139             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11140             return RFAILED;
11141          }
11142       }
11143    }
11144    return ROK;
11145 }
11146
11147 /*******************************************************************
11148  *
11149  * @brief Fills PuschCfg received by CU
11150  *
11151  * @details
11152  *
11153  *    Function : extractPuschCfg
11154  *
11155  *    Functionality: Fills PuschCfg received  by CU
11156  *
11157  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11158  *             PuschCfg *macPuschCfg
11159  * @return void
11160  *
11161  * ****************************************************************/
11162
11163 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11164 {
11165    uint8_t timeDomIdx = 0;
11166    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11167    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11168
11169    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11170    {
11171       if(cuPuschCfg->choice.setup)
11172       {
11173          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11174          {
11175              macPuschCfg->dataScramblingId = \
11176                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11177          }
11178          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11179          {
11180             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11181             {
11182                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11183                {
11184                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11185                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11186                   {
11187                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11188                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11189                   }
11190                   if(dmrsUlCfg->transformPrecodingDisabled)
11191                   {
11192                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11193                      {
11194                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11195                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11196                      }
11197                   }
11198                }
11199             }
11200          }
11201          /*Res Alloc Type for UL */
11202          if(cuPuschCfg->choice.setup->resourceAllocation)
11203          {
11204             macPuschCfg->resourceAllocType = \
11205                cuPuschCfg->choice.setup->resourceAllocation;
11206          }
11207          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11208          {
11209             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11210             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11211             {
11212                if(timeDomAllocList->choice.setup)
11213                {
11214                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11215                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11216                   {
11217                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11218                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11219                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11220                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11221                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11222                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11223                   }
11224                }
11225             }
11226          }
11227          if(cuPuschCfg->choice.setup->transformPrecoder)
11228             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11229       }
11230    }
11231 }
11232
11233 /*******************************************************************
11234  *
11235  * @brief Function to fill pucch Power Control
11236  *
11237  * @details
11238  *
11239  *    Function : extractPucchPowerControl
11240  *
11241  *    Functionality: Function to fill pucch Power Control
11242  *
11243  * @params[in] PucchPowerControl *pwrCtrl,
11244  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11245  * @return void
11246  *
11247  * ****************************************************************/
11248
11249 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11250 {
11251    uint8_t arrIdx;
11252
11253    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11254       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11255    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11256       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11257    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11258       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11259    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11260       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11261    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11262       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11263    if(cuPwrCtrlCfg->p0_Set)
11264    {
11265       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11266       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11267       {
11268          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11269             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11270          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11271             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11272       }
11273    }
11274    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11275    {
11276       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11277       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11278       {
11279          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11280             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11281       }
11282    }
11283 }
11284  
11285  /*******************************************************************
11286  *
11287  * @brief Function to extractResrcSetToAddModList sent by CU
11288  *
11289  * @details
11290  *
11291  *    Function : extractResrcSetToAddModList
11292  *
11293  *    Functionality: Fucntion to extractResrcSetToAddModList
11294  *
11295  * @params[in] PucchResrcSetCfg pointer,
11296  *             struct PUCCH_Config__resourceSetToAddModList pointer
11297  * @return void
11298  *
11299  * ****************************************************************/
11300
11301 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11302 {
11303    uint8_t arrIdx, rsrcListIdx;
11304
11305    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11306    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11307    {
11308       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11309          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11310       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11311          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11312       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11313       {
11314          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11315             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11316       }
11317
11318       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11319       {
11320          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11321             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11322       }
11323       else
11324       {
11325          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11326       }
11327    }
11328 }/* End of extractResrcSetToAddModList */
11329
11330 /*******************************************************************
11331  *
11332  * @brief Fills extractResrcToAddModList sent by CU
11333  *
11334  * @details
11335  *
11336  *    Function : extractResrcToAddModList
11337  *
11338  *    Functionality: Fills extractResrcToAddModList
11339  *
11340  * @params[in] PucchResrcCfg pointer,
11341  *             struct PUCCH_Config__resourceToAddModList pointer
11342  * @return ROk/RFAILED
11343  *
11344  * ****************************************************************/
11345
11346 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11347 {
11348    uint8_t arrIdx;
11349    
11350    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11351    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11352    {
11353       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11354         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11355       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11356         cuResrcList->list.array[arrIdx]->startingPRB;
11357       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11358       {
11359          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11360            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11361       }
11362       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11363       {
11364          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11365            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11366       }
11367       /* PUCCH RSRC FORMAT */
11368       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11369       {
11370          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11371          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11372          {
11373             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11374             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11375             {
11376                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11377                return RFAILED;
11378             }
11379             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11380                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11381             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11382                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11383             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11384                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11385          }
11386       }
11387       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11388       {
11389          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11390          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11391          {
11392             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11393             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11394             {
11395                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11396                return RFAILED;
11397             }
11398             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11399                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11400             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11401                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11402             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11403                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11404             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11405                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11406          }
11407       }
11408       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11409       {
11410          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11411          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11412          {
11413             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11414             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11415             {
11416                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11417                return RFAILED;
11418             }
11419             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11420                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11421             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11422                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11423             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11424                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11425          }
11426       }
11427       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11428       {
11429          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11430          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11431          {
11432             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11433             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11434             {
11435                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11436                return RFAILED;
11437             }
11438             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11439                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11440             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11441                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11442             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11443                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11444          }
11445       }
11446       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11447       {
11448          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11449          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11450          {
11451             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11452             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11453             {
11454                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11455                return RFAILED;
11456             }
11457             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11458                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11459             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11460                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11461             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11462                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11463             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11464                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11465          }
11466       }
11467    }
11468    return ROK;
11469
11470 }/* End of extractResrcToAddModList */
11471
11472 /*******************************************************************
11473  *
11474  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11475  *
11476  * @details
11477  *
11478  *    Function : fillPucchSchedReqPeriodAndOffset
11479  *
11480  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11481  *
11482  * @params[in] macPeriodicty,
11483  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11484  * @return void
11485  *
11486  * ****************************************************************/
11487
11488 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11489    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11490 {
11491    macPeriodicty = cuPeriodicty->present;
11492    switch(macPeriodicty)
11493    {
11494       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11495          {
11496             macOffset     = cuPeriodicty->choice.sym2;
11497             break;
11498          }
11499       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11500          {
11501             macOffset     = cuPeriodicty->choice.sym6or7;
11502             break;
11503          }
11504       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11505          {
11506             macOffset     = cuPeriodicty->choice.sl1;
11507             break;
11508          }
11509       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11510          {
11511             macOffset = cuPeriodicty->choice.sl2;
11512             break;
11513          }
11514       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11515          {
11516             macOffset = cuPeriodicty->choice.sl4;
11517             break;
11518          }
11519       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11520          {
11521             macOffset = cuPeriodicty->choice.sl5;
11522             break;
11523          }
11524       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11525          {
11526             macOffset = cuPeriodicty->choice.sl8;
11527             break;
11528          }
11529       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11530          {
11531             macOffset = cuPeriodicty->choice.sl10;
11532             break;
11533          }
11534       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11535          {
11536             macOffset = cuPeriodicty->choice.sl16;
11537             break;
11538          }
11539       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11540          {
11541             macOffset = cuPeriodicty->choice.sl20;
11542             break;
11543          }
11544       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11545          {
11546             macOffset = cuPeriodicty->choice.sl40;
11547             break;
11548          }
11549       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11550          {
11551             macOffset = cuPeriodicty->choice.sl80;
11552             break;
11553          }
11554       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11555          {
11556             macOffset = cuPeriodicty->choice.sl160;
11557             break;
11558          }
11559       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11560          {
11561             macOffset = cuPeriodicty->choice.sl320;
11562             break;
11563          }
11564       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11565          {
11566             macOffset = cuPeriodicty->choice.sl640;
11567             break;
11568          }
11569       default :
11570          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11571    }
11572 }
11573
11574 /*******************************************************************
11575  *
11576  * @brief Function to extractPucchFormatCfg sent by CU
11577  *
11578  * @details
11579  *
11580  *    Function : extractPucchFormatCfg
11581  *
11582  *    Functionality: Function to extractPucchFormatCfg
11583  *
11584  * @params[in] PucchFormatCfg pointer,
11585  *             PUCCH_FormatConfig_t pointer
11586  * @return void
11587  *
11588  * ****************************************************************/
11589
11590 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11591  {
11592     if(cuFormatCfg->interslotFrequencyHopping)
11593        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11594     if(cuFormatCfg->additionalDMRS)  
11595        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11596     if(cuFormatCfg->maxCodeRate)
11597        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11598     if(cuFormatCfg->nrofSlots)  
11599        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11600     if(cuFormatCfg->pi2BPSK)  
11601        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11602     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11603        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11604  }/* End of extractPucchFormatCfg */
11605
11606 /*******************************************************************
11607  *
11608  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11609  *
11610  * @details
11611  *
11612  *    Function : extractSchedReqCfgToAddMod
11613  *
11614  *    Functionality: Function to extractSchedReqCfgToAddMod
11615  *
11616  * @params[in] PucchSchedReqCfg pointer,
11617  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11618  * @return void
11619  *
11620  * ****************************************************************/
11621
11622 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11623 {
11624    uint8_t arrIdx;
11625
11626    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11627    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11628    {
11629       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11630          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11631       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11632          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11633       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11634       {
11635          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11636             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11637       }
11638       if(cuSchedReqList->list.array[arrIdx]->resource)
11639       {
11640          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11641             *cuSchedReqList->list.array[arrIdx]->resource;
11642       }
11643    }
11644
11645 }/* End of extractSchedReqCfgToAddMod */
11646
11647  /*******************************************************************
11648  *
11649  * @brief Fills PucchCfg received by CU
11650  *
11651  * @details
11652  *
11653  *    Function : extractPucchCfg
11654  *
11655  *    Functionality: Fills PucchCfg received  by CU
11656  *
11657  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11658  *                is send by CU, which we have stored in F1UeContextSetupDb,
11659  *             PucchCfg *macPucchCfg = Used to Store the information which
11660  *                needs to send in other layer, as well as this can be the variable
11661  *                which stores the information in DuCb,
11662  *             PucchCfg *storedPucchCfg = Null in case of sending the
11663  *                information to other layer else it will have Pucch Cfg which
11664  *                we have stored in copyOfmacUeCfg.
11665  * @return ROK/RFAILED
11666  *
11667  * ****************************************************************/
11668
11669 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11670 PucchCfg *storedPucchCfg)        
11671 {
11672    uint8_t arrIdx;
11673
11674    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11675    {
11676       if(cuPucchCfg->choice.setup)
11677       {
11678          /* Resource Set Cfg */ 
11679          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11680          {
11681             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11682             if(macPucchCfg->resrcSet == NULLP)
11683             {
11684                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11685                return RFAILED;
11686             }
11687             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11688             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11689          }
11690          
11691          /* Resource Cfg */ 
11692          if(cuPucchCfg->choice.setup->resourceToAddModList)
11693          {
11694             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11695             if(macPucchCfg->resrc == NULLP)
11696             {
11697                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11698                return RFAILED;
11699             }
11700             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11701             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11702          }
11703          
11704          /* Format 1 Cfg */ 
11705          if(cuPucchCfg->choice.setup->format1)
11706          {
11707             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11708             if(macPucchCfg->format1 == NULLP)
11709             {
11710                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11711                return RFAILED;
11712             }
11713             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11714             extractPucchFormatCfg(macPucchCfg->format1,\
11715                cuPucchCfg->choice.setup->format1->choice.setup);
11716          }
11717          
11718          /* Format 2 Cfg */
11719          if(cuPucchCfg->choice.setup->format2)
11720          {
11721             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11722             if(macPucchCfg->format2 == NULLP)
11723             {
11724                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11725                return RFAILED;
11726             }
11727             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11728             extractPucchFormatCfg(macPucchCfg->format2,\
11729                cuPucchCfg->choice.setup->format2->choice.setup);
11730          }
11731          
11732          /* Format 3 Cfg */
11733          if(cuPucchCfg->choice.setup->format3)
11734          {
11735             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11736             if(macPucchCfg->format3 == NULLP)
11737             {
11738                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11739                return RFAILED;
11740             }
11741             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11742             extractPucchFormatCfg(macPucchCfg->format3,\
11743                cuPucchCfg->choice.setup->format3->choice.setup);
11744          }
11745
11746          /* Format 4 Cfg */
11747          if(cuPucchCfg->choice.setup->format4)
11748          {
11749             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11750             if(macPucchCfg->format4 == NULLP)
11751             {
11752                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11753                return RFAILED;
11754             }
11755             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11756             extractPucchFormatCfg(macPucchCfg->format4,\
11757                cuPucchCfg->choice.setup->format4->choice.setup);
11758          }
11759
11760          /* Sched Req List */
11761          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11762          {
11763             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11764             if(macPucchCfg->schedReq == NULLP)
11765             {
11766                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11767                return RFAILED;
11768             }
11769             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11770             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11771             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11772          }
11773
11774          /*TODO: Add support for  Spatial Info */
11775
11776          /* MultiCsiCfg */
11777          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11778          {
11779             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11780             if(macPucchCfg->multiCsiCfg == NULLP)
11781             {
11782                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11783                return RFAILED;
11784             }
11785             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11786             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11787             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11788             {
11789                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11790                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11791             }
11792          }
11793
11794          /* Dl_DataToUL_ACK */ 
11795          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11796     {
11797        if(storedPucchCfg)
11798        {
11799           if(storedPucchCfg->dlDataToUlAck)
11800           {
11801              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11802           }
11803           else
11804           {
11805             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11806           }
11807        }
11808        else
11809        {
11810           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11811        }
11812        if(macPucchCfg->dlDataToUlAck == NULLP)
11813        {
11814           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11815           return RFAILED;
11816        }
11817        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11818        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11819        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11820        {
11821           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11822           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11823        }
11824          }
11825
11826          /* Power Control */
11827          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11828          {
11829             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
11830             if(macPucchCfg->powerControl == NULLP)
11831             {
11832                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
11833                return RFAILED;
11834             }
11835             extractPucchPowerControl(macPucchCfg->powerControl,\
11836                cuPucchCfg->choice.setup->pucch_PowerControl);
11837          }
11838       }
11839    }
11840    return ROK;
11841 }
11842
11843 /*******************************************************************
11844  *
11845  * @brief Fills ServingCellReconfig received by CU
11846  *
11847  * @details
11848  *
11849  *    Function : extractSpCellDedicatedCfg
11850  *
11851  *    Functionality: Fills ServingCellReconfig received  by CU
11852  *
11853  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
11854  *                  CU, which we have stored in F1UeContextSetupDb,
11855  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
11856  *                  which  needs to send in other layer, as well as this can be the
11857  *                  variable which stores the information in DuCb, 
11858  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
11859  *                  information to other layer else it will have ServCellCfgInfo which
11860  *                  we have stored in copyOfmacUeCfg.
11861  * @return ROK/RFAILD
11862  *
11863  * ****************************************************************/
11864 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
11865 ServCellRecfgInfo *storedSrvCellCfg)
11866 {
11867    uint8_t ret = ROK;
11868    BWP_DownlinkDedicated_t *dlBwp = NULLP;
11869    BWP_UplinkDedicated_t   *ulBwp = NULLP;
11870
11871    if(cuSrvCellCfg->initialDownlinkBWP)
11872    {
11873       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
11874       if(dlBwp->pdcch_Config)
11875       {
11876          if(dlBwp->pdcch_Config->choice.setup)
11877          {
11878             macSrvCellCfg->initDlBwp.pdcchPresent = true;
11879             if(storedSrvCellCfg)
11880             {
11881                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
11882                {
11883                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11884                }
11885                else
11886                {
11887                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11888                }
11889             }
11890             else
11891             {
11892                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11893             }
11894          }
11895       }
11896       if(dlBwp->pdsch_Config)
11897       {
11898          if(dlBwp->pdsch_Config->choice.setup)
11899          {
11900             macSrvCellCfg->initDlBwp.pdschPresent = true;
11901             
11902             if(storedSrvCellCfg)
11903             {
11904                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
11905                {
11906                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11907                }
11908                else
11909                {
11910                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
11911                         &storedSrvCellCfg->initDlBwp.pdschCfg);
11912                }
11913             }
11914             else
11915             {
11916                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11917             }
11918          }
11919       }
11920    }
11921    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
11922       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
11923    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
11924       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
11925    if(cuSrvCellCfg->bwp_InactivityTimer)
11926    {
11927       if(macSrvCellCfg->bwpInactivityTmr)
11928       {
11929          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11930       }
11931       else
11932       {
11933          macSrvCellCfg->bwpInactivityTmr = NULLP;
11934          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
11935          if(macSrvCellCfg->bwpInactivityTmr)
11936          {
11937             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11938          }
11939          else
11940          {
11941             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
11942             return RFAILED;
11943          }
11944       }
11945    }
11946    if(cuSrvCellCfg->pdsch_ServingCellConfig)
11947    {
11948       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
11949       {
11950          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
11951          if(ret == RFAILED)
11952          {
11953             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
11954             return RFAILED;
11955          }
11956       }
11957    }
11958    if(cuSrvCellCfg->uplinkConfig)
11959    {
11960       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
11961       {
11962          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
11963          if(ulBwp->pusch_Config)
11964          {
11965             macSrvCellCfg->initUlBwp.puschPresent = true;
11966             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
11967          }
11968          if(ulBwp->pucch_Config)
11969          {
11970             macSrvCellCfg->initUlBwp.pucchPresent = true;
11971             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
11972             if(storedSrvCellCfg)
11973             {
11974                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
11975                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11976                else
11977                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
11978                   &storedSrvCellCfg->initUlBwp.pucchCfg);
11979             }
11980             else
11981             {
11982                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11983             }
11984          }
11985       }
11986       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
11987          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
11988    }
11989    return ret;
11990 }
11991
11992 #ifdef NR_DRX
11993
11994 /*******************************************************************
11995  *
11996  * @brief fill long cycle offset value of drx in UE structure
11997  *
11998  * @details
11999  *
12000  *    Function : fillLongCycleOffsetValueInUeDb
12001  *
12002  *    Functionality: fill long cycle offset value of drx in UE structure
12003  *
12004  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12005  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12006  *
12007  * @return ROK     - success
12008  *         RFAILED - failure
12009  *
12010  * ****************************************************************/
12011 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12012 {
12013
12014    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12015    switch(drx_LongCycleStartOffset->present)
12016    {
12017       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12018          {
12019             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12020             break;
12021          }
12022       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12023          {
12024             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12025             break;
12026          }
12027       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12028          {
12029             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12030             break;
12031          }
12032       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12033         {
12034             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12035             break;
12036          }
12037       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12038          {
12039             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12040             break;
12041          }
12042       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12043          {
12044             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12045             break;
12046          }
12047       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12048          {
12049             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12050             break;
12051          }
12052       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12053          {
12054             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12055             break;
12056          }
12057       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12058          {
12059             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12060             break;
12061          }
12062       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12063          {
12064             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12065             break;
12066          }
12067       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12068          {
12069             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12070             break;
12071          }
12072       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12073          {
12074             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12075             break;
12076          }
12077       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12078          {
12079             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12080             break;
12081          }
12082       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12083          {
12084             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12085             break;
12086          }
12087       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12088          {
12089             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12090             break;
12091          }
12092       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12093          {
12094             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12095             break;
12096          }
12097       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12098          {
12099             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12100             break;
12101          }
12102       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12103          {
12104             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12105             break;
12106          }
12107        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12108          {
12109             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12110             break;
12111          }
12112       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12113          {
12114             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12115             break;
12116          }
12117       default :
12118          break;
12119    }
12120 }
12121
12122 /*******************************************************************
12123  *
12124  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12125  *which recive from CU or storedDrxCfg which is already stored
12126  *
12127  * @details
12128  *
12129  *    Function : extractDrxConfiguration 
12130  *
12131  *    Functionality: Fills Reconfig Cell group Info received by CU
12132  *   
12133  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12134  *                       is send by CU, which we have stored in F1UeContextSetupDb
12135  *             DrxCfg * drxCfg  = Used to Store the information,
12136  *                      which needs to send in other layer, as well as this can be
12137  *                      the variable which stores the information in DuCb,
12138  *             DrxCfg *storedDrxCfg = Null in case of sending the
12139  *                      information to other layer else it will have the drx information 
12140  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12141  *
12142  * @return void
12143  *
12144  * ****************************************************************/
12145 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12146 {
12147    struct DRX_ConfigRrc *cuDrxConfig;
12148
12149    if(storedDrxCfg)
12150    {
12151       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12152    }
12153    else
12154    {
12155       if(cuMacCellGrpDrxConfig)
12156       {
12157          switch(cuMacCellGrpDrxConfig->present)
12158          {
12159             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12160                break;
12161
12162             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12163                {
12164                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12165                   if(cuDrxConfig)
12166                   {
12167                      switch(cuDrxConfig->drx_onDurationTimer.present)
12168                      {
12169                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12170                            break;
12171                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12172                            {
12173                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12174                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12175                               drx_onDurationTimer.choice.milliSeconds);
12176                               break;
12177                            }
12178                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12179                            {
12180                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12181                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12182                               break;
12183                            }
12184                      }
12185                   }
12186                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12187                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12188                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12189                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12190                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12191                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12192                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12193                   if(cuDrxConfig->shortDRX)
12194                   {
12195                      drxCfg->shortDrxPres=true;
12196                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12197                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12198                   }
12199                   else
12200                      drxCfg->shortDrxPres=false;
12201
12202                   break;
12203                }
12204
12205             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12206                break;
12207          }
12208       }
12209    }
12210 }
12211 #endif
12212
12213 /*******************************************************************
12214  *
12215  * @brief Fills Reconfig Cell group Info received by CU
12216  *
12217  * @details
12218  *
12219  *    Function : extractUeRecfgCellInfo
12220  *
12221  *    Functionality: Fills Reconfig Cell group Info received by CU
12222  *   
12223  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12224  *                       is send by CU, which we have stored in F1UeContextSetupDb
12225  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12226  *                      which needs to send in other layer, as well as this can be
12227  *                      the variable which stores the information in DuCb,
12228  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12229  *                      information to other layer else it will have copyOfmacUeCfg
12230  *                      which we have stored in F1UeContextSetupDb.
12231  *
12232  * @return ROK/RFAILED
12233  *
12234  * ****************************************************************/
12235 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12236 {
12237    uint8_t ret = ROK;
12238    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12239    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12240    SpCellConfig_t            *spcellCfg = NULLP;
12241    ServingCellConfig_t       *servCellCfg = NULLP;
12242
12243    if(cellGrp)
12244    {
12245       /* Fill MacCell Group Reconfig  */
12246       if(cellGrp->mac_CellGroupConfig)
12247       {
12248          macUeCfg->macCellGrpCfgPres = true;
12249          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12250
12251 #ifdef NR_DRX         
12252          if(macCellGroup->drx_ConfigRrc)
12253          {
12254             if(storedMacUeCfg)
12255             {
12256                if(!storedMacUeCfg->macCellGrpCfgPres) 
12257                {
12258                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12259                }
12260                else
12261                {
12262                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12263                }
12264             }
12265             else
12266             {
12267                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12268             }
12269          }
12270 #endif
12271
12272          if(macCellGroup->schedulingRequestConfig)
12273          {
12274             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12275          }
12276          if(macCellGroup->tag_Config)
12277          {
12278             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12279          }
12280          if(macCellGroup->bsr_Config)
12281          {
12282             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12283             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12284             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12285             {
12286                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12287                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12288             }
12289          }
12290          if(macCellGroup->phr_Config)
12291          {
12292             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12293             {
12294                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12295                if(macCellGroup->phr_Config->choice.setup)
12296                {
12297                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12298                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12299                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12300                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12301                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12302                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12303                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12304                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12305                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12306                   macCellGroup->phr_Config->choice.setup->dummy;
12307                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12308                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12309                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12310                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12311                }
12312             }
12313          }
12314       }
12315       /* Fill Physical Cell Group Reconfig */
12316       if(cellGrp->physicalCellGroupConfig)
12317       {
12318          macUeCfg->phyCellGrpCfgPres = true;
12319          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12320          if(phyCellGrpCfg->p_NR_FR1)
12321          {
12322             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12323                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12324          }
12325          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12326       }
12327       /* Fill SpCell Reconfig */
12328       if(cellGrp->spCellConfig)
12329       {
12330          macUeCfg->spCellCfgPres = true;
12331          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12332          if(spcellCfg->servCellIndex)
12333          {
12334             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12335          }
12336          /* Fill Serving cell Reconfig info */
12337          if(cellGrp->spCellConfig->spCellConfigDedicated)
12338          {
12339             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12340             if(storedMacUeCfg)
12341             {
12342                if(!storedMacUeCfg->spCellCfgPres)
12343                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12344                else
12345                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12346                         &storedMacUeCfg->spCellCfg.servCellCfg);
12347             }
12348             else
12349             {
12350                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12351             }
12352             if(ret == RFAILED)
12353             {
12354                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12355             }
12356          }
12357       }
12358    }
12359    return ret;
12360 }
12361 /*******************************************************************
12362 *
12363 * @brief free the memory allocated by decoder
12364 *
12365 * @details
12366 *
12367 *    Function : freeAperDecodeNrcgi 
12368 *
12369 *    Functionality: Free Nrcgi values
12370 *
12371 * @params[in] NRCGI_t *nrcgi
12372 * @return void
12373 *
12374 * ****************************************************************/
12375
12376
12377 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12378 {
12379     if(nrcgi->pLMN_Identity.buf != NULLP)
12380     {
12381        free(nrcgi->pLMN_Identity.buf);
12382     }
12383     if(nrcgi->nRCellIdentity.buf != NULLP)
12384     {
12385        free(nrcgi->nRCellIdentity.buf);
12386     }
12387 }
12388 /*******************************************************************
12389 *
12390 * @brief free the memory allocated by decoder
12391 *
12392 * @details
12393 *
12394 *    Function : freeAperDecodeCuToDuInfo 
12395 *
12396 *    Functionality:  Free Cu To Du Information
12397 *
12398 * @params[in] CUtoDURRCInformation_t *rrcMsg
12399 * @return void
12400 *
12401 * ****************************************************************/
12402
12403
12404 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12405 {
12406    uint8_t ieIdx =0;
12407    uint8_t arrIdx =0;
12408
12409    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12410    {
12411       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12412          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12413       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12414    }
12415
12416    if(rrcMsg->iE_Extensions)
12417    {
12418       if(rrcMsg->iE_Extensions->list.array)
12419       {
12420          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12421          {
12422             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12423             {
12424                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12425                {
12426                   case ProtocolIE_ID_id_CellGroupConfig:
12427                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12428                      {
12429                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12430                      }
12431                      break;
12432                   default:
12433                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12434                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12435                      break;
12436                }
12437             }
12438          }
12439          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12440          {
12441             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12442          }
12443          free(rrcMsg->iE_Extensions->list.array);
12444
12445       }
12446
12447       free(rrcMsg->iE_Extensions);
12448    }
12449 }
12450 /*******************************************************************
12451 *
12452 * @brief free the memory allocated by decoder
12453 *
12454 * @details 
12455 *
12456 *    Function : freeAperDecodeSplCellList
12457 *
12458 *    Functionality: Free Spl Cell List 
12459                     where memory allocated by aper_decoder
12460 *
12461 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12462 * @return void
12463 *
12464 * ****************************************************************/
12465
12466
12467 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12468 {
12469     uint8_t  cellIdx =0;
12470
12471     if(spCellLst->list.array != NULLP)
12472     {
12473        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12474        {
12475           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12476           {
12477              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12478           }
12479           if(spCellLst->list.array[cellIdx]!=NULLP)
12480           {
12481              free(spCellLst->list.array[cellIdx]);
12482           }
12483        }
12484        free(spCellLst->list.array);
12485     }
12486 }
12487 /*******************************************************************
12488 *
12489 * @brief free the memory allocated by decoder
12490 *
12491 * @details
12492 *
12493 *    Function : freeAperDecodeSRBSetup 
12494 *
12495 *    Functionality: added free part for the memory allocated by aper_decoder
12496 *
12497 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12498 * @return void
12499 *
12500 ****************************************************************/
12501
12502
12503 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12504 {
12505     uint8_t srbIdx =0;
12506     if(srbSet->list.array != NULLP)
12507     {
12508        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12509        {
12510           if(srbSet->list.array[srbIdx]!=NULLP)
12511           {
12512              free(srbSet->list.array[srbIdx]);
12513           }
12514        }
12515        free(srbSet->list.array);
12516     }
12517 }
12518
12519 /*******************************************************************
12520 *
12521 * @brief free the memory allocated by decoder
12522 *
12523 * @details
12524 *
12525 *    Function : freeAperDecodeULTnlInfo
12526 *
12527 *    Functionality: added free part for the memory allocated by aper_decoder
12528 *
12529 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12530 * @return void
12531 *
12532 * ****************************************************************/
12533
12534
12535 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12536 {
12537    uint8_t ulIdx=0;
12538    if(ulInfo->list.array != NULLP)
12539    {
12540       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12541       {
12542          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12543          {
12544             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12545             {
12546                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12547                      transportLayerAddress.buf != NULLP)
12548                {
12549                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12550                         !=NULLP)
12551                   {
12552                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12553                   }
12554                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12555                         transportLayerAddress.buf);
12556                }
12557                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12558             }
12559          }
12560          if(ulInfo->list.array[ulIdx]!=NULLP)
12561          {
12562             free(ulInfo->list.array[ulIdx]);
12563          }
12564       }
12565       free(ulInfo->list.array);
12566    }
12567 }
12568 /*******************************************************************
12569 *
12570 * @brief free the memory allocated by decoder
12571 *
12572 * @details
12573 *
12574 *    Function : freeAperDecodeDRBSetup  
12575 *
12576 *    Functionality: free DRBSetup which is allocated by decoder
12577 *
12578 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12579 * @return void
12580 *
12581 * ****************************************************************/
12582
12583 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12584 {
12585    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12586    uint8_t  flowIdx =0;
12587    uint8_t  drbIdx =0;
12588
12589    if(drbSet->list.array != NULLP)
12590    {
12591       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12592       {
12593          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12594          {
12595             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12596             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12597             {
12598                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12599                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12600                {
12601                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12602                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12603                   {
12604                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12605                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12606                      {
12607
12608                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12609                         {
12610
12611                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12612                            {
12613
12614                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12615                                     buf!=NULLP)
12616                               {
12617
12618                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12619                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12620                                  {
12621
12622                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12623                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12624                                     {
12625
12626                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12627                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12628                                        {
12629                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12630                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12631                                                 qoSFlowLevelQoSParameters.\
12632                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12633                                           {
12634                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12635                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12636                                                    qoSFlowLevelQoSParameters.\
12637                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12638                                              {
12639
12640                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12641                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12642                                                       qoSFlowLevelQoSParameters.\
12643                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12644                                                 {
12645
12646
12647                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12648                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12649                                                          qoSFlowLevelQoSParameters.\
12650                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12651                                                 }
12652
12653                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12654                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12655                                                       qoSFlowLevelQoSParameters.\
12656                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12657                                              }
12658
12659                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12660
12661                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12662                                                    qoSFlowLevelQoSParameters.\
12663                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12664                                           }
12665                                        }
12666                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12667                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12668                                        {
12669
12670                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12671                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12672                                        }
12673                                     }
12674
12675                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12676                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12677                                  }
12678
12679                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12680                                        DRB_Information.sNSSAI.sD->buf);
12681                               }
12682
12683                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12684                            }
12685
12686                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12687
12688                         }
12689
12690                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12691
12692                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12693                      }
12694
12695                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12696                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12697                   }
12698
12699                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12700                         qoS_Characteristics.choice.non_Dynamic_5QI);
12701                }
12702                free(drbSetItem->qoSInformation.choice.choice_extension);
12703             }
12704             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12705             if(drbSetItem->uLConfiguration)
12706             {
12707                free(drbSetItem->uLConfiguration);
12708             }
12709          }
12710          if(drbSet->list.array[drbIdx]!=NULLP)
12711          {
12712             free(drbSet->list.array[drbIdx]);
12713          }
12714       }
12715       free(drbSet->list.array);
12716    }
12717 }
12718
12719
12720 /*******************************************************************
12721  *
12722  * @brief builds Mac Cell Cfg
12723  *
12724  * @details
12725  *
12726  *    Function : procUeRecfgCellInfo
12727  *
12728  *    Functionality: builds Mac Cell Cfg
12729  *
12730  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12731  *                       needs to send in other layer, as well as this can be
12732  *                       the variable which stores the information in DuCb.
12733  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12734  *                       information to other layer else it will have copyOfmacUeCfg  
12735  *                       which we have stored in F1UeContextSetupDb
12736  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12737  *                        by CU, which we have stored in F1UeContextSetupDb 
12738  *
12739  * @return void 
12740  *
12741  * ****************************************************************/
12742 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12743 {
12744    uint8_t ret = ROK;
12745    CellGroupConfigRrc_t *cellGrp = NULLP;
12746
12747    if(cellInfo)
12748    {
12749       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12750       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12751       if(ret == RFAILED)
12752          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
12753    }
12754    if(ret == RFAILED)
12755    {
12756       freeUeRecfgCellGrpInfo(macUeCfgToSend);
12757    }
12758    return ret;
12759 }
12760
12761 /*******************************************************************
12762  *
12763  * @brief Filling modulation info in mac ue cfg
12764  *
12765  * @details
12766  *
12767  *    Function : duFillModulationDetails
12768  *
12769  *    Functionality: Filling modulation info in mac ue cfg
12770  *
12771  * @params[in] MAC UE Config to be updated
12772  *             Current UE configuration
12773  *             UE NR capability from CU
12774  * @return ROK     - success
12775  *         RFAILED - failure
12776  *
12777  * ****************************************************************/
12778 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
12779 {
12780    UE_NR_Capability_t *ueNrCap=NULLP;
12781
12782    if(!ueCap && oldUeCfg)
12783    {
12784       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12785       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12786    }
12787    else
12788    {
12789       ueNrCap = (UE_NR_Capability_t *)ueCap;
12790
12791       /* Filling DL modulation info */
12792       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12793          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12794          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12795       {
12796          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12797          {
12798             case ModulationOrder_qpsk:
12799                {
12800                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12801                   break;
12802                }
12803             case ModulationOrder_qam16:
12804                {
12805                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12806                   break;
12807                }
12808             case ModulationOrder_qam64:
12809                {
12810                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12811                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12812                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12813                   break;
12814                }
12815             case ModulationOrder_qam256:
12816                {
12817                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12818                   break;
12819                }
12820             default:
12821                {
12822                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12823                   if(oldUeCfg)
12824                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12825                   break;
12826                }
12827          }
12828       }
12829       else
12830       {
12831          if(oldUeCfg)
12832             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12833       }
12834
12835       /* Filling UL modulation info */
12836       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
12837          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
12838          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
12839       {
12840          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
12841          {
12842             case ModulationOrder_qpsk:
12843                {
12844                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
12845                   break;
12846                }
12847             case ModulationOrder_qam16:
12848                {
12849                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
12850                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
12851                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
12852                   break;
12853                }
12854             case ModulationOrder_qam64:
12855                {
12856                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
12857                   break;
12858                }
12859             case ModulationOrder_qam256:
12860                {
12861                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
12862                   break;
12863                }
12864             default:
12865                {
12866                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
12867                   if(oldUeCfg)
12868                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12869                   break;
12870                }
12871          }
12872       }
12873       else
12874       {
12875          if(oldUeCfg)
12876             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12877       }
12878    }
12879 }
12880
12881 /*******************************************************************
12882  *
12883  * @brief Function to extract info from CU to DU RRC container extension
12884  *
12885  * @details
12886  *
12887  *    Function : extractCuToDuRrcInfoExt
12888  *
12889  *    Functionality: Function to extract info from CU to DU RRC container
12890  *    extension
12891  *
12892  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
12893  *
12894  * @return ROK
12895  *         RFAILED
12896  *
12897  * ****************************************************************/
12898 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
12899 {
12900    uint8_t ieIdx =0;
12901    uint16_t recvBufLen =0;
12902    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
12903    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
12904    asn_dec_rval_t rval; /* Decoder return value */
12905    memset(&rval, 0, sizeof(asn_dec_rval_t));
12906
12907    if(protocolIeExtn)
12908    {
12909       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
12910       {
12911          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
12912          switch(extIeInfo->id)
12913          {
12914             case ProtocolIE_ID_id_CellGroupConfig:
12915                {
12916                   /* decoding the CellGroup Buf received */
12917                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
12918                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
12919                   if(cellGrpCfg)
12920                   {
12921                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
12922                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
12923                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
12924                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12925                      {
12926                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12927                         return RFAILED;
12928                      }
12929                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
12930
12931                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
12932                         return NULLP;
12933                      ueCfgDb->cellGrpCfg = cellGrpCfg;
12934                   }
12935                   break;
12936                }
12937
12938             case ProtocolIE_ID_id_HandoverPreparationInformation:
12939                {
12940                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
12941                   break;
12942                }
12943
12944             default:
12945                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
12946                break;
12947          }
12948       }
12949    }
12950    return ROK;
12951 }
12952
12953 /*******************************************************************
12954  *
12955  * @brief Fills Srb List received by CU
12956  *
12957  * @details
12958  *
12959  *    Function : procSrbListToSetup
12960  *
12961  *    Functionality: Fills Srb List received  by CU
12962  *
12963  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
12964  *             DuLcCfg pointer
12965  *             RlcBearerCfg pointer
12966  * @return void
12967  *
12968  * ****************************************************************/
12969 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
12970 {
12971
12972    /* Filling RLC INFO */
12973    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
12974
12975    /* Filling MAC INFO */
12976    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
12977    { 
12978       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
12979       return RFAILED;
12980    }
12981
12982    return ROK;
12983 }
12984
12985
12986
12987 /*******************************************************************
12988  *
12989  * @brief extract Srb List received by CU
12990  *
12991  * @details
12992  *
12993  *    Function : extractSrbListToSetup
12994  *
12995  *    Functionality: extract Srb List received by CU
12996  *                   for both MAC and RLC
12997  *
12998  * @params[in] SRBs_ToBeSetup_Item_t pointer
12999  *             DuUeCfg pointer
13000  * @return ROK/RFAIED
13001  *
13002  * ****************************************************************/
13003
13004 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13005 {
13006    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13007    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13008    DuLcCfg *macLcCtxt = NULLP;
13009    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13010
13011    if(srbCfg)
13012    {
13013       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13014       {
13015          macLcCtxt = NULL;
13016          rlcLcCtxt = NULL;
13017
13018          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13019          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13020          { 
13021             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13022             ret = RFAILED;
13023             break;
13024          }
13025          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13026          {
13027             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13028             ret = RFAILED;
13029             break;
13030          }
13031
13032          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13033          {
13034             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13035             {
13036                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13037                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13038                break;
13039             }
13040          }
13041          if(!macLcCtxt)
13042          {
13043             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13044             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13045             ueCfgDb->numMacLcs++;
13046          }
13047          if(!rlcLcCtxt)
13048          {
13049             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13050             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13051             ueCfgDb->numRlcLcs++;
13052          }
13053
13054          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13055
13056          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13057                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13058          if(ret == RFAILED)
13059          {
13060             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13061             break;
13062          }
13063       }
13064    }
13065    else
13066       ret = RFAILED;
13067
13068    return ret;
13069 }
13070
13071 /*******************************************************************
13072  *
13073  * @brief Fills Drb List received by CU
13074  *
13075  * @details
13076  *
13077  *    Function : procDrbListToSetupMod
13078  *
13079  *    Functionality: Fills Drb List received by CU
13080  *                   for both MAC and RLC
13081  *
13082  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13083  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13084  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13085  * @return void
13086  *
13087  * ****************************************************************/
13088
13089 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13090 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13091 {
13092    uint8_t cfgIdx = 0;
13093    RlcMode rlcModeInfo;
13094
13095    if(drbItem != NULLP)
13096    {
13097       /* Filling RLC INFO */
13098       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13099       qoSInformation);
13100
13101       /* Filling MAC INFO */
13102       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13103       { 
13104          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13105          return RFAILED;
13106       }
13107    }
13108    else if(drbSetupModItem != NULLP)
13109    {
13110       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13111       &drbSetupModItem->qoSInformation);
13112
13113       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13114       {
13115          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13116          return RFAILED;
13117       }
13118    }
13119    else if(drbModItem != NULLP)
13120    {
13121       /* Drb to Mod IEs doesnot have rlcMode to be modified
13122        * in ASN. Hence no change in RLC configurations */
13123       if(storedRlcUeCfg != NULLP)
13124       {
13125          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13126          {
13127             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13128             {
13129                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13130                break;
13131             }
13132          }
13133       }
13134
13135       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13136       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13137       {
13138          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13139          return RFAILED;
13140       }
13141    }
13142    return ROK;
13143 }
13144
13145 /*******************************************************************
13146  *
13147  * @brief extract Drb List received by CU
13148  *
13149  * @details
13150  *
13151  *    Function : extractDrbListToSetupMod
13152  *
13153  *    Functionality: extract Drb List received by CU
13154  *                   for both MAC and RLC
13155  *
13156  * @params[in] DRBs_ToBeSetup_Item_t pointer
13157  *             DuUeCfg pointer
13158  * @return ROK/RFAIED
13159  *
13160  * ****************************************************************/
13161
13162 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13163  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13164 {
13165    uint8_t ret = ROK;
13166    uint8_t drbIdx = 0, rlcLcIdx = 0;
13167    uint8_t drbId = 0, lcId = 0;
13168    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13169    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13170    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13171    DuLcCfg *macLcCtxt = NULLP;
13172    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13173
13174    ret = ROK;
13175    if(drbCount > 0)
13176    {
13177       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13178       {
13179          macLcCtxt = NULL;
13180          rlcLcCtxt = NULL;
13181
13182          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13183          { 
13184             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13185             ret = RFAILED;
13186             break;
13187          }
13188          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13189          {
13190             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13191             ret = RFAILED;
13192             break;
13193          }
13194
13195          if(drbModCfg != NULLP)
13196          {
13197             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13198             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13199          }
13200          else if(drbCfg != NULLP)
13201             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13202          else if(drbSetupModCfg != NULL)
13203          {
13204             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13205             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13206          }
13207
13208          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13209          {
13210             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13211                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13212             {
13213                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13214                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13215                break;
13216             }
13217          }
13218          if(!macLcCtxt)
13219          {
13220             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13221             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13222             ueCfgDb->numMacLcs++;
13223          }
13224          if(!rlcLcCtxt)
13225          {
13226             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13227             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13228             ueCfgDb->numRlcLcs++;
13229          }
13230
13231          if(drbModCfg != NULLP)
13232          {
13233             lcId = fetchLcId(drbId);
13234             if(lcId < MIN_DRB_LCID)
13235             {
13236                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13237                break;
13238             } 
13239             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13240             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13241             if(ret == RFAILED)
13242             {
13243                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13244                break;
13245             }
13246             ueCfgDb->numDrbModified++;
13247          }
13248          else
13249          {
13250             lcId = getDrbLcId(drbBitMap);
13251             if(lcId == RFAILED)
13252             {
13253                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13254                ret = RFAILED;
13255                break;
13256             }
13257             if(drbCfg != NULL)
13258             {
13259                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13260                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13261                if(ret == RFAILED)
13262                {
13263                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13264                   break;
13265                }
13266             }
13267             else if(drbSetupModCfg != NULL)
13268             {
13269                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13270                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13271                if(ret == RFAILED)
13272                {
13273                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13274                   break;
13275                }
13276                ueCfgDb->numDrbSetupMod++;
13277             }
13278          }
13279          ueCfgDb->numDrb++;
13280  
13281          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13282                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13283          if(ret == RFAILED)
13284          {
13285             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13286             break;
13287          }
13288       }
13289    }
13290    else
13291       ret = RFAILED;
13292
13293    return ret;
13294 }
13295
13296 /*******************************************************************
13297  *
13298  * @brief extract Drb List received from CU
13299  *
13300  * @details
13301  *
13302  *    Function : extractDrbListToRelease
13303  *
13304  *    Functionality: extract Drb List received from CU
13305  *                   for both MAC and RLC
13306  *
13307  * @params[in] DRBs_ToBeReleased_Item_t pointer
13308  *             DuUeCfg pointer
13309  * @return ROK/RFAIED
13310  *
13311  * ****************************************************************/
13312
13313 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13314 {
13315    uint8_t ret = ROK, teIdx = 0;
13316    uint8_t drbIdx = 0, rlcLcIdx = 0;
13317    uint8_t drbId = 0, lcId = 0;
13318    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13319    DuLcCfg *macLcCtxt = NULLP;
13320    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13321
13322    ret = ROK;
13323    if(drbCount > 0)
13324    {
13325       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13326       {
13327          macLcCtxt = NULL;
13328          rlcLcCtxt = NULL;
13329
13330          if(drbToRel != NULLP)
13331          {
13332             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13333             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13334          }
13335          else
13336          {
13337             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13338             return RFAILED;
13339          }
13340
13341          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13342          {
13343             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13344             {
13345                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13346                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13347                break;
13348             }
13349          }
13350
13351          if(!macLcCtxt)
13352          {
13353             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13354             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13355             ueCfgDb->numMacLcs++;
13356          }
13357          if(!rlcLcCtxt)
13358          {
13359             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13360             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13361             ueCfgDb->numRlcLcs++;
13362          }
13363          lcId = fetchLcId(drbId);
13364          if(lcId < MIN_DRB_LCID)
13365          {
13366             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13367             break;
13368          } 
13369
13370          /* Filling RLC INFO */
13371          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13372          /* Filling MAC INFO */
13373          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13374          { 
13375             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13376             return RFAILED;
13377          }
13378          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13379          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13380          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13381
13382          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13383          {
13384             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13385                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13386             {
13387                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13388                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13389                break;
13390             }
13391          }
13392
13393          ueCfgDb->numDrb++;
13394          if(ret == RFAILED)
13395          {
13396             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13397             break;
13398          }
13399
13400          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13401                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13402       }
13403    }
13404    else
13405       ret = RFAILED;
13406
13407    return ret;
13408 }
13409
13410 /*******************************************************************
13411  *
13412  * @brief Function to extract Dl RRC Msg received from CU
13413  *
13414  * @details
13415  *
13416  *    Function : extractDlRrcMsg
13417  *
13418  *    Functionality: Function to extract Dl RRC Msg received from CU
13419  *
13420  * @params[in] F1AP message
13421  * @return ROK     - success
13422  *         RFAILED - failure
13423  *
13424  * ****************************************************************/
13425
13426 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13427    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13428 {
13429    uint8_t ret = ROK;
13430    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13431    if(dlRrcMsg->rrcMsgSize > 0)
13432    {
13433       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13434       if(!dlRrcMsg->rrcMsgPdu)
13435       {
13436          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13437          ret = RFAILED;
13438       }
13439       else
13440       {
13441          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13442          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13443          dlRrcMsg->srbId = SRB1_LCID;
13444          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13445       }
13446    }
13447    return ret;
13448 }
13449
13450 /*******************************************************************
13451  *
13452  * @brief Extract UE capability info 
13453  *
13454  * @details
13455  *
13456  *    Function : extractUeCapability
13457  *
13458  *    Functionality: Extract UE capability info and stores in ue Cb
13459  *
13460  * @params[in] Octet string of UE capability RAT container list
13461  * @return ROK     - success
13462  *         RFAILED - failure
13463  *
13464  * ****************************************************************/
13465 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13466 {
13467    uint8_t  idx;
13468    uint16_t recvBufLen;
13469    asn_dec_rval_t rval;
13470    UE_NR_Capability_t  *ueNrCap = NULLP;
13471    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13472
13473    /* Decoding UE Capability RAT Container List */
13474    recvBufLen = ueCapablityListBuf->size;
13475    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13476    if(!ueCapRatContList)
13477    {
13478       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13479       return NULLP;
13480    }
13481    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13482    memset(&rval, 0, sizeof(asn_dec_rval_t));
13483    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13484           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13485    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13486    {
13487       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13488       return NULLP;
13489    }
13490    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13491
13492    /* Free encoded buffer after decoding */
13493
13494    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13495    {
13496       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13497       {
13498          /* Decoding UE NR Capability */
13499           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13500           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13501           if(!ueNrCap)
13502           {
13503              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13504              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13505              return NULLP;
13506           } 
13507           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13508           memset(&rval, 0, sizeof(asn_dec_rval_t));
13509           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13510                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13511           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13512           {
13513              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13514              return NULLP;
13515           }
13516           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13517           
13518           /* Free encoded buffer after decoding */
13519           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13520       }
13521       free(ueCapRatContList->list.array[idx]);
13522    }
13523
13524    /* Free Memory*/
13525    free(ueCapRatContList->list.array);
13526    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13527    return ueNrCap;
13528 }
13529  
13530 /*******************************************************************
13531 *
13532 * @brief free UE context setup request from CU
13533 *
13534 * @details
13535 *
13536 *    Function : freeAperDecodeF1UeContextSetupReq
13537 *
13538 *    Functionality: freeing part for the memory allocated by aper_decoder
13539 *
13540 * @params[in] F1AP message
13541 * @return ROK     - success
13542 *         RFAILED - failure
13543 *
13544 * ****************************************************************/
13545 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13546 {
13547    uint8_t ieIdx = 0;
13548
13549    if(ueSetReq->protocolIEs.list.array != NULLP)
13550    {
13551       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13552       {
13553          if(ueSetReq->protocolIEs.list.array[ieIdx])
13554          {
13555             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13556             {
13557                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13558                   break;
13559                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13560                   break;
13561                case ProtocolIE_ID_id_SpCell_ID:
13562                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13563                   break;
13564                case ProtocolIE_ID_id_ServCellIndex:
13565                   break;
13566                case ProtocolIE_ID_id_SpCellULConfigured:
13567                   break;
13568                case ProtocolIE_ID_id_CUtoDURRCInformation:
13569
13570                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13571                   break;
13572                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13573
13574                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13575                   break;
13576                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13577
13578                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13579                   break;
13580                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13581
13582                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13583                   break;
13584                case ProtocolIE_ID_id_RRCContainer:
13585                   {
13586
13587                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13588                      {
13589
13590                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13591                      }
13592                      break;
13593                   }
13594                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13595                   break;
13596                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13597                   {
13598                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13599                      {
13600                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13601                      }
13602                      break;
13603                   }
13604 #ifdef NR_DRX
13605                case ProtocolIE_ID_id_DRXCycle:
13606                   {
13607                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13608                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13609                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13610                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13611                      break;
13612                   }
13613 #endif             
13614                 default:
13615                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13616             } 
13617             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13618          }
13619       }
13620       free(ueSetReq->protocolIEs.list.array);
13621    }
13622 }
13623 /*******************************************************************
13624  *
13625  * @brief Process UE context setup request from CU
13626  *
13627  * @details
13628  *
13629  *    Function : procF1UeContextSetupReq
13630  *
13631  *    Functionality: Process UE context setup request from CU
13632  *
13633  * @params[in] F1AP message
13634  * @return ROK     - success
13635  *         RFAILED - failure
13636  *
13637  * ****************************************************************/
13638 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13639 {
13640    int8_t ueIdx = -1;
13641    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13642    //uint8_t servCellIdx = 0;
13643    bool ueCbFound = false, hoInProgress = false;
13644    uint16_t cellIdx=0;
13645    uint64_t nrCellId = 0;
13646    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13647    DuUeCb   *duUeCb = NULL;
13648    UEContextSetupRequest_t   *ueSetReq = NULL;
13649    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13650    CUtoDURRCInformation_t *rrcInfo = NULL;
13651 #ifdef NR_DRX
13652    DRXCycle_t *drxCycle;
13653 #endif
13654    ret = ROK;
13655
13656    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13657    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13658    {
13659       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13660       {
13661          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13662             {
13663                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13664                break;
13665             }
13666
13667          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13668             {
13669                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13670                break;
13671             }
13672
13673          case ProtocolIE_ID_id_SpCell_ID:
13674             {
13675                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13676
13677                GET_CELL_IDX(nrCellId, cellIdx);
13678                if(!duCb.actvCellLst[cellIdx])
13679                {
13680                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13681                   ret = RFAILED;
13682                }
13683                break;
13684             }
13685
13686          case ProtocolIE_ID_id_ServCellIndex:
13687             {
13688                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13689                break;
13690             }
13691
13692          case ProtocolIE_ID_id_SpCellULConfigured:
13693             {
13694                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13695                   UL, SUL or UL+SUL for the indicated cell for the UE */
13696                break;
13697             }
13698
13699          case ProtocolIE_ID_id_CUtoDURRCInformation:
13700             {
13701                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13702
13703                /* Search if UE context is present */
13704                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13705                {
13706                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13707                   {
13708                      ueCbFound = true;
13709                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13710                      break;
13711                   }
13712                }
13713
13714                /* Check if UE Handover scenario */
13715                if(rrcInfo->iE_Extensions)
13716                {
13717                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13718                   {
13719                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13720                      {
13721                         hoInProgress = true;
13722                         break;
13723                      }
13724                   }
13725                }
13726                
13727                /* If UE context is not present, but UE is in handover */
13728                if(!ueCbFound && hoInProgress)
13729                {
13730                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13731                   if(ueIdx != -1)
13732                      gnbDuUeF1apId = ueIdx +1;
13733                   else
13734                   {
13735                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13736                      ret = RFAILED;
13737                      break;
13738                   }
13739                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13740                   duUeCb->f1UeDb = NULL;
13741                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13742                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13743                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13744                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13745                }
13746
13747                if(duUeCb)
13748                {
13749                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13750                   if(duUeCb->f1UeDb)
13751                   {
13752                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13753                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13754                      duUeCb->f1UeDb->cellIdx = cellIdx;
13755                   }
13756                   else
13757                   {
13758                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13759                      ret = RFAILED;
13760                      break;
13761                   }
13762                }
13763                else
13764                {
13765                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13766                   ret = RFAILED;
13767                   break;
13768                }
13769                  
13770                /* Extract UE capability info */
13771                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13772                {
13773                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13774                }
13775
13776                /* Extract IE extension */
13777                if(rrcInfo->iE_Extensions)
13778                {
13779                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13780                   {
13781                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13782                      //TODO: Update the failure cause in ue context Setup Response
13783                      ret = RFAILED;
13784                   }
13785                }
13786                break;
13787             } 
13788
13789 #ifdef NR_DRX
13790          case ProtocolIE_ID_id_DRXCycle:
13791             {
13792                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
13793                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
13794                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
13795                if(drxCycle->shortDRXCycleLength)
13796                {
13797                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
13798                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
13799                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
13800                }
13801                if(drxCycle->shortDRXCycleTimer)
13802                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
13803
13804                break;
13805             }
13806
13807 #endif
13808          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13809             {
13810                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13811                         &duUeCb->f1UeDb->duUeCfg))
13812                {
13813                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13814                   //TODO: Update the failure cause in ue context Setup Response
13815                   ret = RFAILED;
13816                }
13817                break;
13818             }
13819
13820          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13821             {
13822                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13823
13824                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13825                {
13826                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13827                   //TODO: Update the failure cause in ue context Setup Response
13828                   ret = RFAILED;
13829                }
13830                break;
13831             }
13832          case ProtocolIE_ID_id_RRCContainer:
13833             {
13834                /* Filling Dl RRC Msg Info */
13835                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
13836                if(!duUeCb->f1UeDb->dlRrcMsg)
13837                {
13838                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
13839                   ret = RFAILED;
13840                }
13841                else
13842                {
13843                   duUeCb->f1UeDb->dlRrcMsgPres = true;
13844                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
13845                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
13846                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
13847                }          
13848                break;
13849             }
13850
13851          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13852             {
13853                if(duUeCb->f1UeDb->dlRrcMsg)
13854                {
13855                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
13856                   {
13857                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
13858                   }
13859                   else
13860                   {
13861                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
13862                   }
13863                }
13864                break;
13865             }
13866
13867          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13868             {
13869                /* MaximumBitRate Uplink */
13870                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
13871                if(bitRateSize > 0)
13872                {
13873                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
13874                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
13875                   {
13876                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
13877                      ret = RFAILED;
13878                   }
13879                   else
13880                   {
13881                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
13882                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
13883                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
13884                   }
13885                }
13886                else
13887                   ret = RFAILED;
13888                break;
13889             }
13890
13891          default:
13892             {
13893                break;
13894             }
13895       } /* End of switch */
13896
13897       /* In case of any failure in any IE */
13898       if(ret == RFAILED)
13899       {
13900          // BuildAndSendUeContextSetupRsp(cellId,ueId);
13901          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
13902          break;
13903       }
13904    } /* End of for loop of IEs */
13905
13906    if(ret == ROK)
13907       ret = duProcUeContextSetupRequest(duUeCb);
13908
13909    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
13910    return ret;
13911
13912 }
13913 /*******************************************************************
13914  * @brief Free the memory allocated for Dl Tunnel Info
13915  *
13916  * @details
13917  *
13918  *    Function : freeDlTnlInfo
13919  *
13920  *    Functionality:
13921  *       Free the memory allocated for Dl Tunnel Info
13922  *
13923  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
13924  * @return void
13925  *
13926  * ****************************************************************/
13927
13928 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
13929 {
13930    uint8_t arrIdx = 0;
13931
13932    if(tnlInfo)
13933    {
13934       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
13935       {
13936          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
13937                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
13938          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
13939                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
13940          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13941          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13942       }
13943       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
13944    }
13945 }
13946
13947 /*******************************************************************
13948  * @brief Free the memory allocated for DRB setup List
13949  *
13950  * @details
13951  *
13952  *    Function : freeDrbSetupList
13953  *
13954  *    Functionality:
13955  *       Free the memory allocated for DRB setup list
13956  *
13957  * @params[in] DRBs_Setup_List_t *
13958  * @return void
13959  *
13960  * ****************************************************************/
13961 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
13962 {
13963    uint8_t arrIdx = 0;
13964    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13965
13966    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13967    {
13968       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13969       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
13970       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
13971    }
13972    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13973 }
13974
13975 /*******************************************************************
13976  * @brief Free the memory allocated for UE Setup response
13977  *
13978  * @details
13979  *
13980  *    Function : FreeUeContextSetupRsp
13981  *
13982  *    Functionality:
13983  *       Free the memory allocated for UE Setup response
13984  *
13985  * @params[in] F1AP PDU for UE setup response
13986  * @return ROK     - success
13987  *         RFAILED - failure
13988  *
13989  * ****************************************************************/
13990 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
13991 {
13992    uint8_t idx;
13993    UEContextSetupResponse_t *ueSetRsp = NULLP;
13994
13995    if(f1apMsg)
13996    {
13997       if(f1apMsg->choice.successfulOutcome)
13998       {
13999          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14000                     UEContextSetupResponse;
14001          if(ueSetRsp->protocolIEs.list.array)
14002          {
14003             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14004             {
14005                if(ueSetRsp->protocolIEs.list.array[idx])
14006                {
14007                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14008                   {
14009                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14010                         break;
14011                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14012                         break;
14013                      case ProtocolIE_ID_id_C_RNTI:
14014                         break;
14015                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14016                         {
14017                            CellGroupConfig_t *cellGrpCfg = NULLP;
14018                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14019                                          DUtoCURRCInformation.cellGroupConfig;
14020                            if(cellGrpCfg->buf != NULLP)
14021                            {
14022                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14023                               cellGrpCfg = NULLP;
14024                            }
14025                            break;
14026                         }
14027                      case ProtocolIE_ID_id_DRBs_Setup_List:
14028                         {
14029                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14030                            break;
14031                         }
14032                      default:
14033                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14034                               ueSetRsp->protocolIEs.list.array[idx]->id);
14035                         break;
14036                   }
14037                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14038                         sizeof(UEContextSetupResponseIEs_t));
14039                }
14040             }
14041             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14042                   ueSetRsp->protocolIEs.list.size);
14043          }
14044          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14045       }
14046       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14047    }
14048 }
14049
14050 /*******************************************************************
14051  *
14052  * @brief Builds Ue context Setup Rsp DU To CU Info
14053  *
14054  * @details
14055  *
14056  *    Function : EncodeUeCntxtDuToCuInfo
14057  *
14058  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14059  *
14060  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14061  *
14062  * @return ROK     - success
14063  *         RFAILED - failure
14064  *
14065  ******************************************************************/
14066
14067 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14068 {
14069    asn_enc_rval_t        encRetVal;
14070
14071    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14072    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14073    encBufSize = 0;
14074    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14075    /* Encode results */
14076    if(encRetVal.encoded == ENCODE_FAIL)
14077    {
14078       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14079             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14080       return RFAILED;
14081    }
14082    else
14083    {
14084       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14085 #ifdef DEBUG_ASN_PRINT
14086       for(int i=0; i< encBufSize; i++)
14087       {
14088          printf("%x",encBuf[i]);
14089       }
14090 #endif
14091    }
14092    duToCuCellGrp->size = encBufSize;
14093    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14094    if(!duToCuCellGrp->buf)
14095    {
14096       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14097    }
14098    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14099    return ROK;
14100 }
14101
14102 /*******************************************************************
14103  *
14104  * @brief Fills Dl Gtp tunnel Info
14105  *
14106  * @details
14107  *
14108  *    Function : fillGtpTunnelforDl
14109  *
14110  *    Functionality: Fills Dl Gtp tunnel Info
14111  *
14112  * @params[in] 
14113  *
14114  * @return ROK     - success
14115  *         RFAILED - failure
14116  *
14117  * ****************************************************************/
14118
14119 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14120 {
14121    uint8_t bufSize = 0;
14122
14123    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14124    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14125    if(gtpDl->transportLayerAddress.buf == NULLP)
14126    {
14127       return RFAILED;
14128    }
14129    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14130
14131    /*GTP TEID*/
14132    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14133    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14134    if(gtpDl->gTP_TEID.buf == NULLP)
14135    {
14136       return RFAILED;
14137    }
14138    bufSize = 3; /*forming an Octect String*/
14139    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14140
14141    return ROK;
14142 }
14143
14144 /*******************************************************************
14145  *
14146  * @brief Fills DL Tunnel Setup List
14147  *
14148  * @details
14149  *
14150  *    Function : fillDlTnlSetupList
14151  *
14152  *    Functionality: Fills the DL Tunnel Setup List
14153  *
14154  * @params[in] 
14155  *
14156  * @return ROK     - success
14157  *         RFAILED - failure
14158  *
14159  * ****************************************************************/
14160
14161 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14162 {
14163    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14164
14165    eleCount = 1;
14166    dlTnlInfo->list.count = eleCount; 
14167    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14168
14169    /* Initialize the DL Tnl Setup List Members */
14170    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14171    if(dlTnlInfo->list.array == NULLP)
14172    {
14173       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14174       ret = RFAILED;
14175    }
14176    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14177    {
14178       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14179       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14180       {
14181          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14182          return RFAILED;
14183       }
14184       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14185       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14186       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14187       {
14188          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14189          return RFAILED;
14190       }
14191       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14192                tnlCfg->tnlCfg1);
14193       if(ret != ROK)
14194          break;
14195    }
14196    return ret;
14197 }
14198
14199 /*******************************************************************
14200  *
14201  * @brief Fills the Drb Setup List for Ue Context Setup Response
14202  *
14203  * @details
14204  *
14205  *    Function : fillDrbSetupList
14206  *
14207  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14208  *
14209  * @params[in] 
14210  *
14211  * @return ROK     - success
14212  *         RFAILED - failure
14213  *
14214  * ****************************************************************/
14215 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14216 {
14217    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14218    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14219
14220    eleCount = ueCfg->numDrb;
14221    drbSetupList->list.count = eleCount;
14222    drbSetupList->list.size = \
14223         (eleCount * sizeof(DRBs_Setup_Item_t *));
14224
14225    /* Initialize the Drb Setup List Members */
14226    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14227    if(drbSetupList->list.array == NULLP)
14228    {
14229       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14230       ret = RFAILED;
14231    }
14232
14233    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14234    {
14235       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14236       if(drbSetupList->list.array[arrIdx] == NULLP)
14237       {
14238          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14239          return RFAILED;
14240       }
14241       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14242       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14243       drbItemIe->criticality = Criticality_reject;
14244       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14245       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14246       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14247           &ueCfg->upTnlInfo[arrIdx]);
14248       if(ret != ROK)
14249          break;
14250    }
14251    return ret;
14252 }
14253
14254 /*******************************************************************
14255  *
14256  * @brief Builds and sends the UE Setup Response
14257  *
14258  * @details
14259  *
14260  *    Function : BuildAndSendUeContextSetupRsp
14261  *
14262  *    Functionality: Constructs the UE Setup Response and sends
14263  *                   it to the DU through SCTP.
14264  *
14265  * @params[in] uint8_t cellId,uint8_t ueId
14266  *
14267  * @return ROK     - success
14268  *         RFAILED - failure
14269  *
14270  * ****************************************************************/
14271 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14272 {
14273    uint8_t   idx, ret, cellIdx, elementCnt;
14274    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14275    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14276    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14277    F1AP_PDU_t               *f1apMsg = NULLP;
14278    UEContextSetupResponse_t *ueSetRsp = NULLP;
14279    DuUeCb                   *ueCb = NULLP;
14280
14281    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14282
14283    while(true)
14284    {
14285       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14286       if(f1apMsg == NULLP)
14287       {
14288          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14289          ret = RFAILED;
14290          break;
14291       }
14292
14293       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14294       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14295             sizeof(SuccessfulOutcome_t));
14296       if(f1apMsg->choice.successfulOutcome == NULLP)
14297       {
14298          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14299          ret = RFAILED;
14300          break;
14301       }
14302
14303       f1apMsg->choice.successfulOutcome->procedureCode = \
14304                                                          ProcedureCode_id_UEContextSetup;
14305       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14306       f1apMsg->choice.successfulOutcome->value.present = \
14307                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14308
14309       ueSetRsp =
14310          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14311       elementCnt = 5;
14312       ueSetRsp->protocolIEs.list.count = elementCnt;
14313       ueSetRsp->protocolIEs.list.size = \
14314                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14315
14316       /* Initialize the UESetup members */
14317       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14318             ueSetRsp->protocolIEs.list.size);
14319       if(ueSetRsp->protocolIEs.list.array == NULLP)
14320       {
14321          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14322          ret = RFAILED;
14323          break;
14324       }
14325
14326       for(idx=0; idx<elementCnt; idx++)
14327       {
14328          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14329                sizeof(UEContextSetupResponseIEs_t));
14330          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14331          {
14332             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14333             ret = RFAILED;
14334             break;
14335          }
14336       }
14337       /* Fetching Ue Cb Info*/
14338       GET_CELL_IDX(cellId, cellIdx);
14339       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14340       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14341       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14342
14343       idx = 0;
14344       /*GNB CU UE F1AP ID*/
14345       ueSetRsp->protocolIEs.list.array[idx]->id = \
14346                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14347       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14348       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14349                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14350       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14351
14352       /*GNB DU UE F1AP ID*/
14353       idx++;
14354       ueSetRsp->protocolIEs.list.array[idx]->id = \
14355                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14356       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14357       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14358                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14359       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14360
14361
14362       /*DUtoCURRC Information */
14363       idx++;
14364       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14365                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14366       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14367       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14368                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14369       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14370
14371       /* CRNTI */
14372       idx++;
14373       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14374       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14375       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14376       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14377
14378
14379       /* Drb Setup List */
14380       idx++;
14381       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14382                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14383       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14384       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14385                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14386       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14387             &ueCb->f1UeDb->duUeCfg);
14388       if(ret == RFAILED)
14389       {
14390          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14391          freeF1UeDb(ueCb->f1UeDb);
14392          ueCb->f1UeDb = NULLP;
14393          break;
14394       }
14395
14396       /* Free UeContext Db created during Ue context Req */
14397       freeF1UeDb(ueCb->f1UeDb);
14398       ueCb->f1UeDb = NULLP;
14399
14400       /* TODO: To send Drb list */
14401       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14402
14403       /* Encode the UE context setup response type as APER */
14404       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14405       encBufSize = 0;
14406       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14407             encBuf);
14408       /* Encode results */
14409       if(encRetVal.encoded == ENCODE_FAIL)
14410       {
14411          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14412                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14413          ret = RFAILED;
14414          break;
14415       }
14416       else
14417       {
14418          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14419 #ifdef DEBUG_ASN_PRINT
14420          for(int i=0; i< encBufSize; i++)
14421          {
14422             printf("%x",encBuf[i]);
14423          }
14424 #endif
14425       }
14426
14427       /* Sending  msg  */
14428       if(sendF1APMsg()  != ROK)
14429       {
14430          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14431          ret = RFAILED;
14432          break;
14433       }
14434       break;
14435    }
14436    FreeUeContextSetupRsp(f1apMsg);
14437    return ret;
14438 }/* End of BuildAndSendUeContextSetupRsp */
14439
14440 /*******************************************************************
14441 *
14442 * @brief  Build And Send Ue Context Rsp 
14443 *
14444 * @details
14445 *
14446 *    Function : BuildAndSendUeCtxtRsp 
14447 *
14448 *    Functionality : Build And Send Ue Context Rsp
14449
14450 * @params[in]
14451 * @return sucess = ROK
14452 *         failure = RFAILED
14453 *
14454 * ****************************************************************/
14455 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14456 {
14457    uint8_t cellIdx = 0, actionType = 0; 
14458
14459    GET_CELL_IDX(cellId, cellIdx);
14460    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14461
14462    switch(actionType)
14463    {
14464       case UE_CTXT_SETUP:
14465          {
14466             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14467             {
14468                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14469                return RFAILED;
14470             }
14471             break;
14472          }
14473       case UE_CTXT_MOD:
14474          {
14475             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14476             {
14477                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14478                return RFAILED;
14479             }
14480             break;
14481          }
14482       default:
14483          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14484          break;
14485
14486    }
14487    return ROK;
14488 }
14489
14490 /*******************************************************************
14491  *
14492  * @brief deallocating the memory of  F1reset msg
14493  *
14494  * @details
14495  *
14496  *    Function : FreeF1ResetReq
14497  *
14498  *    Functionality :
14499  *         - freeing memory of F1reset request msg
14500  *
14501  * @params[in]
14502  * @return void
14503  *
14504  *
14505  * ****************************************************************/
14506 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14507 {
14508    uint8_t idx =0 ;
14509    Reset_t *f1ResetMsg;
14510
14511    if(f1apMsg)
14512    {
14513       if(f1apMsg->choice.initiatingMessage)
14514       {
14515          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14516
14517          if(f1ResetMsg->protocolIEs.list.array)
14518          {
14519             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14520             {
14521                if(f1ResetMsg->protocolIEs.list.array[idx])
14522                {
14523                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14524                }
14525             }
14526             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14527          }
14528          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14529       }
14530       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14531    }
14532 }
14533 /*******************************************************************
14534  *
14535  * @brief Build and Send F1reset request 
14536  *
14537  * @details
14538  *
14539  *    Function : BuildAndSendF1ResetReq
14540  *
14541  *    Functionality:
14542  *         - Build and Send F1reset request msg
14543  *
14544  * @params[in]
14545  * @return ROK     - success
14546  *         RFAILED - failure
14547  *
14548  * ****************************************************************/
14549 uint8_t BuildAndSendF1ResetReq()
14550 {
14551    uint8_t          elementCnt=0;
14552    uint8_t          idx=0;
14553    uint8_t          ret= RFAILED;
14554    Reset_t          *f1ResetMsg = NULLP;
14555    F1AP_PDU_t       *f1apMsg = NULLP;
14556    asn_enc_rval_t   encRetVal;
14557    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14558    do
14559    {
14560       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14561       if(f1apMsg == NULLP)
14562       {
14563          break;
14564       }
14565       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14566       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14567       if(f1apMsg->choice.initiatingMessage == NULLP)
14568       {
14569          break;
14570       }
14571       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14572       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14573       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14574
14575       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14576
14577       elementCnt = 3;
14578       f1ResetMsg->protocolIEs.list.count = elementCnt;
14579       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14580
14581       /* Initialize the F1Setup members */
14582       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14583       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14584       {
14585          break;
14586       }
14587       for(idx=0; idx<elementCnt; idx++)
14588       {
14589          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14590          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14591          {
14592             break;
14593          }
14594       }
14595
14596       /*TransactionID*/
14597       idx=0;
14598       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14599       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14600       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14601       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14602
14603       /*Cause*/
14604       idx++;
14605       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14606       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14607       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14608       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14609       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14610
14611       /*Reset Type*/
14612       idx++;
14613       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14614       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14615       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14616       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14617       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14618
14619       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14620
14621       /* Encode the F1SetupRequest type as APER */
14622       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14623       encBufSize = 0;
14624       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14625             encBuf);
14626
14627       /* Encode results */
14628       if(encRetVal.encoded == ENCODE_FAIL)
14629       {
14630          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14631                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14632          break;
14633       }
14634       else
14635       {
14636          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14637 #ifdef DEBUG_ASN_PRINT
14638          for(idx=0; idx< encBufSize; idx++)
14639          {
14640             printf("%x",encBuf[idx]);
14641          }
14642 #endif
14643       }
14644
14645       if(sendF1APMsg() != ROK)
14646       {
14647          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14648          break;
14649       }
14650
14651       ret = ROK;
14652       break;
14653    }while(true);
14654
14655    FreeF1ResetReq(f1apMsg);
14656    return ret;
14657 }
14658 /*******************************************************************
14659  *
14660  * @brief Build And Send F1ResetAck
14661  *
14662  * @details
14663  *
14664  *    Function : BuildAndSendF1ResetAck
14665  *
14666  *    Functionality:
14667  *         - Build And Send  F1ResetRSP
14668  *
14669  * @return ROK     - success
14670  *         RFAILED - failure
14671  *
14672  * ****************************************************************/
14673 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14674 {
14675    uint8_t idx;
14676    ResetAcknowledge_t *f1ResetAck;
14677
14678    if(f1apMsg)
14679    {
14680       if(f1apMsg->choice.successfulOutcome)
14681       {
14682          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14683
14684          if(f1ResetAck->protocolIEs.list.array)
14685          {
14686             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14687             {
14688                if(f1ResetAck->protocolIEs.list.array[idx])
14689                {
14690                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14691                }
14692             }
14693             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14694          }
14695          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14696       }
14697       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14698    }
14699 }
14700
14701 /*******************************************************************
14702  *
14703  * @brief Build And Send F1ResetAck
14704  *
14705  * @details
14706  *
14707  *    Function : BuildAndSendF1ResetAck
14708  *
14709  *    Functionality:
14710  *         - Build And Send  F1ResetRSP
14711  *
14712  *  @params[in]
14713  * @return ROK     - success
14714  *         RFAILED - failure
14715  *
14716  * ****************************************************************/
14717 uint8_t BuildAndSendF1ResetAck()
14718 {
14719    uint8_t                idx = 0;
14720    uint8_t                elementCnt = 0;
14721    uint8_t                ret = RFAILED;
14722    F1AP_PDU_t             *f1apMsg = NULL;
14723    ResetAcknowledge_t     *f1ResetAck = NULLP;
14724    asn_enc_rval_t         encRetVal;
14725    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14726
14727    do{
14728       /* Allocate the memory for F1ResetRequest_t */
14729       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14730       if(f1apMsg == NULLP)
14731       {
14732          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14733          break;
14734       }
14735
14736       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14737
14738       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14739       if(f1apMsg->choice.successfulOutcome == NULLP)
14740       {
14741          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14742          break;
14743       }
14744       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14745       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14746       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14747
14748       elementCnt = 1;
14749
14750       f1ResetAck->protocolIEs.list.count = elementCnt;
14751       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14752
14753       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14754       if(f1ResetAck->protocolIEs.list.array == NULLP)
14755       {
14756          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14757          break;
14758       }
14759
14760       for(idx=0; idx<elementCnt; idx++)
14761       {
14762          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14763          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14764          {
14765             break;
14766          }
14767       }
14768       /*TransactionID*/
14769       idx = 0;
14770       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14771       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14772       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14773       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14774
14775       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14776
14777       /* Encode the F1SetupRequest type as UPER */
14778       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14779       encBufSize = 0;
14780       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14781
14782       /* Check encode results */
14783       if(encRetVal.encoded == ENCODE_FAIL)
14784       {
14785          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14786                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14787          break;
14788       }
14789       else
14790       {
14791          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14792 #ifdef DEBUG_ASN_PRINT
14793          for(int i=0; i< encBufSize; i++)
14794          {
14795             printf("%x",encBuf[i]);
14796          }
14797 #endif
14798       }
14799       /* Sending msg */
14800       if(sendF1APMsg() != ROK)
14801       {
14802          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14803          break;
14804       }
14805
14806       ret = ROK;
14807       break;
14808    }while(true);
14809
14810    FreeF1ResetAck(f1apMsg);
14811    return ret;
14812 }
14813 /******************************************************************
14814 *
14815 * @brief free F1 reset msg allocated by aper_decoder 
14816 *
14817 * @details
14818 *
14819 *    Function : freeAperDecodeF1ResetMsg 
14820 *
14821 *    Functionality: free F1 reset msg allocated by aper_decoder 
14822 *
14823 * @params[in] Reset_t *f1ResetMsg 
14824 * @return void 
14825 *
14826 * ****************************************************************/
14827
14828 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14829 {
14830    uint8_t ieIdx =0;
14831    if(f1ResetMsg->protocolIEs.list.array)
14832    {
14833       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
14834       {
14835          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
14836          {
14837             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
14838          }
14839       }
14840       free(f1ResetMsg->protocolIEs.list.array);
14841    }
14842 }
14843
14844 /******************************************************************
14845  *
14846  * @brief Processes DL RRC Message Transfer  sent by CU
14847  *
14848  * @details
14849  *
14850  *    Function : procF1ResetReq
14851  *
14852  *    Functionality: Processes DL RRC Message Transfer sent by CU
14853  *
14854  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14855  * @return ROK     - success
14856  *         RFAILED - failure
14857  *
14858  * ****************************************************************/
14859 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
14860 {
14861    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
14862    uint8_t       ieIdx = 0;
14863    uint8_t        ret = ROK;
14864    Reset_t       *f1ResetMsg = NULLP;
14865
14866    DU_LOG("\nINFO   -->  Processing F1 reset request");
14867    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14868
14869    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
14870    {
14871       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
14872       {
14873          case ProtocolIE_ID_id_TransactionID:
14874             break;
14875
14876          case ProtocolIE_ID_id_Cause:
14877             break;
14878
14879          case ProtocolIE_ID_id_ResetType:
14880             {
14881                break;
14882             }
14883
14884          default:
14885             break;
14886       }
14887    }
14888    ret = BuildAndSendF1ResetAck();
14889    DU_LOG("\nINFO   -->  UE release is not supported for now");
14890
14891    freeAperDecodeF1ResetMsg(f1ResetMsg);
14892
14893    return ret;
14894 }
14895
14896 /*******************************************************************
14897  *
14898  * @brief free the RRC delivery report
14899  *
14900  * @details
14901  *
14902  *    Function : freeRrcDeliveryReport
14903  *
14904  *    Functionality: free the RRC delivery report
14905  *
14906  * @params[in]
14907  * @return ROK     - success
14908  *         RFAILED - failure
14909  *
14910  * ****************************************************************/
14911 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
14912 {
14913    uint8_t idx=0;
14914    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14915
14916    if(f1apMsg)
14917    {
14918       if(f1apMsg->choice.initiatingMessage)
14919       {
14920          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14921          if(rrcDeliveryReport->protocolIEs.list.array)
14922          {
14923             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
14924                   idx++)
14925             {
14926                if(rrcDeliveryReport->protocolIEs.list.array[idx])
14927                {
14928                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
14929                         sizeof(RRCDeliveryReportIEs_t));
14930                }   
14931             }
14932             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
14933                   rrcDeliveryReport->protocolIEs.list.size);
14934          }
14935          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14936       }
14937       DU_FREE(f1apMsg,
14938             sizeof(F1AP_PDU_t));
14939    }
14940 }
14941
14942 /*******************************************************************
14943 *
14944 * @brief Builds and sends the RRC delivery report
14945 *
14946 * @details
14947 *
14948 *    Function : BuildAndSendRrcDeliveryReport
14949 *
14950 *    Functionality: Builds and sends the RRC delivery report
14951 *
14952 * @params[in]
14953 *
14954 * @return ROK     - success
14955 *         RFAILED - failure
14956 *
14957 * ****************************************************************/
14958 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
14959    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
14960 {
14961    uint8_t             ret = RFAILED;
14962    uint8_t             idx    = 0;
14963    uint8_t             idx1   = 0;
14964    uint8_t             elementCnt = 0;
14965    F1AP_PDU_t          *f1apMsg = NULLP;
14966    asn_enc_rval_t      encRetVal;  
14967    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14968
14969    do{
14970
14971       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
14972       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14973       if(f1apMsg == NULLP)
14974       {
14975          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14976          break;
14977       }
14978       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14979       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14980       if(f1apMsg->choice.initiatingMessage == NULLP)
14981       {
14982          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
14983          break;
14984       }
14985       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
14986       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
14987       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
14988
14989       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14990       elementCnt = 4;
14991       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
14992       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
14993
14994       /* Initialize the F1Setup members */
14995       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
14996       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
14997       {
14998          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
14999          break;
15000       }
15001       for(idx =0 ;idx <elementCnt; idx++)
15002       {
15003          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15004          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15005          {
15006             break;
15007          }
15008       }
15009
15010       idx1 = 0;
15011
15012       /*GNB CU UE F1AP ID*/
15013       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15014       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15015       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15016       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15017
15018       /*GNB DU UE F1AP ID*/
15019       idx1++;
15020       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15021       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15022       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15023       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15024
15025       /*RRC delivery status*/
15026       idx1++;
15027       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15028       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15029       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15030       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15031       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15032       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15033       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15034
15035       /* SRB ID */ 
15036       idx1++;
15037       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15038       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15039       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15040       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15041
15042       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15043
15044       /* Encode the RRC DELIVERY REPORT type as APER */
15045       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15046       encBufSize = 0;
15047       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15048             encBuf);
15049
15050       /* Encode results */
15051       if(encRetVal.encoded == ENCODE_FAIL)
15052       {
15053          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15054                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15055          break;
15056       }
15057       else
15058       {
15059          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15060 #ifdef DEBUG_ASN_PRINT
15061          for(idx=0; idx< encBufSize; idx++)
15062          {
15063             printf("%x",encBuf[idx]);
15064          }
15065 #endif
15066       }
15067
15068       /* Sending msg */
15069       if(sendF1APMsg() != ROK)
15070       {
15071          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15072          break;
15073       }
15074       ret = ROK;
15075       break;
15076
15077    }while(true);
15078
15079    freeRrcDeliveryReport(f1apMsg);
15080    return ret;
15081 }
15082
15083 /*******************************************************************
15084  *
15085  * @brief Processes cells to be activated
15086  *
15087  * @details
15088  *
15089  *    Function : extractCellsToBeActivated
15090  *
15091  *    Functionality:
15092  *      - Processes cells to be activated list received in F1SetupRsp
15093  *
15094  * @params[in] void
15095  * @return ROK     - success
15096  *         RFAILED - failure
15097  *
15098  * ****************************************************************/
15099
15100 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15101 {
15102    uint8_t  ret = ROK;
15103    uint16_t idx, pci = 0;
15104    uint64_t nci;
15105    Cells_to_be_Activated_List_Item_t cell;
15106
15107    for(idx=0; idx<cellsToActivate.list.count; idx++)
15108    {
15109       nci = 0;
15110       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15111       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15112
15113       if(cell.nRPCI)
15114       {
15115          pci = *cell.nRPCI;
15116       }
15117       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15118    }
15119    return ret;
15120 }
15121 /******************************************************************
15122 *
15123 * @brief Processes F1 Setup Response allocated by aper_decoder 
15124 *
15125 * @details
15126 *
15127 *    Function : freeF1SetupRsp 
15128 *
15129 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15130 *
15131 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15132 * @return void 
15133 *
15134 * ****************************************************************/
15135
15136 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15137 {
15138    uint8_t ieIdx =0;
15139    uint8_t arrIdx =0;
15140    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15141    RRC_Version_t      *rrcVer =NULLP;
15142
15143    if(f1SetRspMsg->protocolIEs.list.array)
15144    {
15145       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15146       {
15147          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15148          {
15149             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15150             {
15151                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15152                   {
15153                      cellToActivate =
15154                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15155                      if(cellToActivate->list.array)
15156                      {
15157                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15158                         {
15159                            if(cellToActivate->list.array[arrIdx])
15160                            {
15161
15162                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15163                               pLMN_Identity.buf)
15164                               {
15165                                  if(cellToActivate->list.array[0]->value.choice.\
15166                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15167                                  {
15168                                     free(cellToActivate->list.array[0]->value.choice.\
15169                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15170                                  }
15171
15172                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15173                                        nRCGI.pLMN_Identity.buf);
15174                               }
15175                               free(cellToActivate->list.array[arrIdx]);
15176                            }
15177                         }
15178                         free(cellToActivate->list.array);
15179                      }
15180                      break;
15181                   }
15182                case ProtocolIE_ID_id_TransactionID:
15183                   {
15184                      break;
15185                   }
15186                case ProtocolIE_ID_id_gNB_CU_Name:
15187                   {
15188                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15189                      break;
15190                   }
15191                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15192                   {
15193                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15194                      if(rrcVer->latest_RRC_Version.buf)
15195                      {
15196                         if(rrcVer->iE_Extensions)
15197                         {
15198                            if(rrcVer->iE_Extensions->list.array)
15199                            {
15200                               if(rrcVer->iE_Extensions->list.array[0])
15201                               {
15202                                  if(rrcVer->iE_Extensions->list.\
15203                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15204                                  {
15205                                     free(rrcVer->iE_Extensions->list.\
15206                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15207                                  }
15208                                  free(rrcVer->iE_Extensions->list.array[0]);
15209                               }
15210                               free(rrcVer->iE_Extensions->list.array);
15211                            }
15212                            free(rrcVer->iE_Extensions);
15213                         }
15214                         free(rrcVer->latest_RRC_Version.buf);
15215                      }
15216                      break;
15217
15218                   }
15219                default:
15220                   {
15221                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15222                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15223                   }
15224             }
15225             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15226          }
15227       }
15228       free(f1SetRspMsg->protocolIEs.list.array);
15229    }
15230 }
15231 /******************************************************************
15232  *
15233  * @brief Processes F1 Setup Response sent by CU
15234  *
15235  * @details
15236  *
15237  *    Function : procF1SetupRsp
15238  *
15239  *    Functionality: Processes F1 Setup Response sent by CU
15240  *
15241  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15242  * @return ROK     - success
15243  *         RFAILED - failure
15244  *
15245  * ****************************************************************/
15246 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15247 {
15248    uint8_t ret = ROK;
15249    uint16_t idx =0;
15250    F1SetupResponse_t *f1SetRspMsg = NULLP;
15251    GNB_CU_Name_t     *cuName = NULLP;
15252    F1SetupRsp  f1SetRspDb;
15253    RRC_Version_t      *rrcVer =NULLP;
15254    
15255    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15256
15257    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15258    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15259
15260    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15261    {
15262       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15263       {
15264          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15265             {
15266                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15267                      value.choice.Cells_to_be_Activated_List);
15268                break;
15269             }
15270          case ProtocolIE_ID_id_TransactionID:
15271             {
15272                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15273                                     value.choice.TransactionID;
15274                break;
15275             }
15276          case ProtocolIE_ID_id_gNB_CU_Name:
15277             {
15278                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15279                         value.choice.GNB_CU_Name;
15280                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15281                break;
15282             }
15283          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15284             {
15285                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15286                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15287                      (const char*)rrcVer->latest_RRC_Version.buf);
15288                break;
15289             }
15290          default:
15291             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15292                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15293       }
15294       duProcF1SetupRsp();
15295    }
15296    
15297    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15298
15299    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15300    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15301    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15302    {
15303       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15304       return RFAILED;
15305    }
15306    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15307
15308    if(BuildAndSendE2SetupReq() != ROK)
15309    {
15310       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15311       return RFAILED;
15312    }
15313    return ret;
15314 }
15315 /*******************************************************************
15316 *
15317 * @brief free GNB DU config update ack
15318 *
15319 * @details
15320 *
15321 *    Function : freeAperDecodeGnbDuAck 
15322 *
15323 *    Functionality: Processes GNB DU config update ack And
15324 *                     added free part for the memory allocated by aper_decoder
15325 *
15326 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15327 * @return ROK     - success
15328 *         RFAILED - failure
15329 *
15330 * ****************************************************************/
15331
15332 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15333 {
15334    uint8_t ieIdx = 0;
15335
15336    if(gnbDuAck->protocolIEs.list.array)
15337    {
15338       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15339       {
15340          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15341          {
15342             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15343          }
15344       }
15345       free(gnbDuAck->protocolIEs.list.array);
15346    }
15347 }
15348
15349 /*******************************************************************
15350 *
15351 * @brief Building  result of gnb-du config update ack output
15352 *
15353 * @details
15354 *
15355 *    Function : duProcGnbDuCfgUpdAckMsg 
15356 *
15357 *    Functionality: 
15358 *        Building output of gnb-du config update ack 
15359 *
15360 * @params[in] transId
15361 * @return void
15362 *
15363 * ****************************************************************/
15364
15365 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15366 {
15367    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15368    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15369    uint16_t cellIdx =0, crnti=0;
15370    uint64_t cellId =0;
15371    CmLList *f1apPduNode = NULLP;
15372    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15373    F1AP_PDU_t *f1apMsgPdu = NULLP;
15374    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15375    BIT_STRING_t *cellIdentity=NULLP;
15376    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15377    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15378    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15379
15380    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15381    f1apPduNode = searchFromReservedF1apPduList(transId);
15382    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15383    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15384
15385    if(f1apMsgPdu)
15386    {
15387       if(f1apMsgPdu->choice.initiatingMessage)
15388       {
15389          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15390          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15391          {
15392             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15393             {
15394                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15395                   {
15396                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15397                                      Served_Cells_To_Delete_List;
15398                      if(cellsToDelete->list.array)
15399                      {
15400                         if(cellsToDelete->list.array[arrIdx])
15401                         {
15402                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15403                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15404                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15405                            {
15406                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15407                               bitStringToInt(cellIdentity, &cellId);
15408
15409                               GET_CELL_IDX(cellId, cellIdx);
15410                               if(duCb.actvCellLst[cellIdx] != NULLP)
15411                               {
15412                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15413                               }
15414                            }
15415                         }
15416                      }
15417
15418                      if(duCb.actvCellLst[cellIdx] != NULLP)
15419                      {
15420                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15421                         {
15422                            ret = duSendCellDeletReq(cellId);
15423                            if(ret == RFAILED)
15424                            {
15425                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15426                               request for cellId[%lu]", cellId);
15427                            }
15428                         }
15429                         else
15430                         {
15431                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15432                            while(totalActiveUe)
15433                            {
15434                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15435                               {
15436                                  ueIdx++;
15437                                  continue;
15438                               }
15439
15440                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15441                               GET_UE_ID(crnti,ueId);
15442                               /* Sending Ue Context release request only for maximum supporting UEs */
15443                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15444                               if(ret == RFAILED)
15445                               {
15446                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15447                                  request for cellId[%lu]", cellId);
15448                               }
15449                               ueIdx++;
15450                               totalActiveUe--;
15451                            }
15452                         }
15453                      }
15454                      else
15455                      {
15456                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15457                         ret = RFAILED;
15458                      }
15459                      break;
15460                   }
15461
15462                default:
15463                   break;
15464             }
15465          }
15466       }
15467    }
15468    
15469    FreeDUConfigUpdate(f1apMsgPdu);
15470    deleteFromReservedF1apPduList(f1apPduNode);
15471    return ret;
15472 }
15473
15474 /*******************************************************************
15475 *
15476 * @brief Processes GNB DU config update ack
15477 *
15478 * @details
15479 *
15480 *    Function : procF1GNBDUCfgUpdAck
15481 *
15482 *    Functionality: added free part for the memory allocated by aper_decoder
15483 *
15484 * @params[in] F1AP_PDU_t *f1apMsg 
15485 * @return void 
15486 *
15487 * ****************************************************************/
15488 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15489 {
15490    uint8_t ieIdx=0,transId=0;
15491    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15492
15493    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15494    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15495
15496    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15497    {
15498       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15499       {
15500          case ProtocolIE_ID_id_TransactionID:
15501             {
15502                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15503                break;
15504             }
15505          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15506             {
15507                break;
15508             }
15509          default :
15510             {
15511                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15512                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15513                break;
15514             }
15515       }
15516    }
15517    
15518    duProcGnbDuCfgUpdAckMsg(transId);
15519     
15520 #if 0
15521    /* presently we are not supporting F1 Reset from DU to CU , we are only
15522     * supporting F1 Reset from CU to DU */
15523
15524    if(BuildAndSendF1ResetReq() != ROK)
15525    {
15526       return RFAILED;
15527    }
15528 #endif
15529
15530    freeAperDecodeGnbDuAck(gnbDuAck);
15531    return ROK;
15532 }
15533 /******************************************************************
15534 *
15535 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15536 *
15537 * @details
15538 *
15539 *    Function : freeAperDecodef1DlRrcMsg 
15540 *
15541 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15542 *
15543 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15544 * @return ROK     - success
15545 *         RFAILED - failure
15546 *
15547 * ****************************************************************/
15548
15549 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15550 {
15551    uint8_t ieIdx =0;
15552    RRCContainer_t *rrcContainer = NULLP;
15553
15554    if(f1DlRrcMsg->protocolIEs.list.array)
15555    {
15556       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15557       {
15558          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15559          {
15560             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15561             {
15562                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15563                   break;
15564                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15565                   break;
15566                case ProtocolIE_ID_id_SRBID:
15567                   break;
15568                case ProtocolIE_ID_id_RRCContainer:
15569                   {
15570                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15571                      free(rrcContainer->buf);
15572                   }
15573                case ProtocolIE_ID_id_ExecuteDuplication:
15574                   break;
15575                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15576                   break;
15577                   break;
15578             }
15579             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15580          }
15581       }
15582       free(f1DlRrcMsg->protocolIEs.list.array);
15583    }
15584 }
15585 /******************************************************************
15586  *
15587  * @brief Processes DL RRC Message Transfer  sent by CU
15588  *
15589  * @details
15590  *
15591  *    Function : procF1DlRrcMsgTrans
15592  *
15593  *    Functionality: Processes DL RRC Message Transfer sent by CU
15594  *
15595  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15596  * @return ROK     - success
15597  *         RFAILED - failure
15598  *
15599  * ****************************************************************/
15600 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15601 {
15602    uint8_t  idx, ret;
15603    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15604    F1DlRrcMsg dlMsg;
15605    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15606
15607    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15608    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15609
15610    ret = ROK;
15611
15612    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15613    {
15614       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15615       {
15616          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15617             {
15618                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15619                break;
15620             }
15621          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15622             {
15623                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15624                break;
15625             }
15626          case ProtocolIE_ID_id_SRBID:
15627             {
15628                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15629                break;
15630             }
15631          case ProtocolIE_ID_id_ExecuteDuplication:
15632             dlMsg.execDup = true;
15633             break;
15634
15635          case ProtocolIE_ID_id_RRCContainer:
15636             {
15637                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15638                {
15639              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15640              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15641              if(dlMsg.rrcMsgPdu)
15642              {
15643                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15644                       dlMsg.rrcMsgSize);
15645              }
15646              else
15647              {
15648                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15649                 return RFAILED;
15650              }
15651           }
15652           else
15653           {
15654              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15655                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15656              return RFAILED;
15657           }
15658           break;
15659        }
15660     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15661        {
15662           dlMsg.deliveryStatRpt = true;
15663           break;
15664        }
15665     default:
15666        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15667              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15668       }
15669    }
15670
15671    ret = duProcDlRrcMsg(&dlMsg);
15672
15673    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15674    return ret;
15675 }
15676 /*******************************************************************
15677  *
15678 * @brief Builds the DRB to be Setup Mod list
15679 *
15680 * @details
15681 *
15682 *    Function : 
15683 *
15684 *    Functionality: Constructs the DRB to be Setup Mod list
15685 *
15686 * @params[in] DRBs_SetupMod_List_t *drbSet
15687 *
15688 * @return ROK     - success
15689 *         RFAILED - failure
15690 *
15691 * ****************************************************************/
15692 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15693 {
15694    uint8_t srbIdx = 0;
15695    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15696
15697    srbList->list.count = ueCfg->numRlcLcs;
15698    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15699
15700    DU_ALLOC(srbList->list.array, srbList->list.size);
15701    if(srbList->list.array == NULLP)
15702    {
15703       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15704       return RFAILED;
15705    }
15706
15707    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15708    {
15709       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15710       if(srbList->list.array[srbIdx] == NULLP)
15711       {
15712          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15713          return RFAILED;
15714       }
15715    } 
15716
15717    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15718    {
15719       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15720       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15721       srbItemIe->criticality = Criticality_reject;
15722       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15723       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15724       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15725    }
15726    return ROK;
15727 }
15728
15729 /*******************************************************************
15730  *
15731 * @brief Builds the DRB to be Setup Mod list
15732 *
15733 * @details
15734 *
15735 *    Function : 
15736 *
15737 *    Functionality: Constructs the DRB to be Setup Mod list
15738 *
15739 * @params[in] DRBs_SetupMod_List_t *drbSet
15740 *
15741 * @return ROK     - success
15742 *         RFAILED - failure
15743 *
15744 * ****************************************************************/
15745
15746 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15747 {
15748    uint8_t arrIdx =0;
15749    uint8_t drbCnt =0;
15750    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15751
15752    drbCnt = ueCfg->numDrbSetupMod;
15753
15754    drbSet->list.count = drbCnt;
15755    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15756    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15757    if(drbSet->list.array == NULLP)
15758    {
15759       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15760       return  RFAILED;
15761    }
15762    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15763    {
15764       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15765       if(drbSet->list.array[arrIdx] == NULLP)
15766       {
15767               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15768               return  RFAILED;
15769       }
15770
15771       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15772       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15773       drbItemIe->criticality = Criticality_reject;
15774       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15775       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15776       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15777       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15778       {
15779          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15780          return RFAILED;
15781       }
15782       
15783    }
15784
15785    return ROK;
15786 }
15787 /*******************************************************************
15788 * @brief Free the memory allocated for DRB setup List
15789 *
15790 * @details
15791 *
15792 *    Function : FreeDrbSetupModList 
15793 *
15794 *    Functionality:
15795 *       Free the memory allocated for DRB setup list
15796 *
15797 * @params[in] DRBs_Setup_List_t *
15798 * @return void
15799 *
15800 * ****************************************************************/
15801 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15802 {
15803    uint8_t arrIdx = 0;
15804    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15805
15806    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15807    {
15808       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15809       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15810       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15811    }
15812    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15813 }
15814
15815 /*******************************************************************
15816 *
15817 * @brief Builds the DRB to be Mod list
15818 *
15819 * @details
15820 *
15821 *    Function : 
15822 *
15823 *    Functionality: Constructs the DRB to be Mod list
15824 *
15825 * @params[in] DRBs_Modified_List_t *drbModList
15826 *
15827 * @return ROK     - success
15828 *         RFAILED - failure
15829 *
15830 * ****************************************************************/
15831
15832 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
15833 {
15834    uint8_t arrIdx =0, drbIdx = 0;
15835    uint8_t drbCnt =0;
15836    struct DRBs_Modified_ItemIEs *drbItemIe;
15837
15838    drbCnt = ueCfg->numDrbModified;
15839
15840    drbModList->list.count = drbCnt;
15841    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
15842    DU_ALLOC(drbModList->list.array, drbModList->list.size);
15843    if(drbModList->list.array == NULLP)
15844    {
15845       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
15846       return  RFAILED;
15847    }
15848
15849    drbIdx = 0;
15850    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
15851    {
15852       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
15853       {
15854          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
15855          if(drbModList->list.array[drbIdx] == NULLP)
15856          {
15857             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
15858             return  RFAILED;
15859          }
15860
15861          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
15862          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
15863          drbItemIe->criticality = Criticality_reject;
15864          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
15865          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15866          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
15867                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
15868          {
15869             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
15870             return RFAILED;
15871          }
15872          drbIdx++;
15873       } 
15874    }
15875
15876    return ROK;
15877 }
15878
15879 /*******************************************************************
15880 * @brief Free the memory allocated for DRB Mod List
15881 *
15882 * @details
15883 *
15884 *    Function : FreeDrbModList 
15885 *
15886 *    Functionality:
15887 *       Free the memory allocated for DRB modified list
15888 *
15889 * @params[in] DRBs_Modified_List_t *
15890 * @return void
15891 *
15892 * ****************************************************************/
15893 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
15894 {
15895    uint8_t arrIdx = 0;
15896    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
15897
15898    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
15899    {
15900       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
15901       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
15902       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
15903    }
15904    DU_FREE(drbModList->list.array, drbModList->list.size);
15905 }
15906
15907 /*******************************************************************
15908 * @brief Free the memory allocated for SRB setup List
15909 *
15910 * @details
15911 *
15912 *    Function : FreeSrbSetupModList 
15913 *
15914 *    Functionality:
15915 *       Free the memory allocated for SRB setup list
15916 *
15917 * @params[in] SRBs_Setup_List_t *
15918 * @return void
15919 *
15920 * ****************************************************************/
15921 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
15922 {
15923    uint8_t srbIdx = 0;
15924    
15925    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
15926       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15927    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
15928 }
15929
15930 /*******************************************************************
15931 * @brief Free the memory allocated for UE Context Mod Response
15932 *
15933 * @details
15934 *
15935 *    Function : FreeUeContextModResp 
15936 *
15937 *    Functionality:
15938 *       Free the memory allocated for UE Context Mod Response
15939 *
15940 * @params[in] F1AP_PDU_t *f1apMsg
15941 * @return void
15942 *
15943 * ****************************************************************/
15944
15945 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
15946 {
15947    uint8_t ieIdx;
15948    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15949    if(f1apMsg)
15950    {
15951       if(f1apMsg->choice.successfulOutcome)
15952       {
15953          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15954          if(ueContextModifyRes->protocolIEs.list.array)
15955          {
15956             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
15957             {
15958                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
15959                {
15960                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
15961                   {
15962                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15963                         break;
15964                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15965                         break;
15966                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
15967                         {
15968                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15969                             value.choice.DRBs_SetupMod_List));
15970                             break;
15971                         }
15972                      case ProtocolIE_ID_id_DRBs_Modified_List:
15973                         {
15974                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15975                             value.choice.DRBs_Modified_List));
15976                             break;
15977                         }
15978                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
15979                         {
15980                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
15981                               SRBs_SetupMod_List));
15982                            break; 
15983                         }
15984                   }
15985                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15986                }
15987
15988             }
15989             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15990          }
15991          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15992       }
15993       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15994    }
15995 }
15996
15997 /*****************************************************************i
15998 *
15999 * @brief Creating the ue context modifcation response and sending
16000 *
16001 * @details
16002 *
16003 *    Function : BuildAndSendUeContextModRsp 
16004 *
16005 *    Functionality:
16006 *         - Creating the ue context modifcation response 
16007 *
16008 * @params[in] uint8_t cellId,uint8_t ueId
16009 * @return ROK     - success
16010 *         RFAILED - failure
16011 *
16012 * ****************************************************************/
16013 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16014 {
16015    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16016    uint8_t   elementCnt = 0;
16017    uint8_t   ret = RFAILED;
16018    F1AP_PDU_t *f1apMsg = NULLP;
16019    asn_enc_rval_t  encRetVal;
16020    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16021
16022    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16023
16024    while(true)
16025    {
16026       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16027       if(f1apMsg == NULLP)
16028       {
16029          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16030          break;
16031       }
16032
16033       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16034
16035       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16036       if(f1apMsg->choice.successfulOutcome == NULLP)
16037       {
16038          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16039          break;
16040       }
16041       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16042       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16043       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16044
16045       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16046   
16047       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16048       {
16049          elementCnt = 2;
16050          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16051             elementCnt++;
16052          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16053             elementCnt++; 
16054       }
16055       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16056       {
16057          elementCnt = 5;
16058       }
16059       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16060          elementCnt = 2;
16061       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16062       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16063
16064       /* Initialize the UE context modification members */
16065       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16066       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16067       {
16068          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16069          break;
16070       }
16071
16072       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16073       {
16074          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16075          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16076          {
16077             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16078             break;
16079          }
16080       }
16081
16082       ieIdx=0;
16083       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16084       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16085       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16086       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16087       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16088
16089       ieIdx++;
16090       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16091       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16092       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16093       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16094       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16095
16096       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16097       {
16098          ieIdx++;
16099          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16100          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16101          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16102          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16103          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16104       }
16105
16106       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16107            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16108       { 
16109          ieIdx++;
16110          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16111          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16112          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16113                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16114          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16115          {
16116             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16117             {
16118                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16119                {
16120                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16121                }
16122             }
16123          }
16124          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16125                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16126          if(ret != ROK)
16127          {
16128             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16129             break;
16130          }
16131       }
16132
16133       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16134       { 
16135          ieIdx++;
16136          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16137          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16138          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16139                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16140          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16141                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16142          if(ret != ROK)
16143          {
16144             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16145             break;
16146          }
16147       }
16148
16149       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16150       {
16151          ieIdx++;
16152          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16153          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16154          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16155                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16156          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16157          {
16158             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16159             {
16160                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16161                      sizeof(DuRlcBearerCfg));
16162             }
16163          }
16164          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16165                &ueCb->f1UeDb->duUeCfg);
16166          if(ret != ROK)
16167          {
16168             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16169             break;
16170          }
16171       }
16172
16173       freeF1UeDb(ueCb->f1UeDb);
16174       ueCb->f1UeDb = NULLP;
16175
16176       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16177
16178       /* Encode the F1SetupRequest type as APER */
16179       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16180       encBufSize = 0;
16181       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16182
16183       /* Encode results */
16184       if(encRetVal.encoded == ENCODE_FAIL)
16185       {
16186          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16187                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16188          ret = RFAILED;
16189          break;
16190       }
16191       else
16192       {
16193          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16194 #ifdef DEBUG_ASN_PRINT
16195          for(int i=0; i< encBufSize; i++)
16196          {
16197             printf("%x",encBuf[i]);
16198          }
16199 #endif
16200       }
16201
16202       /* Sending  msg  */
16203       if(sendF1APMsg() != ROK && (ret == ROK))
16204       {
16205          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16206          ret = RFAILED;
16207          break;
16208       }
16209
16210       ret = ROK;
16211       break;
16212    }
16213    FreeUeContextModResp(f1apMsg);
16214    return ret;
16215 }
16216
16217 /*******************************************************************
16218  *
16219  * @brief Deallocating the memory allocated by the aper decoder
16220  *          for QOSInfo
16221  *
16222  * @details
16223  *
16224  *    Function : freeAperDecodeQosInfo
16225  *
16226  *    Functionality:  Deallocating the memory allocated for QOSInfo
16227  *
16228  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16229  *
16230  * @return void
16231  *
16232  * ****************************************************************/
16233
16234 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16235 {
16236    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16237    {
16238       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16239       {
16240          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16241          {
16242             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16243          }
16244          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16245       }
16246       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16247    }
16248 }
16249 /*******************************************************************
16250  *
16251  * @brief Deallocating the memory allocated by the aper decoder
16252  *          for UlTnlInfoforDrb
16253  *
16254  * @details
16255  *
16256  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16257  *
16258  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16259  *
16260  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16261  *
16262  * @return void
16263  *
16264  * ****************************************************************/
16265 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16266 {
16267    uint8_t arrIdx =0;
16268
16269    if(ulInfo->list.array)
16270    {
16271       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16272       {
16273          if(ulInfo->list.array[arrIdx])
16274          {
16275             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16276             {
16277                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16278                {
16279                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16280                   {
16281                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16282                            gTP_TEID.buf);
16283                   }
16284                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16285                         transportLayerAddress.buf);
16286                }
16287                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16288             }
16289             free(ulInfo->list.array[arrIdx]);
16290          }
16291       }
16292       free(ulInfo->list.array);
16293    }
16294 }
16295
16296 /*******************************************************************
16297  *
16298  * @brief Deallocating the memory allocated by the aper decoder
16299  *          for DrbSetupModItem  
16300  *
16301  * @details
16302  *
16303  *    Function : freeAperDecodeDrbSetupModItem 
16304  *
16305  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16306  *
16307  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16308  *
16309  * @return void
16310  *
16311  * ****************************************************************/
16312
16313 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16314 {
16315    uint8_t arrIdx =0;
16316    SNSSAI_t *snssai =NULLP;
16317    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16318
16319    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16320    switch(drbItem->qoSInformation.present)
16321    {
16322       case QoSInformation_PR_NOTHING:
16323          break;
16324       case QoSInformation_PR_eUTRANQoS:
16325          {
16326             if(drbItem->qoSInformation.choice.eUTRANQoS)
16327             {
16328                free(drbItem->qoSInformation.choice.eUTRANQoS);
16329             }
16330             break;
16331          }
16332       case QoSInformation_PR_choice_extension:
16333          {
16334             if(drbItem->qoSInformation.choice.choice_extension)
16335             {
16336                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16337                      DRB_Information.dRB_QoS);
16338                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16339                if(snssai->sST.buf)
16340                {
16341                   free(snssai->sST.buf);
16342                }
16343                if(snssai->sD)
16344                {
16345                   if(snssai->sD->buf)
16346                   {
16347                      free(snssai->sD->buf);
16348                   }
16349                   free(snssai->sD);
16350                }
16351
16352                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16353                          DRB_Information.flows_Mapped_To_DRB_List;
16354                if(flowMap->list.array)
16355                {
16356                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16357                   {
16358                      if(flowMap->list.array[arrIdx] )
16359                      {
16360                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16361                         free(flowMap->list.array[arrIdx]);
16362                      }
16363                   }
16364                   free(flowMap->list.array);
16365                }
16366
16367                free(drbItem->qoSInformation.choice.choice_extension);
16368             }
16369             break;
16370          }
16371
16372    }
16373    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16374    if(drbItem->uLConfiguration)
16375    {
16376       free(drbItem->uLConfiguration);
16377    }
16378 }
16379
16380 /*******************************************************************
16381  *
16382  * @brief Deallocating the memory allocated by the aper decoder
16383  *          for DrbToBeSetupModList
16384  *
16385  * @details
16386  *
16387  *    Function : freeAperDecodeDrbToBeSetupModList
16388  *
16389  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16390  *
16391  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16392  *
16393  * @return void
16394  *
16395  * ****************************************************************/
16396
16397 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16398 {
16399    uint8_t arrIdx =0;
16400    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16401
16402    if(drbSet->list.array)
16403    {
16404       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16405       {
16406          if(drbSet->list.array[arrIdx] != NULLP)
16407          {
16408             if(arrIdx == 0)
16409             {
16410                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16411                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16412             }
16413             free(drbSet->list.array[arrIdx]);
16414          }
16415       }
16416       free(drbSet->list.array);
16417    }
16418
16419 }
16420
16421 /*******************************************************************
16422  *
16423  * @brief Deallocating the memory allocated by the aper decoder
16424  *          for DrbSetupModItem  
16425  *
16426  * @details
16427  *
16428  *    Function : freeAperDecodeDrbModifiedItem 
16429  *
16430  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16431  *
16432  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16433  *
16434  * @return void
16435  *
16436  * ****************************************************************/
16437
16438 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16439 {
16440    uint8_t arrIdx =0;
16441    SNSSAI_t *snssai =NULLP;
16442    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16443
16444    if(drbItem->qoSInformation != NULLP)
16445    {
16446       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16447       switch(drbItem->qoSInformation->present)
16448       {
16449          case QoSInformation_PR_NOTHING:
16450             break;
16451          case QoSInformation_PR_eUTRANQoS:
16452             {
16453                if(drbItem->qoSInformation->choice.eUTRANQoS)
16454                {
16455                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16456                }
16457                break;
16458             }
16459          case QoSInformation_PR_choice_extension:
16460             {
16461                if(drbItem->qoSInformation->choice.choice_extension)
16462                {
16463                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16464                         DRB_Information.dRB_QoS);
16465                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16466                   if(snssai->sST.buf)
16467                   {
16468                      free(snssai->sST.buf);
16469                   }
16470                   if(snssai->sD)
16471                   {
16472                      if(snssai->sD->buf)
16473                      {
16474                         free(snssai->sD->buf);
16475                      }
16476                      free(snssai->sD);
16477                   }
16478
16479                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16480                             DRB_Information.flows_Mapped_To_DRB_List;
16481                   if(flowMap->list.array)
16482                   {
16483                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16484                      {
16485                         if(flowMap->list.array[arrIdx] )
16486                         {
16487                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16488                            free(flowMap->list.array[arrIdx]);
16489                         }
16490                      }
16491                      free(flowMap->list.array);
16492                   }
16493
16494                   free(drbItem->qoSInformation->choice.choice_extension);
16495                }
16496                break;
16497             }
16498       }
16499       free(drbItem->qoSInformation);
16500    }
16501    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16502    if(drbItem->uLConfiguration)
16503    {
16504       free(drbItem->uLConfiguration);
16505    }
16506 }
16507
16508 /*******************************************************************
16509  *
16510  * @brief Deallocating the memory allocated by the aper decoder
16511  *          for DrbToBeSetupModList
16512  *
16513  * @details
16514  *
16515  *    Function : freeAperDecodeDrbToBeModifiedList
16516  *
16517  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16518  *
16519  * @params[in] DRBs_ToBeModified_List_t *drbSet
16520  *
16521  * @return void
16522  *
16523  * ****************************************************************/
16524
16525 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16526 {
16527    uint8_t arrIdx =0;
16528    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16529
16530    if(drbSet->list.array)
16531    {
16532       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16533       {
16534          if(drbSet->list.array[arrIdx] != NULLP)
16535          {
16536             if(arrIdx == 0)
16537             {
16538                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16539                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16540             }
16541             free(drbSet->list.array[arrIdx]);
16542          }
16543       }
16544       free(drbSet->list.array);
16545    }
16546
16547 }
16548
16549 /*******************************************************************
16550  *
16551  * @brief Deallocating the memory allocated by the aper decoder
16552  *          for DrbToBeSetupModList
16553  *
16554  * @details
16555  *
16556  *    Function : freeAperDecodeDrbToBeReleasedList
16557  *
16558  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16559  *
16560  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16561  *
16562  * @return void
16563  *
16564  * ****************************************************************/
16565
16566 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16567 {
16568    uint8_t arrIdx =0;
16569
16570    if(drbSet->list.array)
16571    {
16572       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16573       {
16574          if(drbSet->list.array[arrIdx] != NULLP)
16575          {
16576             free(drbSet->list.array[arrIdx]);
16577          }
16578       }
16579       free(drbSet->list.array);
16580    }
16581
16582 }
16583 /*******************************************************************
16584  *
16585  * @brief Deallocating the memory allocated by the aper decoder
16586  *          for UeContextModificationReqMsg
16587  *
16588  * @details
16589  *
16590  *    Function : freeAperDecodeUeContextModificationReqMsg
16591  *
16592  *    Functionality:  Deallocating memory allocated for
16593  *                  UeContextModificationReqMsg
16594  *
16595  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16596  *
16597  * @return void
16598  *
16599  * ****************************************************************/
16600 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16601 {
16602    uint8_t arrIdx, ieId;
16603
16604    if(ueContextModifyReq->protocolIEs.list.array)
16605    {
16606       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16607       {
16608          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16609          {
16610             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16611             switch(ieId)
16612             {
16613                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16614                   break;
16615                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16616                   break;
16617                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16618                   {
16619                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16620                            value.choice.DRBs_ToBeSetupMod_List);
16621                      break;
16622                   }
16623                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16624                   {
16625                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16626                            value.choice.DRBs_ToBeModified_List);
16627                      break;
16628                   }
16629                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16630                   {
16631                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16632                            value.choice.DRBs_ToBeReleased_List);
16633                      break;
16634                   }
16635                case ProtocolIE_ID_id_TransmissionActionIndicator:
16636                   break;
16637                case ProtocolIE_ID_id_RRCContainer:
16638                   {
16639                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16640                   }
16641             }
16642             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16643          }
16644       }
16645       free(ueContextModifyReq->protocolIEs.list.array);
16646    }
16647 }
16648 /*******************************************************************
16649  *
16650  * @brief processing the F1 UeContextModificationReq
16651  *
16652  * @details
16653  *
16654  *    Function : procF1UeContextModificationReq
16655  *
16656  *    Functionality:  processing the F1 UeContextModificationReq
16657  *
16658  * @params[in] F1AP_PDU_t *f1apMsg
16659  *
16660  * @return
16661  * ****************************************************************/
16662 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16663 {
16664    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16665    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16666    DuUeCb   *duUeCb = NULLP;
16667    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16668    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16669    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16670    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16671
16672    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16673    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16674    {
16675       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16676       {
16677          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16678             {
16679                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16680                break;
16681             }
16682          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16683             {
16684                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16685                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16686                {
16687                   if(duCb.actvCellLst[cellIdx])
16688                   {
16689                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16690                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16691                      {
16692                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16693                         if(duUeCb->f1UeDb == NULLP)
16694                         {
16695                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16696                            duUeCb->f1UeDb->cellIdx = cellIdx;
16697                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16698                         }
16699                         break;
16700                      }
16701                   }
16702                }
16703                if(duUeCb == NULLP)
16704                {
16705                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16706                   ret = RFAILED;
16707                }
16708                break;
16709             }
16710
16711          case ProtocolIE_ID_id_RRCContainer:
16712             {
16713                /* Filling Dl RRC Msg Info */
16714                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16715                if(!duUeCb->f1UeDb->dlRrcMsg)
16716                {
16717                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16718                         Memory allocation failed ");
16719                   ret = RFAILED;
16720                }
16721                else
16722                {
16723                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16724                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16725                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16726                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16727                         value.choice.RRCContainer);
16728                }
16729
16730                break;
16731             }
16732
16733          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16734          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16735          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16736             {
16737                if(duUeCb->f1UeDb)
16738                {
16739                   /*DRBs to be Added*/
16740                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
16741                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
16742                   {
16743                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16744                                       choice.DRBs_ToBeSetupMod_List;
16745
16746                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
16747                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
16748                      {
16749                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
16750                         ret = RFAILED;
16751                      }
16752                   }
16753
16754                   /*DRBs to be Modified*/
16755                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
16756                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
16757
16758                   {
16759                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16760                                       choice.DRBs_ToBeModified_List;
16761                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
16762                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
16763                      {
16764                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
16765                         ret = RFAILED;
16766                      }
16767                   }
16768                   /*DRBs to be Released*/
16769                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
16770                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
16771
16772                   {
16773                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16774                                       choice.DRBs_ToBeReleased_List;
16775                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
16776                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
16777                      {
16778                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
16779                         ret = RFAILED;
16780                      }
16781                   }
16782                }
16783                break;
16784             }
16785
16786          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
16787             {
16788                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
16789                if(duUeCb->f1UeDb)
16790                {
16791                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
16792                }
16793                break;
16794             }
16795
16796          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
16797             {
16798                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
16799                   RRCReconfigurationCompleteIndicator_true)
16800                {
16801                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
16802                }
16803                break;
16804             }
16805          case ProtocolIE_ID_id_TransmissionActionIndicator:
16806             {
16807                if(duUeCb->f1UeDb)
16808                {
16809                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
16810                   {
16811                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
16812                   }
16813                   else 
16814                   {
16815                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
16816                   }
16817                }
16818                break;
16819             }
16820
16821          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
16822             {
16823                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
16824                {
16825                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
16826                }
16827                break;
16828             }
16829 #ifdef NR_DRX
16830          case ProtocolIE_ID_id_DRXConfigurationIndicator:
16831             {
16832                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
16833                break;
16834             }
16835 #endif
16836               
16837       }
16838    }
16839
16840    if(ret != RFAILED) 
16841    {
16842       ret = duProcUeContextModReq(duUeCb);
16843    }
16844    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
16845    return ret; 
16846 }
16847
16848 /*****************************************************************i
16849 *
16850 * @brief Free memory allocated for UE Context Release Request
16851 *
16852 * @details
16853 *
16854 *    Function : FreeUeContextReleaseReq
16855 *
16856 *    Functionality:
16857 *         - Free memory allocated for UE Context Release Request
16858 *
16859 * @params[in] F1AP_PDU_t *f1apMsg
16860 * @return void 
16861 *
16862 * *************************************************************/
16863 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
16864 {
16865    uint8_t ieIdx;
16866    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
16867    
16868    if(f1apMsg)
16869    {
16870       if(f1apMsg->choice.initiatingMessage)
16871       {
16872          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
16873          if(ueReleaseReq->protocolIEs.list.array)
16874          {
16875             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
16876             {
16877                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
16878             }
16879             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
16880          }
16881          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
16882       }
16883       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16884    }
16885
16886 }
16887 /*****************************************************************i
16888 *
16889 * @brief Build and Send UE Context Release Request  
16890 *
16891 * @details
16892 *
16893 *    Function : BuildAndSendUeContextReleaseReq
16894 *
16895 *    Functionality:
16896 *         - Build and Send UE Context Release Request 
16897 *
16898 * @params[in]
16899 * @return ROK     - success
16900 *         RFAILED - failure
16901 *
16902 * *************************************************************/
16903 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
16904 {
16905    bool memAllocFail = false;
16906    uint8_t ieIdx =0;
16907    uint8_t ret = RFAILED;
16908    uint16_t cellIdx =0;
16909    uint16_t crnti = 0;
16910    uint8_t  elementCnt = 0;
16911    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
16912    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
16913    asn_enc_rval_t encRetVal; 
16914    F1AP_PDU_t *f1apMsg = NULLP;
16915    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
16916
16917    DU_LOG("\nINFO  --> Building the UE Context Release Request");
16918    do
16919    {
16920       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16921       if(f1apMsg == NULLP)
16922       {
16923          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
16924          break;
16925       }
16926
16927       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
16928       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
16929       if(f1apMsg->choice.initiatingMessage == NULLP)
16930       {
16931          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
16932          initiatingMessage");   
16933          break;
16934       }
16935       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
16936       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
16937       f1apMsg->choice.initiatingMessage->value.present = \
16938       InitiatingMessage__value_PR_UEContextReleaseRequest;
16939
16940       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
16941
16942       elementCnt = 2;
16943
16944       ueReleaseReq->protocolIEs.list.count = elementCnt;
16945       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
16946
16947       /* Initialize the F1Setup members */
16948       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
16949       if(ueReleaseReq->protocolIEs.list.array == NULLP)
16950       {
16951          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
16952          break;
16953       }
16954       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16955       {
16956          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
16957                sizeof(UEContextReleaseRequest_t));
16958          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
16959          {
16960             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
16961             memAllocFail = true;  
16962             break;
16963          }
16964       }
16965       if(memAllocFail == true)
16966          break;
16967
16968       /* Fetching Ue Cb Info*/
16969       GET_CELL_IDX(cellId, cellIdx);
16970       if(duCb.actvCellLst[cellIdx] == NULLP)
16971       {
16972          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
16973          break;
16974       }
16975       else
16976       {
16977          GET_CRNTI(crnti, ueId);
16978          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
16979          {
16980             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
16981             break;
16982          }
16983          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
16984          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
16985       }
16986
16987       ieIdx=0; 
16988       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
16989       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16990       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
16991       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
16992       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16993       
16994       ieIdx++;
16995       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16996       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16997       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
16998       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
16999       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17000       
17001       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17002
17003       /* Encode the F1SetupRequest type as APER */
17004       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17005       encBufSize = 0;
17006       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17007       /* Encode results */
17008       if(encRetVal.encoded == ENCODE_FAIL)
17009       {
17010          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17011                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17012          break;
17013       }
17014       else
17015       {
17016          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17017 #ifdef DEBUG_ASN_PRINT
17018          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17019          {
17020             printf("%x",encBuf[ieIdx]);
17021          }
17022 #endif
17023       }
17024
17025       /* Sending msg */
17026       if(sendF1APMsg() != ROK)
17027       {
17028          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17029          break;
17030       }
17031       ret = ROK;
17032       break;
17033    }while(true);
17034
17035    FreeUeContextReleaseReq(f1apMsg);
17036    return ret;
17037 }
17038 /*****************************************************************i
17039  *
17040  * @brief Free memory allocated for UE Context Release Complete
17041  *
17042  * @details
17043  *
17044  *    Function : FreeUeContextReleaseComplete
17045  *
17046  *    Functionality:
17047  *         - Free memory allocated for UE Context Release Complete
17048  *
17049  * @params[in] F1AP_PDU_t *f1apMsg
17050  * @return void
17051  *
17052  * *************************************************************/
17053 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17054 {
17055    uint8_t ieIdx;
17056    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17057
17058    if(f1apMsg)
17059    {
17060       if(f1apMsg->choice.successfulOutcome)
17061       {
17062          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17063          if(ueReleaseComplete->protocolIEs.list.array)
17064          {
17065             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17066             {
17067                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17068             }
17069             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17070          }
17071          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17072       }
17073       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17074    }
17075
17076 }
17077 /*****************************************************************i
17078  *
17079  * @brief Build and Send UE Context Release Complete
17080  *
17081  * @details
17082  *
17083  *    Function : BuildAndSendUeContextReleaseComplete
17084  *
17085  *    Functionality:
17086  *         - Build and Send UE Context Release Complete
17087  *
17088  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17089  * @return ROK     - success
17090  *         RFAILED - failure
17091  *
17092  * *************************************************************/
17093 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17094 {
17095    bool memAllocFail = false;
17096    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17097    asn_enc_rval_t encRetVal;
17098    F1AP_PDU_t *f1apMsg = NULLP;
17099    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17100
17101    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17102    do
17103    {
17104       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17105       if(f1apMsg == NULLP)
17106       {
17107          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17108          break;
17109       }
17110
17111       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17112       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17113       if(f1apMsg->choice.successfulOutcome == NULLP)
17114       {
17115          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17116                successfulOutcome");
17117          break;
17118       }
17119       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17120       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17121       f1apMsg->choice.successfulOutcome->value.present = \
17122       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17123
17124       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17125
17126       elementCnt = 2;
17127       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17128       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17129
17130       /* Initialize the UE Release Complete members */
17131       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17132       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17133       {
17134          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17135          break;
17136       }
17137       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17138       {
17139          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17140                sizeof(UEContextReleaseComplete_t));
17141          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17142          {
17143             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17144             elements");
17145             memAllocFail = true;
17146             break;
17147          }
17148       }
17149       if(memAllocFail == true)
17150          break;
17151
17152
17153       ieIdx=0;
17154       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17155       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17156       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17157       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17158       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17159
17160       ieIdx++;
17161       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17162       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17163       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17164       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17165       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17166
17167       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17168
17169       /* Encode the F1SetupComplete type as APER */
17170       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17171       encBufSize = 0;
17172       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17173       /* Encode results */
17174       if(encRetVal.encoded == ENCODE_FAIL)
17175       {
17176          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17177                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17178          break;
17179       }
17180       else
17181       {
17182          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17183 #ifdef DEBUG_ASN_PRINT
17184          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17185          {
17186             printf("%x",encBuf[ieIdx]);
17187          }
17188 #endif
17189       }
17190
17191       /* Sending msg */
17192       if(sendF1APMsg() != ROK)
17193       {
17194          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17195          break;
17196       }
17197       ret = ROK;
17198       break;
17199    }while(true);
17200    
17201    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17202          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17203    {
17204       ret = duSendCellDeletReq(cellId);
17205       if(ret != ROK)
17206       {
17207          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17208                Delete req for CellId");
17209       }
17210    }
17211    FreeUeContextReleaseComplete(f1apMsg);
17212    return ret;
17213
17214 }
17215
17216 /*******************************************************************
17217 *
17218 * @brief added free part for the memory allocated by aper_decoder 
17219 *
17220 * @details
17221 *
17222 *    Function : freeAperDecodeUeContextReleaseCommand 
17223 *
17224 *    Functionality: added free part for the memory allocated by aper_decoder
17225 *
17226 * @params[in] F1AP_PDU_t *f1apMsg
17227 * @return void
17228 *
17229 * ****************************************************************/
17230 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17231 {
17232    uint8_t ieIdx=0;
17233    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17234
17235    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17236    
17237    if(ueContextReleaseCommand->protocolIEs.list.array)
17238    {
17239       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17240       {
17241          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17242          {
17243             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17244             {
17245                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17246                   break;
17247                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17248                   break;
17249                case ProtocolIE_ID_id_Cause:
17250                   break;
17251                case ProtocolIE_ID_id_RRCContainer:
17252                {
17253                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17254                   {
17255                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17256                   }
17257                   break;
17258                }
17259                default :
17260                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17261                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17262                   break;
17263             }
17264          }
17265          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17266       }
17267       free(ueContextReleaseCommand->protocolIEs.list.array);
17268    }
17269 }
17270 /*******************************************************************
17271 *
17272 * @brief processing of UE Context Release Command
17273 *
17274 * @details
17275 *
17276 *    Function : procF1UeContextReleaseCommand 
17277 *
17278 *    Functionality: processing of UE Context Release Command
17279 *
17280 * @params[in] F1AP_PDU_t *f1apMsg
17281 * @return void
17282 *
17283 * ****************************************************************/
17284 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17285 {
17286    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17287    uint16_t cellIdx =0, cellId = 0;
17288    bool ueIdxFound = false;
17289    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17290    DuUeCb   *duUeCb = NULLP;
17291    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17292
17293    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17294
17295    if(ueContextReleaseCommand->protocolIEs.list.array)
17296    {
17297       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17298       {
17299          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17300          {
17301             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17302             {
17303                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17304                   {
17305                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17306                                     value.choice.GNB_CU_UE_F1AP_ID;
17307                      break;
17308                   }
17309
17310                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17311                   {
17312                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17313                                      value.choice.GNB_DU_UE_F1AP_ID;
17314                      break;
17315                   }
17316
17317                case ProtocolIE_ID_id_Cause:
17318                   {
17319                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17320                      {
17321                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17322                         {
17323                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17324                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17325                            {
17326                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17327                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17328                               ueIdxFound = true;
17329                               break;
17330                            }
17331                         }
17332                         if(ueIdxFound == true)
17333                         {
17334                            break;
17335                         }
17336                      }
17337                      
17338                      if(!ueIdxFound)
17339                      {
17340                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17341                         ret = RFAILED;
17342                      }
17343                      break;
17344                   }
17345
17346                case ProtocolIE_ID_id_RRCContainer:
17347                   {
17348                      if(ueIdxFound == true)  
17349                      {
17350                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17351                         if(duUeCb->f1UeDb)
17352                         {
17353                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17354                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17355                            duUeCb->f1UeDb->cellIdx = cellIdx;
17356                            /* Filling Dl RRC Msg Info */
17357                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17358                            if(!duUeCb->f1UeDb->dlRrcMsg)
17359                            {
17360                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17361                                     Memory allocation failed ");
17362                               ret = RFAILED;
17363                            }
17364                            else
17365                            {
17366                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17367                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17368                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17369                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17370                                     value.choice.RRCContainer);
17371                            }
17372
17373                         }
17374                         else
17375                         {
17376                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17377                                  Memory allocation failed ");
17378                            ret = RFAILED;
17379
17380                         }
17381                      }
17382                      break;
17383                   }
17384                default :
17385                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17386                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17387                   break;
17388             }
17389          }
17390       }
17391    }
17392    if(ret != RFAILED)
17393    {
17394       duProcUeContextReleaseCommand(cellId, duUeCb);
17395    }
17396    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17397    return ret;
17398 }
17399
17400 /**************************************************************
17401  *
17402  * @brief free the memory allocated by aper decoder for paging
17403  *
17404  * @details
17405  *
17406  *    Function : freeAperDecodePagingMsg
17407  *
17408  *    Functionality:
17409  *         - free the memory allocated by aper decoder for
17410  *         the paging f1ap msg
17411  *
17412  * @params[in] Paging_t   *paging
17413  * @return ROK     - success
17414  *         RFAILED - failure
17415  *
17416  ****************************************************************/
17417 void freeAperDecodePagingMsg(Paging_t   *paging)
17418 {
17419    uint8_t ieIdx, cellIdx;
17420    PagingCell_ItemIEs_t *pagingCellItemIes;
17421    PagingCell_Item_t *pagingCellItem;
17422    PagingCell_list_t  *pagingCelllist;
17423
17424    if(paging)
17425    {
17426       if(paging->protocolIEs.list.array)
17427       {
17428          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17429          {
17430             if(paging->protocolIEs.list.array[ieIdx])
17431             {
17432                switch(paging->protocolIEs.list.array[ieIdx]->id)
17433                {
17434                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17435                      {
17436                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17437                         break;
17438                      }
17439                   case ProtocolIE_ID_id_PagingIdentity:
17440                      {
17441                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17442                         {
17443                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17444                            {
17445                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17446                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17447                               {
17448                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17449                               }
17450                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17451                            }
17452                         }
17453                         break;
17454                      }
17455                   case ProtocolIE_ID_id_PagingCell_List:
17456                      {
17457                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17458                         if(pagingCelllist->list.array)
17459                         {
17460                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17461                            {
17462                               if(pagingCelllist->list.array[cellIdx])
17463                               {
17464                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17465                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17466                                  {
17467                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17468                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17469                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17470                                  }
17471                                  free(pagingCelllist->list.array[cellIdx]);
17472                               }
17473                            }
17474                            free(pagingCelllist->list.array);
17475                         }
17476                         break;
17477                      }
17478                }
17479                free(paging->protocolIEs.list.array[ieIdx]);
17480             }
17481          }
17482          free(paging->protocolIEs.list.array);
17483
17484       }
17485    }
17486 }
17487
17488 /**************************************************************
17489  *
17490  * @brief processing the paging f1ap msg received from CU 
17491  *
17492  * @details
17493  *
17494  *    Function : procPagingMsg
17495  *
17496  *    Functionality:
17497  *         - processing the paging f1ap msg received from CU
17498  *
17499  * @params[in] F1AP_PDU_t *f1apMsg
17500  * @return ROK     - success
17501  *         RFAILED - failure
17502  *
17503  *
17504  ****************************************************************/
17505 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17506 {
17507    uint8_t ieIdx = 0, cellListIdx = 0;
17508    uint64_t cellId = 0;
17509    Paging_t   *paging = NULLP;
17510    PagingCell_list_t  *pagingCelllist = NULLP;
17511    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17512    PagingCell_Item_t *pagingCellItem = NULLP;
17513    DuPagingMsg *tmpPagingParam = NULLP;
17514
17515    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17516    if(paging)
17517    {
17518       if(paging->protocolIEs.list.array)
17519       {
17520          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17521          if(tmpPagingParam == NULLP)
17522          {
17523             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17524             freeAperDecodePagingMsg(paging);
17525             return RFAILED;
17526          }
17527          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17528          {
17529             if(paging->protocolIEs.list.array[ieIdx])
17530             {
17531                switch(paging->protocolIEs.list.array[ieIdx]->id)
17532                {
17533                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17534                      {
17535                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17536                                          &tmpPagingParam->pagUeId);
17537                         break;
17538                      }
17539
17540                   case ProtocolIE_ID_id_PagingIdentity:
17541                      {
17542                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17543                         {
17544                            case PagingIdentity_PR_cNUEPagingIdentity: 
17545                               {
17546                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17547                                  {
17548                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17549                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17550
17551                                  }
17552                                  break;
17553                               }
17554                             case PagingIdentity_PR_rANUEPagingIdentity:
17555                                {
17556                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17557                                   break;
17558                                }
17559                             default:
17560                                {
17561                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17562                                   continue;
17563                                }
17564                         }
17565                      }
17566
17567                   case ProtocolIE_ID_id_PagingDRX:
17568                      {
17569                         tmpPagingParam->pagingDrxPres = TRUE;
17570                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17571                         break;
17572                      }
17573
17574                   case ProtocolIE_ID_id_PagingPriority:
17575                      {
17576                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17577                         break;
17578                      }
17579
17580                   case ProtocolIE_ID_id_PagingCell_List:
17581                      {
17582                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17583                         if(pagingCelllist->list.array)
17584                         {
17585                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17586                            {
17587                               if(pagingCelllist->list.array[cellListIdx])
17588                               {
17589                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17590                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17591                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17592                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17593                                  {
17594                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17595                                     continue;
17596                                  }
17597                               }
17598                            }
17599                         }
17600                         break;
17601                      }
17602                    default:
17603                      {
17604                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17605                          break;
17606                      }
17607                }
17608             }
17609          }
17610       }
17611    }
17612    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17613    freeAperDecodePagingMsg(paging);
17614   
17615    return ROK;
17616 }
17617
17618 /**************************************************************
17619  *
17620  * @brief Handles received F1AP message and sends back response  
17621  *
17622  * @details
17623  *
17624  *    Function : F1APMsgHdlr
17625  *
17626  *    Functionality:
17627  *         - Decodes received F1AP control message
17628  *         - Prepares response message, encodes and sends to SCTP
17629  *
17630  * @params[in] 
17631  * @return ROK     - success
17632  *         RFAILED - failure
17633  *
17634  * ****************************************************************/
17635 void F1APMsgHdlr(Buffer *mBuf)
17636 {
17637    int i =0;
17638    char *recvBuf =NULLP;
17639    MsgLen copyCnt =0;
17640    MsgLen recvBufLen =0;
17641    F1AP_PDU_t *f1apMsg =NULLP;
17642    asn_dec_rval_t rval; /* Decoder return value */
17643    F1AP_PDU_t f1apasnmsg ;
17644    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17645    ODU_PRINT_MSG(mBuf, 0,0);
17646
17647    /* Copy mBuf into char array to decode it */
17648    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17649    DU_ALLOC(recvBuf, (Size)recvBufLen);
17650
17651    if(recvBuf == NULLP)
17652    {
17653       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17654       return;
17655    }
17656    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17657    {
17658       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17659       return;
17660    }
17661
17662 #ifdef DEBUG_ASN_PRINT
17663    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17664    for(i=0; i< recvBufLen; i++)
17665    {
17666       printf("%x",recvBuf[i]);
17667    }
17668 #endif
17669
17670    /* Decoding flat buffer into F1AP messsage */
17671    f1apMsg = &f1apasnmsg;
17672    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17673
17674    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17675
17676    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17677    {
17678       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17679       return;
17680    }
17681    printf("\n");
17682    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17683
17684    switch(f1apMsg->present)
17685    {
17686       case F1AP_PDU_PR_successfulOutcome:
17687          {
17688             switch(f1apMsg->choice.successfulOutcome->value.present)
17689             {
17690                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17691                   {
17692                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17693                      break;
17694                   }
17695                case SuccessfulOutcome__value_PR_F1SetupResponse:
17696                   {                             
17697 #ifndef ODU_TEST_STUB
17698                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17699 #endif
17700                      break;
17701                   }
17702
17703                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17704                   {
17705                      procF1GNBDUCfgUpdAck(f1apMsg);
17706                      break;
17707                   }
17708
17709                default:
17710                   {
17711                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17712                            f1apMsg->choice.successfulOutcome->value.present);
17713                      return;
17714                   }
17715             }/* End of switch(successfulOutcome) */
17716             free(f1apMsg->choice.successfulOutcome);
17717             break;
17718          }
17719       case F1AP_PDU_PR_initiatingMessage:
17720          {
17721             switch(f1apMsg->choice.initiatingMessage->value.present)
17722             {
17723                case InitiatingMessage__value_PR_Reset:
17724                   {
17725                      procF1ResetReq(f1apMsg);
17726                      break;
17727                   }
17728                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17729                   {
17730                      procF1DlRrcMsgTrans(f1apMsg);
17731                      break;
17732                   }
17733                case InitiatingMessage__value_PR_UEContextSetupRequest:
17734                   {
17735                      procF1UeContextSetupReq(f1apMsg);
17736                      break;
17737                   }
17738                case InitiatingMessage__value_PR_UEContextModificationRequest:
17739                   {
17740                      procF1UeContextModificationReq(f1apMsg);
17741                      break;
17742                   }
17743                case InitiatingMessage__value_PR_UEContextReleaseCommand:
17744                   {
17745                       procF1UeContextReleaseCommand(f1apMsg);
17746                       break;
17747                   }
17748                case InitiatingMessage__value_PR_Paging:
17749                   {
17750                      procPagingMsg(f1apMsg);
17751                      break;
17752                   }
17753                default:
17754                   {
17755                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
17756                            f1apMsg->choice.initiatingMessage->value.present);
17757                      return;
17758                   }
17759             }/* End of switch(initiatingMessage) */
17760             free(f1apMsg->choice.initiatingMessage);
17761             break;
17762          }
17763
17764       default:
17765          {
17766             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
17767             return;
17768          }
17769          free(f1apMsg);
17770
17771    }/* End of switch(f1apMsg->present) */
17772    
17773    DU_FREE(recvBuf, (Size)recvBufLen);
17774 } /* End of F1APMsgHdlr */
17775
17776 /**********************************************************************
17777   End of file
17778  **********************************************************************/