[Epic-ID: ODUHIGH-510][Task-ID: ODUHIGH-514] DU-initiated E2 Reset Procedure
[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_e2ap_mgr.h"
37 #include "du_e2ap_msg_hdl.h"
38 #include "du_mgr_main.h"
39 #include "du_mgr.h"
40 #include "du_utils.h"
41 #include "du_ue_mgr.h"
42 #include "RAT-Type.h"
43 #include "NRFreqInfo.h"
44 #include "NRCGI.h"
45 #include "TDD-Info.h"
46 #include "NR-Mode-Info.h"
47 #include "ServedPLMNs-List.h"
48 #include "GNB-DU-Served-Cells-List.h"
49 #include "Served-Cell-Information.h"
50 #include "ProtocolExtensionContainer.h"
51 #include "RRC-Version.h"
52 #include "FDD-Info.h"
53 #include "FreqBandNrItem.h"
54 #include "ServedPLMNs-Item.h"
55 #include "GNB-DU-Served-Cells-Item.h"
56 #include "SliceSupportItem.h"
57 #include "FeatureSetUplinkPerCC.h"
58 #include "SliceSupportItem.h"
59 #include "Served-Cells-To-Modify-Item.h"
60 #include "Served-Cells-To-Delete-List.h"
61 #include "Served-Cells-To-Delete-Item.h"
62 #include "QoSInformation.h"
63 #include "ULUPTNLInformation-ToBeSetup-List.h"
64 #include "DRB-Information.h"
65 #include "DRBs-ToBeSetup-Item.h"
66 #include "DRBs-ToBeSetupMod-Item.h"
67 #include "DRBs-ToBeModified-Item.h"
68 #include "CUtoDURRCInformation.h"
69 #include "SCell-ToBeSetup-List.h"
70 #include "SRBs-ToBeSetup-List.h"
71 #include "DRBs-ToBeSetup-List.h"
72 #include "SRBs-ToBeSetup-Item.h"
73 #include "DRBs-ToBeModified-List.h"
74 #include "RRCContainer.h"
75 #include "UE-CapabilityRAT-ContainerList.h"
76 #include "DRBs-Setup-List.h"
77 #include "CellGroupConfig.h"
78 #include "ResetAll.h"
79 #include "ResetType.h"
80 #include "Cells-to-be-Activated-List.h"
81 #include "GNB-CU-Name.h"
82 #include "SRBs-SetupMod-List.h"
83 #include "DRBs-SetupMod-List.h"
84 #include "DRBs-ToBeSetupMod-List.h"
85 #include "PagingCell-Item.h"
86 #include "PagingCell-list.h"
87 #include "QoS-Characteristics.h"
88 #include "ULUPTNLInformation-ToBeSetup-Item.h"
89 #include "Flows-Mapped-To-DRB-Item.h"
90 #include "NonDynamic5QIDescriptor.h"
91 #include "Dynamic5QIDescriptor.h"
92 #include "FeatureSetDownlinkPerCC.h"
93 #include "FeatureSets.h"
94 #include "UE-NR-Capability.h"
95 #include "UE-CapabilityRAT-Container.h"
96 #include "UE-CapabilityRAT-ContainerListRRC.h"
97 #include "GNB-DU-System-Information.h"
98 #include "CellGroupConfigRrc.h"
99 #include "MAC-CellGroupConfig.h"
100 #include "SchedulingRequestConfig.h"
101 #include "SchedulingRequestToAddMod.h"
102 #include "BSR-Config.h"
103 #include "TAG-Config.h"
104 #include "TAG.h"
105 #include "PHR-Config.h"
106 #include "RLC-Config.h"
107 #include "UL-AM-RLC.h"
108 #include "DL-AM-RLC.h"
109 #include "LogicalChannelConfig.h"
110 #include "RLC-BearerConfig.h"
111 #include "PhysicalCellGroupConfig.h"
112 #include "SpCellConfig.h"
113 #include "TDD-UL-DL-ConfigDedicated.h"
114 #include "ServingCellConfig.h"
115 #include "ControlResourceSet.h"
116 #include "SearchSpace.h"
117 #include "PDCCH-Config.h"
118 #include "PDSCH-TimeDomainResourceAllocation.h"
119 #include "PDSCH-TimeDomainResourceAllocationList.h"
120 #include "PDSCH-CodeBlockGroupTransmission.h"
121 #include "PDSCH-ServingCellConfig.h"
122 #include "DMRS-DownlinkConfig.h"
123 #include "PDSCH-Config.h"
124 #include "BWP-DownlinkDedicated.h"
125 #include "BWP-Downlink.h"
126 #include "PUSCH-TimeDomainResourceAllocation.h"
127 #include "PUSCH-TimeDomainResourceAllocationList.h"
128 #include "DMRS-UplinkConfig.h"
129 #include "PUSCH-Config.h"
130 #include "SRS-ResourceId.h"
131 #include "SRS-Resource.h"
132 #include "SRS-ResourceSet.h"
133 #include "SRS-Config.h"
134 #include "BWP-UplinkDedicated.h"
135 #include "PUSCH-ServingCellConfig.h"
136 #include "UplinkConfig.h"
137 #include "DUtoCURRCContainer.h"
138 #include "GBR-QoSFlowInformation.h"
139 #include "QoSFlowLevelQoSParameters.h"
140 #include "PUCCH-Config.h"
141 #include "PUCCH-ResourceSet.h"
142 #include "PUCCH-Resource.h"
143 #include "PUCCH-PowerControl.h"
144 #include "P0-PUCCH.h"
145 #include "PUCCH-PathlossReferenceRS.h"
146 #include "PUCCH-format0.h"
147 #include "PUCCH-format1.h"
148 #include "PUCCH-format2.h"
149 #include "PUCCH-format3.h"
150 #include "PUCCH-format4.h"
151 #include "PUCCH-FormatConfig.h"
152 #include "SchedulingRequestResourceConfig.h"
153 #include<ProtocolIE-Field.h>
154 #include "ProtocolExtensionField.h"
155 #include "odu_common_codec.h"
156 #include "du_mgr.h"
157 #include "du_cell_mgr.h"
158 #include "du_f1ap_msg_hdl.h"
159 #include "DRBs-Setup-Item.h"
160 #include "DLUPTNLInformation-ToBeSetup-List.h"
161 #include "DLUPTNLInformation-ToBeSetup-Item.h"
162 #include "UPTransportLayerInformation.h"
163 #include "GTPTunnel.h"
164 #include "SupportedSULFreqBandItem.h"
165 #include "du_f1ap_conversions.h"
166 #include "CNUEPagingIdentity.h"
167 #include "PCCH-Config.h"
168 #include "SCS-SpecificCarrier.h"
169 #include "FrequencyInfoDL.h"
170 #include "DownlinkConfigCommon.h"
171 #include "FrequencyInfoUL.h"
172 #include "UplinkConfigCommon.h"
173 #include "TDD-UL-DL-ConfigCommon.h"
174 #include "RACH-ConfigDedicated.h"
175 #include "CFRA-SSB-Resource.h"
176 #include "BWP-UplinkCommon.h"
177 #include "ReconfigurationWithSync.h"
178 #include "BCCH-DL-SCH-Message.h"
179 #include "du_sys_info_hdl.h"
180 #include "DRX-ConfigRrc.h"
181 #include "MeasurementTimingConfigurationRrc.h"
182 #include "MeasurementTimingConfigurationRrc-IEs.h"
183 #include "MeasTimingList.h"
184 #include "MeasTiming.h"
185 #include "Cells-Status-List.h"
186 #include "Cells-Status-Item.h"
187
188 #ifdef O1_ENABLE
189 #include "CmInterface.h"
190 extern StartupConfig g_cfg;
191 #endif
192
193 DuCfgParams duCfgParam;
194
195 /******************************************************************
196  *
197  * @brief Function to fetch lcId based on DRB Id
198  *
199  * @details
200  *
201  *    Function : fetchLcId
202  *
203  *    @params[in] drbId
204  *
205  *    Functionality: Function to fetch lcId based on DRB Id
206  *
207  * Returns: lcId - SUCCESS
208  *          RFAILED - FAILURE
209  *****************************************************************/
210
211 uint8_t fetchLcId(uint8_t drbId)
212 {
213    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
214
215    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
216    {
217       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
218       {
219          if(duCb.actvCellLst[cellIdx] != NULLP)
220          {
221             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
222             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
223             {
224                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
225                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
226                {
227                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
228                   return lcId;
229                }
230             }
231          }
232       }
233    }
234    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
235    return RFAILED;
236 }
237
238 /*******************************************************************
239 *
240 * @brief Adding F1AP pdu to reserved pdu list
241 *
242 * @details
243 *
244 *    Function : addToReservedF1apPduList 
245 *
246 *    Functionality: Adding F1AP pdu to reserved pdu list.
247 *     These pdu are awaiting aknowledgment from CU
248 *
249 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
250 *
251 * @return ROK - success
252 *         RFAILED - failure
253 *
254 * ****************************************************************/
255 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
256 {
257    CmLList         *node = NULLP;
258    ReservedF1apPduInfo *pduInfo = NULLP;
259    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
260    if(pduInfo)
261    {
262       DU_ALLOC(node, sizeof(CmLList));
263       if(node)
264       {
265          pduInfo->transId = transId;
266          pduInfo->f1apMsg = (void*) f1apPdu;
267
268          node->node = (PTR)pduInfo;
269          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
270       }
271    }
272 }
273
274 /*******************************************************************
275 *
276 * @brief searching for F1AP pdu from ReservedF1apPduList 
277 *
278 * @details
279 *
280 *    Function : searchFromReservedF1apPduList 
281 *
282 *    Functionality: searching for F1AP pdu information
283 *
284 * @params[in] uint8_t transId
285 *
286 * @return pointer to F1AP_PDU_t
287 *
288 * ****************************************************************/
289
290 CmLList *searchFromReservedF1apPduList(uint8_t transId)
291 {
292    CmLList         *node;
293    ReservedF1apPduInfo *f1apPdu;
294    if(duCb.reservedF1apPduList.count)
295    {
296       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
297       while(node)
298       {
299          f1apPdu = (ReservedF1apPduInfo*)node->node;
300          if(f1apPdu->transId == transId)
301          {
302             return node;
303          }
304          node = node->next;
305       }
306    }
307    return NULL;
308 }
309
310 /*******************************************************************
311 *
312 * @brief deleting F1AP pdu information from ReservedF1apPduList
313 *
314 * @details
315 *
316 *    Function : deleteFromReservedF1apPduList 
317 *
318 *    Functionality: deleting pdu information from ReservedF1apPduList
319 *
320 * @params[in] CmLList *node 
321 *
322 * @return void 
323 *
324 * ****************************************************************/
325
326 void deleteFromReservedF1apPduList(CmLList *node)
327 {
328    ReservedF1apPduInfo *f1apPdu;
329
330    if(node != NULL)
331    {
332       f1apPdu = (ReservedF1apPduInfo *)node->node;
333       cmLListDelFrm(&duCb.reservedF1apPduList, node);
334       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
335       DU_FREE(node, sizeof(CmLList));
336       node = NULL;
337    }
338 }
339
340 /*******************************************************************
341  *
342  * @brief Builds Uplink Info for NR 
343  *
344  * @details
345  *
346  *    Function : BuildULNRInfo
347  *
348  *    Functionality: Building NR Uplink Info
349  *
350  * @params[in] NRFreqInfo_t *ulnrfreq
351  * @return ROK     - success
352  *         RFAILED - failure
353  *
354  * ****************************************************************/
355 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
356 {
357    uint8_t idx=0;
358    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
359                        fdd.ulNrFreqInfo.nrArfcn;
360    ulnrfreq->freqBandListNr.list.count = 1;
361    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
362    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
363    if(ulnrfreq->freqBandListNr.list.array == NULLP)
364    {
365       return RFAILED;
366    }
367    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
368    {
369       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
370       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
371       {
372          return RFAILED;
373       }
374    }
375    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
376                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
377                                                                  freqBand[0].nrFreqBand;
378    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
379    return ROK;
380 }
381 /*******************************************************************
382  *
383  * @brief Builds Downlink NR Info 
384  *
385  * @details
386  *
387  *    Function : BuildDLNRInfo
388  *
389  *    Functionality: Building Downlink NR Info
390  *    
391  * @params[in] NRFreqInfo_t *dlnrfreq
392  * @return ROK     - success
393  *         RFAILED - failure
394  *
395  * ****************************************************************/
396 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
397 {
398    uint8_t idx=0;
399    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
400                        fdd.dlNrFreqInfo.nrArfcn;
401    dlnrfreq->freqBandListNr.list.count = 1;
402    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
403    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
404    if(dlnrfreq->freqBandListNr.list.array == NULLP)
405    {
406       return RFAILED;   
407    }
408    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
409    {
410       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
411       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
412       {
413          return RFAILED;
414       }
415    }   
416    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
417                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
418                                                                  freqBand[0].nrFreqBand;
419    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
420
421    return ROK;
422 }
423
424 /*******************************************************************
425  *
426  * @brief Builds Nrcgi 
427  *
428  * @details
429  *
430  *    Function : BuildNrcgi
431  *
432  *    Functionality: Building the PLMN ID and NR Cell id
433  *
434  * @params[in] NRCGI_t *nrcgi
435  * @return ROK     - success
436  *         RFAILED - failure
437  *
438  * ****************************************************************/
439 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
440 {
441    uint8_t ret;
442    uint8_t byteSize = 5;
443    /* Allocate Buffer Memory */
444    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
445    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
446    if(nrcgi->pLMN_Identity.buf == NULLP)
447    {
448       return RFAILED;
449    }
450    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
451          nrcgi->pLMN_Identity.buf); // Building PLMN function
452    if(ret != ROK)
453    {
454       return RFAILED;
455    }
456    /*nrCellIdentity*/
457    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
458    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
459    if(nrcgi->nRCellIdentity.buf == NULLP)
460    {
461       return RFAILED;
462    }
463    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
464
465    return ROK;
466 }
467 /*******************************************************************
468  *
469  * @brief Builds FiveGStac 
470  *
471  * @details
472  *
473  *    Function : BuildFiveGSTac
474  *
475  *    Functionality: Building the FiveGSTac
476  *
477  * @params[in] OCTET_STRING_t *fivegsTac
478  * @return ROK     - success
479  *         RFAILED - failure
480  *
481  * ****************************************************************/
482 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
483 {
484    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
485    if(servcell->fiveGS_TAC == NULLP)
486    {
487       return RFAILED;
488    }
489    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
490    DU_ALLOC(servcell->fiveGS_TAC->buf,\
491          sizeof(servcell->fiveGS_TAC->size));
492    if(servcell->fiveGS_TAC->buf == NULLP)
493    {
494       return RFAILED;
495    }
496    servcell->fiveGS_TAC->buf[0] = 0;
497    servcell->fiveGS_TAC->buf[1] = 0;
498    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
499    return ROK;  
500 }
501
502 /*******************************************************************
503  *
504  * @brief fill nr frequency information
505  *
506  * @details
507  *
508  *    Function : fillNrTddInfo 
509  *
510  *    Functionality: fill nr frequency information
511  *
512  * @params[in] NRFreqInfo_t freqInfo
513  * @return ROK     - success
514  *         RFAILED - failure
515  *
516  * ****************************************************************/
517 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
518 {
519    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
520    NRFreqInfo_t *freqInfo = NULLP;
521
522    if(tddInfo == NULLP)
523    {
524       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
525       return RFAILED;
526    }
527    
528    freqInfo = &tddInfo->nRFreqInfo;
529    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
530
531    freqInfo->freqBandListNr.list.count = elementCnt; 
532    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
533    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
534    if(!freqInfo->freqBandListNr.list.array)
535    {
536       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
537       return RFAILED;
538    }
539
540    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
541    {
542       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
543       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
544       {
545          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
546          return RFAILED;
547       }
548
549       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
550       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
551
552       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
553       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
554       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
555
556       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
557             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
558       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
559       {
560          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
561          return RFAILED;
562       }
563
564       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
565       {
566          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
567                sizeof(SupportedSULFreqBandItem_t));
568          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
569          {
570             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
571             return RFAILED;
572          }
573
574          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
575          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
576       }
577    }
578
579    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
580    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
581
582    return ROK;
583 }
584
585 /*******************************************************************
586  *
587  * @brief Builds NR Mode 
588  *
589  * @details
590  *
591  *    Function : BuildNrMode
592  *
593  *    Functionality: Building the NR Mode
594  *
595  * @params[in] NR_Mode_Info_t *fdd
596  * @return ROK     - success
597  *         RFAILED - failure
598  *
599  * ****************************************************************/
600 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
601 {
602    uint8_t BuildDLNRInforet=0;
603    uint8_t BuildULNRInforet=0; 
604    
605 #ifdef NR_TDD
606    mode->present = NR_Mode_Info_PR_tDD;
607 #else
608    mode->present = NR_Mode_Info_PR_fDD;
609 #endif   
610    
611    if(mode->present == NR_Mode_Info_PR_fDD)
612    {
613       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
614       if(mode->choice.fDD == NULLP)
615       {
616          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
617          return RFAILED;
618       }
619       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
620       if(BuildULNRInforet != ROK)
621       {
622          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
623          return RFAILED;    
624       }
625       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
626       if(BuildDLNRInforet != ROK)
627       {
628          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
629          return RFAILED;
630       }
631       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
632                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
633                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
634       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
635                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
636                                                           f1Mode.mode.fdd.ulTxBw.nrb;
637       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
638                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
639                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
640       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
641                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
642                                                           f1Mode.mode.fdd.dlTxBw.nrb;
643    }
644    else if(mode->present == NR_Mode_Info_PR_tDD) 
645    {
646       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
647       if(mode->choice.tDD == NULLP)
648       {
649          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
650          return RFAILED;
651       }
652
653       if(fillNrTddInfo(mode->choice.tDD) != ROK)
654       {
655          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
656          return RFAILED;
657       }
658
659    }
660
661    return ROK;
662 }
663 /*******************************************************************
664  *
665  * @brief Builds IE Extensions for Served PLMNs 
666  *
667  * @details
668  *
669  *    Function : BuildExtensions
670  *
671  *    Functionality: Building the IE Extensions
672  *
673  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
674  * @return ROK     - success
675  *         RFAILED - failure
676  *
677  * ****************************************************************/
678 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
679 {
680    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
681    uint8_t elementCnt=0, extensionCnt=0;
682
683    extensionCnt=IE_EXTENSION_LIST_COUNT;
684    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
685    if((*ieExtend) == NULLP)
686    {
687       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
688       return RFAILED;
689    }
690    (*ieExtend)->list.count = extensionCnt;
691    (*ieExtend)->list.size = \
692                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
693    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
694    if((*ieExtend)->list.array == NULLP)
695    {
696       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
697       return RFAILED;
698    }
699    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
700    {
701       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
702             sizeof(ServedPLMNs_ItemExtIEs_t));
703       if((*ieExtend)->list.array[plmnidx] == NULLP)
704       {
705          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
706          return RFAILED;
707       }
708    }
709    
710    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
711    idx = 0;
712    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
713    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
714    (*ieExtend)->list.array[idx]->extensionValue.present = \
715    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
716    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
717       list.count = elementCnt;
718    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
719       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
720       list.count * sizeof(SliceSupportItem_t *);
721
722    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
723          list.array, elementCnt * sizeof(SliceSupportItem_t *));
724    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
725          list.array == NULLP)
726    {
727       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
728       return RFAILED;
729    }
730
731    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
732    {
733       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
734             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
735       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
736             list.array[sliceLstIdx] == NULLP) 
737       {
738          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
739          return RFAILED;
740       }
741       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
742          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
743       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
744             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
745             extensionValue.choice.SliceSupportList.\
746             list.array[sliceLstIdx]->sNSSAI.sST.size);
747       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
748             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
749       {
750          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
751          return RFAILED;
752       }
753       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
754          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
755          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
756       
757       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
758             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
759       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
760             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
761       {
762          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
763          return RFAILED;
764       }
765       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
766          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
767       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
768             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
769             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
770       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
771             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
772       {
773          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
774          return RFAILED;
775       }
776       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
777       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
778       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
779       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
780    }
781    return ROK;
782 }
783 /*******************************************************************
784  *
785  * @brief Builds Served PLMN 
786  *
787  * @details
788  *
789  *    Function : BuildServedPlmn
790  *
791  *    Functionality: Building the Served PLMN
792  *
793  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
794  * @return ROK     - success
795  *         RFAILED - failure
796  *
797  * ****************************************************************/
798 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
799 {  
800    uint8_t  plmnidx;
801    uint8_t  servPlmnCnt=1;
802    uint8_t buildPlmnIdret=0;
803    uint8_t BuildExtensionsret=0;
804    srvplmn->list.count = servPlmnCnt;
805    srvplmn->list.size = \
806                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
807    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
808    if(srvplmn->list.array == NULLP)
809    {
810       return RFAILED;
811    }
812    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
813    {   
814       DU_ALLOC(srvplmn->list.array[plmnidx],\
815             sizeof(ServedPLMNs_Item_t));
816       if(srvplmn->list.array[plmnidx] == NULLP)
817       {
818          return RFAILED;
819       }  
820    }
821    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
822    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
823    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
824          srvplmn->list.array[0]->pLMN_Identity.buf);
825    if(buildPlmnIdret!= ROK)
826    {
827       return RFAILED;
828    }
829    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
830    if(BuildExtensionsret!= ROK)
831    {
832       return RFAILED;
833    }
834    return ROK;
835 }
836
837 /*******************************************************************
838  *
839  * @brief Frees Measurement Timing configuration 
840  *
841  * @details
842  *
843  *    Function : FreeMeasTimingConf
844  *
845  *    Functionality: Frees Timing Configuration
846  *
847  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
848  * @return ROK     - success
849  *         RFAILED - failure
850  *
851  * ****************************************************************/
852 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
853 {
854    uint8_t measIeIdx = 0;
855    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
856
857    if(measTimingConfRrc.criticalExtensions.choice.c1)
858    {
859       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
860       {
861          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
862          if(measTimingConfIEs->measTiming)
863          {
864             if(measTimingConfIEs->measTiming->list.array)
865             {
866                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
867                {
868                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
869                   {
870                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
871                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
872                   }
873                }
874                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
875             }
876             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
877          }
878          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
879       }
880       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
881    }
882 }
883
884 /*******************************************************************
885  *
886  * @brief Builds MEasuerment Timing Configuration
887  *
888  * @details
889  *
890  *    Function : BuildMeasTimingConf
891  *
892  *    Functionality: Building Measurement Timing Configuration
893  *
894  * @params[in] Pointer to octet string to store Measurement timing
895  *             Configuration
896  * @return ROK     - success
897  *         RFAILED - failure
898  *
899  * ****************************************************************/
900 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
901 {
902    uint8_t ret = RFAILED;
903    uint8_t elementCnt = 0;
904    uint8_t measIeIdx = 0;
905    asn_enc_rval_t encRetVal;
906    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
907    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
908    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
909
910    while(true)
911    {
912       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
913       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
914       if(!measTimingConfRrc.criticalExtensions.choice.c1)
915       {
916          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
917          break;
918       }
919       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
920
921       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
922       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
923       {
924          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
925          break;
926       }
927       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
928
929       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
930       if(!measTimingConfIEs->measTiming)
931       {
932          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
933          break;
934       }
935
936       elementCnt = 1;  
937       measTimingConfIEs->measTiming->list.count = elementCnt;
938       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
939       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
940       if(!measTimingConfIEs->measTiming->list.array)
941       {
942          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
943          break;
944       }
945
946       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
947       {
948          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
949          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
950          {
951             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
952             break;
953          }
954       }
955       if(measIeIdx < elementCnt)
956       {
957          break;
958       }
959
960       measIeIdx = 0;
961       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
962       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
963       {
964          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
965          break;
966       }
967       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
968       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
969       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
970       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
971       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
972       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
973
974       /* Encode the F1SetupRequest type as APER */
975       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
976
977       memset(encBuf, 0, ENC_BUF_MAX_LEN);
978       encBufSize = 0;
979       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
980
981       /* Encode results */
982       if(encRetVal.encoded == ENCODE_FAIL)
983       {     
984          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
985                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
986          break;
987       }     
988       else  
989       {     
990          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
991 #ifdef DEBUG_ASN_PRINT
992          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
993          {
994             printf("%x",encBuf[measIeIdx]);
995          }
996 #endif
997
998          measTimingConf->size = encBufSize;
999          DU_ALLOC(measTimingConf->buf, encBufSize);
1000          if(measTimingConf->buf == NULLP)
1001          {
1002             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
1003             return RFAILED;
1004          }
1005          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1006
1007          FreeMeasTimingConf(measTimingConfRrc);
1008
1009          ret = ROK;
1010          break;
1011       }
1012    }
1013    return ret;
1014 }
1015
1016 /*******************************************************************
1017  *
1018  * @brief Builds Served Cell List
1019  *
1020  * @details
1021  *
1022  *    Function : BuildServedCellList
1023  *
1024  *    Functionality: Building Served Cell List
1025  *
1026  * @params[in] PLMNID plmn
1027  * @return ROK     - success
1028  *         RFAILED - failure
1029  *
1030  * ****************************************************************/
1031
1032 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1033 {
1034    uint8_t  BuildNrcgiret=0;
1035    uint8_t  BuildFiveGSTacret=0;
1036    uint8_t  BuildServedPlmnret=0;
1037    uint8_t  BuildNrModeret=0;
1038    uint8_t  idx;
1039    uint8_t  plmnidx;
1040    uint8_t  plmnCnt=1;
1041    GNB_DU_Served_Cells_Item_t *srvCellItem;
1042    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1043    duServedCell->list.count = plmnCnt;
1044
1045    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1046    if(duServedCell->list.array == NULLP)
1047    {
1048       return RFAILED;
1049    }
1050    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1051    {
1052       DU_ALLOC(duServedCell->list.array[plmnidx],\
1053             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1054       if(duServedCell->list.array[plmnidx] == NULLP)
1055       {
1056          return RFAILED;
1057       }
1058    }
1059    idx = 0;
1060    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1061    duServedCell->list.array[idx]->criticality = Criticality_reject;
1062    duServedCell->list.array[idx]->value.present = \
1063                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1064    srvCellItem = \
1065                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1066    /*nRCGI*/
1067    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1068    if(BuildNrcgiret != ROK)
1069    {
1070       return RFAILED;
1071    }
1072    /*nRPCI*/
1073    srvCellItem->served_Cell_Information.nRPCI = \
1074                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1075
1076    /* fiveGS_TAC */
1077    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1078    if(BuildFiveGSTacret != ROK)
1079    {
1080       return RFAILED;
1081    }
1082
1083    /* Served PLMNs */
1084    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1085    if(BuildServedPlmnret !=ROK)
1086    {
1087       return RFAILED;
1088    }
1089
1090    /* nR Mode Info with FDD/TDD */
1091    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1092    if(BuildNrModeret != ROK)
1093    {
1094       return RFAILED;
1095    }
1096
1097    /*Measurement timing Config*/
1098    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1099       return RFAILED;
1100
1101    /* GNB DU System Information */
1102    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1103          sizeof(GNB_DU_System_Information_t));
1104    if(!srvCellItem->gNB_DU_System_Information)
1105    {
1106       return RFAILED;
1107    }
1108    /* MIB */
1109    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1110    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1111          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1112    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1113    {
1114       return RFAILED;
1115    }
1116    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1117          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1118
1119    /* SIB1 */
1120    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1121                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1122
1123    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1124          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1125    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1126    {
1127       return RFAILED;
1128    }
1129    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1130    {
1131       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1132                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1133    }
1134    return ROK; 
1135 }                                                                                                                  
1136 /*******************************************************************
1137  *
1138  * @brief Builds RRC Version 
1139  *
1140  * @details
1141  *
1142  *    Function : BuildRrcVer
1143  *
1144  *    Functionality: Building RRC Version
1145  *
1146  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1147  * @return ROK     - success
1148  *         RFAILED - failure
1149  *
1150  * ****************************************************************/
1151 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1152 {
1153    uint8_t rrcExt;
1154    uint8_t rrcLatest;
1155    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1156    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1157    if(rrcVer->latest_RRC_Version.buf == NULLP)
1158    {
1159       return RFAILED;
1160    }
1161    rrcVer->latest_RRC_Version.buf[0] = 0;
1162    rrcVer->latest_RRC_Version.bits_unused = 5;
1163    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1164    if(rrcVer->iE_Extensions == NULLP)
1165    {  
1166       return RFAILED;
1167    }
1168    rrcVer->iE_Extensions->list.count = 1;
1169    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1170    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1171    if(rrcVer->iE_Extensions->list.array == NULLP)
1172    {
1173       return RFAILED;
1174    }
1175    rrcExt = 0;
1176    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1177          sizeof(RRC_Version_ExtIEs_t));
1178    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1179    {
1180       return RFAILED;
1181    }
1182    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1183                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1184    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1185    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1186                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1187    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1188       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1189    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1190          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1191          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1192    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1193          .Latest_RRC_Version_Enhanced.buf == NULLP)
1194    {
1195       return RFAILED;
1196    }
1197    rrcLatest = 0;
1198    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1199       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1200    rrcLatest++;
1201    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1202       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1203    rrcLatest++;
1204    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1205       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1206    return ROK;
1207 }
1208 /*******************************************************************
1209  *
1210  * @brief Sends F1 msg over SCTP
1211  *
1212  * @details
1213  *
1214  *    Function : sendF1APMsg
1215  *
1216  *    Functionality: Sends F1 msg over SCTP
1217  *
1218  * @params[in] Region region
1219  *             Pool pool
1220  * @return ROK     - success
1221  *         RFAILED - failure
1222  *
1223  * ****************************************************************/
1224 uint8_t sendF1APMsg()
1225 {
1226    Buffer *mBuf = NULLP;
1227   
1228    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1229    {
1230       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1231       {
1232             ODU_PRINT_MSG(mBuf, 0,0);
1233
1234             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1235             {
1236                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1237                ODU_PUT_MSG_BUF(mBuf);
1238                return RFAILED;
1239             }
1240       }
1241       else
1242       {
1243          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1244          ODU_PUT_MSG_BUF(mBuf);
1245          return RFAILED;
1246       }
1247       ODU_PUT_MSG_BUF(mBuf);
1248    }
1249    else
1250    {
1251       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1252       return RFAILED;
1253    }
1254    return ROK; 
1255 } /* sendF1APMsg */
1256
1257 /*******************************************************************
1258  *
1259  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1260  *
1261  * @details
1262  *
1263  *    Function :  FreeRrcVer
1264  *
1265  *    Functionality: deallocating the memory of function BuildRrcVer
1266  *
1267  * @params[in] RRC_Version_t *rrcVer
1268  * 
1269  * @return void
1270  *
1271  *****************************************************************/
1272 void FreeRrcVer(RRC_Version_t *rrcVer)
1273 {
1274    if(rrcVer->latest_RRC_Version.buf != NULLP)
1275    {
1276       if(rrcVer->iE_Extensions != NULLP)
1277       {
1278          if(rrcVer->iE_Extensions->list.array != NULLP)
1279          {
1280             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1281             {
1282                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1283                      != NULLP)
1284                {
1285                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1286                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1287                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1288                }
1289                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1290             }
1291             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1292          }
1293          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1294       }
1295       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1296    }
1297 }
1298
1299 /*******************************************************************
1300  *
1301  * @brief Deallocating memory of TDD NrFreqInfo 
1302  *
1303  * @details
1304  *
1305  *    Function : freeTddNrFreqInfo 
1306  *
1307  *    Functionality: freeTddNrFreqInfo 
1308  *
1309  * @params[in]  F1AP_PDU_t *f1apDuCfg
1310  *
1311  * @return ROK     - void
1312  *
1313  * ****************************************************************/
1314 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1315 {
1316    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1317
1318    if(freqInfo->freqBandListNr.list.array)
1319    {
1320       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1321       {
1322          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1323          {
1324             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1325             {
1326                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1327                {
1328                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1329                         sizeof(SupportedSULFreqBandItem_t));
1330                }
1331                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1332                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1333
1334             }
1335             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1336          }
1337       }
1338       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1339    }
1340 }
1341
1342 /*******************************************************************
1343  *
1344  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1345  *
1346  * @details
1347  *
1348  *    Function : freeFddNrFreqInfo 
1349  *
1350  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1351  *
1352  * @params[in]  
1353  *
1354  * @return ROK     - void
1355  *
1356  * ****************************************************************/
1357 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1358 {
1359    uint8_t arrIdx =0;
1360
1361    if(fDD != NULLP)
1362    {
1363       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1364       {
1365          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1366                array[arrIdx], sizeof(FreqBandNrItem_t));
1367          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1368                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1369       }
1370
1371       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1372       {
1373          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1374                array[arrIdx], sizeof(FreqBandNrItem_t));
1375          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1376                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1377       }
1378       DU_FREE(fDD,sizeof(FDD_Info_t));
1379    }
1380 }
1381
1382 /*******************************************************************
1383  *
1384  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1385  *
1386  * @details
1387  *
1388  *    Function :  FreeServedCellList
1389  *
1390  *    Functionality:  deallocating the memory of function BuildServedCellList
1391
1392  *
1393  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1394  *
1395  * @return void
1396  *
1397  * ****************************************************************/
1398 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1399 {
1400    uint8_t   plmnCnt= 1;
1401    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1402    uint8_t  plmnIdx=0, sliceIdx=0;
1403    GNB_DU_Served_Cells_Item_t *srvCellItem;
1404    ServedPLMNs_Item_t  *servedPlmnItem;
1405    SliceSupportItem_t  *sliceSupportItem;
1406
1407    if(duServedCell->list.array!=NULLP)
1408    {
1409       if(duServedCell->list.array[0]!=NULLP)
1410       {
1411          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1412
1413          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1414                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1415          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1416                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1417
1418          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1419          {
1420             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1421                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1422             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1423          }
1424
1425          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1426          {
1427             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1428             {
1429                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1430                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1431
1432                if(servedPlmnItem->iE_Extensions != NULLP)
1433                {
1434                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1435                   {
1436                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1437                      {
1438                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1439                               SliceSupportList.list.array != NULLP)
1440                         {
1441                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1442                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1443                            {
1444                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1445                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1446                               {
1447                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1448                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1449
1450                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1451
1452                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1453                                  {
1454                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1455                                           sliceSupportItem->sNSSAI.sD->size);
1456                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1457                                  }
1458
1459                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1460                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1461                               }
1462                            }
1463                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1464                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1465                                  extensionValue.choice.SliceSupportList.list.size);
1466                         }
1467                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1468                               sizeof(ServedPLMNs_ItemExtIEs_t));
1469                      }
1470                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1471                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1472                   }
1473                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1474                }
1475                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1476                      sizeof(ServedPLMNs_Item_t));
1477             }
1478             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1479                   sizeof(ServedPLMNs_Item_t *));
1480          }
1481
1482          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1483          {
1484             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1485          }
1486          else   
1487          {
1488             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1489             {
1490                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1491                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1492             }
1493          }
1494          
1495          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1496                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1497
1498          if(srvCellItem->gNB_DU_System_Information != NULLP)
1499          {
1500             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1501             {
1502                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1503                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1504             }
1505
1506             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1507             { 
1508                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1509                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1510             }
1511
1512             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1513          }
1514
1515          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1516       }
1517       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1518    }
1519 }
1520
1521 /*******************************************************************
1522  *
1523  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1524  *
1525  * @details
1526  *
1527  *    Function :  FreeF1SetupReq
1528  *
1529  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1530  *
1531  * @params[in] F1AP_PDU_t *f1apMsg
1532  *
1533  * @return void
1534  *
1535  * ****************************************************************/
1536 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1537 {
1538    uint8_t ieIdx, ieIdx2;
1539    F1SetupRequest_t *f1SetupReq=NULLP;
1540
1541    if(f1apMsg != NULLP)
1542    {
1543       if(f1apMsg->choice.initiatingMessage != NULLP)
1544       {
1545          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1546          if(f1SetupReq->protocolIEs.list.array != NULLP)
1547          {
1548             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1549             {
1550                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1551                {
1552                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1553                   {
1554                      case ProtocolIE_ID_id_TransactionID:
1555                         break;
1556                      case ProtocolIE_ID_id_gNB_DU_ID:
1557                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1558                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1559                         break;
1560                      case ProtocolIE_ID_id_gNB_DU_Name:
1561                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1562                               strlen((char *)duCfgParam.duName));
1563                         break;
1564                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1565                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1566                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1567                         break;
1568                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1569                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1570                         break;
1571                      default:
1572                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1573                         break;
1574                   }
1575                }
1576             }
1577             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1578             {
1579                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1580             }
1581             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1582                   f1SetupReq->protocolIEs.list.size);
1583          }
1584          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1585       }
1586       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1587    }
1588 }
1589
1590 /*******************************************************************
1591  *
1592  * @brief Builds and Send the F1SetupRequest
1593  *
1594  * @details
1595  *
1596  *    Function : BuildAndSendF1SetupReq
1597  *
1598  * Functionality:Fills the F1SetupRequest
1599  *
1600  * @return ROK     - success
1601  *         RFAILED - failure
1602  *
1603  ******************************************************************/
1604 uint8_t BuildAndSendF1SetupReq()
1605 {
1606    uint8_t   ret, ieIdx, elementCnt;
1607    F1AP_PDU_t                 *f1apMsg = NULLP;
1608    F1SetupRequest_t           *f1SetupReq=NULLP;
1609    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1610    RRC_Version_t              *rrcVer=NULLP;
1611    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1612    ret= RFAILED;
1613
1614    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1615    do
1616    {
1617       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1618       if(f1apMsg == NULLP)
1619       {
1620          break;
1621       }
1622       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1623       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1624       if(f1apMsg->choice.initiatingMessage == NULLP)
1625       {
1626          break;
1627       }
1628       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1629       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1630       f1apMsg->choice.initiatingMessage->value.present = \
1631                                                          InitiatingMessage__value_PR_F1SetupRequest;
1632
1633       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1634
1635       elementCnt = 5;
1636
1637       f1SetupReq->protocolIEs.list.count = elementCnt;
1638       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1639
1640       /* Initialize the F1Setup members */
1641       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1642       if(f1SetupReq->protocolIEs.list.array == NULLP)
1643       {
1644          break;
1645       }
1646       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1647       {
1648          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1649                sizeof(F1SetupRequestIEs_t));
1650          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1651          {
1652             break;
1653          }
1654       }
1655
1656       ieIdx = 0;
1657       /*TransactionID*/
1658       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1659       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1660       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1661                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1662       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1663                                                                               TRANS_ID;
1664
1665       /*DU ID*/
1666       ieIdx++;
1667       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1668       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1669       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1670                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1671       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1672                                                                               sizeof(uint8_t);
1673
1674       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1675             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1676       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1677             NULLP)
1678       {
1679          break;
1680       }
1681
1682       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1683                                                                                 duCfgParam.duId;
1684       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1685        * However this string is decoded successfully on online decoders.
1686        * Since this is an optional IE and the value received in it are not
1687        * used as of now, eliminating this IE for now to avoid wireshark error.
1688        */
1689       /*DU Name*/
1690       if(duCfgParam.duName != NULL)
1691       {
1692          ieIdx++;
1693          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1694          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1695          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1696          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1697          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1698                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1699          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1700          {
1701             break;
1702          }
1703          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1704                (char*)duCfgParam.duName);
1705       }
1706
1707       /*Served Cell list */
1708       ieIdx++;
1709       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1710                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1711       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1712       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1713                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1714       duServedCell = &f1SetupReq->protocolIEs.list.\
1715                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1716       if(BuildServedCellList(duServedCell))
1717       {
1718          break;
1719       }
1720
1721       /*RRC Version*/
1722       ieIdx++;
1723       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1724                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1725       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1726       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1727                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1728       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1729       if(BuildRrcVer(rrcVer))
1730       {
1731          break;
1732       }
1733
1734       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1735
1736       /* Encode the F1SetupRequest type as APER */
1737       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1738       encBufSize = 0;
1739       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1740             encBuf);
1741
1742       /* Encode results */
1743       if(encRetVal.encoded == ENCODE_FAIL)
1744       {
1745          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1746                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1747          break;
1748       }
1749       else
1750       {
1751          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1752 #ifdef DEBUG_ASN_PRINT
1753          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1754          {
1755             printf("%x",encBuf[ieIdx]);
1756          }
1757 #endif
1758
1759          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1760          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1761          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1762          {
1763             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1764             return RFAILED;
1765          }
1766          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1767       }
1768
1769       /* Sending msg */
1770       if(sendF1APMsg() != ROK)
1771       {
1772          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1773          break;
1774       }
1775
1776       ret=ROK;
1777       break;
1778    }while(true);
1779
1780    FreeF1SetupReq(f1apMsg);
1781
1782    return ret;
1783 }/* End of BuildAndSendF1SetupReq */
1784
1785 /*******************************************************************
1786  *
1787  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1788  *
1789  * @details
1790  *
1791  *    Function : freeCellsToModifyItem 
1792  *
1793  *    Functionality: Deallocating memory of variables allocated in
1794  *                    BuildAndSendDUConfigUpdate function
1795  *
1796  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1797  *
1798  * @return ROK     - void
1799  *
1800  * ****************************************************************/
1801
1802 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1803 {
1804    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1805    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1806    SliceSupportItem_t *sliceSupportItem = NULLP;
1807
1808    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1809    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1810
1811    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1812            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1813    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1814          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1815
1816    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1817    {
1818       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1819       {
1820          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1821
1822          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1823
1824          if(servedPlmnItem->iE_Extensions != NULLP)
1825          {
1826             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1827             {
1828                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1829                {
1830                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1831                         list.array != NULLP)
1832                   {
1833                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1834                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1835                      {
1836                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1837                               list.array[sliceLstIdx] != NULLP)
1838                         {
1839
1840                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1841                                               SliceSupportList.list.array[sliceLstIdx];
1842
1843                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1844                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1845                            {
1846                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1847                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1848                            }
1849                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1850                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1851                         }
1852                      }
1853                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1854                            choice.SliceSupportList.list.array,\
1855                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1856                            extensionValue.choice.SliceSupportList.list.size);
1857                   }
1858                }
1859                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1860                {
1861                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1862                }
1863                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1864             }
1865             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1866          }
1867       }
1868       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1869       {
1870          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1871       }
1872       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1873          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1874    }
1875    
1876    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1877    {
1878       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1879    }  
1880    else
1881    {
1882       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1883       {
1884          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1885          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1886       }
1887    }
1888    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1889          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1890 }
1891
1892 /*******************************************************************
1893  *
1894  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1895  *
1896  * @details
1897  *
1898  *    Function : FreeDUConfigUpdate
1899  *
1900  *    Functionality: Deallocating memory of variables allocated in
1901  *                    BuildAndSendDUConfigUpdate function
1902  *
1903  * @params[in]  F1AP_PDU_t *f1apDuCfg
1904  *
1905  * @return ROK     - void
1906  *
1907  * ****************************************************************/
1908 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1909 {
1910    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1911    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1912    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1913    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1914    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1915    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1916    Cells_Status_ItemIEs_t *cellStatusItemIE;
1917
1918    if(f1apDuCfg != NULLP)
1919    {
1920       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1921       {
1922          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1923                        value.choice.GNBDUConfigurationUpdate;
1924          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1925          {
1926             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1927             {
1928                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1929                {
1930                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1931                   {
1932                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1933                         {
1934                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1935                                            value.choice.Served_Cells_To_Modify_List;
1936                            if(cellsToModify->list.array != NULLP)
1937                            {
1938                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1939                               {
1940                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1941                                  {
1942                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1943                                           Served_Cells_To_Modify_Item);
1944                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1945                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1946                                  }
1947                               }
1948                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1949                            }
1950                            break;
1951                         }
1952                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1953                         {
1954                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1955                                            value.choice.Served_Cells_To_Delete_List;
1956                            if(cellsToDelete->list.array != NULLP)
1957                            {
1958                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1959                               {
1960                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1961                                  {
1962                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1963                                           cellsToDelete->list.array[cellDeleteIdx]);
1964                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1965                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1966                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1967                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1968                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1969                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1970                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1971                                  }
1972                               }
1973                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1974                            }
1975
1976                            break;
1977                         }
1978                      case ProtocolIE_ID_id_gNB_DU_ID:
1979                         {
1980                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1981                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1982                            break;
1983                         }
1984                      case ProtocolIE_ID_id_Cells_Status_List:
1985                         {
1986                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
1987                            {
1988                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
1989                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
1990                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
1991                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
1992                            }
1993                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
1994                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
1995                         }
1996                   }
1997                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1998                         sizeof(GNBDUConfigurationUpdateIEs_t));
1999                }
2000             }
2001             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2002          }
2003          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2004       }
2005       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2006    }
2007 }
2008
2009 /*******************************************************************
2010  *
2011  * @brief Fills Served Plmns required in ServCellInfo IE
2012  *
2013  * @details
2014  *
2015  *    Function : fillServedPlmns
2016  *
2017  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2018  *
2019  * @params[in] Pointer to ServedPLMNs_List_t *
2020  *
2021  * @return ROK     - success
2022  *         RFAILED - failure
2023  *
2024  *****************************************************************/
2025
2026 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2027 {
2028    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2029
2030    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2031    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2032          array[arrayIdx]->pLMN_Identity.size);
2033    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2034    {
2035       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2036       return RFAILED;
2037    }
2038    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2039          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2040    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2041    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2042    {
2043       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2044       return RFAILED;
2045    }
2046
2047    ieListCnt=1;
2048    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2049    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2050    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2051          iE_Extensions->list.size);
2052    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2053    {
2054       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2055       return RFAILED;
2056    }
2057    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2058    {
2059       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2060             sizeof(ServedPLMNs_ItemExtIEs_t));
2061       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2062       {
2063          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2064          return RFAILED;
2065       }
2066    }
2067    
2068    ieIdx = 0;
2069    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2070    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2071    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2072    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2073    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2074    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2075       list.count = elementCnt;
2076    servedPlmn->list.array[arrayIdx]->\
2077       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2078       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2079    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2080          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2081          list.array,servedPlmn->list.array[arrayIdx]->\
2082          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2083    if(servedPlmn->list.array[arrayIdx]->\
2084          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2085          list.array == NULLP)
2086    {
2087       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2088       return RFAILED;
2089    }
2090
2091    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2092    {
2093       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2094       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2095       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2096       if(servedPlmn->list.array[arrayIdx]->\
2097       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2098       list.array[sliceLstIdx] == NULLP)
2099       {   
2100          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2101          return RFAILED;
2102       }
2103       
2104       servedPlmn->list.array[arrayIdx]->\
2105       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2106       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2107       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2108       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2109       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2110       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2111       sNSSAI.sST.size);
2112       
2113       if(servedPlmn->list.array[arrayIdx]->\
2114       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2115       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2116       {
2117          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2118          return RFAILED;
2119       }
2120       servedPlmn->list.array[arrayIdx]->\
2121       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2122       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2123       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2124
2125       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2126       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2127       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2128       if(servedPlmn->list.array[arrayIdx]->\
2129       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2130       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2131       {
2132          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2133          return RFAILED;
2134       }
2135       servedPlmn->list.array[arrayIdx]->\
2136       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2137       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2138       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2139       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2140       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2141       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2142       list.array[sliceLstIdx]->sNSSAI.sD->size);
2143       if(servedPlmn->list.array[arrayIdx]->\
2144       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2145       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2146       {
2147          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2148          return RFAILED;
2149       }
2150       memcpy(servedPlmn->list.array[arrayIdx]->\
2151       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2152       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2153       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2154       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2155       list.array[sliceLstIdx]->sNSSAI.sD->size);
2156    }
2157    return ROK;
2158 }
2159
2160 /*******************************************************************
2161  *
2162  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2163  *
2164  * @details
2165  *
2166  *    Function : fillNrFddInfo
2167  *
2168  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2169  *
2170  * @params[in] FDD_Info_t *fDD
2171  *
2172  * @return ROK     - success
2173  *         RFAILED - failure
2174  *
2175  *****************************************************************/
2176
2177 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2178 {
2179    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2180       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2181    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2182    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2183    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2184          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2185    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2186    {
2187       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2188       return RFAILED;
2189    }
2190
2191    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2192       sizeof(FreqBandNrItem_t));
2193    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2194    {
2195       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2196       return RFAILED;
2197    }
2198    
2199    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2200       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2201       freqBand[0].nrFreqBand;
2202    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2203    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2204       dlNrFreqInfo.nrArfcn;
2205    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2206    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2207    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2208    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2209    {
2210       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2211       return RFAILED;
2212    }
2213    
2214    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2215    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2216    {
2217       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2218       return RFAILED;
2219    }
2220
2221    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2222       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2223       freqBand[0].nrFreqBand;
2224    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2225    
2226    /*Transmission Bandwidth*/
2227    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2228       f1Mode.mode.fdd.ulTxBw.nrScs;
2229    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2230       f1Mode.mode.fdd.ulTxBw.nrb;
2231    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2232       f1Mode.mode.fdd.dlTxBw.nrScs;
2233    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2234       f1Mode.mode.fdd.dlTxBw.nrb;
2235
2236    return ROK;
2237 }
2238
2239 /*******************************************************************
2240  *
2241  * @brief Fills ServCellInfo IE
2242  *
2243  * @details
2244  *
2245  *    Function : fillServedCellInfo
2246  *
2247  *    Functionality: Fills ServCellInfo
2248  *
2249  * @params[in] Pointer to Served_Cell_Information_t *
2250  *
2251  * @return ROK     - success
2252  *         RFAILED - failure
2253  *
2254  *****************************************************************/
2255
2256 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2257 {
2258    uint8_t ieIdx, ieListCnt;
2259
2260    /*nRCGI*/
2261    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2262    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2263          srvCellInfo->nRCGI.pLMN_Identity.size);
2264    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2265    {
2266       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2267       return RFAILED;
2268    }
2269    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2270          srvCellInfo->nRCGI.pLMN_Identity.buf);
2271    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2272    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2273          srvCellInfo->nRCGI.nRCellIdentity.size);
2274    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2275    {   
2276       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2277       return RFAILED;
2278    }
2279    
2280    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2281    /*nRPCI*/
2282    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2283
2284    /*servedPLMNs*/
2285    ieListCnt = 1;
2286    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2287    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2288    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2289    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2290    {
2291       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2292       return RFAILED;
2293    }
2294    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2295    {
2296       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2297       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2298       {
2299          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2300          return RFAILED;
2301       }
2302    }
2303    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2304    {
2305       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2306       return RFAILED;
2307    }
2308
2309 #ifndef NR_TDD
2310    /*nR Mode Info with FDD*/
2311    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2312    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2313    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2314    {
2315       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2316       return RFAILED;
2317    }
2318    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2319    {
2320        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2321       return RFAILED;
2322    }
2323 #else
2324    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2325    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2326    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2327    {
2328       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2329       return RFAILED;
2330    }
2331    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2332    {
2333       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2334       return RFAILED;
2335    }
2336 #endif
2337
2338    /*Measurement timing Config*/
2339    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2340       return RFAILED;
2341
2342    return ROK;
2343 }
2344
2345 /*******************************************************************
2346  *
2347  * @brief Fills ServCellToModItem IE
2348  *
2349  * @details
2350  *
2351  *    Function : fillServCellToModItem
2352  *
2353  *    Functionality: Fills ServCellToModItem IE
2354  *
2355  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2356  *
2357  * @return ROK     - success
2358  *         RFAILED - failure
2359  *
2360  *****************************************************************/
2361
2362 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2363 {
2364    /*pLMN_Identity*/
2365    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2366    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2367    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2368    {
2369       return RFAILED;
2370    }
2371    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2372          modifyItem->oldNRCGI.pLMN_Identity.buf);
2373
2374    /*nRCellIdentity*/
2375    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2376    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2377          modifyItem->oldNRCGI.nRCellIdentity.size);
2378    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2379    {
2380       return RFAILED;
2381    }
2382    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2383
2384    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2385       return RFAILED;
2386    else
2387       return ROK;
2388 }
2389
2390 /*******************************************************************
2391  *
2392  * @brief Builds ServCellToModList
2393  *
2394  * @details
2395  *
2396  *    Function : buildServCellToModList
2397  *
2398  *    Functionality: Builds the serv cell to Mod List
2399  *
2400  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2401  *
2402  * @return ROK     - success
2403  *         RFAILED - failure
2404  *
2405  *****************************************************************/
2406
2407 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2408 {
2409    uint8_t ieListCnt, ieIdx;
2410    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2411
2412    ieListCnt = 1;
2413    cellsToModify->list.count = ieListCnt;
2414    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2415    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2416    if(cellsToModify->list.array == NULLP)
2417    {
2418       return RFAILED;
2419    }
2420    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2421    {
2422       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2423       if(cellsToModify->list.array[ieIdx] == NULLP)
2424       {
2425          return RFAILED;
2426       }
2427    }
2428    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2429    cellsToModify->list.array[0]->criticality = Criticality_reject;
2430    cellsToModify->list.array[0]->value.present =\
2431       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2432    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2433
2434    if(fillServCellToModItem(modifyItem))
2435       return RFAILED;
2436    else
2437       return ROK;
2438 }
2439 /*******************************************************************
2440  *
2441  * @brief filling the DeleteItemList
2442  *
2443  * @details
2444  *
2445  *    Function : fillCellToDeleteItem 
2446  *
2447  *    Functionality: Filling the DeleteItemIe 
2448  *
2449  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2450  *
2451  * @return ROK     - success
2452  *         RFAILED - failure
2453  *
2454  *****************************************************************/
2455 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2456 {
2457    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2458    
2459    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2460    deleteItemIe->criticality = Criticality_reject;
2461    deleteItemIe->value.present =\
2462    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2463    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2464
2465    /*pLMN_Identity*/
2466    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2467    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2468    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2469    {
2470       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2471       return RFAILED;
2472    }
2473    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2474          deleteItem->oldNRCGI.pLMN_Identity.buf);
2475
2476    /*nRCellIdentity*/
2477    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2478    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2479          deleteItem->oldNRCGI.nRCellIdentity.size);
2480    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2481    {
2482       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2483       return RFAILED;
2484    }
2485    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2486    return ROK;
2487
2488
2489 /*******************************************************************
2490  *
2491  * @brief Builds ServCellToDeleteList
2492  *
2493  * @details
2494  *
2495  *    Function : buildServCellToDeleteList
2496  *
2497  *    Functionality: Builds the serv cell to delete List
2498  *
2499  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2500  *
2501  * @return ROK     - success
2502  *         RFAILED - failure
2503  *
2504  *****************************************************************/
2505  
2506 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2507 {
2508    uint8_t ieListCnt, arrIdx;
2509    
2510    ieListCnt = 1;
2511    cellsToDelete->list.count = ieListCnt;
2512    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2513    
2514    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2515    if(cellsToDelete->list.array == NULLP)
2516    {
2517       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2518       return RFAILED;
2519    }
2520    
2521    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2522    {
2523       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2524       if(cellsToDelete->list.array[arrIdx] == NULLP)
2525       {
2526          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2527          return RFAILED;
2528       }
2529    }
2530    
2531    arrIdx=0;
2532    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2533    {
2534       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2535       return RFAILED;
2536    }
2537    return ROK;
2538 }
2539
2540 /*******************************************************************
2541  *
2542  * @brief Builds CellsStatusList
2543  *
2544  * @details
2545  *
2546  *    Function : buildCellsStatusList
2547  *
2548  *    Functionality: Builds the Cell Status List
2549  *
2550  * @params[in] Pointer to Cells_Status_List_t *
2551  *
2552  * @return ROK     - success
2553  *         RFAILED - failure
2554  *
2555  *****************************************************************/
2556 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2557 {
2558    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2559    Cells_Status_ItemIEs_t *cellStatusItemIE;
2560
2561    elementCnt = 1;
2562    cellStatusList->list.count = elementCnt;
2563    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2564    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2565
2566    for(idx = 0; idx < elementCnt; idx++)
2567    {
2568       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2569       if(!cellStatusList->list.array[idx])
2570       {
2571          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2572          return RFAILED;
2573       }
2574    }
2575    idx = 0;
2576    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2577    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2578    cellStatusItemIE->criticality = Criticality_reject;
2579    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2580    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2581    if(ret == RFAILED)
2582    {
2583          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2584          return RFAILED;
2585    }
2586    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2587    return ROK;
2588 }
2589
2590 /*******************************************************************
2591  *
2592  * @brief Builds and sends the DUConfigUpdate
2593  *
2594  * @details
2595  *
2596  *    Function : BuildAndSendDUConfigUpdate
2597  *
2598  *    Functionality: Constructs the DU Update message and sends
2599  *                   it to the CU through SCTP.
2600  *
2601  * @params[in] void **buf,Buffer to which encoded pattern is written into
2602  * @params[in] int *size,size of buffer
2603  *
2604  * @return ROK     - success
2605  *         RFAILED - failure
2606  *
2607  * ****************************************************************/
2608 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2609 {
2610    uint8_t ret =0, ieIdx=0, elementCnt=0;
2611    bool memAlloctionFailure = false;
2612    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2613    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2614    asn_enc_rval_t encRetVal;     /* Encoder return value */
2615    
2616    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2617    ret= RFAILED;
2618
2619    while(true)
2620    {
2621       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2622       /* Allocate the memory for F1DuCfg */
2623       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2624       if(f1apDuCfg == NULLP)
2625       {
2626          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2627          break;
2628       }
2629
2630       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2631       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2632       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2633       {
2634          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2635          break;
2636       }
2637
2638       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2639                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2640       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2641       f1apDuCfg->choice.initiatingMessage->value.present = \
2642                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2643       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2644                     choice.GNBDUConfigurationUpdate;
2645       elementCnt = 4;
2646       duCfgUpdate->protocolIEs.list.count = elementCnt;
2647       duCfgUpdate->protocolIEs.list.size = \
2648                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2649
2650       /* Initialize the F1Setup members */
2651       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2652       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2653       {
2654          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2655          break;
2656       }
2657       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2658       {
2659          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2660          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2661          {
2662             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2663             memAlloctionFailure = true;
2664             break;
2665          }
2666       }
2667       
2668       if(memAlloctionFailure == true)
2669       {
2670          break;
2671       }
2672       /*TransactionID*/
2673       ieIdx = 0;
2674       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2675       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2676       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2677       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2678       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2679       
2680       ieIdx++;
2681       if(servCellAction == SERV_CELL_TO_MODIFY)
2682       {
2683          /*Served Cell to Modify */
2684          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2685          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2686          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2687          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2688          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2689          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2690                   Served_Cells_To_Modify_List))
2691          {
2692             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2693             break;
2694          }
2695       }
2696       else
2697       {
2698          /*Served Cell to Delete */ 
2699          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2700          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2701          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2702          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2703          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2704          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2705          Served_Cells_To_Delete_List)!=ROK)
2706          {
2707             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2708             break;
2709          }
2710          
2711       }
2712       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2713       
2714       /*Cell Status List*/
2715       ieIdx++;
2716       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2717       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2718       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2719            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2720       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2721       if(ret == RFAILED)
2722       {
2723          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2724          break;
2725       }
2726
2727       /*GNB DU ID */
2728       ieIdx++;
2729       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2730       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2731       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2732       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2733       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2734       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2735             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2736       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2737       {
2738          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2739          break;
2740       }
2741       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2742
2743       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2744
2745       /* Encode the DU Config Update type as APER */
2746       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2747       encBufSize = 0;
2748       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2749
2750       /* Checking encode results */
2751       if(encRetVal.encoded == ENCODE_FAIL)
2752       {
2753          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2754                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2755          break;
2756       }
2757       else
2758       {
2759          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2760 #ifdef DEBUG_ASN_PRINT
2761          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2762          {
2763             printf("%x",encBuf[ieIdx]);
2764          }
2765 #endif
2766       }
2767       /* Sending msg */
2768       if(sendF1APMsg() != ROK)
2769       {
2770          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2771          break;
2772       }
2773
2774       ret = ROK;
2775       break;
2776    }
2777   
2778    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2779    return ret;
2780 }
2781
2782
2783 /*******************************************************************
2784  *
2785  * @brief free the ULRRCMessageTransfer
2786  *
2787  * @details
2788  *
2789  *    Function : FreeULRRCMessageTransfer
2790  *
2791  *    Functionality: Deallocating the memory of variable allocated in
2792  *                      FreeULRRCMessageTransfer
2793  *
2794  * @params[in]
2795  *
2796  * @return ROK     - void
2797  *
2798  ******************************************************************/
2799 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2800 {
2801    uint8_t idx1;
2802    ULRRCMessageTransfer_t  *ulRRCMsg;
2803
2804    if(f1apMsg != NULLP)
2805    { 
2806       if(f1apMsg->choice.initiatingMessage != NULLP)
2807       {
2808          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2809          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2810          {
2811             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2812             {
2813                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2814                {
2815                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2816                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2817                   {
2818                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2819                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2820                   }
2821                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2822                }
2823             }
2824             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2825          }
2826          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2827       }
2828       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2829    }
2830 }
2831 /*******************************************************************
2832  *
2833  * @brief Builds and sends the ULRRCMessageTransfer 
2834  *
2835  * @details
2836  *
2837  *    Function : BuildAndSendULRRCMessageTransfer
2838  *
2839  *    Functionality: Constructs the UL RRC Message Transfer and sends
2840  *                   it to the CU through SCTP.
2841  *
2842  * @params[in] 
2843  *
2844  * @return ROK     - success
2845  *         RFAILED - failure
2846  *
2847  * ****************************************************************/
2848 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2849       uint16_t msgLen, uint8_t *rrcMsg)
2850 {
2851    uint8_t                 elementCnt=0, idx1=0, idx=0;
2852    uint8_t                 ret = RFAILED;
2853    F1AP_PDU_t              *f1apMsg = NULLP;
2854    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2855    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2856    
2857    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2858
2859    while(true)
2860    {
2861       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2862
2863       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2864       if(f1apMsg == NULLP)
2865       {
2866          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2867          break;
2868       }
2869       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2870       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2871       if(f1apMsg->choice.initiatingMessage == NULLP)
2872       {
2873          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2874          break;
2875       }
2876       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2877       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2878       f1apMsg->choice.initiatingMessage->value.present = \
2879                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2880       ulRRCMsg =
2881          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2882       elementCnt = 4;
2883       ulRRCMsg->protocolIEs.list.count = elementCnt;
2884       ulRRCMsg->protocolIEs.list.size = \
2885                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2886
2887       /* Initialize the F1Setup members */
2888       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2889       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2890       {
2891          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2892          break;
2893       }
2894       for(idx=0; idx<elementCnt; idx++)
2895       {
2896          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2897          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2898          {
2899             break;
2900          }
2901       }
2902
2903       idx1 = 0;
2904
2905       /*GNB CU UE F1AP ID*/
2906       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2907       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2908       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2909                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2910       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2911
2912       /*GNB DU UE F1AP ID*/
2913       idx1++;
2914       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2915       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2916       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2917                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2918       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2919
2920       /*SRBID*/
2921       idx1++;
2922       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2923       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2924       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2925                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2926       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2927
2928       /*RRCContainer*/
2929       idx1++;
2930       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2931       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2932       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2933                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2934       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2935       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2936             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2937       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2938       {
2939          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2940          break;
2941       }
2942       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2943       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2944             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2945
2946       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2947
2948       /* Encode the F1SetupRequest type as APER */
2949       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2950       encBufSize = 0;
2951       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2952             encBuf);
2953       /* Encode results */
2954       if(encRetVal.encoded == ENCODE_FAIL)
2955       {
2956          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2957                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2958          break;
2959       }
2960       else
2961       {
2962          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2963 #ifdef DEBUG_ASN_PRINT
2964          for(int i=0; i< encBufSize; i++)
2965          {
2966             printf("%x",encBuf[i]);
2967          }
2968 #endif
2969       }
2970
2971       /* Sending  msg  */
2972       if(sendF1APMsg()  !=      ROK)
2973       {
2974          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2975          break;
2976       }
2977       ret = ROK;
2978       break;
2979    }
2980    FreeULRRCMessageTransfer(f1apMsg);
2981
2982    return ret;
2983 }/* End of BuildAndSendULRRCMessageTransfer*/
2984
2985 /*******************************************************************
2986  *
2987  * @brief Builds tag config 
2988  *
2989  * @details
2990  *
2991  *    Function : BuildTagConfig 
2992  *
2993  *    Functionality: Builds tag config in MacCellGroupConfig
2994  *
2995  * @params[in] TAG_Config *tag_Config
2996  *
2997  * @return ROK     - success
2998  *         RFAILED - failure
2999  *
3000  * ****************************************************************/
3001 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3002 {
3003    struct TAG_Config__tag_ToAddModList *tagList;
3004    uint8_t                     idx, elementCnt;
3005
3006    tagConfig->tag_ToReleaseList = NULLP;
3007    tagConfig->tag_ToAddModList = NULLP;
3008    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3009    if(!tagConfig->tag_ToAddModList)
3010    {
3011       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3012       return RFAILED;
3013    }
3014
3015    if(ueCb == NULLP)
3016       elementCnt = ODU_VALUE_ONE;
3017    else
3018       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3019
3020    tagList = tagConfig->tag_ToAddModList;
3021    tagList->list.count = elementCnt;
3022    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3023
3024    tagList->list.array = NULLP;
3025    DU_ALLOC(tagList->list.array, tagList->list.size);
3026    if(!tagList->list.array)
3027    {
3028       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3029       return RFAILED;
3030    }
3031
3032    for(idx=0; idx<tagList->list.count; idx++)
3033    {
3034       tagList->list.array[idx] = NULLP;
3035       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3036       if(!tagList->list.array[idx])
3037       {
3038          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3039          return RFAILED;
3040       }
3041    }
3042
3043    if(ueCb == NULLP)
3044    {
3045       idx = 0;
3046       tagList->list.array[idx]->tag_Id = TAG_ID;
3047       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3048    }
3049    else
3050    {
3051       for(idx=0; idx<tagList->list.count; idx++)
3052       {
3053          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3054          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3055       }
3056    }
3057
3058    return ROK;
3059 }
3060
3061 /*******************************************************************
3062  *
3063  * @brief Builds PHR Config 
3064  *
3065  * @details
3066  *
3067  *    Function : BuildPhrConfig
3068  *
3069  *    Functionality: Builds phrConfig in MacCellGroupConfig
3070  *
3071  * @params[in] PHR Config *
3072  *
3073  * @return ROK     - success
3074  *         RFAILED - failure
3075  *
3076  * ****************************************************************/
3077 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3078 {
3079
3080    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3081    phrConfig->choice.setup = NULLP;
3082    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3083    if(!phrConfig->choice.setup)
3084    {
3085       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3086       return RFAILED;
3087    }
3088
3089    if(ueCb == NULLP)
3090    {
3091       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3092       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3093       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3094       phrConfig->choice.setup->multiplePHR              = false;
3095       phrConfig->choice.setup->dummy                    = false;
3096       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3097       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3098    }
3099    else
3100    {
3101       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3102       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3103       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3104       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3105       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3106       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3107       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3108    }
3109
3110    return ROK;
3111 }
3112
3113 /*******************************************************************
3114  *
3115  * @brief Builds BSR Config 
3116  *
3117  * @details
3118  *
3119  *    Function : BuildBsrConfig
3120  *
3121  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3122  *
3123  * @params[in] BSR_Config *bsrConfig
3124  *
3125  * @return ROK     - success
3126  *         RFAILED - failure
3127  *
3128  * ****************************************************************/
3129 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3130 {
3131    if(ueCb == NULLP)
3132    {
3133       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3134       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3135       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3136    }
3137    else
3138    {
3139       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3140       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3141
3142       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3143       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3144       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3145       {
3146          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3147          return RFAILED;
3148       }
3149       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3150    }
3151
3152    return ROK;
3153 }
3154
3155 /*******************************************************************
3156  *
3157  * @brief Builds scheduling request config 
3158  *
3159  * @details
3160  *
3161  *    Function : BuildSchedulingReqConfig 
3162  *
3163  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3164  *
3165  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3166  *
3167  * @return ROK     - success
3168  *         RFAILED - failure
3169  *
3170  * ****************************************************************/
3171 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3172 {
3173    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3174    uint8_t                     idx, elementCnt;
3175
3176    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3177    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3178          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3179    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3180    {
3181       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3182       return RFAILED;
3183    }
3184
3185    if(ueCb == NULLP)
3186       elementCnt = ODU_VALUE_ONE;
3187    else
3188       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3189
3190    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3191    schReqList->list.count = elementCnt;
3192    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3193
3194    schReqList->list.array = NULLP;
3195    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3196    if(!schReqList->list.array)
3197    {
3198       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3199       return RFAILED;
3200    }
3201
3202    for(idx=0; idx<schReqList->list.count; idx++)
3203    {
3204       schReqList->list.array[idx] = NULLP;
3205       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3206       if(!schReqList->list.array[idx])
3207       {
3208          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3209          return RFAILED;
3210       }
3211    }
3212
3213    if(ueCb == NULLP)
3214    {
3215       idx = 0;
3216       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3217
3218       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3219       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3220       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3221       {
3222          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3223          return RFAILED;
3224       }
3225       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3226       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3227    }
3228    else
3229    {
3230       for(idx=0; idx<schReqList->list.count; idx++)
3231       {
3232          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3233
3234          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3235          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3236          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3237          {
3238             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3239             return RFAILED;
3240          }
3241          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3242          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3243       }
3244    }
3245
3246    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3247
3248    return ROK;
3249 }
3250
3251 /*******************************************************************
3252  *
3253  * @brief Builds RLC Configuration for AM mode
3254  *
3255  * @details
3256  *
3257  *    Function : BuildRlcConfigAm
3258  *
3259  *    Functionality: 
3260  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3261  *
3262  * @params[in] AmBearerCfg *amCfg
3263  *             RLC_Config_t  *rlcConfig
3264  *
3265  * @return ROK     - success
3266  *         RFAILED - failure
3267  *
3268  * ****************************************************************/
3269 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3270 {
3271    rlcConfig->choice.am = NULLP;
3272    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3273    if(!rlcConfig->choice.am)
3274    {
3275       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3276       return RFAILED;
3277    }
3278
3279    /* Fill AM UL configuration */
3280    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3281    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3282    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3283    {
3284       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3285       return RFAILED;
3286    }
3287
3288    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3289    if(amCfg == NULLP)
3290    {
3291       
3292       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN_12BIT; /*As per Spec 38.331, "Network configures only value size12 in SN-FieldLengthAM for SRB"*/
3293       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3294       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3295       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3296       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3297    }
3298    else
3299    {
3300       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3301       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3302       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3303       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3304       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3305    }
3306
3307    /* Fill AM DL configuraion */
3308    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3309    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3310    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3311    {
3312       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3313       return RFAILED;
3314    }
3315
3316    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3317    if(amCfg == NULLP)
3318    {
3319       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN_12BIT; /*As per Spec 38.331, "Network configures only value size12 in SN-FieldLengthAM for SRB"*/
3320       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3321       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3322    }
3323    else /* Fill AM configuration from DU database */
3324    {
3325       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3326       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3327       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3328    }
3329    return ROK;
3330 }
3331
3332 /*******************************************************************
3333  *
3334  * @brief Builds RLC Config for UM Bidirection
3335  *
3336  * @details
3337  *
3338  *    Function : BuildRlcConfig UmBiDir
3339  *
3340  *    Functionality: 
3341  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3342  *
3343  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3344  *             RLC_Config_t *rlcConfig
3345  *
3346  * @return ROK     - success
3347  *         RFAILED - failure
3348  *
3349  * ****************************************************************/
3350 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3351 {
3352    rlcConfig->choice.um_Bi_Directional = NULLP;
3353    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3354    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3355    {
3356       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3357       return RFAILED;
3358    }
3359
3360    /* Fill UM Bidirectional UL configuration */
3361    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3362    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3363    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3364    {
3365       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3366       return RFAILED;
3367    }
3368
3369    if(umBiDirCfg != NULLP)
3370    {
3371       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3372    }
3373
3374    /* Fill UM Bidirectional DL configuration */
3375    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3376    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3377    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3378    {
3379       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3380       return RFAILED;
3381    }
3382
3383    if(umBiDirCfg != NULLP)
3384    {
3385       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3386       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3387    }
3388
3389    return ROK;
3390 }
3391
3392 /*******************************************************************
3393  *
3394  * @brief Builds RLC Config for UM Uni directional UL
3395  *
3396  * @details
3397  *
3398  *    Function : BuildRlcConfigUmUniDirUl
3399  *
3400  *    Functionality: 
3401  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3402  *
3403  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3404  *             RLC_Config_t *rlcConfig
3405  *
3406  * @return ROK     - success
3407  *         RFAILED - failure
3408  *
3409  * ****************************************************************/
3410 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3411 {
3412    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3413    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3414    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3415    {
3416       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3417       return RFAILED;
3418    }
3419
3420    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3421    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3422    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3423    {
3424       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3425       return RFAILED;
3426    }
3427
3428    if(umUniDirDlCfg != NULLP)
3429    {
3430       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3431    }
3432
3433    return ROK;
3434 }
3435
3436 /*******************************************************************
3437  *
3438  * @brief Builds RLC Config for UM Uni directional DL
3439  *
3440  * @details
3441  *
3442  *    Function : BuildRlcConfigUmUniDirDl
3443  *
3444  *    Functionality: 
3445  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3446  *
3447  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3448  *             RLC_Config_t *rlcConfig
3449  *
3450  * @return ROK     - success
3451  *         RFAILED - failure
3452  *
3453  * ****************************************************************/
3454 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3455 {
3456    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3457    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3458    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3459    {
3460       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3461       return RFAILED;
3462    }
3463
3464    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3465    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3466    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3467    {
3468       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3469       return RFAILED;
3470    }
3471
3472    if(umUniDirUlCfg != NULLP)
3473    {
3474       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3475       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3476    }
3477
3478    return ROK;
3479 }
3480
3481 /*******************************************************************
3482  *
3483  * @brief Builds RLC Config
3484  *
3485  * @details
3486  *
3487  *    Function : BuildRlcConfig
3488  *
3489  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3490  *
3491  * @params[in] RLC_Config_t *rlcConfig
3492  *
3493  * @return ROK     - success
3494  *         RFAILED - failure
3495  *
3496  * ****************************************************************/
3497 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3498 {
3499    
3500    /* Fill default values if rbCfg is NULL */
3501    if(rbCfg == NULLP)
3502    {
3503       rlcConfig->present = RLC_Config_PR_am;
3504       BuildRlcConfigAm(NULLP, rlcConfig);
3505    }
3506    /* If RbCfg is present, fill RLC configurations from DU Database */
3507    else
3508    {
3509       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3510       switch(rlcConfig->present)
3511       {
3512          case RLC_Config_PR_am:
3513             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3514             break;
3515          case RLC_Config_PR_um_Bi_Directional:
3516             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3517             break;
3518          case RLC_Config_PR_um_Uni_Directional_UL:
3519             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3520             break;
3521          case RLC_Config_PR_um_Uni_Directional_DL:
3522             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3523             break;
3524          case RLC_Config_PR_NOTHING:
3525          default:
3526             break;
3527       }
3528    }
3529
3530    return ROK;
3531 }
3532
3533 /*******************************************************************
3534  *
3535  * @brief Builds MAC LC Config
3536  *
3537  * @details
3538  *
3539  *    Function : BuildMacLCConfig 
3540  *
3541  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3542  *
3543  * @params[in] struct LogicalChannelConfig macLcConfig
3544  *
3545  * @return ROK     - success
3546  *         RFAILED - failure
3547  *
3548  * ****************************************************************/
3549 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3550 {
3551    macLcConfig->ul_SpecificParameters = NULLP;
3552    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3553    if(!macLcConfig->ul_SpecificParameters)
3554    {
3555       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3556       return RFAILED;
3557    }
3558
3559    if(lcCfgDb == NULLP)
3560    {
3561       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3562       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3563       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3564    }
3565    else
3566    {
3567       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3568       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3569       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3570    }
3571
3572    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3573    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3574    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3575    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3576
3577    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3578    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3579    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3580    {
3581       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3582       return RFAILED;
3583    }
3584
3585    if(lcCfgDb == NULLP)
3586       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3587    else
3588       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3589
3590    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3591    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3592    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3593    {
3594       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3595       return RFAILED;
3596    }
3597
3598    if(lcCfgDb == NULLP)
3599       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3600    else
3601       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3602
3603    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3604    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3605    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3606
3607    return ROK;
3608 }
3609
3610 /*******************************************************************
3611  *
3612  * @brief Builds RLC Bearer to Add/Mod list
3613  *
3614  * @details
3615  *
3616  *    Function :BuildRlcBearerToAddModList 
3617  *
3618  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3619  *
3620  * @params[in] rlc_BearerToAddModList
3621  *
3622  * @return ROK     - success
3623  *         RFAILED - failure
3624  *
3625  * ****************************************************************/
3626 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3627 {
3628    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3629
3630    if(ueCb == NULLP)
3631       elementCnt = 1;
3632    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3633       elementCnt = ueCb->duRlcUeCfg.numLcs;
3634    else
3635    {
3636       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3637       {
3638          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3639             elementCnt++;
3640       }
3641    }
3642    rlcBearerList->list.count = elementCnt;
3643    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3644
3645    rlcBearerList->list.array = NULLP;
3646    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3647    if(!rlcBearerList->list.array)
3648    {
3649       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3650       return RFAILED;
3651    }
3652
3653    for(idx=0; idx<rlcBearerList->list.count; idx++)
3654    {
3655       rlcBearerList->list.array[idx] = NULLP;
3656       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3657       if(!rlcBearerList->list.array[idx])
3658       {
3659          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3660          return RFAILED;
3661       }
3662    }
3663
3664    if(ueCb == NULLP)
3665    {
3666       idx=0;
3667       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3668       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3669       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3670       {     
3671          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3672          return RFAILED;
3673       }     
3674       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3675       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3676       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3677
3678       /* Fill RLC related Configurations for this Radio Bearer */
3679       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3680       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3681       if(!rlcBearerList->list.array[idx]->rlc_Config)
3682       {
3683          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3684          return RFAILED;
3685       }
3686       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3687       {
3688          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3689          return RFAILED;
3690       }
3691
3692       /* Fill MAC related configurations for this Radio Bearer */
3693       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3694       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3695       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3696       {
3697          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3698          return RFAILED;
3699       }
3700       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3701       {
3702          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3703          return RFAILED;
3704       }
3705    }
3706    else
3707    {
3708       idx=0;
3709       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3710       {
3711          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3712             continue;
3713
3714          /* Fill Logical channel identity */
3715          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3716
3717          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3718          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3719          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3720          {
3721             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3722             return RFAILED;
3723          }
3724          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3725                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3726          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3727          {
3728             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3729                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3730                break;
3731             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3732                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3733                break;
3734             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3735             default:
3736                break;
3737          }
3738          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3739
3740          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3741
3742          /* Fill RLC related Configurations for this Radio Bearer */
3743          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3744          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3745          if(!rlcBearerList->list.array[idx]->rlc_Config)
3746          {
3747             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3748             return RFAILED;
3749          }
3750          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3751          {
3752             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3753             return RFAILED;
3754          }
3755
3756          /* Fill MAC related configurations for this Radio Bearer */
3757          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3758          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3759          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3760          {
3761             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3762             return RFAILED;
3763          }
3764          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3765          {
3766             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3767             {
3768                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3769                {
3770                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3771                   return RFAILED;
3772                }
3773                break;
3774             }
3775          }
3776
3777          idx++;
3778       }
3779    }
3780    return ROK;
3781 }
3782
3783 /*******************************************************************
3784  *
3785  * @brief Build Control resource set to add/modify list 
3786  *
3787  * @details
3788  *
3789  *    Function : BuildControlRSetToAddModList
3790  *
3791  *    Functionality: Build Control resource set to add/modify list
3792  *
3793  * @params[in] 
3794  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3795  *
3796  * @return ROK     - success
3797  *         RFAILED - failure
3798  *
3799  * ****************************************************************/
3800 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3801 {
3802    uint8_t idx;
3803    uint8_t elementCnt;
3804    uint8_t numBytes, bitsUnused;
3805    struct ControlResourceSet *controlRSet;
3806    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3807    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3808
3809    if(pdcchCfg == NULLP)
3810       elementCnt = 1;
3811    else
3812       elementCnt = pdcchCfg->numCRsetToAddMod;
3813
3814    controlRSetList->list.count = elementCnt;
3815    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3816
3817    controlRSetList->list.array = NULLP;
3818    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3819    if(!controlRSetList->list.array)
3820    {
3821       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3822       return RFAILED;
3823    }
3824
3825    for(idx = 0; idx < elementCnt; idx++)
3826    {
3827       controlRSetList->list.array[idx] = NULLP;
3828       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3829       if(!controlRSetList->list.array[idx])
3830       {
3831          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3832          return RFAILED;
3833       }
3834    }
3835
3836    for(idx = 0; idx < elementCnt; idx++)
3837    {
3838       controlRSet = controlRSetList->list.array[idx];
3839
3840       if(pdcchCfg == NULLP)
3841          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3842       else
3843          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3844
3845       /* size 6 bytes
3846        * 3 LSBs unsued
3847        * Bit string stored ff0000000000
3848        */
3849       numBytes = 6;
3850       bitsUnused = 3;
3851       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3852
3853       controlRSet->frequencyDomainResources.buf = NULLP;
3854       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3855       if(!controlRSet->frequencyDomainResources.buf)
3856       {
3857          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3858          return RFAILED;
3859       }
3860
3861       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3862
3863       if(pdcchCfg == NULLP)
3864       {
3865          coreset0EndPrb = CORESET0_END_PRB;
3866          coreset1StartPrb = coreset0EndPrb + 6;
3867          coreset1NumPrb = CORESET1_NUM_PRB;
3868          /* calculate the PRBs */
3869          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3870          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3871          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3872
3873          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3874          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3875          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3876       }
3877       else
3878       {
3879          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3880          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3881          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3882          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3883          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3884       }
3885       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3886       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3887       controlRSet->tci_PresentInDCI = NULLP;
3888
3889 #if 0
3890       uint8_t tciStateIdx;
3891
3892       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3893             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3894       if(!controlRset->tci_StatesPDCCH_ToAddList)
3895       {
3896          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3897          return RFAILED;
3898       }
3899
3900       elementCnt = 1;
3901       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3902       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3903       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3904             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3905          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3906          {
3907             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3908             return RFAILED;
3909          }
3910
3911       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3912       {
3913          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3914          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3915          {
3916             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3917             return RFAILED;
3918          }
3919       }
3920
3921       tciStateIdx = 0;
3922       /* TODO */
3923       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3924
3925       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3926       if(!controlRset->tci_PresentInDCI)
3927       {
3928          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3929          return RFAILED;
3930       }
3931       /* TODO */
3932       *(controlRset->tci_PresentInDCI);
3933 #endif
3934
3935       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3936       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3937       if(!controlRSet->pdcch_DMRS_ScramblingID)
3938       {
3939          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3940          return RFAILED;
3941       }
3942       if(pdcchCfg == NULLP)
3943          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3944       else
3945          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3946    }
3947    return ROK;
3948 } /* End BuildControlRSetToAddModList */
3949
3950 /*******************************************************************
3951  *
3952  * @brief Build search space to add/modify list
3953  *
3954  * @details
3955  *
3956  *    Function : BuildSearchSpcToAddModList
3957  *
3958  *    Functionality: Build search space to add/modify list
3959  *
3960  * @params[in] 
3961  * @return ROK     - success
3962  *         RFAILED - failure
3963  *
3964  * ****************************************************************/
3965 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3966 {
3967    uint8_t idx;
3968    uint8_t numBytes;
3969    uint8_t byteIdx;
3970    uint8_t bitsUnused;
3971    uint8_t elementCnt;
3972    struct SearchSpace *searchSpc;
3973
3974    if(pdcchCfg == NULLP)
3975       elementCnt = 1;
3976    else
3977       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3978
3979    searchSpcList->list.count = elementCnt;
3980    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3981
3982    searchSpcList->list.array = NULLP;
3983    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3984    if(!searchSpcList->list.array)
3985    {
3986       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3987       return RFAILED;
3988    }
3989
3990    for(idx = 0; idx < elementCnt; idx++)
3991    {
3992       searchSpcList->list.array[idx] = NULLP;
3993       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3994       if(!searchSpcList->list.array[idx])
3995       {
3996          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3997          return RFAILED;
3998       }
3999    }
4000
4001    for(idx = 0; idx < elementCnt; idx++)
4002    {
4003       searchSpc = searchSpcList->list.array[idx];
4004
4005       if(pdcchCfg == NULLP)
4006          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4007       else
4008          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4009
4010       searchSpc->controlResourceSetId = NULLP;
4011       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4012       if(!searchSpc->controlResourceSetId)
4013       {
4014          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4015          return RFAILED;
4016       }
4017       if(pdcchCfg == NULLP)
4018          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4019       else
4020          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4021
4022       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4023       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4024       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4025       {
4026          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4027          return RFAILED;
4028       }
4029       if(pdcchCfg == NULLP)
4030          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4031       else
4032          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4033
4034       searchSpc->duration = NULLP;
4035       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4036       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4037       if(!searchSpc->monitoringSymbolsWithinSlot)
4038       {
4039          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4040          return RFAILED;
4041       }
4042
4043       /* Values taken from reference logs :
4044        * size 2 bytes
4045        * 2 LSBs unsued
4046        * Bit string stores 8000
4047        */
4048       numBytes = 2;
4049       bitsUnused = 2;
4050       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4051       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4052       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4053       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4054       {
4055          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4056          return RFAILED;
4057       }
4058       if(pdcchCfg == NULLP)
4059       {
4060          byteIdx = 0;
4061          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4062          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4063       }
4064       else
4065          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4066       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4067
4068       searchSpc->nrofCandidates = NULLP;
4069       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4070       if(!searchSpc->nrofCandidates)
4071       {
4072          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4073          return RFAILED;
4074       }
4075
4076       if(pdcchCfg == NULLP)
4077       {
4078          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4079          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4080          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4081          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4082          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4083       }
4084       else
4085       {
4086          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4087          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4088          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4089          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4090          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4091       }
4092
4093       searchSpc->searchSpaceType = NULLP;
4094       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4095       if(!searchSpc->searchSpaceType)
4096       {
4097          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4098          return RFAILED;
4099       }
4100       if(pdcchCfg == NULLP)
4101          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4102       else
4103          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4104
4105       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4106       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4107       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4108       {
4109          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4110          return RFAILED;
4111       }  
4112       if(pdcchCfg == NULLP)
4113          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4114       else
4115          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4116    }
4117    return ROK;
4118 }/* End BuildSearchSpcToAddModList */
4119
4120 /*******************************************************************
4121  *
4122  * @brief Builds BWP DL dedicated PDCCH config
4123  *
4124  * @details
4125  *
4126  *    Function : BuildBWPDlDedPdcchCfg
4127  *
4128  *    Functionality: Builds BWP DL dedicated PDCCH config
4129  *
4130  * @params[in] struct PDCCH_Config *pdcchCfg
4131  *
4132  * @return ROK     - success
4133  *         RFAILED - failure
4134  *
4135  * ****************************************************************/
4136 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4137 {
4138    pdcchCfg->controlResourceSetToAddModList = NULLP;
4139    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4140    if(!pdcchCfg->controlResourceSetToAddModList)
4141    {
4142       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4143       return RFAILED;
4144    }
4145
4146    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4147    {
4148       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4149       return RFAILED;
4150    }
4151
4152    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4153
4154    pdcchCfg->searchSpacesToAddModList = NULLP;
4155    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4156    if(!pdcchCfg->searchSpacesToAddModList)
4157    {
4158       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4159       return RFAILED;
4160    }
4161
4162    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4163    {
4164       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4165       return RFAILED;
4166    }
4167
4168    pdcchCfg->searchSpacesToReleaseList = NULLP;
4169    pdcchCfg->downlinkPreemption = NULLP;
4170    pdcchCfg->tpc_PUSCH = NULLP;
4171    pdcchCfg->tpc_PUCCH = NULLP;
4172    pdcchCfg->tpc_SRS = NULLP;
4173
4174    return ROK;
4175 }
4176
4177 /*******************************************************************
4178  *
4179  * @brief Builds DMRS DL PDSCH Mapping type A
4180  *
4181  * @details
4182  *
4183  *    Function : BuildDMRSDLPdschMapTypeA
4184  *
4185  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4186  *
4187  * @params[in]
4188  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4189  * @return ROK     - success
4190  *         RFAILED - failure
4191  *
4192  * ****************************************************************/
4193 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4194 {
4195    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4196    dmrsDlCfg->choice.setup = NULLP;
4197    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4198    if(!dmrsDlCfg->choice.setup)
4199    {
4200       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4201       return RFAILED;
4202    }
4203
4204    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4205    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4206    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4207    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4208    {
4209       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4210       return RFAILED;
4211    }
4212    if(pdschCfg == NULLP)
4213       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4214    else
4215       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4216
4217    dmrsDlCfg->choice.setup->maxLength = NULLP;
4218    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4219    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4220    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4221
4222    return ROK;
4223 }
4224
4225 /*******************************************************************
4226  *
4227  * @brief Builds TCI states to add/modify list
4228  *
4229  * @details
4230  *
4231  *    Function : BuildTCIStatesToAddModList
4232  *
4233  *    Functionality:Builds TCI states to add/modify list
4234  *
4235  * @params[in] 
4236  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4237  *
4238  * @return ROK     - success
4239  *         RFAILED - failure
4240  *
4241  * ****************************************************************/
4242 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4243 {
4244    return ROK;
4245 }
4246
4247 /*******************************************************************
4248  *
4249  * @brief Builds PDSCH time domain allocation list
4250  *
4251  * @details
4252  *
4253  *    Function : BuildPdschTimeDomAllocList
4254  *
4255  *    Functionality: Builds PDSCH time domain allocation list
4256  *
4257  * @params[in] 
4258  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4259  *
4260  * @return ROK     - success
4261  *         RFAILED - failure
4262  *
4263  * ****************************************************************/
4264 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4265 {
4266    uint8_t idx;
4267    uint8_t elementCnt;
4268    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4269
4270    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4271
4272    timeDomAllocList->choice.setup = NULLP;
4273    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4274    if(!timeDomAllocList->choice.setup)
4275    {
4276       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4277       return RFAILED;
4278    }
4279
4280 if(pdschCfg == NULLP)
4281    elementCnt = 2;
4282 else
4283 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4284    timeDomAllocList->choice.setup->list.count = elementCnt;
4285    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4286
4287    timeDomAllocList->choice.setup->list.array = NULLP;
4288    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4289    if(!timeDomAllocList->choice.setup->list.array)
4290    {
4291       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4292       return RFAILED;
4293    }
4294
4295    for(idx = 0; idx < elementCnt; idx++)
4296    {
4297       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4298       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4299             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4300       if(!timeDomAllocList->choice.setup->list.array[idx])
4301       {
4302          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4303          return RFAILED;
4304       }
4305    }
4306
4307    if(pdschCfg == NULLP)
4308    {
4309       idx = 0;
4310       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4311       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4312       if(!timeDomAlloc->k0)
4313       {
4314          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4315          return RFAILED;
4316       }
4317       *(timeDomAlloc->k0) = 0;
4318       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4319       timeDomAlloc->startSymbolAndLength = \
4320                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4321
4322       idx++;
4323       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4324       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4325       if(!timeDomAlloc->k0)
4326       {
4327          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4328          return RFAILED;
4329       }
4330       *(timeDomAlloc->k0) = 1;
4331       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4332       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4333    }
4334    else
4335    {
4336       for(idx = 0; idx < elementCnt; idx++)
4337       {
4338          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4339          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4340          {
4341             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4342             if(!timeDomAlloc->k0)
4343             {
4344                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4345                return RFAILED;
4346             }
4347             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4348          }
4349          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4350          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4351       }
4352    }
4353
4354    return ROK;
4355 }
4356
4357 /*******************************************************************
4358  *
4359  * @brief Builds PDSCH PRB Bundling type
4360  *
4361  * @details
4362  *
4363  *    Function : BuildPdschPrbBundlingType
4364  *
4365  *    Functionality: Builds PDSCH PRB Bundling type
4366  *
4367  * @params[in] 
4368  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4369  *
4370  * @return ROK     - success
4371  *         RFAILED - failure
4372  *
4373  * ****************************************************************/
4374 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4375 {
4376    if(pdschCfg == NULLP)
4377       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4378    else
4379       prbBndlType->present = pdschCfg->bundlingType;
4380
4381    prbBndlType->choice.staticBundling = NULLP;
4382    DU_ALLOC(prbBndlType->choice.staticBundling, \
4383          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4384    if(!prbBndlType->choice.staticBundling)
4385    {
4386       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4387       return RFAILED;
4388    }
4389    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4390
4391    return ROK;
4392 }
4393
4394 /*******************************************************************
4395  *
4396  * @brief Builds BWP DL dedicated PDSCH config 
4397  *
4398  * @details
4399  *
4400  *    Function : BuildBWPDlDedPdschCfg
4401  *
4402  *    Functionality: Builds BWP DL dedicated PDSCH config
4403  *
4404  * @params[in] struct PDSCH_Config *pdschCfg
4405  *
4406  * @return ROK     - success
4407  *         RFAILED - failure
4408  *
4409  * ****************************************************************/
4410 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4411 {
4412    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4413
4414    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4415    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4416    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4417    {
4418       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4419       return RFAILED;
4420    }
4421
4422    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4423    {
4424       return RFAILED;
4425    }
4426
4427    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4428    pdschCfg->tci_StatesToAddModList = NULLP;
4429    pdschCfg->tci_StatesToReleaseList = NULLP;
4430    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4431 #if 0
4432    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4433    if(!pdschCfg->tci_StatesToAddModList)
4434    {
4435       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4436       return RFAILED;
4437    }
4438    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4439    {
4440       return RFAILED;
4441    }
4442 #endif
4443
4444 if(pdschCfgDb == NULLP)
4445    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4446 else
4447 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4448
4449    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4450    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4451    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4452    {
4453       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4454       return RFAILED;
4455    }
4456    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4457    {
4458       return RFAILED;
4459    }
4460
4461    pdschCfg->pdsch_AggregationFactor = NULLP;
4462    pdschCfg->rateMatchPatternToAddModList = NULLP;
4463    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4464    pdschCfg->rateMatchPatternGroup1 = NULLP;
4465    pdschCfg->rateMatchPatternGroup2 = NULLP;
4466    if(pdschCfgDb == NULLP)
4467       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4468    else
4469       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4470    pdschCfg->mcs_Table = NULLP;
4471
4472    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4473    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4474    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4475    {
4476       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4477       return RFAILED;
4478    }
4479    if(pdschCfgDb == NULLP)
4480       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4481    else
4482       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4483
4484    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4485    {
4486       return RFAILED;
4487    }
4488
4489    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4490    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4491    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4492    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4493    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4494    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4495    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4496
4497    return ROK;
4498 }
4499
4500 /*******************************************************************
4501  *
4502  * @brief Builds intitial DL BWP
4503  * @details
4504  *
4505  *    Function : BuildInitialDlBWP 
4506  *
4507  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4508  *
4509  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4510  *
4511  * @return ROK     - success
4512  *         RFAILED - failure
4513  *
4514  * ****************************************************************/
4515 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4516 {
4517    PdcchConfig *pdcchCfg = NULLP;
4518    PdschConfig *pdschCfg = NULLP;
4519
4520    if(initiDlBwp)
4521    {
4522       if(initiDlBwp->pdcchPresent)
4523          pdcchCfg = &initiDlBwp->pdcchCfg;
4524       if(initiDlBwp->pdschPresent)
4525          pdschCfg = &initiDlBwp->pdschCfg;
4526    }
4527
4528    dlBwp->pdcch_Config = NULLP;
4529    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4530    if(!dlBwp->pdcch_Config)
4531    {
4532       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4533       return RFAILED;
4534    }
4535    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4536
4537    dlBwp->pdcch_Config->choice.setup = NULLP;
4538    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4539    if(!dlBwp->pdcch_Config->choice.setup)
4540    {
4541       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4542       return RFAILED;
4543    }
4544    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4545    {
4546       return RFAILED;
4547    }
4548
4549    dlBwp->pdsch_Config = NULLP;
4550    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4551    if(!dlBwp->pdsch_Config)
4552    {
4553       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4554       return RFAILED;
4555    }
4556    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4557
4558    dlBwp->pdsch_Config->choice.setup = NULLP;
4559    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4560    if(!dlBwp->pdsch_Config->choice.setup)
4561    {
4562       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4563       return RFAILED;
4564    }
4565
4566    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4567    {
4568       return RFAILED;
4569    }
4570
4571    dlBwp->sps_Config = NULLP;
4572    dlBwp->radioLinkMonitoringConfig = NULLP; 
4573    return ROK;
4574 }
4575
4576 /*******************************************************************
4577  *
4578  * @brief Builds DMRS UL Pusch Mapping type A
4579  *
4580  * @details
4581  *
4582  *    Function : BuildDMRSULPuschMapTypeA
4583  *
4584  *    Functionality: Builds DMRS UL Pusch Mapping type A
4585  *
4586  * @params[in] 
4587  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4588  * @return ROK     - success
4589  *         RFAILED - failure
4590  *
4591  * ****************************************************************/
4592 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4593 {
4594    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4595    dmrsUlCfg->choice.setup= NULLP;
4596    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4597    if(!dmrsUlCfg->choice.setup)
4598    {
4599       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4600       return RFAILED;
4601    }
4602
4603    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4604    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4605    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4606    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4607    {
4608       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4609       return RFAILED;
4610    }
4611    if(ulDmrsCfgDb == NULLP)
4612       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4613    else
4614       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4615
4616    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4617    dmrsUlCfg->choice.setup->maxLength = NULLP;
4618    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4619    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4620    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4621    {
4622       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4623       return RFAILED;
4624    }
4625
4626    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4627    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4628          sizeof(long));
4629    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4630    {
4631       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4632       return RFAILED;
4633    }
4634    if(ulDmrsCfgDb == NULLP)
4635       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4636    else
4637       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4638
4639    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4640    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4641    return ROK;
4642 }
4643
4644 /*******************************************************************
4645  *
4646  * @brief Build PUSCH time domain allocation list
4647  *
4648  * @details
4649  *
4650  *    Function : BuildPuschTimeDomAllocList
4651  *
4652  *    Functionality: Build PUSCH time domain allocation list
4653  *
4654  * @params[in] 
4655  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4656  *
4657  * @return ROK     - success
4658  *         RFAILED - failure
4659  *
4660  * ****************************************************************/
4661 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4662 {
4663    uint8_t idx;
4664    uint8_t elementCnt;
4665    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4666
4667    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4668    timeDomAllocList->choice.setup = NULLP;
4669    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4670    if(!timeDomAllocList->choice.setup)
4671    {
4672       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4673       return RFAILED;
4674    }
4675
4676    if(puschCfgDb == NULLP)
4677       elementCnt = 2;
4678    else
4679       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4680
4681    timeDomAllocList->choice.setup->list.count = elementCnt;
4682    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4683    timeDomAllocList->choice.setup->list.array = NULLP;
4684    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4685    if(!timeDomAllocList->choice.setup->list.array)
4686    {
4687       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4688       return RFAILED;
4689    }
4690
4691    for(idx = 0; idx < elementCnt; idx++)
4692    {
4693       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4694       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4695       if(!timeDomAllocList->choice.setup->list.array[idx])
4696       {
4697          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4698          return RFAILED;
4699       }
4700    }
4701
4702    for(idx = 0; idx < elementCnt; idx++)
4703    {
4704       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4705       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4706       if(!timeDomAlloc->k2)
4707       {
4708          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4709          return RFAILED;
4710       }
4711       if(puschCfgDb == NULLP)
4712       {
4713          if(idx == 0)
4714             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4715          else if(idx == 1)
4716             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4717
4718          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4719          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4720       }
4721       else
4722       {
4723          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4724          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4725          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4726       }
4727    }
4728
4729    return ROK;
4730 }
4731
4732 /*******************************************************************
4733  *
4734  * @brief Builds BWP UL dedicated PUSCH Config
4735  *
4736  * @details
4737  *
4738  *    Function : BuildBWPUlDedPuschCfg
4739  *
4740  *    Functionality:
4741  *      Builds BWP UL dedicated PUSCH Config
4742  *
4743  * @params[in] : PUSCH_Config_t *puschCfg
4744  *    
4745  * @return ROK     - success
4746  *         RFAILED - failure
4747  *
4748  * ****************************************************************/
4749 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4750 {
4751    DmrsUlCfg *ulDmrsCfg = NULLP;
4752    
4753    if(puschCfgDb)
4754       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4755
4756    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4757    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4758    if(!puschCfg->dataScramblingIdentityPUSCH)
4759    {
4760       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4761       return RFAILED;
4762    }
4763    if(puschCfgDb == NULLP)
4764       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4765    else
4766       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4767
4768    puschCfg->txConfig = NULLP;
4769    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4770    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4771    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4772    {
4773       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4774       return RFAILED;
4775    }
4776
4777    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4778    {
4779       return RFAILED;
4780    }
4781
4782    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4783    puschCfg->pusch_PowerControl = NULLP;
4784    puschCfg->frequencyHopping = NULLP;
4785    puschCfg->frequencyHoppingOffsetLists = NULLP;
4786
4787    if(puschCfgDb == NULLP)
4788       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4789    else
4790       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4791
4792    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4793    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4794    if(!puschCfg->pusch_TimeDomainAllocationList)
4795    {
4796       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4797       return RFAILED;
4798    }
4799
4800    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4801    {
4802       return RFAILED;
4803    }
4804
4805    puschCfg->pusch_AggregationFactor = NULLP;
4806    puschCfg->mcs_Table = NULLP;
4807    puschCfg->mcs_TableTransformPrecoder = NULLP;
4808    puschCfg->transformPrecoder = NULLP;
4809    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4810    if(!puschCfg->transformPrecoder)
4811    {
4812       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4813       return RFAILED;
4814    }
4815    if(puschCfgDb == NULLP)
4816       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4817    else
4818       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4819
4820    puschCfg->codebookSubset = NULLP;
4821    puschCfg->maxRank = NULLP;
4822    puschCfg->rbg_Size = NULLP;
4823    puschCfg->uci_OnPUSCH = NULLP;
4824    puschCfg->tp_pi2BPSK = NULLP;
4825
4826    return ROK;
4827 }
4828
4829 /*******************************************************************
4830  *
4831  * @brief Builds PUCCH resource set add/modify list
4832  *
4833  * @details
4834  *
4835  *    Function : BuildPucchRsrcSetAddModList
4836  *
4837  *    Functionality:
4838  *      Builds PUCCH resource set add/modify list
4839  *
4840  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4841  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4842  *
4843  * @return ROK     - success
4844  *         RFAILED - failure
4845  *
4846  * ****************************************************************/
4847 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4848    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4849 {
4850    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4851    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4852
4853    if(rsrcSetCfgDb == NULLP)
4854       elementCnt = 1;
4855    else
4856       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4857
4858    resourceSetToAddModList->list.count = elementCnt;
4859    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4860    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4861    if(resourceSetToAddModList->list.array == NULLP)
4862    {
4863       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4864       return RFAILED;
4865    }
4866    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4867    {
4868       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4869       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4870       {
4871          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4872          return RFAILED;
4873       }
4874    }
4875
4876    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4877    {
4878       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4879
4880       /* Resource set Id */
4881       if(rsrcSetCfgDb == NULLP)
4882          rsrcSet->pucch_ResourceSetId = 1;
4883       else
4884          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4885  
4886       /* Resource list of a resource set */
4887       if(rsrcSetCfgDb == NULLP)
4888          elementCnt = 1;
4889       else
4890          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4891       rsrcSet->resourceList.list.count = elementCnt;
4892       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4893       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4894       if(rsrcSet->resourceList.list.array == NULLP)
4895       {
4896          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4897          return RFAILED;
4898       }
4899
4900       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4901       {
4902          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4903          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4904          {
4905             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4906             return RFAILED;
4907          }
4908       }
4909       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4910       {
4911          if(rsrcSetCfgDb == NULLP)
4912             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4913          else
4914             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4915       }
4916
4917       /* Max payload size (minus 1) in a Resource set */
4918       rsrcSet->maxPayloadMinus1 = NULLP;
4919       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4920       {
4921          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4922          if(rsrcSet->maxPayloadMinus1 == NULLP)
4923          {
4924             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4925             return RFAILED;
4926          }
4927          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4928       }
4929    }
4930    return ROK;
4931 }
4932
4933 /*******************************************************************
4934  *
4935  * @brief Builds PUCCH resource add/modify list
4936  *
4937  * @details
4938  *
4939  *    Function : BuildPucchRsrcAdddModList
4940  *
4941  *    Functionality:
4942  *      Builds PUCCH resource add/modify list
4943  *
4944  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4945  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4946  *
4947  * @return ROK     - success
4948  *         RFAILED - failure
4949  *
4950  * ****************************************************************/
4951 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4952 {
4953    uint8_t elementCnt = 0, rsrcIdx = 0;
4954    PUCCH_Resource_t *rsrc = NULLP;
4955
4956    if(rsrcCfgDb == NULLP)
4957       elementCnt = 1;
4958    else
4959       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4960    resourceToAddModList->list.count = elementCnt;
4961    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4962    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4963    if(resourceToAddModList->list.array == NULLP)
4964    {
4965       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4966       return RFAILED;
4967    }
4968    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4969    {
4970       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4971       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4972       {
4973          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4974          return RFAILED;
4975       }
4976    }
4977
4978    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4979    {
4980       rsrc = resourceToAddModList->list.array[rsrcIdx];
4981
4982       if(rsrcCfgDb == NULLP)
4983       {
4984          rsrc->pucch_ResourceId = 1;
4985          rsrc->startingPRB = 0;
4986          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4987          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4988          if(rsrc->format.choice.format1 == NULLP)
4989          {
4990             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4991             return RFAILED;
4992          }  
4993          rsrc->format.choice.format1->initialCyclicShift = 0;
4994          rsrc->format.choice.format1->nrofSymbols = 4;
4995          rsrc->format.choice.format1->startingSymbolIndex = 0;
4996          rsrc->format.choice.format1->timeDomainOCC = 0;
4997       }
4998       else
4999       {
5000          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
5001          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5002          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5003          {
5004             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5005             if(rsrc->intraSlotFrequencyHopping == NULLP)
5006             {
5007                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5008                return RFAILED;
5009             }
5010             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5011          }
5012          else
5013             rsrc->intraSlotFrequencyHopping = NULLP;
5014
5015          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5016          {
5017             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5018             if(rsrc->secondHopPRB == NULLP)
5019             {
5020                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5021                return RFAILED;
5022             }
5023             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5024          }
5025          else
5026             rsrc->secondHopPRB = NULLP;
5027          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5028
5029          switch(rsrc->format.present)
5030          {
5031             case PUCCH_Resource__format_PR_NOTHING:
5032                break;
5033             case PUCCH_Resource__format_PR_format0:
5034                {
5035                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5036                   if(rsrc->format.choice.format0 == NULLP)
5037                   {
5038                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5039                      return RFAILED;
5040                   }
5041                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5042                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5043                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5044                   break;
5045                }
5046
5047             case PUCCH_Resource__format_PR_format1:
5048                {
5049                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5050                   if(rsrc->format.choice.format1 == NULLP)
5051                   {
5052                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5053                      return RFAILED;
5054                   }  
5055                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5056                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5057                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5058                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5059                   break;
5060                }
5061
5062             case PUCCH_Resource__format_PR_format2:
5063                {
5064                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5065                   if(rsrc->format.choice.format2 == NULLP)
5066                   {
5067                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5068                      return RFAILED;
5069                   } 
5070                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5071                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5072                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5073                   break;
5074                }
5075
5076             case PUCCH_Resource__format_PR_format3:
5077                {
5078                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5079                   if(rsrc->format.choice.format3 == NULLP)
5080                   {
5081                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5082                      return RFAILED;
5083                   }
5084                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5085                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5086                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5087                   break;
5088                }
5089
5090             case PUCCH_Resource__format_PR_format4:
5091                {
5092                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5093                   if(rsrc->format.choice.format4 == NULLP)
5094                   {
5095                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5096                      return RFAILED;
5097                   }
5098                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5099                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5100                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5101                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5102                   break;
5103                }
5104          }
5105       }
5106    }
5107    return ROK;
5108 }
5109
5110 /*******************************************************************
5111  *
5112  * @brief Builds PUCCH format  config
5113  *
5114  * @details
5115  *
5116  *    Function : BuildPucchFormat
5117  *
5118  *    Functionality: Builds PUCCH format  config
5119  *
5120  * @params[in] : PucchFormatCfg *formatDb
5121  *               PUCCH_FormatConfig_t *format
5122  *
5123  * @return ROK     - success
5124  *         RFAILED - failure
5125  *
5126  * ****************************************************************/
5127 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5128 {
5129    /* Inter Slot Fequency hopping */
5130    format->interslotFrequencyHopping = NULLP;
5131    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5132    {
5133       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5134       if(format->interslotFrequencyHopping)
5135       {
5136          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5137          return RFAILED;
5138       }
5139       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5140    }
5141
5142    /* Additional DMRS */
5143    format->additionalDMRS = NULLP;
5144    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5145    {
5146       DU_ALLOC(format->additionalDMRS, sizeof(long));
5147       if(format->additionalDMRS)
5148       {
5149          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5150          return RFAILED;
5151       }
5152       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5153    }
5154
5155     /* Maximum code rate */
5156    format->maxCodeRate = NULLP;
5157    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5158    {
5159       DU_ALLOC(format->maxCodeRate, sizeof(long));
5160       if(format->maxCodeRate)
5161       {
5162          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5163          return RFAILED;
5164       }  
5165       *(format->maxCodeRate) = formatDb->maxCodeRate;
5166    }
5167  
5168    /* Number of slots */
5169    format->nrofSlots = NULLP;
5170    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5171    {
5172       DU_ALLOC(format->nrofSlots, sizeof(long));
5173       if(format->nrofSlots == NULLP)
5174       {
5175          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5176          return RFAILED;
5177       }
5178       if(formatDb == NULLP)
5179          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5180       else
5181          *(format->nrofSlots) = formatDb->numSlots;
5182    }
5183
5184    /* Pi2BPSK*/
5185    format->pi2BPSK = NULLP;
5186    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5187    {
5188       DU_ALLOC(format->pi2BPSK, sizeof(long));
5189       if(format->pi2BPSK)
5190       {     
5191          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5192          return RFAILED;
5193       }     
5194       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5195    }
5196
5197    /* Simultaneous HARQ ACK and CSI */
5198    format->simultaneousHARQ_ACK_CSI = NULLP;
5199    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5200    {
5201       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5202       if(format->simultaneousHARQ_ACK_CSI)
5203       {     
5204          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5205          return RFAILED;
5206       }     
5207       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5208    }
5209
5210    return ROK;
5211 }
5212
5213
5214 /*******************************************************************
5215  *
5216  * @brief Builds PUCCH scheduling request list
5217  *
5218  * @details
5219  *
5220  *    Function : BuildPucchSchReqAddModList
5221  *
5222  *    Functionality:
5223  *      Builds PUCCH scheduling request list
5224  *
5225  * @params[in] : PucchSchedReqCfg *schReqDb
5226  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5227  *
5228  * @return ROK     - success
5229  *         RFAILED - failure
5230  *
5231  * ****************************************************************/
5232 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5233    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5234 {
5235    uint8_t elementCnt = 0, schReqIdx = 0;
5236    SchedulingRequestResourceConfig_t *schReqRsrc;
5237
5238    elementCnt = schReqDb->schedAddModListCount;
5239    schReqRsrcToAddModList->list.count = elementCnt;
5240    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5241
5242    schReqRsrcToAddModList->list.array = NULLP;
5243    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5244    if(schReqRsrcToAddModList->list.array == NULLP)
5245    {
5246       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5247       return RFAILED;
5248    }
5249
5250    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5251    {
5252       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5253       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5254       {
5255          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5256          return RFAILED;
5257       }
5258    }
5259
5260    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5261    {
5262       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5263       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5264       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5265
5266       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5267       {
5268          schReqRsrc->periodicityAndOffset = NULLP;
5269          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5270          if(schReqRsrc->periodicityAndOffset == NULLP)
5271          {
5272             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5273             return RFAILED;
5274          }
5275
5276          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5277          switch(schReqRsrc->periodicityAndOffset->present)
5278          {
5279             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5280                break;
5281             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5282                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5283                break;
5284             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5285                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5286                break;
5287             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5288                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5289                break;
5290             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5291                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5292                break;
5293             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5294                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5295                break;
5296             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5297                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5298                break;
5299             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5300                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5301                break;
5302             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5303                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5304                break;
5305             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5306                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5307                break;
5308             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5309                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5310                break;
5311             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5312                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5313                break;
5314             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5315                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5316                break;
5317             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5318                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5319                break;
5320             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5321                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5322                break;
5323             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5324                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5325                break;
5326          }
5327       }
5328
5329       if(schReqDb->schedAddModList[schReqIdx].resrc)
5330       {
5331          schReqRsrc->resource = NULLP;
5332          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5333          if(schReqRsrc->resource == NULLP)
5334          {
5335             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5336             return RFAILED;
5337          }
5338          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5339
5340       }
5341    }
5342    return ROK;
5343 }
5344
5345 /*******************************************************************
5346  *
5347  * @brief Builds PUCCH multi csi resource list
5348  *
5349  * @details
5350  *
5351  *    Function : BuildPucchMultiCsiRsrcList
5352  *
5353  *    Functionality:
5354  *      Builds PUCCH multi csi resource list
5355  *
5356  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5357  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5358  *
5359  * @return ROK     - success
5360  *         RFAILED - failure
5361  *
5362  * ****************************************************************/
5363 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5364 {
5365    uint8_t elementCnt = 0, rsrcIdx = 0;
5366
5367    elementCnt = multiCsiDb->multiCsiResrcListCount;
5368    multiCsiRsrcList->list.count = elementCnt;
5369    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5370    multiCsiRsrcList->list.array = NULLP;
5371    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5372    if(multiCsiRsrcList->list.array == NULLP)
5373    {
5374       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5375       return RFAILED;
5376    }
5377
5378    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5379    {
5380       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5381       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5382       {
5383          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5384          return RFAILED;
5385       }
5386    }
5387
5388    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5389    {
5390       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5391    }
5392    return ROK;
5393 }
5394
5395 /*******************************************************************
5396  *
5397  * @brief Builds DL data -to- Ul Ack list
5398  *
5399  * @details
5400  *
5401  *    Function : BuildDlDataToUlAckList
5402  *
5403  *    Functionality: Builds DL data -to- Ul Ack list
5404  *
5405  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5406  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5407  *
5408  * @return ROK     - success
5409  *         RFAILED - failure
5410  *
5411  * ****************************************************************/
5412 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5413 {
5414    uint8_t elementCnt = 0, arrIdx = 0;
5415
5416    if(dlDataToUlAckDb == NULLP)
5417       elementCnt = 2;
5418    else
5419       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5420
5421    dlDataToUlACKList->list.count = elementCnt;
5422    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5423    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5424    if(dlDataToUlACKList->list.array == NULLP)
5425    {
5426       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5427       return RFAILED;
5428    }   
5429
5430    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5431    {
5432       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5433       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5434       {
5435          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5436          return RFAILED;
5437       }   
5438    }
5439
5440    if(dlDataToUlAckDb == NULLP)
5441    {
5442       arrIdx = 0;
5443       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5444       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5445    }
5446    else
5447    {
5448       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5449       {
5450          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5451       }
5452    }
5453    return ROK;
5454 }
5455
5456 /*******************************************************************
5457  *
5458  * @brief Builds BWP UL dedicated PUCCH Config
5459  *
5460  * @details
5461  *
5462  *    Function : BuildBWPUlDedPucchCfg
5463  *
5464  *    Functionality:
5465  *      Builds BWP UL dedicated PUCCH Config
5466  *
5467  * @params[in] : PUCCH_Config_t *pucchCfg
5468  *
5469  * @return ROK     - success
5470  *         RFAILED - failure
5471  *
5472  * ****************************************************************/
5473 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5474 {
5475    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5476    PucchResrcCfg *rsrcCfgDb = NULLP;
5477    PucchFormatCfg *format1Db = NULLP;
5478    PucchFormatCfg *format2Db = NULLP;
5479    PucchFormatCfg *format3Db = NULLP;
5480    PucchFormatCfg *format4Db = NULLP;
5481    PucchSchedReqCfg *schReqDb = NULLP;   
5482    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5483    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5484
5485    if(pucchCfgDb)
5486    {
5487       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5488       rsrcCfgDb = pucchCfgDb->resrc;
5489       format1Db = pucchCfgDb->format1;
5490       format2Db = pucchCfgDb->format2;
5491       format3Db = pucchCfgDb->format3;
5492       format4Db = pucchCfgDb->format4;
5493       schReqDb = pucchCfgDb->schedReq;
5494       multiCsiDb = pucchCfgDb->multiCsiCfg;
5495       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5496    }
5497
5498    /* RESOURCE SET */
5499    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5500    if(pucchCfg->resourceSetToAddModList == NULL)
5501    {
5502       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5503       return RFAILED;
5504    }
5505
5506    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5507    {
5508       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5509       return RFAILED;
5510    }
5511
5512    /* PUCCH RESOURCE */
5513    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5514    if(pucchCfg->resourceToAddModList == NULLP)
5515    {
5516       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5517       return RFAILED;
5518    }
5519
5520    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5521    {
5522       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5523       return RFAILED;
5524    }
5525
5526    /* PUCCH Format 1 */
5527    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5528    if(pucchCfg->format1 == NULLP)
5529    {
5530       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5531       return RFAILED;
5532    }
5533    
5534    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5535    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5536    if(pucchCfg->format1->choice.setup == NULLP)
5537    {
5538       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5539       return RFAILED;
5540    }
5541
5542    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5543    {
5544       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5545       return RFAILED;
5546    }
5547
5548    /* PUCCH Format 2 */
5549    if(format2Db)
5550    {
5551       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5552       if(pucchCfg->format2 == NULLP)
5553       {
5554          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5555          return RFAILED;
5556       }
5557
5558       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5559       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5560       if(pucchCfg->format2->choice.setup == NULLP)
5561       {
5562          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5563          return RFAILED;
5564       }
5565
5566       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5567       {
5568          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5569          return RFAILED;
5570       }
5571    }
5572
5573    /* PUCCH Format 3 */
5574    if(format3Db)
5575    {
5576       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5577       if(pucchCfg->format3 == NULLP)
5578       {
5579          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5580          return RFAILED;
5581       }
5582
5583       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5584       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5585       if(pucchCfg->format3->choice.setup == NULLP)
5586       {
5587          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5588          return RFAILED;
5589       }
5590
5591       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5592       {
5593          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5594          return RFAILED;
5595       }
5596    }
5597
5598    /* PUCCH Format 4 */
5599    if(format4Db)
5600    {
5601       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5602       if(pucchCfg->format4 == NULLP)
5603       {
5604          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5605          return RFAILED;
5606       }
5607
5608       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5609       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5610       if(pucchCfg->format4->choice.setup == NULLP)
5611       {
5612          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5613          return RFAILED;
5614       }
5615
5616       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5617       {
5618          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5619          return RFAILED;
5620       }
5621    }
5622
5623    /* Scheduling Request */
5624    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5625    {
5626       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5627       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5628       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5629       {
5630          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5631          return RFAILED;
5632       }
5633
5634       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5635       {
5636          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5637          return RFAILED;
5638       }
5639    }
5640
5641    /* Multi CSI */
5642    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5643    {
5644       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5645       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5646       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5647       {
5648          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5649          return RFAILED;
5650       }
5651
5652       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5653       {
5654          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5655          return RFAILED;
5656       }
5657    }
5658
5659    /* DL DATA TO UL ACK */
5660    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5661    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5662    {
5663       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5664       return RFAILED;
5665    }
5666
5667    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5668    {
5669       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5670       return RFAILED;
5671    }
5672    
5673    /* TODO : spatial relation info add/mod list and power control*/
5674
5675    return ROK;
5676 }
5677
5678 /*******************************************************************
5679  *
5680  * @brief Fills SRS resource to add/modify list 
5681  *
5682  * @details
5683  *
5684  *    Function : BuildSrsRsrcAddModList
5685  *
5686  *    Functionality: Fills SRS resource to add/modify list
5687  *
5688  * @params[in] 
5689  * @return ROK     - success
5690  *         RFAILED - failure
5691  *
5692  * ****************************************************************/
5693 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5694 {
5695    uint8_t   elementCnt;
5696    uint8_t   rsrcIdx;
5697
5698    elementCnt = 1;
5699    resourceList->list.count = elementCnt;
5700    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5701    resourceList->list.array = NULLP;
5702    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5703    if(!resourceList->list.array)
5704    {
5705       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5706       return RFAILED;
5707    }
5708
5709    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5710    {
5711       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5712       if(!resourceList->list.array[rsrcIdx])
5713       {
5714          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5715          return RFAILED;
5716       }
5717    }
5718
5719    rsrcIdx = 0;
5720    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5721    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5722    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5723
5724    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5725    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5726          sizeof(struct SRS_Resource__transmissionComb__n2));
5727    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5728    {
5729       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5730       return RFAILED;
5731    }
5732    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5733       = SRS_COMB_OFFSET_N2;
5734    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5735       = SRS_CYCLIC_SHIFT_N2;
5736
5737    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5738                                                                       PUSCH_START_SYMBOL;
5739    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5740                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5741    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5742                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5743
5744    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5745    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5746    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5747    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5748    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5749    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5750                                                                SRS_Resource__groupOrSequenceHopping_neither;
5751
5752    /* Setting resource type to aperiodic for intergration purposes */
5753    resourceList->list.array[rsrcIdx]->resourceType.present = \
5754                                                              SRS_Resource__resourceType_PR_aperiodic;
5755    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5756    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5757          sizeof(struct SRS_Resource__resourceType__aperiodic));
5758    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5759    {
5760       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5761       return RFAILED;
5762    }
5763
5764    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5765
5766    return ROK;
5767 }
5768
5769 /*******************************************************************
5770  *
5771  * @brief Build SRS resource set Add/mod list
5772  *
5773  * @details
5774  *
5775  *    Function : BuildSrsRsrcSetAddModList
5776  *
5777  *    Functionality: Build SRS resource set Add/mod list
5778  *
5779  * @params[in] 
5780  * @return ROK     - success
5781  *         RFAILED - failure
5782  *
5783  * ****************************************************************/
5784    uint8_t BuildSrsRsrcSetAddModList
5785 (
5786  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5787  )
5788 {
5789    uint8_t  elementCnt;
5790    uint8_t  rSetIdx;
5791    uint8_t  rsrcIdx;
5792    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5793
5794    elementCnt = 1;
5795    rsrcSetList->list.count = elementCnt;
5796    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5797    rsrcSetList->list.array = NULLP;
5798    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5799    if(!rsrcSetList->list.array)
5800    {
5801       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5802       return RFAILED;
5803    }
5804
5805    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5806    {
5807       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5808       if(!rsrcSetList->list.array[rSetIdx])
5809       {
5810          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5811          return RFAILED;
5812       }
5813    }
5814
5815    rSetIdx = 0;
5816    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5817
5818    /* Fill Resource Id list in resource set */
5819    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5820    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5821          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5822    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5823    {
5824       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5825       return RFAILED;
5826    }
5827
5828    elementCnt = 1;
5829    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5830    rsrcIdList->list.count = elementCnt;
5831    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5832    rsrcIdList->list.array = NULLP;
5833    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5834    if(!rsrcIdList->list.array)
5835    {
5836       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5837       return RFAILED;
5838    }
5839
5840    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5841    {
5842       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5843       if(!rsrcIdList->list.array[rsrcIdx])
5844       {
5845          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5846          return RFAILED;
5847       }
5848    }
5849
5850    rsrcIdx = 0;
5851    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5852
5853    /* Fill resource type */
5854    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5855                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5856
5857    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5858    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5859          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5860    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5861    {
5862       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5863       return RFAILED;
5864    }
5865    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5866       = APERIODIC_SRS_RESRC_TRIGGER;
5867
5868    /* TODO : Fill values for below IEs as expected by Viavi */
5869    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5870    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5871
5872
5873    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5874    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5875    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5876    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5877    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5878
5879    return ROK;
5880 }
5881
5882 /*******************************************************************
5883  *
5884  * @brief Builds BWP UL dedicated SRS Config
5885  *
5886  * @details
5887  *
5888  *    Function : BuildBWPUlDedSrsCfg
5889  *
5890  *    Functionality: Builds BWP UL dedicated SRS Config
5891  *
5892  * @params[in] SRS Config 
5893  * @return ROK     - success
5894  *         RFAILED - failure
5895  *
5896  * ****************************************************************/
5897 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5898 {
5899    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5900    srsCfg->srs_ResourceSetToAddModList = NULLP;
5901    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5902          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5903    if(!srsCfg->srs_ResourceSetToAddModList)
5904    {
5905       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5906       return RFAILED;
5907    }
5908    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5909    {
5910       return RFAILED;
5911    }
5912
5913    srsCfg->srs_ResourceToReleaseList = NULLP;
5914
5915    /* Resource to Add/Modify list */
5916    srsCfg->srs_ResourceToAddModList = NULLP;
5917    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5918          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5919    if(!srsCfg->srs_ResourceToAddModList)
5920    {
5921       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5922       return RFAILED;
5923    }
5924
5925    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5926    {
5927       return RFAILED;
5928    }
5929    srsCfg->tpc_Accumulation = NULLP;
5930
5931    return ROK;
5932 }
5933
5934
5935
5936 /*******************************************************************
5937  *
5938  * @brief Builds Pusch Serving cell Config
5939  *
5940  * @details
5941  *
5942  *    Function : BuildPuschSrvCellCfg
5943  *
5944  *    Functionality: Builds Pusch Serving cell Config
5945  *
5946  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5947  *
5948  * @return ROK     - success
5949  *         RFAILED - failure
5950  *
5951  * ****************************************************************/
5952 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5953 {
5954    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5955    puschCfg->choice.setup = NULLP;
5956    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5957    if(!puschCfg->choice.setup)
5958    {
5959       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5960       return RFAILED;
5961    }
5962
5963    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5964    puschCfg->choice.setup->rateMatching = NULLP;
5965    puschCfg->choice.setup->xOverhead = NULLP;
5966    puschCfg->choice.setup->ext1 = NULLP;
5967
5968    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5969    if(!puschCfg->choice.setup->ext1)
5970    {
5971       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5972       return RFAILED;
5973    }
5974
5975    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5976    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5977    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5978    {
5979       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5980       return RFAILED;
5981    }
5982    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5983
5984    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5985    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5986    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5987    {
5988       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5989       return RFAILED;
5990    }
5991    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5992
5993    return ROK;
5994 }
5995
5996 /*******************************************************************
5997  *
5998  * @brief Builds inital UL BWP
5999  *
6000  * @details
6001  *
6002  *    Function : BuildInitialUlBWP
6003  *
6004  *    Functionality: Builds initial UL BWP
6005  *
6006  * @params[in] BWP_UplinkDedicated_t *ulBwp
6007  * @return ROK     - success
6008  *         RFAILED - failure
6009  *
6010  * ****************************************************************/
6011 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6012 {
6013    PucchCfg *pucchCfg = NULLP;
6014    PuschCfg *puschCfg = NULLP;
6015
6016    if(initUlBwp)
6017    {
6018       if(initUlBwp->pucchPresent)
6019          pucchCfg = &initUlBwp->pucchCfg;
6020       if(initUlBwp->puschPresent)
6021          puschCfg = &initUlBwp->puschCfg;
6022    }
6023
6024    ulBwp->pucch_Config = NULLP;
6025    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6026    if(!ulBwp->pucch_Config)
6027    {
6028       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6029       return RFAILED;
6030    }
6031
6032    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6033    ulBwp->pucch_Config->choice.setup = NULLP;
6034    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6035    if(!ulBwp->pucch_Config->choice.setup)
6036    {
6037       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6038       return RFAILED;
6039    }
6040
6041    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6042    {
6043       return RFAILED;
6044    }
6045
6046    /* Fill BWP UL dedicated PUSCH config */
6047    ulBwp->pusch_Config = NULLP;
6048    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6049    if(!ulBwp->pusch_Config)
6050    {
6051       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6052       return RFAILED;
6053    }
6054
6055    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6056    ulBwp->pusch_Config->choice.setup = NULLP;
6057    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6058    if(!ulBwp->pusch_Config->choice.setup)
6059    {
6060       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6061       return RFAILED;
6062    }
6063
6064    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6065    {
6066       return RFAILED;
6067    }
6068
6069    ulBwp->configuredGrantConfig = NULLP;
6070
6071    /* Fill BPW UL dedicated SRS config */
6072    ulBwp->srs_Config = NULLP;
6073    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6074    if(!ulBwp->srs_Config)
6075    {
6076       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6077       return RFAILED;
6078    }
6079
6080    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6081    ulBwp->srs_Config->choice.setup = NULLP;
6082    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6083    if(!ulBwp->srs_Config->choice.setup)
6084    {
6085       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6086       return RFAILED;
6087    }
6088
6089    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6090    {
6091       return RFAILED;   
6092    }
6093
6094    ulBwp->beamFailureRecoveryConfig = NULLP;
6095
6096    return ROK;
6097 }
6098
6099 /*******************************************************************
6100  *
6101  * @brief Builds UL config
6102  * @details
6103  *
6104  *    Function : BuildUlCfg 
6105  *
6106  *    Functionality: Builds UL config in spCellCfgDed
6107  *
6108  * @params[in] UplinkConfig_t *ulCfg
6109  *
6110  * @return ROK     - success
6111  *         RFAILED - failure
6112  *
6113  * ****************************************************************/
6114 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6115 {
6116    InitialUlBwp *initUlBwp = NULLP;
6117
6118    if(servCellRecfg)
6119    {
6120       initUlBwp = &servCellRecfg->initUlBwp;
6121    }
6122
6123    ulCfg->initialUplinkBWP = NULLP;
6124    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6125    if(!ulCfg->initialUplinkBWP)
6126    {
6127       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6128       return RFAILED;
6129    }
6130
6131    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6132    {
6133       return RFAILED;
6134    }
6135
6136    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6137    ulCfg->uplinkBWP_ToAddModList = NULLP;
6138    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6139    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6140    if(!ulCfg->firstActiveUplinkBWP_Id)
6141    {
6142       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6143       return RFAILED;
6144    }
6145    if(servCellRecfg == NULLP)
6146       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6147    else
6148       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6149
6150    ulCfg->pusch_ServingCellConfig = NULLP;
6151    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6152    if(!ulCfg->pusch_ServingCellConfig)
6153    {
6154       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6155       return RFAILED;
6156    }
6157
6158    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6159    {
6160       return RFAILED;
6161    }
6162
6163    ulCfg->carrierSwitching = NULLP;
6164    ulCfg->ext1 = NULLP;
6165    return ROK;
6166 }
6167
6168 /*******************************************************************
6169  *
6170  * @brief Builds PDSCH serving cell config
6171  * @details
6172  *
6173  *    Function : BuildPdschSrvCellCfg
6174  *
6175  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6176  *
6177  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6178  *
6179  * @return ROK     - success
6180  *         RFAILED - failure
6181  *
6182  * ****************************************************************/
6183 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6184 {
6185    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6186    pdschCfg->choice.setup = NULLP;
6187    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6188    if(!pdschCfg->choice.setup)
6189    {
6190       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6191       return RFAILED;
6192    }
6193
6194    /* Code Block Group Transmission */
6195    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6196    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6197    {
6198       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6199       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6200       {
6201          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6202          return RFAILED;
6203       }
6204
6205       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6206       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6207       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6208       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6209       {
6210          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6211          return RFAILED;
6212       }
6213
6214       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6215          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6216       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6217          *(pdschServCellDb->codeBlkGrpFlushInd);
6218    }
6219
6220    /* xOverhead */
6221    pdschCfg->choice.setup->xOverhead = NULLP;
6222    if(pdschServCellDb && pdschServCellDb->xOverhead)
6223    {
6224       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6225       if(pdschCfg->choice.setup->xOverhead == NULLP)
6226       {
6227          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6228          return RFAILED;
6229       }
6230       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6231    }
6232
6233    /* Number of HARQ processes */
6234    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6235    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6236    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6237    {
6238       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6239       return RFAILED;
6240    }
6241
6242    if(pdschServCellDb == NULLP)
6243    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6244    else
6245    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6246
6247    pdschCfg->choice.setup->pucch_Cell = NULLP;
6248
6249    /* Extension */
6250    pdschCfg->choice.setup->ext1 = NULLP;
6251    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6252    {
6253       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6254       if(pdschCfg->choice.setup->ext1 == NULLP)
6255       {
6256          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6257          return RFAILED;
6258       }
6259
6260       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6261       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6262       {
6263          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6264          return RFAILED;
6265       }
6266       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6267    }
6268
6269    return ROK;
6270 }
6271
6272 /*******************************************************************
6273  *
6274  * @brief Builds CSI Meas config
6275  * @details
6276  *
6277  *    Function : BuildCsiMeasCfg 
6278  *
6279  *    Functionality: Builds CSI Meas config in spCellCfgDed
6280  *
6281  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6282  *
6283  * @return ROK     - success
6284  *         RFAILED - failure
6285  *
6286  * ****************************************************************/
6287 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6288 {
6289
6290    return ROK;
6291 }
6292
6293 /*******************************************************************
6294  *
6295  * @brief Builds DL BWP to add/modify list
6296  * @details
6297  *
6298  *    Function : BuildDlBwpToAddModList
6299  *
6300  *    Functionality: Builds DL BWP to add/modify list
6301  *
6302  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6303  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6304  *
6305  * @return ROK     - success
6306  *         RFAILED - failure
6307  *
6308  * ****************************************************************/ 
6309 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6310 {
6311    uint8_t elementCnt, idx;
6312
6313    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6314    dlBwpAddModList->list.count = elementCnt;
6315    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6316    dlBwpAddModList->list.array = NULLP;
6317    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6318    if(dlBwpAddModList->list.array == NULLP)
6319    {
6320       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6321       return RFAILED;
6322    }
6323
6324    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6325    {
6326       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6327       if(dlBwpAddModList->list.array[idx] == NULLP)
6328       {
6329          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6330          return RFAILED;
6331       }
6332    }
6333
6334    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6335    {
6336       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6337       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6338       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6339    }
6340    return ROK;
6341 }
6342
6343 /*******************************************************************
6344  *
6345  * @brief Builds Spcell config dedicated
6346  * @details
6347  *
6348  *    Function : BuildSpCellCfgDed
6349  *
6350  *    Functionality: Builds sp cell config dedicated in spCellCfg
6351  *
6352  * @params[in] ServingCellConfig_t srvCellCfg
6353  *
6354  * @return ROK     - success
6355  *         RFAILED - failure
6356  *
6357  * ****************************************************************/
6358 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6359 {
6360    ServCellRecfgInfo *servCellRecfg = NULLP;
6361    InitialDlBwp *initDlBwp = NULLP;
6362    PdschServCellCfg *pdschServCellDb = NULLP;
6363
6364    if(ueCb)
6365    {
6366       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6367       initDlBwp = &servCellRecfg->initDlBwp;
6368       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6369    }
6370
6371    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6372
6373    srvCellCfg->initialDownlinkBWP = NULLP;
6374    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6375    if(!srvCellCfg->initialDownlinkBWP)
6376    {
6377       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6378       return RFAILED;
6379    }
6380
6381    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6382    {
6383       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6384       return RFAILED;
6385    }
6386
6387    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6388
6389    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6390    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6391    {
6392       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6393       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6394       {
6395          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6396          return RFAILED;
6397       }
6398
6399       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6400       {
6401          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6402          return RFAILED;
6403       }
6404    }
6405
6406    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6407    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6408    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6409    {
6410       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6411       return RFAILED;
6412    }
6413    if(ueCb == NULLP)
6414       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6415    else
6416       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6417
6418    srvCellCfg->bwp_InactivityTimer = NULLP;
6419
6420    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6421    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6422    if(!srvCellCfg->defaultDownlinkBWP_Id)
6423    {
6424       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6425       return RFAILED;
6426    }
6427    if(ueCb == NULLP)
6428       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6429    else
6430       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6431
6432    srvCellCfg->uplinkConfig = NULLP;
6433    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6434    if(!srvCellCfg->uplinkConfig)
6435    {
6436       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6437       return RFAILED;
6438    }
6439
6440    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6441    {
6442       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6443       return RFAILED;
6444    }
6445    srvCellCfg->supplementaryUplink = NULLP;
6446    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6447
6448    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6449    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6450    if(!srvCellCfg->pdsch_ServingCellConfig)
6451    {
6452       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6453       return RFAILED;
6454    }
6455
6456    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6457    {
6458       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6459       return RFAILED;
6460    }
6461
6462    srvCellCfg->csi_MeasConfig = NULLP;
6463 #if 0
6464    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6465       if(!srvCellCfg->csi_MeasConfig)
6466       {
6467          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6468          return RFAILED;
6469       }
6470
6471    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6472    {
6473       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6474       return RFAILED;
6475    }
6476 #endif
6477    srvCellCfg->sCellDeactivationTimer = NULLP;
6478    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6479    srvCellCfg->tag_Id = TAG_ID;
6480    srvCellCfg->dummy = NULLP;
6481    srvCellCfg->pathlossReferenceLinking = NULLP;
6482    srvCellCfg->servingCellMO = NULLP;
6483    srvCellCfg->ext1 = NULLP;
6484
6485    return ROK;
6486 }
6487
6488 /*******************************************************************
6489  *
6490  * @brief Fills SCS specific carrier list in DL frequency info
6491  *
6492  * @details
6493  *
6494  *    Function : BuildScsSpecificCarrierListDl
6495  *
6496  *    Functionality: Fills SCS specific carrier list in DL frequency info
6497  *
6498  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6499  *
6500  * @return ROK     - success
6501  *         RFAILED - failure
6502  *
6503  * ****************************************************************/
6504 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6505 {
6506    uint8_t elementCnt = 0, listIdx = 0;
6507    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6508
6509    elementCnt = ODU_VALUE_ONE;
6510    scsCarrierList->list.count = elementCnt;
6511    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6512
6513    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6514    if(!scsCarrierList->list.array)
6515    {
6516       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6517          in BuildScsSpecificCarrierListDl()");
6518       return RFAILED;
6519    }
6520
6521    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6522    {
6523       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6524       if(!scsCarrierList->list.array[listIdx])
6525       {    
6526          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6527             element in BuildScsSpecificCarrierListDl()");
6528          return RFAILED;
6529       }    
6530    }
6531
6532    listIdx = 0;
6533    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6534    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6535    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6536
6537    return ROK;
6538 }
6539
6540 /*******************************************************************
6541  *
6542  * @brief Fills DL frequency info in DL config common
6543  *
6544  * @details
6545  *
6546  *    Function : BuildFreqInfoDl
6547  *
6548  *    Functionality: Fills DL frequency info in DL config common
6549  *
6550  * @params[in] Pointer to DownlinkConfigCommon_t
6551  *
6552  * @return ROK     - success
6553  *         RFAILED - failure
6554  *
6555  * ****************************************************************/
6556 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6557 {
6558    uint8_t freqBandIdx = 0, elementCnt = 0;
6559    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6560
6561    /* TODO : Fill SSB Absolute Frequency */
6562    /*
6563       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6564       if(!frequencyInfoDL->absoluteFrequencySSB)
6565       {
6566       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6567       return RFAILED;
6568       }
6569       frequencyInfoDL->absoluteFrequencySSB = ?;
6570       */
6571
6572    /* NR Multi Frequency Band List */
6573    elementCnt = ODU_VALUE_ONE;
6574    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6575    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6576
6577    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6578    if(!frequencyInfoDL->frequencyBandList.list.array)
6579    {
6580       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6581       return RFAILED;
6582    }
6583
6584    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6585    {
6586       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6587       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6588       {
6589          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6590          return RFAILED;
6591       }
6592    }
6593
6594    freqBandIdx = 0;
6595    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6596
6597    /* TODO : Absolute Frequency to Point A */
6598    //frequencyInfoDL->absoluteFrequencyPointA
6599
6600    /* Subcarrier Spacing specifc carrier List */
6601    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6602    {
6603       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6604       return RFAILED;
6605    }
6606
6607    return ROK;
6608
6609 }
6610
6611 /*******************************************************************
6612  *
6613  * @brief Fills DL config common in Serving cell config common
6614  *
6615  * @details
6616  *
6617  *    Function : BuildDlConfigCommon
6618  *
6619  *    Functionality: Fills DL config common in Serving cell config common
6620  *
6621  * @params[in] Pointer to DownlinkConfigCommon_t
6622  *
6623  * @return ROK     - success
6624  *         RFAILED - failure
6625  *
6626  * ****************************************************************/
6627 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6628 {
6629    /* DL Frequency Info */
6630    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6631    if(!dlCfgCommon->frequencyInfoDL)
6632    {
6633       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6634       return RFAILED;
6635    }
6636    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6637    {
6638       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6639       return RFAILED;
6640    }
6641
6642    /* DL BWP config common */
6643    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6644    if(!dlCfgCommon->initialDownlinkBWP)
6645    {
6646       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6647       return RFAILED;
6648    }
6649    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6650    {
6651       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6652       return RFAILED;
6653    }
6654
6655    return ROK;
6656 }
6657
6658 /*******************************************************************
6659  *
6660  * @brief Fills SCS specific carrier list in UL frequency Info
6661  *
6662  * @details
6663  *
6664  *    Function : BuildScsSpecificCarrierListUl
6665  *
6666  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6667  *
6668  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6669  *
6670  * @return ROK     - success
6671  *         RFAILED - failure
6672  *
6673  * ****************************************************************/
6674 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6675 {
6676    uint8_t elementCnt = 0, listIdx = 0; 
6677    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6678
6679    elementCnt = ODU_VALUE_ONE;
6680    scsCarrierList->list.count = elementCnt;
6681    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6682
6683    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6684    if(!scsCarrierList->list.array)
6685    {
6686       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6687       return RFAILED;
6688    }
6689
6690    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6691    {
6692       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6693       if(!scsCarrierList->list.array[listIdx])
6694       {    
6695          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6696          return RFAILED;
6697       }    
6698    }
6699    listIdx = 0; 
6700    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6701    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6702    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6703
6704    return ROK;
6705 }
6706
6707 /*******************************************************************
6708  *
6709  * @brief Fills frequency info in UL config common
6710  *
6711  * @details
6712  *
6713  *    Function : BuildFreqInfoUl
6714  *
6715  *    Functionality: Fills frequency info in UL config common
6716  *
6717  * @params[in] Pointer to FrequencyInfoUL_t
6718  *
6719  * @return ROK     - success
6720  *         RFAILED - failure
6721  *
6722  * ****************************************************************/
6723 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6724 {
6725    uint8_t elementCnt = 0, listIdx= 0;
6726    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6727
6728    /* NR Multi Frequency Band List */
6729    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6730    if(!frequencyInfoUL->frequencyBandList)
6731    {
6732       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6733       return RFAILED;
6734    }
6735
6736    elementCnt = ODU_VALUE_ONE;
6737    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6738    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6739
6740    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6741    if(!frequencyInfoUL->frequencyBandList->list.array)
6742    {
6743       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6744       return RFAILED;
6745    }
6746
6747    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6748    {
6749       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6750       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6751       {
6752          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6753          return RFAILED;
6754       }
6755    }
6756
6757    listIdx = 0;
6758    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6759
6760    /* TODO : Fill Absolute frequency point A */
6761    /*
6762       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6763       if(!frequencyInfoUL->absoluteFrequencyPointA)
6764       {
6765       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6766       return RFAILED;
6767       }
6768     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6769     */
6770
6771    /* Subcarrier Spacing specifc carrier */
6772    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6773    {
6774       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6775       return RFAILED;
6776    }
6777
6778    /* P-MAX */
6779    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6780    if(!frequencyInfoUL->p_Max)
6781    {
6782       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6783       return RFAILED;
6784    }
6785    *frequencyInfoUL->p_Max = ulCfg.pMax;
6786
6787    return ROK;
6788 }
6789
6790 /*******************************************************************
6791  *
6792  * @brief Fills UL config common in Serving cell config common
6793  *
6794  * @details
6795  *
6796  *    Function : BuildUlConfigCommon
6797  *
6798  *    Functionality: Fills UL config common in Serving cell config common
6799  *
6800  * @params[in] Pointer to UplinkConfigCommon_t
6801  *
6802  * @return ROK     - success
6803  *         RFAILED - failure
6804  *
6805  * ****************************************************************/
6806 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6807 {
6808    /* UL Frequency Info */
6809    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6810    if(!ulCfgCommon->frequencyInfoUL)
6811    {
6812       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6813       return RFAILED;
6814    }
6815
6816    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6817    {
6818       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6819       return RFAILED;
6820    }
6821
6822    /* UL BWP common */
6823    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6824    if(!ulCfgCommon->initialUplinkBWP)
6825    {
6826       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6827       return RFAILED;
6828    }
6829
6830    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6831    {
6832       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6833       return RFAILED;
6834    }
6835
6836    /* Time Alignment timer */
6837    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6838
6839    return ROK;
6840 }
6841
6842 /*******************************************************************
6843  *
6844  * @brief Fills SSB position in burst in SP cell config common
6845  *
6846  * @details
6847  *
6848  *    Function : BuildSsbPosInBurst
6849  *
6850  *    Functionality: 
6851  *       Fills SSB position in burst in SP cell config common
6852  *
6853  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6854  *
6855  * @return ROK     - success
6856  *         RFAILED - failure
6857  *
6858  * ****************************************************************/
6859 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6860 {
6861    uint8_t bitStringSizeInBytes = 0;
6862
6863    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6864
6865    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6866    bitStringSizeInBytes = 1;
6867    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6868
6869    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6870    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6871    {
6872       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6873       return RFAILED;
6874    }
6875
6876    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6877                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6878    {
6879       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6880       return RFAILED;
6881    }
6882
6883    return ROK;
6884 }
6885
6886 /*******************************************************************
6887  *
6888  * @brief Fills SP cell config common in Reconfig with Sync
6889  *
6890  * @details
6891  *
6892  *    Function : BuildSpCellConfigCommon
6893  *
6894  *    Functionality: Fills SP cell config common in Reconfig with Sync
6895  *
6896  * @params[in] Pointer to ServingCellConfigCommon_t
6897  *
6898  * @return ROK     - success
6899  *         RFAILED - failure
6900  *
6901  * ****************************************************************/
6902 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6903 {
6904    /* Physical Cell Identity */
6905    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6906    if(!spCellConfigCommon->physCellId)
6907    {
6908       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6909       return RFAILED;
6910    } 
6911    *(spCellConfigCommon->physCellId) = NR_PCI;
6912
6913    /* Downlink Config Common */
6914    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6915    if(!spCellConfigCommon->downlinkConfigCommon)
6916    {
6917       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6918       return RFAILED;
6919    }
6920    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6921    {
6922       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6923       return RFAILED;
6924    }
6925
6926    /* Uplinlink Config Common */
6927    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6928    if(!spCellConfigCommon->uplinkConfigCommon)
6929    {
6930       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6931       return RFAILED;
6932    }
6933    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6934    {
6935       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6936       return RFAILED;
6937    }
6938
6939    /* Timing Advance offset */
6940    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6941    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6942    {
6943       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6944       return RFAILED;
6945    }
6946    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6947
6948    /* SSB Position In Burst */
6949    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6950    if(!spCellConfigCommon->ssb_PositionsInBurst)
6951    {
6952       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6953       return RFAILED;
6954    }
6955    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6956    {
6957       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6958       return RFAILED;
6959    }
6960
6961    /* SSB Periodicity in Serving cell */
6962    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6963    if(!spCellConfigCommon->ssb_periodicityServingCell)
6964    {
6965       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6966          BuildSpCellConfigCommon()");
6967       return RFAILED;
6968    }
6969    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6970       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6971
6972    /* DMRS Type A position */
6973    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6974
6975    /* SSB subcarrier spacing */
6976    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6977    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6978    {
6979       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6980       return RFAILED;
6981    }
6982    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6983
6984    /* TDD UL-DL configuration common */
6985    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6986    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6987    {
6988       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6989       return RFAILED;
6990    }
6991    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6992    {
6993       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6994       return RFAILED;
6995    }
6996
6997    /* SS PBCH Block Power */
6998    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6999
7000    return ROK;
7001 }
7002
7003 /*******************************************************************
7004  *
7005  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7006  *
7007  * @details
7008  *
7009  *    Function : BuildRecfgWithSync
7010  *
7011  *    Functionality: 
7012  *       Fills dedicated RACH configuration in Reconfiguration with sync
7013  *
7014  * @params[in] DU UE CB
7015  *             Pointer to Rach config dedicated struct
7016  *
7017  * @return ROK     - success
7018  *         RFAILED - failure
7019  *
7020  * ****************************************************************/
7021 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7022 {
7023    uint8_t elementCnt = 0, listIdx = 0;
7024    CFRA_t *cfra = NULLP;
7025    struct CFRA__resources__ssb *ssbResource = NULLP;
7026    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7027
7028    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7029
7030    /* Uplink */
7031    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7032    if(!rachCfgDed->choice.uplink)
7033    {
7034       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7035       return RFAILED;
7036    }
7037
7038    /* CFRA : Contention free Random Access */
7039    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7040    if(!rachCfgDed->choice.uplink->cfra)
7041    {
7042       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7043       return RFAILED;
7044    }
7045    cfra = rachCfgDed->choice.uplink->cfra;
7046
7047    /* CFRA occassions */
7048    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7049    if(!cfra->occasions)
7050    {
7051       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7052       return RFAILED;
7053    }
7054
7055    /* CFRA occassions : RACH generic configuration */
7056    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7057    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7058    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7059    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7060    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7061    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7062    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7063    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7064
7065    /* CFRA occassions : SSB per RACH occasion */
7066    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7067    if(!cfra->occasions->ssb_perRACH_Occasion)
7068    {
7069       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7070       return RFAILED;
7071    }
7072    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7073
7074    /* CFRA resource */
7075    cfra->resources.present = CFRA__resources_PR_ssb;
7076
7077    /* CFRA resource : SSB */
7078    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7079    if(!cfra->resources.choice.ssb)
7080    {
7081       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7082       return RFAILED;
7083    }
7084    ssbResource = cfra->resources.choice.ssb;
7085
7086    /* CFRA SSB resource list */
7087    elementCnt = ueCb->cfraResource.numSsb;
7088    ssbResource->ssb_ResourceList.list.count = elementCnt;
7089    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7090
7091    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7092    if(!ssbResource->ssb_ResourceList.list.array)
7093    {
7094       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7095       return RFAILED;
7096    }
7097
7098    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7099    {
7100       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7101       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7102       {
7103          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7104          return RFAILED;
7105       }
7106       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7107       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7108    }
7109
7110    return ROK;
7111 }
7112
7113 /*******************************************************************
7114  *
7115  * @brief Fills reconfiguration with sync in SP cell config
7116  *
7117  * @details
7118  *
7119  *    Function : BuildRecfgWithSync
7120  *
7121  *    Functionality: Fills reconfiguration with sync in SP cell config
7122  *
7123  * @params[in] DU UE CB
7124  *             Pointer to ReconfigurationWithSync_t
7125  *
7126  * @return ROK     - success
7127  *         RFAILED - failure
7128  *
7129  * ****************************************************************/
7130 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7131 {
7132    /* SP Cell Config Common */  
7133    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7134    if(!recfgWithSync->spCellConfigCommon)
7135    {
7136       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7137       return RFAILED;
7138    }
7139
7140    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7141    {
7142       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7143       return RFAILED;
7144    }
7145
7146    /* New UE Identity */
7147    recfgWithSync->newUE_Identity = ueCb->crnti;
7148
7149    /* T304 timer */
7150    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7151
7152    /* RACH configuration dedicated */
7153    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7154    if(!recfgWithSync->rach_ConfigDedicated)
7155    {
7156       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7157       return RFAILED;
7158    }
7159
7160    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7161    {
7162       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7163       return RFAILED;
7164    }
7165
7166    return ROK;
7167 }
7168
7169 /*******************************************************************
7170  *
7171  * @brief Builds Spcell config 
7172  *
7173  * @details
7174  *
7175  *    Function : BuildSpCellCfg 
7176  *
7177  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7178  *
7179  * @params[in] SpCellConfig_t spCellCfg
7180  *
7181  * @return ROK     - success
7182  *         RFAILED - failure
7183  *
7184  * ****************************************************************/
7185 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7186 {
7187    spCellCfg->servCellIndex = NULLP;
7188    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7189    if(!spCellCfg->servCellIndex)
7190    {
7191       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7192       return RFAILED;
7193    }
7194
7195    if(ueCb == NULLP)
7196       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7197    else
7198       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7199
7200    spCellCfg->reconfigurationWithSync = NULLP;
7201    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7202    {
7203       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7204       if(!spCellCfg->reconfigurationWithSync)
7205       {
7206          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7207          return RFAILED;
7208       }
7209
7210       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7211       {
7212          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7213          return RFAILED;
7214       }
7215    }
7216
7217    spCellCfg->rlf_TimersAndConstants = NULLP;
7218    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7219
7220    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7221    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7222    {
7223       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7224       return RFAILED;
7225    }
7226    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7227
7228    spCellCfg->spCellConfigDedicated = NULLP;
7229    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7230    if(!spCellCfg->spCellConfigDedicated)
7231    {
7232       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7233       return RFAILED;
7234    }
7235    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7236    {
7237       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7238       return RFAILED;
7239    }
7240
7241    return ROK;
7242 }
7243
7244 /*******************************************************************
7245  *
7246  * @brief Builds Phy cell group config 
7247  *
7248  * @details
7249  *
7250  *    Function : BuildPhyCellGrpCfg 
7251  *
7252  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7253  *
7254  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7255  *
7256  * @return ROK     - success
7257  *         RFAILED - failure
7258  *
7259  * ****************************************************************/
7260 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7261 {
7262    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7263    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7264
7265    phyCellGrpCfg->p_NR_FR1 = NULLP;
7266    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7267    if(!phyCellGrpCfg->p_NR_FR1)
7268    {
7269       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7270       return RFAILED;
7271    }
7272
7273    if(ueCb == NULLP)
7274    {
7275       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7276       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7277    }
7278    else
7279    {
7280       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7281       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7282    }
7283
7284    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7285    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7286    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7287    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7288    phyCellGrpCfg->cs_RNTI = NULLP;
7289    phyCellGrpCfg->ext1 = NULLP;
7290    phyCellGrpCfg->ext2 = NULLP;
7291
7292    return ROK;
7293 }
7294 #ifdef NR_DRX
7295 /*******************************************************************
7296  *
7297  * @brief fill long cycle offset value of drx
7298  *
7299  * @details
7300  *
7301  *    Function : fillLongCycleOffsetValFromDuCb 
7302  *
7303  *    Functionality: fill long cycle offset value of drx
7304  *
7305  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7306  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7307  *
7308  * @return ROK     - success
7309  *         RFAILED - failure
7310  *
7311  * ****************************************************************/
7312 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7313 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7314 {
7315    
7316    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7317    switch(drx_LongCycleStartOffset->present)
7318    {
7319       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7320          {
7321             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7322             break;
7323          }
7324       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7325          {
7326             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7327             break;
7328          }
7329       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7330          {
7331             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7332             break;
7333          }
7334       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7335          {
7336             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7337             break;
7338          }
7339       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7340          {
7341             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7342             break;
7343          }
7344       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7345          {
7346             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7347             break;
7348          }
7349       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7350          {
7351             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7352             break;
7353          }
7354       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7355          {
7356             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7357             break;
7358          }
7359       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7360          {
7361             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7362             break;
7363          }
7364       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7365          {
7366             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7367             break;
7368          }
7369       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7370          {
7371             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7372             break;
7373          }
7374       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7375          {
7376             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7377             break;
7378          }
7379       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7380          {
7381             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7382             break;
7383          }
7384       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7385          {
7386             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7387             break;
7388          }
7389       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7390          {
7391             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7392             break;
7393          }
7394       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7395          {
7396             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7397             break;
7398          }
7399       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7400          {
7401             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7402             break;
7403          }
7404       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7405          {
7406             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7407             break;
7408          }
7409       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7410          {
7411             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7412             break;
7413          }
7414       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7415          {
7416             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7417             break;
7418          }
7419       default :
7420          break;
7421    }
7422 }
7423 /*******************************************************************
7424  *
7425  * @brief Builds drx config IE 
7426  *
7427  * @details
7428  *
7429  *    Function : BuildDrxConfigRrc 
7430  *
7431  *    Functionality: Build drx config in MacCellGrpCfg 
7432  *
7433  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7434  *
7435  * @return ROK     - success
7436  *         RFAILED - failure
7437  *
7438  * ****************************************************************/
7439 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7440 {
7441    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7442    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7443    if(!drxCfg->choice.setup)
7444    {
7445       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7446       return RFAILED;
7447    }
7448    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7449    {
7450       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7451       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7452       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7453    }
7454    else
7455    {
7456       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7457       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7458       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7459    }
7460    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7461    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7462    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7463    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7464    drxRetransmissionTimerDl);
7465    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7466    drxRetransmissionTimerUl);
7467    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7468    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7469    
7470    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7471    {
7472       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7473       if(drxCfg->choice.setup->shortDRX)
7474       {
7475          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7476          shortDrx.drxShortCycle);
7477          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7478       }
7479       else
7480       {
7481          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7482          return RFAILED;
7483       }
7484    }
7485    return ROK;
7486 }
7487 #endif
7488 /*******************************************************************
7489  *
7490  * @brief Builds Mac cell group config 
7491  *
7492  * @details
7493  *
7494  *    Function : BuildMacCellGrpCfg 
7495  *
7496  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7497  *
7498  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7499  *
7500  * @return ROK     - success
7501  *         RFAILED - failure
7502  *
7503  * ****************************************************************/
7504 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7505 {
7506    macCellGrpCfg->drx_ConfigRrc = NULLP;
7507 #ifdef NR_DRX   
7508    if(ueCb)
7509    {
7510       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7511       if(!macCellGrpCfg->drx_ConfigRrc)
7512       {
7513          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7514          return RFAILED;
7515       }
7516       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7517       {
7518          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7519          return RFAILED;
7520       }
7521    }
7522 #endif
7523    macCellGrpCfg->schedulingRequestConfig = NULLP;
7524    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7525    if(!macCellGrpCfg->schedulingRequestConfig)
7526    {
7527       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7528       return RFAILED;
7529    }
7530
7531    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7532    {
7533       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7534       return RFAILED;
7535    }
7536
7537    macCellGrpCfg->bsr_Config = NULLP;
7538    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7539    if(!macCellGrpCfg->bsr_Config)
7540    {
7541       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7542       return RFAILED;
7543    }
7544
7545    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7546    {
7547       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7548       return RFAILED;
7549    }
7550
7551    macCellGrpCfg->tag_Config = NULLP;
7552    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7553    if(!macCellGrpCfg->tag_Config)
7554    {
7555       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7556       return RFAILED;
7557    }
7558
7559    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7560    {
7561       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7562       return RFAILED;
7563    }
7564
7565    macCellGrpCfg->phr_Config = NULLP;
7566    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7567    if(!macCellGrpCfg->phr_Config)
7568    {
7569       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7570       return RFAILED;
7571    }
7572
7573    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7574    {
7575       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7576       return RFAILED;
7577    }
7578
7579    macCellGrpCfg->skipUplinkTxDynamic = false;
7580    macCellGrpCfg->ext1 = NULLP;
7581
7582    return ROK;
7583 }
7584 /*******************************************************************
7585  *
7586  * @brief Frees memeory allocated for SearchSpcToAddModList
7587  *
7588  * @details
7589  *
7590  *    Function : FreeSearchSpcToAddModList
7591  *
7592  *    Functionality: Deallocating memory of SearchSpcToAddModList
7593  *
7594  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7595  *
7596  * @return void
7597  *
7598  4221 * ****************************************************************/
7599 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7600 {
7601    uint8_t idx1=0;
7602    uint8_t idx2=0;
7603    struct  SearchSpace *searchSpc=NULLP;
7604
7605    if(searchSpcList->list.array)
7606    {
7607       if(searchSpcList->list.array[idx2])
7608       {
7609          searchSpc = searchSpcList->list.array[idx2];
7610          if(searchSpc->controlResourceSetId)
7611          {
7612             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7613             {
7614                if(searchSpc->monitoringSymbolsWithinSlot)
7615                {
7616                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7617                   {
7618                      if(searchSpc->nrofCandidates)
7619                      {
7620                         if(searchSpc->searchSpaceType)
7621                         {
7622                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7623                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7624                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7625                                     SearchSpace__searchSpaceType));
7626                         }
7627                         DU_FREE(searchSpc->nrofCandidates,
7628                               sizeof(struct SearchSpace__nrofCandidates));
7629                      }
7630                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7631                            searchSpc->monitoringSymbolsWithinSlot->size);
7632                   }
7633                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7634                         sizeof(BIT_STRING_t));
7635                }
7636                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7637                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7638             }
7639             DU_FREE(searchSpc->controlResourceSetId,
7640                   sizeof(ControlResourceSetId_t));
7641          }
7642       }
7643       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7644       {
7645          DU_FREE(searchSpcList->list.array[idx1],
7646                sizeof(struct SearchSpace));
7647       }
7648       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7649    }
7650 }
7651 /*******************************************************************
7652  *
7653  * @brief Frees memory allocated for PdschTimeDomAllocList
7654  *
7655  * @details
7656  *
7657  *    Function : FreePdschTimeDomAllocList
7658  *
7659  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7660  *
7661  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7662  *
7663  * @return void
7664  *
7665  * ****************************************************************/
7666 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7667 {
7668    uint8_t idx1=0;
7669
7670    if(timeDomAllocList->choice.setup)
7671    {
7672       if(timeDomAllocList->choice.setup->list.array)
7673       {
7674          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7675          {
7676             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7677             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7678                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7679          }
7680          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7681                timeDomAllocList->choice.setup->list.size);
7682       }
7683       DU_FREE(timeDomAllocList->choice.setup,\
7684             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7685    }
7686 }
7687 /*******************************************************************
7688  *
7689  * @brief Frees memory allocated for PuschTimeDomAllocList
7690  *
7691  *@details
7692  *
7693  *    Function : FreePuschTimeDomAllocList
7694  *
7695  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7696  *
7697  * @params[in] PUSCH_Config_t *puschCfg
7698  *
7699  * @return void
7700  *
7701  * ****************************************************************/
7702 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7703 {
7704    uint8_t rsrcListIdx=0;
7705    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7706
7707    if(puschCfg->pusch_TimeDomainAllocationList)
7708    {
7709       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7710       if(timeDomAllocList_t->choice.setup)
7711       {
7712          if(timeDomAllocList_t->choice.setup->list.array)
7713          {
7714             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7715             {
7716                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7717                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7718                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7719             }
7720             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7721                   timeDomAllocList_t->choice.setup->list.size);
7722          }
7723          DU_FREE(timeDomAllocList_t->choice.setup, \
7724                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7725       }
7726       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7727       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7728             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7729    }
7730
7731 }
7732
7733 /*******************************************************************
7734  *
7735  * @brief Frees memory allocated for Dedicated PUCCH config
7736  *
7737  * @details
7738  *
7739  *    Function : FreeBWPUlDedPucchCfg
7740  *
7741  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7742  *
7743  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7744  *
7745  * @return void
7746  *
7747  * ****************************************************************/
7748 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7749 {
7750    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7751    PUCCH_Config_t *pucchCfg = NULLP;
7752    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7753    PUCCH_Resource_t *rsrc = NULLP;
7754
7755    if(ulBwpPucchCfg)
7756    {
7757       if(ulBwpPucchCfg->choice.setup)
7758       {
7759          pucchCfg = ulBwpPucchCfg->choice.setup;
7760
7761          //Free resource set list
7762          if(pucchCfg->resourceSetToAddModList)
7763          {
7764             if(pucchCfg->resourceSetToAddModList->list.array)
7765             {
7766                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7767                {
7768                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7769                   if(rsrcSet->resourceList.list.array)
7770                   {
7771                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7772                      {
7773                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7774                      }
7775                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7776                   }
7777                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7778                }
7779                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7780             }
7781             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7782          }
7783
7784          //Free resource list
7785          if(pucchCfg->resourceToAddModList)
7786          {
7787             if(pucchCfg->resourceToAddModList->list.array)
7788             {
7789                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7790                {
7791                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7792                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7793                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7794                }
7795                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7796             }
7797             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7798          }
7799
7800          //PUCCH Format 1
7801          if(pucchCfg->format1)
7802          {
7803             if(pucchCfg->format1->choice.setup)
7804             {
7805                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7806                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7807             }
7808             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7809          }
7810          
7811          //DL DATA TO UL ACK
7812          if(pucchCfg->dl_DataToUL_ACK)
7813          {
7814             if(pucchCfg->dl_DataToUL_ACK->list.array)
7815             {
7816                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7817                {
7818                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7819                }
7820                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7821             }
7822             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7823          }
7824
7825          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7826       }
7827       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7828    }
7829 }
7830
7831 /*******************************************************************
7832  *
7833  * @brief Frees memory allocated for InitialUlBWP
7834  *
7835  * @details
7836  *
7837  *    Function : FreeInitialUlBWP
7838  *
7839  *    Functionality: Deallocating memory of InitialUlBWP
7840  *
7841  * @params[in] BWP_UplinkDedicated_t *ulBwp
7842  *
7843  * @return void
7844  *
7845  * ****************************************************************/
7846 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7847 {
7848    uint8_t  rSetIdx, rsrcIdx;
7849    SRS_Config_t   *srsCfg = NULLP;
7850    PUSCH_Config_t *puschCfg = NULLP;
7851    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7852    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7853    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7854    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7855
7856    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7857
7858    if(ulBwp->pusch_Config)
7859    {
7860       if(ulBwp->pusch_Config->choice.setup)
7861       {
7862          puschCfg=ulBwp->pusch_Config->choice.setup;
7863          if(puschCfg->dataScramblingIdentityPUSCH)
7864          {
7865             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7866             {
7867                FreePuschTimeDomAllocList(puschCfg);
7868                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7869                if(dmrsUlCfg->choice.setup)
7870                {
7871                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7872                   {
7873                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7874                      {
7875                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7876                               sizeof(long));
7877                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7878                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7879                      }
7880                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7881                            sizeof(long));
7882                   }
7883                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7884                }
7885                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7886                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7887             }
7888             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7889          }
7890          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7891       }
7892       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7893
7894       /* Free SRS-Config */
7895       if(ulBwp->srs_Config)
7896       {
7897          if(ulBwp->srs_Config->choice.setup)
7898          {
7899             srsCfg = ulBwp->srs_Config->choice.setup;
7900
7901             /* Free Resource Set to add/mod list */
7902             if(srsCfg->srs_ResourceSetToAddModList)
7903             {
7904                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7905                if(rsrcSetList->list.array)
7906                {
7907                   rSetIdx = 0;
7908
7909                   /* Free SRS resource Id list in this SRS resource set */
7910                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7911                   {
7912                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7913
7914                      if(rsrcIdList->list.array)
7915                      {
7916                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7917                         {
7918                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7919                         }
7920                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7921                      }
7922                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7923                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7924                   }
7925
7926                   /* Free resource type info for this SRS resource set */
7927                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7928                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7929
7930                   /* Free memory for each resource set */
7931                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7932                   {
7933                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7934                   }
7935                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7936                }
7937                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7938                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7939             }
7940
7941             /* Free resource to add/modd list */
7942             if(srsCfg->srs_ResourceToAddModList)
7943             {
7944                resourceList = srsCfg->srs_ResourceToAddModList;
7945                if(resourceList->list.array)
7946                {
7947                   rsrcIdx = 0;
7948                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7949                         sizeof(struct SRS_Resource__transmissionComb__n2));
7950                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7951                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7952
7953                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7954                   {
7955                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7956                   }
7957                   DU_FREE(resourceList->list.array, resourceList->list.size);
7958                }
7959                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7960                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7961             }
7962
7963             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7964          }
7965          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7966       }
7967    }
7968 }       
7969 /*******************************************************************
7970  *
7971  * @brief Frees memory allocated for initialUplinkBWP
7972  *
7973  * @details
7974  *
7975  *    Function : FreeinitialUplinkBWP
7976  *
7977  *    Functionality: Deallocating memory of initialUplinkBWP
7978  *
7979  * @params[in] UplinkConfig_t *ulCfg
7980  *
7981  * @return void
7982  *         
7983  *
7984  * ****************************************************************/
7985 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7986 {
7987    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7988    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7989
7990    if(ulCfg->initialUplinkBWP)
7991    {
7992       ulBwp=ulCfg->initialUplinkBWP;
7993       if(ulCfg->firstActiveUplinkBWP_Id)
7994       {
7995          if(ulCfg->pusch_ServingCellConfig)
7996          {
7997             puschCfg=ulCfg->pusch_ServingCellConfig;
7998             if(puschCfg->choice.setup)
7999             {
8000                if(puschCfg->choice.setup->ext1)
8001                {
8002                   DU_FREE(puschCfg->choice.setup->ext1->\
8003                         processingType2Enabled,sizeof(BOOLEAN_t));
8004                   DU_FREE(puschCfg->choice.setup->ext1->\
8005                         maxMIMO_Layers,sizeof(long));
8006                   DU_FREE(puschCfg->choice.setup->ext1, \
8007                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8008                }
8009                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8010             }
8011             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8012          }
8013          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8014       }
8015       FreeInitialUlBWP(ulBwp);
8016       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8017    }
8018 }
8019 /*******************************************************************
8020  *
8021  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8022  *
8023  * @details
8024  *
8025  *    Function : FreeBWPDlDedPdschCfg
8026  *
8027  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8028  *
8029  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8030  *
8031  * @return void
8032  *
8033  *
8034  * ****************************************************************/
8035 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8036 {
8037    struct PDSCH_Config *pdschCfg=NULLP;
8038    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8039    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8040    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8041
8042    if(dlBwp->pdsch_Config->choice.setup)
8043    {
8044       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8045       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8046       {
8047          if(pdschCfg->pdsch_TimeDomainAllocationList)
8048          {
8049             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8050             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8051             {
8052                prbBndlType=&pdschCfg->prb_BundlingType;
8053                DU_FREE(prbBndlType->choice.staticBundling,\
8054                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8055                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8056             }
8057             FreePdschTimeDomAllocList(timeDomAllocList);
8058             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8059                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8060          }
8061          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8062          if(dmrsDlCfg->choice.setup)
8063          {
8064             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8065                   sizeof(long));
8066             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8067          }
8068          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8069                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8070       }
8071       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8072    }
8073 }
8074 /*******************************************************************
8075  *
8076  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8077  *
8078  * @details
8079  *
8080  *    Function : FreeBWPDlDedPdcchCfg
8081  *
8082  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8083  *
8084  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8085  *
8086  * @return void
8087  *         
8088  *
8089  * ****************************************************************/
8090 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8091 {
8092    uint8_t idx1=0;
8093    uint8_t idx2=0;
8094    struct PDCCH_Config *pdcchCfg=NULLP;
8095    struct ControlResourceSet *controlRSet=NULLP;
8096    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8097
8098    if(dlBwp->pdcch_Config->choice.setup)
8099    {
8100       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8101       if(pdcchCfg->controlResourceSetToAddModList)
8102       {
8103          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8104          if(controlRSetList->list.array)
8105          {
8106             controlRSet = controlRSetList->list.array[idx2];
8107             if(controlRSet)
8108             {
8109                if(controlRSet->frequencyDomainResources.buf)
8110                {
8111                   if(controlRSet->pdcch_DMRS_ScramblingID)
8112                   {
8113                      if(pdcchCfg->searchSpacesToAddModList)
8114                      {
8115                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8116                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8117                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8118                      }
8119                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8120                   }
8121                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8122                         controlRSet->frequencyDomainResources.size);
8123                }
8124             }
8125             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8126             {
8127                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8128             }
8129             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8130          }
8131          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8132                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8133       }
8134       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8135    }
8136 }       
8137
8138 /*******************************************************************
8139  *
8140  * @brief Free SCS specific carrier list in DL frequency info
8141  *
8142  * @details
8143  *
8144  *    Function : FreeScsSpecificCarrierListDl
8145  *
8146  *    Functionality: Free SCS specific carrier list in DL frequency info
8147  *
8148  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8149  *
8150  * @return void
8151  *
8152  * ****************************************************************/
8153 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8154 {
8155    uint8_t listIdx = 0;
8156
8157    if(!scsCarrierList->list.array)
8158    {
8159       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8160       {
8161          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8162       }
8163       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8164    }
8165 }
8166
8167 /*******************************************************************
8168  *
8169  * @brief Free DL frequency info in DL config common
8170  *
8171  * @details
8172  *
8173  *    Function : FreeFreqInfoDl
8174  *
8175  *    Functionality: Free DL frequency info in DL config common
8176  *
8177  * @params[in] Pointer to DownlinkConfigCommon_t
8178  *
8179  * @return void
8180  *
8181  * ****************************************************************/
8182 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8183 {
8184    uint8_t freqBandIdx = 0;
8185
8186    /* SSB Absolute Frequency */
8187    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8188
8189    /* NR Multi Frequency Band List */
8190    if(frequencyInfoDL->frequencyBandList.list.array)
8191    {
8192       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8193       {
8194          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8195       }
8196       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8197    }
8198
8199    /* Subcarrier Spacing specifc carrier List */
8200    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8201 }
8202
8203 /*******************************************************************
8204  *
8205  * @brief Free DL config common in Serving cell config common
8206  *
8207  * @details
8208  *
8209  *    Function : FreeDlConfigCommon
8210  *
8211  *    Functionality: Free DL config common in Serving cell config common
8212  *
8213  * @params[in] Pointer to DownlinkConfigCommon_t
8214  *
8215  * @return void
8216  *
8217  * ****************************************************************/
8218 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8219 {
8220    /* DL Frequency Info */
8221    if(dlCfgCommon->frequencyInfoDL)
8222    {
8223       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8224       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8225    }
8226
8227    /* DL BWP config common */
8228    if(dlCfgCommon->initialDownlinkBWP)
8229    {
8230       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8231       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8232    }
8233 }
8234
8235 /*******************************************************************
8236  *
8237  * @brief Free SCS specific carrier list in UL frequency Info
8238  *
8239  * @details
8240  *
8241  *    Function : FreeScsSpecificCarrierListUl
8242  *
8243  *    Functionality: Free SCS specific carrier list in UL frequency Info
8244  *
8245  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8246  *
8247  * @return void
8248  *
8249  * ****************************************************************/
8250 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8251 {
8252    uint8_t listIdx = 0;
8253
8254    if(scsCarrierList->list.array)
8255    {
8256       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8257       {
8258          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8259       }
8260       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8261    }
8262 }
8263
8264 /*******************************************************************
8265  *
8266  * @brief Free frequency info in UL config common
8267  *
8268  * @details
8269  *
8270  *    Function : FreeFreqInfoUl
8271  *
8272  *    Functionality: Free frequency info in UL config common
8273  *
8274  * @params[in] Pointer to FrequencyInfoUL_t
8275  *
8276  * @return void
8277  *
8278  * ****************************************************************/
8279 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8280 {
8281    uint8_t listIdx= 0;
8282
8283    /* NR Multi Frequency Band List */
8284    if(!frequencyInfoUL->frequencyBandList)
8285    {
8286       if(frequencyInfoUL->frequencyBandList->list.array)
8287       {
8288          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8289          {
8290             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8291          }
8292          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8293       }
8294       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8295    }
8296
8297    /* Absolute frequency point A */
8298    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8299
8300    /* Subcarrier Spacing specifc carrier */
8301    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8302
8303    /* P-MAX */
8304    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8305 }
8306
8307 /*******************************************************************
8308  *
8309  * @brief Free UL config common in Serving cell config common
8310  *
8311  * @details
8312  *
8313  *    Function : FreeUlConfigCommon
8314  *
8315  *    Functionality: Free UL config common in Serving cell config common
8316  *
8317  * @params[in] Pointer to UplinkConfigCommon_t
8318  *
8319  * @return void
8320  *
8321  * ****************************************************************/
8322 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8323 {
8324    /* UL Frequency Info */
8325    if(ulCfgCommon->frequencyInfoUL)
8326    {
8327       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8328       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8329    }
8330
8331    /* UL BWP common */
8332    if(ulCfgCommon->initialUplinkBWP)
8333    {
8334       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8335       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8336    }
8337 }
8338
8339 /*******************************************************************
8340  *
8341  * @brief Free SP cell config common in Reconfig with Sync
8342  *
8343  * @details
8344  *
8345  *    Function : FreeSpCellConfigCommon
8346  *
8347  *    Functionality: Free SP cell config common in Reconfig with Sync
8348  *
8349  * @params[in] Pointer to ServingCellConfigCommon_t
8350  *
8351  * @return void
8352  *
8353  * ****************************************************************/
8354 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8355 {
8356    /* Free Physical cell identity */
8357    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8358
8359    /* Free Downlink Config common */
8360    if(spCellConfigCommon->downlinkConfigCommon)
8361    {
8362       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8363       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8364    }
8365
8366    /* Free Uplink Config common */
8367    if(spCellConfigCommon->uplinkConfigCommon)
8368    {
8369       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8370       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8371    }
8372
8373    /* Free Timing Advance offset */
8374    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8375
8376    /* Free SSB Position in Burst */
8377    if(spCellConfigCommon->ssb_PositionsInBurst)
8378    {
8379       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8380          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8381       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8382    }
8383
8384    /* Free SSB Periodicity in Serving cell */
8385    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8386
8387    /* Free SSB subcarrier spacing */
8388    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8389
8390    /* TDD UL-DL configuration common */
8391    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8392 }
8393
8394 /*******************************************************************
8395  *
8396  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8397  *
8398  * @details
8399  *
8400  *    Function : FreeRecfgWithSync
8401  *
8402  *    Functionality:
8403  *       Free dedicated RACH configuration in Reconfiguration with sync
8404  *
8405  * @params[in] Pinter to Rach config dedicated struct
8406  *
8407  * @return void
8408  *
8409  * ****************************************************************/
8410 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8411 {
8412    uint8_t listIdx = 0;
8413    CFRA_t *cfra = NULLP;
8414    struct CFRA__resources__ssb *ssbResource = NULLP;
8415
8416    /* Uplink */
8417    if(rachCfgDed->choice.uplink)
8418    {
8419       /* CFRA : Contention free Random Access */
8420       if(rachCfgDed->choice.uplink->cfra)
8421       {
8422          cfra = rachCfgDed->choice.uplink->cfra;
8423
8424          /* CFRA occassions */
8425          if(cfra->occasions)
8426          {
8427             /* CFRA occassions : SSB per RACH occasion */
8428             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8429             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8430          }
8431
8432          /* CFRA resource */
8433          cfra->resources.present = CFRA__resources_PR_ssb;
8434
8435          /* CFRA resource : SSB */
8436          if(cfra->resources.choice.ssb)
8437          {
8438             ssbResource = cfra->resources.choice.ssb;
8439
8440             /* CFRA SSB resource list */
8441             if(ssbResource->ssb_ResourceList.list.array)
8442             {
8443                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8444                {
8445                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8446                }
8447                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8448             }
8449             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8450          }
8451          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8452       }
8453       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8454    }
8455 }
8456
8457 /*******************************************************************
8458  *
8459  * @brief Frees reconfiguration with sync in SP cell config
8460  *
8461  * @details
8462  *
8463  *    Function : FreeRecfgWithSync
8464  *
8465  *    Functionality: Fress reconfiguration with sync in SP cell config
8466  *
8467  * @params[in] Pointer to ReconfigurationWithSync_t
8468  *
8469  * @return void
8470  *
8471  * ****************************************************************/
8472 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8473 {
8474    /* Free SP Cell config common */
8475    if(recfgWithSync->spCellConfigCommon)
8476    {
8477       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8478       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8479    }
8480
8481    /* Free Dedicated RACH configuration */
8482    if(recfgWithSync->rach_ConfigDedicated)
8483    {
8484       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8485       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8486    }
8487 }
8488
8489 /*******************************************************************
8490  *
8491  * @brief Frees emmory allocated for DUToCURRCContainer 
8492  *
8493  * @details
8494  *
8495  *    Function : FreeMemDuToCuRrcCont
8496  *
8497  *    Functionality: Deallocating memory of DuToCuRrcContainer
8498  *
8499  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8500  *
8501  * @return ROK     - success
8502  *         RFAILED - failure
8503  *
8504  * ****************************************************************/
8505 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8506 {
8507    uint8_t idx=0;
8508    SpCellConfig_t *spCellCfg=NULLP;
8509    ServingCellConfig_t *srvCellCfg=NULLP;
8510    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8511    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8512    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8513    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8514    struct RLC_Config *rlcConfig=NULLP;
8515    struct LogicalChannelConfig *macLcConfig=NULLP;
8516    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8517    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8518    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8519    struct TAG_Config *tagConfig=NULLP;
8520    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8521    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8522    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8523
8524    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8525    if(rlcBearerList)
8526    {
8527       if(rlcBearerList->list.array)
8528       {
8529          for(idx=0; idx<rlcBearerList->list.count; idx++)
8530          {
8531             if(rlcBearerList->list.array[idx])
8532             {  
8533                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8534                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8535                if(rlcConfig)
8536                {
8537                   switch(rlcConfig->present)
8538                   {
8539                      case RLC_Config_PR_NOTHING:
8540                         break;
8541
8542                      case RLC_Config_PR_am:
8543                         {
8544                            if(rlcConfig->choice.am)
8545                            {
8546                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8547                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8548                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8549                            }
8550                            break;
8551                         }
8552                      case RLC_Config_PR_um_Bi_Directional:
8553                         {
8554                            if(rlcConfig->choice.um_Bi_Directional)
8555                            {
8556                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8557                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8558                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8559                            }
8560                            break;
8561                         }
8562                      case RLC_Config_PR_um_Uni_Directional_UL:
8563                         {
8564                            if(rlcConfig->choice.um_Uni_Directional_UL)
8565                            {
8566                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8567                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8568                            }
8569                            break;
8570                         }
8571                      case RLC_Config_PR_um_Uni_Directional_DL:
8572                         {
8573                            if(rlcConfig->choice.um_Uni_Directional_DL )
8574                            {
8575                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8576                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8577                            }
8578                            break;
8579                         }
8580                   }     
8581                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8582                }
8583                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8584                if(macLcConfig)
8585                {
8586                   if(macLcConfig->ul_SpecificParameters)
8587                   {
8588                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8589                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8590                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8591                   }
8592                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8593                }
8594                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8595             }   
8596          }
8597          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8598       }
8599       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8600    }
8601
8602    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8603    if(macCellGrpCfg)
8604    {
8605       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8606
8607       if(drxCfg)
8608       {
8609           switch(drxCfg->present)
8610           {
8611             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8612                break;
8613             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8614             {
8615                if(drxCfg->choice.setup)
8616                {
8617                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8618                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8619                }
8620             }
8621             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8622                break;
8623           }
8624           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8625       }
8626       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8627       if(schedulingRequestConfig)
8628       {
8629          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8630          if(schReqList)
8631          {
8632             if(schReqList->list.array)
8633             {
8634                for(idx=0;idx<schReqList->list.count; idx++)
8635                {
8636                   if(schReqList->list.array[idx])
8637                   {
8638                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8639                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8640                   }
8641                }
8642                DU_FREE(schReqList->list.array, schReqList->list.size);
8643             }
8644             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8645                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8646             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8647       }
8648       if(macCellGrpCfg->bsr_Config)
8649       {
8650          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8651          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8652       }
8653       tagConfig = macCellGrpCfg->tag_Config;
8654       if(tagConfig)
8655       {
8656          tagList = tagConfig->tag_ToAddModList;
8657          if(tagList)
8658          {
8659             if(tagList->list.array)
8660             {
8661                for(idx=0; idx<tagList->list.count; idx++)
8662                {
8663                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8664                }
8665                DU_FREE(tagList->list.array, tagList->list.size);
8666             }
8667             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8668          }
8669          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8670       }
8671
8672       phrConfig = macCellGrpCfg->phr_Config;
8673       if(phrConfig)
8674       {
8675          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8676          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8677       }
8678
8679       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8680    }
8681
8682    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8683    if(phyCellGrpCfg)
8684    {
8685       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8686       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8687    }
8688
8689    spCellCfg = cellGrpCfg->spCellConfig;
8690    if(spCellCfg)
8691    {
8692       /* Free serving cell index */
8693       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8694
8695       /* Free Reconfiguration with sync */
8696       if(spCellCfg->reconfigurationWithSync)
8697       {
8698          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8699          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8700       }
8701
8702       /* Free rlmInSyncOutOfSyncThreshold */
8703       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8704
8705       /* Free SP Cell config dedicated */
8706       if(spCellCfg->spCellConfigDedicated)
8707       {
8708          srvCellCfg = spCellCfg->spCellConfigDedicated;
8709
8710          /* Free TDD UL-DL config dedicated */
8711          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8712
8713          /* Free Initial Downlink BWP */
8714          if(srvCellCfg->initialDownlinkBWP)
8715          {
8716             dlBwp = srvCellCfg->initialDownlinkBWP;
8717
8718             /* Free DL BWP PDCCH Config */
8719             if(dlBwp->pdcch_Config)
8720             {
8721                FreeBWPDlDedPdcchCfg(dlBwp);
8722                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8723             }
8724
8725             /* Free DL BWP PDSCH config */
8726             if(dlBwp->pdsch_Config)
8727             {
8728                FreeBWPDlDedPdschCfg(dlBwp);
8729                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8730             }
8731             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8732          }
8733
8734          /* Free First Active Downlink BWP */
8735          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8736
8737          /* Free Default downlink BWP */
8738          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8739
8740          /* Free Uplink config */
8741          if(srvCellCfg->uplinkConfig)
8742          {
8743             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8744             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8745          }
8746
8747          /* Free PDSCH serving cell config */
8748          if(srvCellCfg->pdsch_ServingCellConfig)
8749          {
8750             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8751             if(pdschCfg->choice.setup)
8752             {
8753                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8754                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8755             }
8756             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8757          }
8758
8759          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8760       }
8761       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8762    }
8763    return ROK;
8764 }
8765
8766 /*******************************************************************
8767  *
8768  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8769  *
8770  * @details
8771  *
8772  *    Function : BuildCellGroupConfigRrc
8773  *
8774  *    Functionality: Builds and copied Cell group config buffer into 
8775  *       DuToCuRrcContainer
8776  *
8777  * @params[in] idx, index in F1AP msg
8778  *             DuToCuRRCContainer, DuToCuRRCContainer
8779  *
8780  * @return ROK     - success
8781  *         RFAILED - failure
8782  *
8783  * ****************************************************************/
8784 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8785 {
8786    uint8_t  ret = ROK;
8787    CellGroupConfigRrc_t  cellGrpCfg;
8788    asn_enc_rval_t        encRetVal;
8789    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8790    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8791
8792    while(true)
8793    {
8794       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8795
8796       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8797       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8798       if(!cellGrpCfg.rlc_BearerToAddModList)
8799       {
8800          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8801          ret = RFAILED;
8802          break;
8803       }
8804       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8805       {
8806          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8807          ret = RFAILED;
8808          break;
8809       }
8810
8811       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8812       cellGrpCfg.mac_CellGroupConfig = NULLP;
8813       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8814       if(!cellGrpCfg.mac_CellGroupConfig)
8815       {
8816          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8817          ret = RFAILED;
8818          break;
8819       }
8820       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8821       {
8822          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8823          ret = RFAILED;
8824          break;
8825       }
8826
8827       cellGrpCfg.physicalCellGroupConfig = NULLP;
8828       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8829       if(!cellGrpCfg.physicalCellGroupConfig)
8830       {
8831          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8832          ret = RFAILED;
8833          break;
8834       }
8835       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8836       {
8837          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8838          ret = RFAILED;
8839          break;
8840       }
8841
8842       cellGrpCfg.spCellConfig = NULLP;
8843       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8844       if(!cellGrpCfg.spCellConfig)
8845       {
8846          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8847          ret = RFAILED;
8848          break;
8849       }
8850       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8851       {
8852          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8853          ret = RFAILED;
8854          break;
8855       }
8856
8857       cellGrpCfg.sCellToAddModList = NULLP;
8858       cellGrpCfg.sCellToReleaseList = NULLP;
8859       cellGrpCfg.ext1 = NULLP;
8860
8861       /* encode cellGrpCfg into duToCuRrcContainer */
8862       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8863       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8864       encBufSize = 0;
8865       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8866       /* Encode results */
8867       if(encRetVal.encoded == ENCODE_FAIL)
8868       {
8869          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8870                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8871          ret = RFAILED;
8872          break;
8873       }
8874       else
8875       {
8876          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8877 #ifdef DEBUG_ASN_PRINT
8878          for(int i=0; i< encBufSize; i++)
8879          {
8880             printf("%x",encBuf[i]);
8881          }
8882 #endif
8883       }
8884
8885       duToCuRrcContainer->size = encBufSize;
8886       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8887       if(!duToCuRrcContainer->buf)
8888       {
8889          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8890          ret = RFAILED;
8891          break;
8892       }
8893       if(ret == ROK)
8894       {
8895          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8896       }
8897       break;
8898    }
8899    FreeMemDuToCuRrcCont(&cellGrpCfg);
8900    return ret;
8901 }
8902
8903 /*******************************************************************
8904  *
8905  * @brief Free memory allocated in InitialULRRCMessage
8906  *
8907  * @details
8908  *
8909  *    Function : freeInitUlRrcMsgTransfer
8910  *
8911  *    Functionality: Free memory allocated in InitialULRRCMessage
8912  *
8913  * @params[in]F1AP_PDU_t  *f1apMsg)
8914  *
8915  * @return ROK     - success
8916  *         RFAILED - failure
8917  *
8918  * ****************************************************************/
8919
8920 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8921 {
8922    uint8_t ieIdx, arrIdx;
8923    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8924
8925    if(f1apMsg)
8926    {
8927       if(f1apMsg->choice.initiatingMessage)
8928       {
8929          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8930             choice.InitialULRRCMessageTransfer;
8931          if(initULRRCMsg->protocolIEs.list.array)
8932          {
8933             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8934             {
8935                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8936                {
8937                   case ProtocolIE_ID_id_NRCGI:
8938                   {
8939                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8940                      {
8941                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8942                         {
8943                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8944                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8945                         }
8946                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8947                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8948                      }
8949                      break;
8950                   }
8951                   case ProtocolIE_ID_id_RRCContainer:
8952                   {
8953                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8954                      {
8955                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8956                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8957                      }
8958                      break;
8959                   }
8960                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8961                   {
8962                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8963                      {
8964                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8965                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8966                      }
8967                      break;
8968                   }
8969                   default:
8970                      break;
8971                }
8972              }
8973              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8974              {
8975                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8976                 {
8977                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8978                       sizeof(InitialULRRCMessageTransferIEs_t));
8979                 }
8980              }
8981              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8982           }
8983          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8984       }
8985       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8986    }
8987    else
8988    {
8989       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8990       return RFAILED;
8991    }
8992    return ROK;
8993 }
8994
8995 /*******************************************************************
8996  *
8997  * @brief Builds and sends the InitialULRRCMessage 
8998  *
8999  * @details
9000  *
9001  *    Function : BuildAndSendInitialRrcMsgTransfer 
9002  *
9003  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9004  *                   it to the CU through SCTP.
9005  *
9006  * @params[in] 
9007  *
9008  * @return ROK     - success
9009  *         RFAILED - failure
9010  *
9011  * ****************************************************************/
9012 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9013       uint16_t rrcContSize, uint8_t *rrcContainer)
9014 {
9015    uint8_t   ret;
9016    uint8_t   elementCnt;
9017    uint8_t   ieIdx, cellIdx, ueIdx;
9018    DuUeCb    *duUeCb = NULLP;
9019    asn_enc_rval_t  encRetVal;
9020    F1AP_PDU_t  *f1apMsg = NULLP;
9021    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9022    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9023
9024    while(true)
9025    {
9026       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9027       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9028       if(f1apMsg == NULLP)
9029       {
9030          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9031          break;
9032       }
9033       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9034       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9035       if(f1apMsg->choice.initiatingMessage == NULLP)
9036       {
9037          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9038          break;
9039       }
9040       f1apMsg->choice.initiatingMessage->procedureCode =\
9041                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9042       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9043       f1apMsg->choice.initiatingMessage->value.present = \
9044                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9045       initULRRCMsg =\
9046                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9047       elementCnt = 5;
9048       initULRRCMsg->protocolIEs.list.count = elementCnt;
9049       initULRRCMsg->protocolIEs.list.size = \
9050                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9051       /* Initialize the F1Setup members */
9052       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9053       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9054       {
9055          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9056                RRCSetupRequestMessageTransferIEs failed");
9057          break;
9058       }
9059       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9060       {
9061          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9062                sizeof(InitialULRRCMessageTransferIEs_t));
9063          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9064          {
9065             break;
9066          }
9067       }
9068       ieIdx = 0;
9069       /*GNB DU UE F1AP ID*/
9070       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9071                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9072       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9073       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9074                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9075       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9076
9077
9078       /*NRCGI*/
9079       ieIdx++;
9080       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9081                                                         ProtocolIE_ID_id_NRCGI;
9082       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9083       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9084                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9085
9086       ret =\
9087            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9088       if(ret!=ROK)
9089       {
9090          break;
9091       }
9092
9093       /*CRNTI*/
9094       ieIdx++;
9095       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9096                                                         ProtocolIE_ID_id_C_RNTI;
9097       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9098       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9099                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9100       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9101
9102       /*RRCContainer*/
9103       ieIdx++;
9104       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9105                                                         ProtocolIE_ID_id_RRCContainer;
9106       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9107       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9108                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9109
9110       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9111       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9112             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9113       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9114       {
9115          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9116          break;
9117       
9118       }
9119       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9120             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9121
9122
9123       /*DUtoCURRCContainer*/
9124       ieIdx++;
9125       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9126       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9127       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9128                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9129
9130       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9131       {
9132          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9133          {
9134             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9135                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9136             {
9137                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9138             }
9139          }
9140       }
9141
9142       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9143       if(ret != ROK)
9144       {
9145          break;
9146       }
9147
9148       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9149
9150       /* Encode the Intial UL RRC Message transfer as APER */
9151       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9152       encBufSize = 0;
9153       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9154       /* Encode results */
9155       if(encRetVal.encoded == ENCODE_FAIL)
9156       {
9157          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9158                structure (at %s)\n",encRetVal.failed_type ? \
9159                encRetVal.failed_type->name : "unknown");
9160          ret = RFAILED;
9161          break;
9162       }
9163       else
9164       {
9165
9166          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9167                Message transfer\n");
9168 #ifdef DEBUG_ASN_PRINT
9169          for(int i=0; i< encBufSize; i++)
9170          {
9171             printf("%x",encBuf[i]);
9172          }
9173 #endif
9174       }
9175       /* Sending  msg  */
9176       if(sendF1APMsg() != ROK)
9177       {
9178          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9179          ret = RFAILED;
9180          break;
9181       }
9182       break;
9183    }
9184    freeInitUlRrcMsgTransfer(f1apMsg);
9185    return ret;
9186 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9187
9188 /*****  UE SETUP REQUEST *****/
9189
9190 /******************************************************************
9191 *
9192 * @brief Function to delete the RLC Lc cfg from UE APP DB
9193 *
9194 * @details
9195 *
9196 *  Function : freeRlcLcCfg
9197 *
9198 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9199 *
9200 *
9201  *****************************************************************/
9202
9203 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9204 {
9205    switch(lcCfg->rlcMode)
9206    {
9207       case RLC_AM :
9208          {
9209             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9210             break;
9211          }
9212       case RLC_UM_BI_DIRECTIONAL :
9213          {
9214             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9215             break;
9216          }
9217       case RLC_UM_UNI_DIRECTIONAL_UL :
9218          {
9219             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9220             break;
9221          }
9222       case RLC_UM_UNI_DIRECTIONAL_DL :
9223          {
9224             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9225             break;
9226          }
9227       default:
9228          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9229          break;
9230    }
9231    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9232 }
9233
9234 /*******************************************************************
9235  *
9236  * @brief Function to free MacLcCfg
9237  *
9238  * @details
9239  *
9240  *    Function : freeMacLcCfg
9241  *
9242  *    Functionality: Function to free MacLcCfg
9243  *
9244  * @params[in] LcCfg *lcCfg,
9245  * @return void
9246  *
9247  * ****************************************************************/
9248
9249 void freeMacLcCfg(LcCfg *lcCfg)
9250 {
9251     /* Deleting DRBQOS */
9252    if(lcCfg->drbQos)
9253    {
9254       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9255    }
9256    /* Deleting SNSSAI */
9257    if(lcCfg->snssai)
9258    {
9259       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9260    }
9261 }
9262 /*******************************************************************
9263  *
9264  * @brief Free UE NR Capability received in UE Context setup request
9265  *
9266  * @details
9267  *
9268  *    Function : freeAperDecodeUeNrCapability
9269  *
9270  *    Functionality:  
9271  *       Free UE NR Capability received in UE Context setup request
9272  *
9273  * @params[in] 
9274  * @return ROK     - success
9275  *         RFAILED - failure
9276  *
9277  * ****************************************************************/
9278 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9279 {
9280    uint8_t arrIdx =0;
9281    FeatureSets_t *featureSets =NULLP;
9282    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9283
9284    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9285    {
9286       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9287       {
9288          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9289             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9290       }
9291       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9292    }
9293
9294    if(ueNrCap->featureSets)
9295    {
9296       featureSets = ueNrCap->featureSets;
9297       if(featureSets->featureSetsDownlinkPerCC)
9298       {
9299          if(featureSets->featureSetsDownlinkPerCC->list.array)
9300          {
9301             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9302             {
9303                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9304                {
9305                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9306                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9307                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9308                }
9309             }
9310             free(featureSets->featureSetsDownlinkPerCC->list.array);
9311          }
9312          free(featureSets->featureSetsDownlinkPerCC);
9313       }
9314       if(featureSets->featureSetsUplinkPerCC)
9315       {
9316          if(featureSets->featureSetsUplinkPerCC->list.array)
9317          {
9318             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9319             {
9320                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9321                {
9322                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9323                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9324                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9325                }
9326             }
9327             free(featureSets->featureSetsUplinkPerCC->list.array);
9328          }
9329          free(featureSets->featureSetsUplinkPerCC);
9330       }
9331       free(ueNrCap->featureSets);
9332    }   
9333 }
9334
9335 /*******************************************************************
9336 *
9337 * @brief Function to free PdcchSearchSpcToAddModList
9338          where memory allocated by aper_decoder
9339 *
9340 * @details
9341 *
9342 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9343 *
9344 *    Functionality: Function to free PdcchSearchSpcToAddModList
9345 *
9346 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9347 * @return void
9348 *
9349 * ****************************************************************/
9350
9351 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9352 {
9353    uint8_t searchSpcArrIdx=0;
9354    uint8_t searchSpcArrIdx1=0;
9355    struct  SearchSpace *searchSpc=NULLP;
9356
9357
9358    if(searchSpcList->list.array)
9359    {
9360       if(searchSpcList->list.array[searchSpcArrIdx1])
9361       {
9362          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9363          if(searchSpc->controlResourceSetId)
9364          {
9365             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9366             {
9367                if(searchSpc->monitoringSymbolsWithinSlot)
9368                {
9369                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9370                   {
9371                      if(searchSpc->nrofCandidates)
9372                      {
9373                         if(searchSpc->searchSpaceType)
9374                         {
9375                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9376                            free(searchSpc->searchSpaceType);
9377                         }
9378                         free(searchSpc->nrofCandidates);
9379                      }
9380                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9381                   }
9382                   free(searchSpc->monitoringSymbolsWithinSlot);
9383                }
9384                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9385             }
9386             free(searchSpc->controlResourceSetId);
9387          }
9388       }
9389       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9390       {
9391          free(searchSpcList->list.array[searchSpcArrIdx]);
9392       }
9393       free(searchSpcList->list.array);
9394    }
9395 }
9396 /*******************************************************************
9397 *
9398 * @brief Function for free part for the memory allocated by aper_decoder
9399
9400 * @details
9401 *
9402 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9403 *
9404 *    Functionality: Function to free BWPDlDedPdcchConfig
9405 *
9406 * @params[in] 
9407 * @return void
9408 *
9409 * ****************************************************************/
9410
9411
9412 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9413 {
9414    uint8_t arrIdx1=0;
9415    uint8_t arrIdx2=0;
9416    struct PDCCH_Config *pdcchCfg=NULLP;
9417    struct ControlResourceSet *controlRSet=NULLP;
9418    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9419    
9420    if(dlBwp->pdcch_Config->choice.setup)
9421    {
9422       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9423       if(pdcchCfg->controlResourceSetToAddModList)
9424       {
9425          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9426          if(controlRSetList->list.array)
9427          {
9428             controlRSet = controlRSetList->list.array[arrIdx2];
9429             if(controlRSet)
9430             {
9431                if(controlRSet->frequencyDomainResources.buf)
9432                {
9433                   if(controlRSet->pdcch_DMRS_ScramblingID)
9434                   {
9435                      if(pdcchCfg->searchSpacesToAddModList)
9436                      {
9437                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9438                         free(pdcchCfg->searchSpacesToAddModList);
9439                      }
9440                      free(controlRSet->pdcch_DMRS_ScramblingID);
9441                   }
9442                   free(controlRSet->frequencyDomainResources.buf);
9443                }
9444             }
9445             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9446             {
9447                free(controlRSetList->list.array[arrIdx1]);
9448             }
9449             free(controlRSetList->list.array);
9450          }
9451          free(pdcchCfg->controlResourceSetToAddModList);
9452       }
9453       free(dlBwp->pdcch_Config->choice.setup);
9454    }
9455 }
9456 /*******************************************************************
9457 *
9458 * @brief Function to free PdschTimeDomAllocationList 
9459 *     where the memory allocated by aper_decoder
9460
9461 * @details
9462 *
9463 *    Function : freeAperDecodePdschTimeDomAllocationList
9464 *
9465 *    Functionality: Function to free PdschTimeDomAllocationList
9466 *
9467 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9468 * @return void
9469 *
9470 * ****************************************************************/
9471
9472
9473 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9474 {
9475    uint8_t arrIdx=0;
9476
9477    if(timeDomAllocList->choice.setup)
9478    {
9479       if(timeDomAllocList->choice.setup->list.array)
9480       {
9481          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9482          {
9483             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9484          }
9485          free(timeDomAllocList->choice.setup->list.array);
9486       }
9487       free(timeDomAllocList->choice.setup);
9488    }
9489 }
9490
9491 /*******************************************************************
9492 *
9493 * @brief Function to free BWPDlDedPdschConfig 
9494 *        where the memory allocated by aper_decoder
9495 *  
9496 * @details
9497 *
9498 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9499 *
9500 *    Functionality: Function to free BWPDlDedPdschConfig 
9501 *
9502 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9503 * @return void
9504 *
9505 * ****************************************************************/
9506
9507
9508 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9509 {
9510    struct PDSCH_Config *pdschCfg=NULLP;
9511    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9512    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9513    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9514
9515    if(dlBwp->pdsch_Config->choice.setup)
9516    {
9517       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9518       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9519       {
9520          if(pdschCfg->pdsch_TimeDomainAllocationList)
9521          {
9522             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9523             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9524             {
9525                prbBndlType=&pdschCfg->prb_BundlingType;
9526                free(prbBndlType->choice.staticBundling);
9527                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9528             }
9529             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9530             free(pdschCfg->pdsch_TimeDomainAllocationList);
9531          }
9532          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9533          if(dmrsDlCfg->choice.setup)
9534          {
9535             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9536             free(dmrsDlCfg->choice.setup);
9537          }
9538          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9539       }
9540       free(dlBwp->pdsch_Config->choice.setup);
9541    }
9542 }
9543 /*******************************************************************
9544 *
9545 * @brief Function to free PuschTimeDomAllocListCfg
9546                  where the memory allocated by aper_decoder
9547 *
9548 * @details
9549 *
9550 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9551 *
9552 *    Functionality: Function to free PuschTimeDomAllocListCfg
9553 *
9554 * @params[in] PUSCH_Config_t *puschCfg 
9555 * @return void
9556 *
9557 * ****************************************************************/
9558
9559
9560 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9561 {
9562    uint8_t arrIdx=0;
9563    uint8_t arrIdx1=0;
9564    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9565
9566    if(puschCfg->pusch_TimeDomainAllocationList)
9567    {
9568       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9569       if(timeDomAllocList_t->choice.setup)
9570       {
9571          if(timeDomAllocList_t->choice.setup->list.array)
9572          {
9573             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9574             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9575             {
9576                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9577             }
9578             free(timeDomAllocList_t->choice.setup->list.array);
9579          }
9580          free(timeDomAllocList_t->choice.setup);
9581       }
9582       free(puschCfg->transformPrecoder);
9583       free(puschCfg->pusch_TimeDomainAllocationList);
9584    }
9585 }
9586 /*******************************************************************
9587 *
9588 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9589 *
9590 * @details
9591 *
9592 *    Function : freeAperDecodeInitialUlBWPConfig 
9593 *
9594 *    Functionality: Function to free InitialUlBWPConfig
9595 *
9596 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9597 * @return void
9598 *
9599 * ****************************************************************/
9600
9601
9602 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9603 {
9604    uint8_t  rSetIdx =0;
9605    uint8_t  rsrcIdx =0;
9606    SRS_Config_t   *srsCfg = NULLP;
9607    PUSCH_Config_t *puschCfg = NULLP;
9608    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9609    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9610    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9611    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9612
9613    if(ulBwp->pusch_Config)
9614    {
9615       if(ulBwp->pusch_Config->choice.setup)
9616       {
9617          puschCfg=ulBwp->pusch_Config->choice.setup;
9618          if(puschCfg->dataScramblingIdentityPUSCH)
9619          {
9620             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9621             {
9622                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9623                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9624                if(dmrsUlCfg->choice.setup)
9625                {
9626                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9627                   {
9628                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9629                      {
9630                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9631                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9632                      }
9633                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9634                   }
9635                   free(dmrsUlCfg->choice.setup);
9636                }
9637                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9638             }
9639             free(puschCfg->dataScramblingIdentityPUSCH);
9640          }
9641          free(ulBwp->pusch_Config->choice.setup);
9642       }
9643       free(ulBwp->pusch_Config);
9644
9645       /* Free SRS-Config */
9646       if(ulBwp->srs_Config)
9647       {
9648          if(ulBwp->srs_Config->choice.setup)
9649          {
9650             srsCfg = ulBwp->srs_Config->choice.setup;
9651
9652             /* Free Resource Set to add/mod list */
9653             if(srsCfg->srs_ResourceSetToAddModList)
9654             {
9655                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9656                if(rsrcSetList->list.array)
9657                {
9658                   rSetIdx = 0;
9659
9660                   /* Free SRS resource Id list in this SRS resource set */
9661                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9662                   {
9663                      rsrcIdList =
9664                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9665
9666                      if(rsrcIdList->list.array)
9667                      {
9668                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9669                               rsrcIdx++)
9670                         {
9671                            free(rsrcIdList->list.array[rsrcIdx]);
9672                         }
9673                         free(rsrcIdList->list.array);
9674                      }
9675                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9676                   }
9677
9678                   /* Free resource type info for this SRS resource set */
9679
9680                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9681
9682                   /* Free memory for each resource set */
9683                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9684                   {
9685                      free(rsrcSetList->list.array[rSetIdx]);
9686                   }
9687                   free(rsrcSetList->list.array);
9688                }
9689                free(srsCfg->srs_ResourceSetToAddModList);
9690             }
9691
9692             /* Free resource to add/modd list */
9693             if(srsCfg->srs_ResourceToAddModList)
9694             {
9695                resourceList = srsCfg->srs_ResourceToAddModList;
9696                if(resourceList->list.array)
9697                {
9698                   rsrcIdx = 0;
9699
9700                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9701                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9702
9703                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9704                   {
9705                      free(resourceList->list.array[rsrcIdx]);
9706                   }
9707                   free(resourceList->list.array);
9708                }
9709                free(srsCfg->srs_ResourceToAddModList);
9710             }
9711
9712             free(ulBwp->srs_Config->choice.setup);
9713          }
9714          free(ulBwp->srs_Config);
9715       }
9716    }
9717 }
9718 /*******************************************************************
9719 *
9720 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9721 *
9722 * @details
9723 *
9724 *    Function : freeAperDecodeinitialUplinkBWPConfig
9725 *
9726 *    Functionality: Function to free initialUplinkBWPConfig
9727 *
9728 * @params[in] UplinkConfig_t *ulCfg 
9729 * @return void
9730 *
9731 * ****************************************************************/
9732
9733
9734 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9735 {
9736    BWP_UplinkDedicated_t *ulBwp=NULLP;
9737    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9738    
9739    if(ulCfg->initialUplinkBWP)
9740    {
9741       ulBwp=ulCfg->initialUplinkBWP;
9742       if(ulCfg->firstActiveUplinkBWP_Id)
9743       {
9744          if(ulCfg->pusch_ServingCellConfig)
9745          {
9746             puschCfg=ulCfg->pusch_ServingCellConfig;
9747             if(puschCfg->choice.setup)
9748             {
9749                if(puschCfg->choice.setup->ext1)
9750                {
9751                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9752                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9753                   free(puschCfg->choice.setup->ext1);
9754                }
9755                free(puschCfg->choice.setup);
9756             }
9757             free(ulCfg->pusch_ServingCellConfig);
9758          }
9759          free(ulCfg->firstActiveUplinkBWP_Id);
9760       }
9761       freeAperDecodeInitialUlBWPConfig(ulBwp);
9762       free(ulCfg->initialUplinkBWP);
9763    }
9764 }
9765
9766 /*******************************************************************
9767  *
9768  * @brief Function to free DuUeCfg
9769  *
9770  * @details
9771  *
9772  *    Function : freeDuUeCfg
9773  *
9774  *    Functionality: Function to free DuUeCfg
9775  *
9776  * @params[in] DuUeCfg *ueCfg
9777  * @return void
9778  *
9779  * ****************************************************************/
9780 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9781 {
9782    uint8_t lcIdx = 0;
9783    uint8_t arrIdx = 0;
9784    SpCellConfig_t *spCellCfg = NULLP;
9785    ServingCellConfig_t *srvCellCfg = NULLP;
9786    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9787    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9788    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9789    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9790    struct RLC_Config *rlcConfig = NULLP;
9791    struct LogicalChannelConfig *macLcConfig = NULLP;
9792    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9793    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9794    struct TAG_Config *tagConfig = NULLP;
9795    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9796    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9797    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9798    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9799   
9800    if(ueCfg->ueNrCapability)
9801    {
9802       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9803       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9804       ueCfg->ueNrCapability = NULLP;
9805    }
9806
9807    if(ueCfg->cellGrpCfg)
9808    {
9809       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9810       if(rlcBearerList)
9811       {
9812          if(rlcBearerList->list.array)
9813          {
9814             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9815             {
9816                if(rlcBearerList->list.array[arrIdx])
9817                {
9818                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9819                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9820
9821                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9822                   {
9823                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9824                   }
9825                   if(rlcConfig)
9826                   {
9827                      if(rlcConfig->choice.am)
9828                      {
9829                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9830                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9831                         free(rlcConfig->choice.am);
9832                      }
9833                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9834                   }
9835                   if(macLcConfig)
9836                   {
9837                      if(macLcConfig->ul_SpecificParameters)
9838                      {
9839                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9840                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9841                         free(macLcConfig->ul_SpecificParameters);
9842                      }
9843                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9844                   }
9845                   free(rlcBearerList->list.array[arrIdx]); 
9846                }
9847             }
9848             free(rlcBearerList->list.array);
9849          }
9850          free(cellGrpCfg->rlc_BearerToAddModList);
9851       }
9852
9853       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9854       if(macCellGrpCfg)
9855       {
9856          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9857          if(schedulingRequestConfig)
9858          {
9859             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9860             if(schReqList)
9861             {
9862                if(schReqList->list.array)
9863                {
9864                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9865                   {
9866                      if(schReqList->list.array[arrIdx])
9867                      {
9868                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9869                         free(schReqList->list.array[arrIdx]);
9870                      }
9871                   }
9872                   free(schReqList->list.array);
9873                }
9874                free(schedulingRequestConfig->schedulingRequestToAddModList);
9875             }
9876             free(macCellGrpCfg->schedulingRequestConfig);
9877          }
9878          if(macCellGrpCfg->bsr_Config)
9879          {
9880             free(macCellGrpCfg->bsr_Config);
9881          }
9882          tagConfig = macCellGrpCfg->tag_Config;
9883          if(tagConfig)
9884          {
9885             tagList = tagConfig->tag_ToAddModList;
9886             if(tagList)
9887             {
9888                if(tagList->list.array)
9889                {
9890                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9891                   {
9892                      free(tagList->list.array[arrIdx]);
9893                   }
9894                   free(tagList->list.array);
9895                }
9896                free(tagConfig->tag_ToAddModList);
9897             }
9898             free(tagConfig); 
9899          }
9900
9901          phrConfig = macCellGrpCfg->phr_Config;
9902          if(phrConfig)
9903          {
9904             free(phrConfig->choice.setup); 
9905             free(phrConfig); 
9906          }
9907
9908          free(macCellGrpCfg); 
9909       }
9910
9911       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9912       if(phyCellGrpCfg)
9913       {
9914          free(phyCellGrpCfg->p_NR_FR1);
9915          free(phyCellGrpCfg); 
9916       }
9917
9918       spCellCfg = cellGrpCfg->spCellConfig;
9919       if(spCellCfg)
9920       {
9921          if(spCellCfg->servCellIndex)
9922          {
9923             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9924             {
9925                if(spCellCfg->spCellConfigDedicated)
9926                {
9927                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9928                   if(srvCellCfg->initialDownlinkBWP)
9929                   {
9930                      dlBwp = srvCellCfg->initialDownlinkBWP;
9931                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9932                      {
9933                         if(srvCellCfg->defaultDownlinkBWP_Id)
9934                         {
9935                            if(srvCellCfg->uplinkConfig)
9936                            {
9937
9938                               if(srvCellCfg->pdsch_ServingCellConfig)
9939                               {
9940                                  pdschCfg=
9941                                     srvCellCfg->pdsch_ServingCellConfig;
9942                                  if(pdschCfg->choice.setup)
9943                                  {
9944
9945                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9946                                     free(pdschCfg->choice.setup);
9947                                  }
9948
9949                                  free(srvCellCfg->pdsch_ServingCellConfig);
9950                               }
9951
9952                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9953                               free(srvCellCfg->uplinkConfig);
9954                            }
9955                            free(srvCellCfg->defaultDownlinkBWP_Id);
9956                         }
9957
9958                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9959                      }
9960                      if(dlBwp->pdcch_Config)
9961                      {
9962                         if(dlBwp->pdsch_Config)
9963                         {
9964                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9965                            free(dlBwp->pdsch_Config);
9966                         }
9967                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9968                         free(dlBwp->pdcch_Config);
9969                      }
9970                      free(srvCellCfg->initialDownlinkBWP);
9971                   }
9972
9973                   free(spCellCfg->spCellConfigDedicated);
9974                }
9975                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9976             }
9977             free(spCellCfg->servCellIndex); 
9978          }
9979          free(spCellCfg);
9980       }
9981       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9982       ueCfg->cellGrpCfg = NULLP;
9983    }
9984
9985    if(ueCfg->ambrCfg)
9986    {
9987       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9988    }
9989
9990    if(actionType != UE_CTXT_CFG_QUERY)
9991    {
9992       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9993       {
9994          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9995       }
9996    }
9997
9998    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9999    {
10000       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
10001    }
10002
10003    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10004    {
10005       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10006    }
10007 }
10008
10009 /*******************************************************************
10010  *
10011  * @brief Function to free UecontextSetupDb
10012  *
10013  * @details
10014  *
10015  *    Function : freeF1UeDb
10016  *
10017  *    Functionality: Function to free UecontextSetupDb
10018  *
10019  * @params[in] UecontextSetupDb *
10020  * @return void
10021  *
10022  * ****************************************************************/
10023
10024 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10025 {
10026    
10027    if(f1UeDb->dlRrcMsg)
10028    {
10029       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10030       {
10031         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10032                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10033       }
10034       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10035    }
10036    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10037    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10038    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10039 }
10040
10041 /*******************************************************************
10042  *
10043  * @brief Function to build Am cfg Info
10044  *
10045  * @details
10046  *
10047  *    Function : extractRlcAmCfg
10048  *
10049  *    Functionality: Function to build Am cfg Info
10050  *
10051  * @params[in] AmBearerCfg *
10052  *             void *
10053  *
10054  * @return ROK/RFAILED
10055  *
10056  * ****************************************************************/
10057
10058 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10059 {
10060    if(rlcAmCfg)
10061    {
10062       /* UL AM */
10063       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10064       {
10065          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10066          /*TODO: Check the timer value when sent by real CU */
10067          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10068          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10069       }
10070
10071       /* DL AM */
10072       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10073       {
10074          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10075          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10076          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10077          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10078          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10079       }
10080    }
10081 }
10082
10083 /*******************************************************************
10084  *
10085  * @brief Function to build Um Bi Info
10086  *
10087  * @details
10088  *
10089  *    Function : extractRlcUmBiCfg
10090  *
10091  *    Functionality: Function to build Um Bi Info
10092  *
10093  * @params[in] UmBiDirBearerCfg *
10094  *             void *
10095  *
10096  * @return ROK/RFAILED
10097  *
10098  * ****************************************************************/
10099
10100 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10101 {
10102    if(rlcBiCfg)
10103    {
10104       /* UL UM BI DIR Cfg */
10105       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10106       {
10107          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10108          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10109       }
10110
10111       /* DL UM BI DIR Cfg */
10112       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10113          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10114    }
10115 }
10116
10117 /*******************************************************************
10118  *
10119  * @brief Function to build Um Ul Info
10120  *
10121  * @details
10122  *
10123  *    Function : extractRlcUmUlCfg
10124  *
10125  *    Functionality: Function to build Um Ul Info
10126  *
10127  * @params[in] UmUniDirUlBearerCfg *
10128  *             void *
10129  *
10130  * @return ROK/RFAILED
10131  *
10132  * ****************************************************************/
10133
10134 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10135 {
10136    if(umUlCfg)
10137    {
10138       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10139       {
10140          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10141          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10142       }
10143    }
10144 }
10145
10146 /*******************************************************************
10147  *
10148  * @brief Function to build Um Uni Dl Info
10149  *
10150  * @details
10151  *
10152  *    Function : extractRlcUmDlCfg
10153  *
10154  *    Functionality: Function to build Um Uni Dl Info
10155  *
10156  * @params[in] UmUniDirDlBearerCfg *
10157  *             void *
10158  *
10159  * @return ROK/RFAILED
10160  *
10161  * ****************************************************************/
10162 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10163 {
10164    if(umDlCfg)
10165    {
10166       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10167          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10168    }
10169 }
10170
10171 /*******************************************************************
10172  *
10173  * @brief Function to extractRlcModeCfg
10174  *
10175  * @details
10176  *
10177  *    Function : extractRlcModeCfg
10178  *
10179  *    Functionality: Function to extractRlcModeCfg
10180  *
10181  * @params[in] RLC_Config_t *
10182  *             RlcBearerCfg *
10183  *             void  *    
10184  * @return ROK/RFAILED
10185  *
10186  * ****************************************************************/
10187 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10188 {
10189    if(lcCfg)
10190    {
10191       switch(rlcMode)
10192       {
10193          case RLC_AM :
10194             {
10195                if(lcCfg->choice.am)
10196                {
10197                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10198                   if(rlcDbCfg->u.amCfg)
10199                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10200                }
10201                break;
10202             }
10203          case RLC_UM_BI_DIRECTIONAL :
10204             {
10205                if(lcCfg->choice.um_Bi_Directional)
10206                {
10207                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10208                   if(rlcDbCfg->u.umBiDirCfg)
10209                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10210                }
10211                break;
10212             }
10213          case RLC_UM_UNI_DIRECTIONAL_UL :
10214             {
10215                if(lcCfg->choice.um_Uni_Directional_DL)
10216                {
10217                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10218                   if(rlcDbCfg->u.umUniDirUlCfg)
10219                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10220                }
10221                break;
10222             }
10223          case RLC_UM_UNI_DIRECTIONAL_DL :
10224             {
10225                if(lcCfg->choice.um_Uni_Directional_UL)
10226                {
10227                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10228                   if(rlcDbCfg->u.umUniDirDlCfg)
10229                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10230                }
10231                break;
10232             }
10233          default:
10234             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10235             break;
10236       }
10237    }
10238 }
10239
10240 /*******************************************************************
10241  *
10242  * @brief Function to extract extractUlLcCfg
10243  *
10244  * @details
10245  *
10246  *    Function : extractUlLcCfg
10247  *
10248  *    Functionality: Function to extract extractUlLcCfg
10249  *
10250  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10251  * @return void
10252  *
10253  * ****************************************************************/
10254
10255 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10256 {
10257    if(ulLcCfg)
10258    {
10259       if(ulLcCfg->ul_SpecificParameters)
10260       {
10261          f1UlLcCfg->priority = \
10262             ulLcCfg->ul_SpecificParameters->priority;
10263       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10264       {
10265          f1UlLcCfg->lcGroup = \
10266            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10267       }
10268       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10269       {
10270          f1UlLcCfg->schReqId = \
10271            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10272       }
10273       f1UlLcCfg->pbr = \
10274          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10275       f1UlLcCfg->bsd = \
10276          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10277       }
10278    }
10279 }
10280
10281 /*******************************************************************
10282 *
10283 * @brief Function to extract Snssai Cfg Info from CU
10284 *
10285 * @details
10286 *
10287 *    Function : extractDrbSnssaiCfg
10288 *
10289 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10290 *
10291 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10292 * @return ROK/RFAILED
10293 *
10294 * ****************************************************************/
10295
10296 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10297 {
10298    if(!(*snssaiToBeShared))
10299    {
10300       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10301       if(snssaiToBeShared == NULLP)
10302       {
10303          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10304          return RFAILED;
10305       }
10306    }
10307    if(RecvSnssai)
10308    {
10309       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10310       if(RecvSnssai->sD)
10311       {
10312          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10313       }
10314       else
10315       {
10316          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10317          return RFAILED;
10318       }
10319    }
10320    return ROK;
10321 }
10322
10323 /*******************************************************************
10324  *
10325  * @brief Function to procRlcLcCfg
10326  *
10327  * @details
10328  *
10329  *    Function : procRlcLcCfg
10330  *
10331  *    Functionality: Function to procRlcLcCfg
10332  *
10333  * @params[in] rbId, lcId, rbType, rlcMod
10334  *             RLC_Config_t *, RlcBearerCfg * , 
10335  * @return void
10336  *
10337  * ****************************************************************/
10338
10339 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10340    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10341 {
10342    DRB_Information_t *drbInfo;
10343
10344    lcCfg->rlcBearerCfg.rbId   = rbId;
10345    lcCfg->configType = configType;
10346
10347    if(rbType == RB_TYPE_SRB)
10348    {
10349       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10350       lcCfg->rlcBearerCfg.lcId   = rbId;
10351       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10352       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10353    }
10354    else if(rbType == RB_TYPE_DRB)
10355    {
10356       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10357       lcCfg->rlcBearerCfg.lcId   = lcId;
10358       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10359       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10360    }
10361    if(f1RlcCfg) /* rlc mode config recived */
10362    {
10363       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10364    }
10365    if(qoSInformation != NULLP)
10366    {
10367       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10368       {
10369          if(qoSInformation->choice.choice_extension->value.present ==\
10370                QoSInformation_ExtIEs__value_PR_DRB_Information)
10371          {
10372             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10373             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10374             {
10375                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10376                return;
10377             }
10378          }
10379       }
10380    }
10381 }
10382
10383 /*******************************************************************
10384  *
10385  * @brief Fills DrbQos Info received by CU
10386  *
10387  * @details
10388  *
10389  *    Function : extractQosInfo
10390  *
10391  *    Functionality: Fills DrbQos Info received  by CU
10392  *
10393  * @params[in] DrbQosInfo *qosToAdd, 
10394  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10395  * @return void
10396  *
10397  * ****************************************************************/
10398
10399 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10400 {
10401    uint8_t qosCntIdx = 0;
10402    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10403
10404    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10405    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10406                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10407    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10408    {
10409       qosToAdd->u.nonDyn5Qi.avgWindow = \
10410                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10411    }
10412
10413    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10414    {
10415       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10416                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10417    }
10418
10419    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10420    {
10421       qosToAdd->u.nonDyn5Qi.priorLevel = \
10422                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10423    }
10424    qosToAdd->ngRanRetPri.priorityLevel = \
10425                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10426    qosToAdd->ngRanRetPri.preEmptionCap = \
10427                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10428    qosToAdd->ngRanRetPri.preEmptionVul = \
10429                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10430    if(qosFlowCfg->gBR_QoS_Flow_Information)
10431    {
10432       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10433             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10434             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10435       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10436             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10437             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10438       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10439             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10440             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10441       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10442             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10443             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10444    }
10445    /*Extracting PDU_SESSION_ID*/
10446    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10447    if(qosIeExt)
10448    {
10449       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10450       {
10451          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10452                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10453          {
10454             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10455             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10456          }
10457       }  
10458    }
10459    qosToAdd->ulPduSessAggMaxBitRate = 0;
10460 }
10461
10462 /*******************************************************************
10463  *
10464  * @brief Function to extract GTP Tunnel Info from CU
10465  *
10466  * @details
10467  *
10468  *    Function : extractUpTnlInfo
10469  *
10470  *    Functionality: Function to extract GTP Tunnel Info from CU
10471  *
10472  * @params[in] F1AP message
10473  * @return ROK/RFAILED
10474  *
10475  * ****************************************************************/
10476
10477 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10478    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10479 {
10480    uint8_t tnlIdx;
10481    uint32_t ipv4_du = 0;
10482    GTPTunnel_t *gtpTunnel = NULLP;
10483
10484    upTnlInfo->drbId = drbId; 
10485    upTnlInfo->configType = configType;
10486 #ifdef O1_ENABLE
10487    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10488 #else
10489    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10490 #endif
10491
10492    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10493    {
10494       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10495       {
10496          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10497          {
10498             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10499             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10500             if(upTnlInfo->tnlCfg1 == NULLP)
10501             {
10502                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10503                return RFAILED;
10504             }
10505             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10506             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10507             if(gtpTunnel->gTP_TEID.size > 0)
10508             {
10509                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10510             }
10511          }
10512          break;
10513       }
10514    }
10515    return ROK;
10516 }
10517
10518 /*******************************************************************
10519 *
10520 * @brief Function to extract Drb Qos Cfg Info from CU
10521 *
10522 * @details
10523 *
10524 *    Function : extractDrbQosCfg 
10525 *
10526 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10527 *
10528 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10529 * @return ROK/RFAILED
10530 *
10531 * ****************************************************************/
10532
10533 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10534 {
10535    if(!macLcToAdd->drbQos)
10536    {
10537       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10538       if(macLcToAdd->drbQos == NULLP)
10539       {
10540          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10541          return RFAILED;
10542       }
10543
10544    }
10545    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10546    {
10547       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10548       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10549    }
10550    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10551    {
10552       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10553       return RFAILED;
10554    }
10555    return ROK;
10556 }
10557 /*******************************************************************
10558  *
10559  * @brief Function to extract DRB info received from CU
10560  *
10561  * @details
10562  *
10563  *    Function : extractDrbCfg
10564  *
10565  *    Functionality: Function to extract DRB info received from CU
10566  *
10567  * @params[in] F1AP message
10568  * @return void
10569  *
10570  * ****************************************************************/
10571 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10572 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10573 {
10574    DRB_Information_t *drbInfo = NULLP;
10575
10576    if(drbItem != NULLP)
10577    {
10578       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10579       {
10580          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10581          return RFAILED;
10582       }
10583       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10584       {
10585          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10586          {
10587             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10588             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10589             {
10590                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10591                return RFAILED;
10592             }
10593          }
10594       }
10595    }
10596    else if(drbSetupModItem != NULLP)
10597    {
10598       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10599       upTnlInfo) != ROK)
10600       {
10601          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10602          return RFAILED;
10603       }
10604       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10605       {
10606          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10607          QoSInformation_ExtIEs__value_PR_DRB_Information)
10608          {
10609             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10610             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10611             {
10612                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10613                return RFAILED;
10614             }
10615
10616          }
10617       }
10618    }
10619    else if(drbModItem != NULLP)
10620    {
10621       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10622       upTnlInfo) != ROK)
10623       {
10624          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10625          return RFAILED;
10626       }
10627       if(drbModItem->qoSInformation != NULLP)
10628       {
10629          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10630          {
10631             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10632                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10633             {
10634                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10635                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10636                {
10637                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10638                   return RFAILED;
10639                }
10640
10641             }
10642          }
10643       }
10644    }
10645    return ROK;
10646 }
10647
10648 /*******************************************************************
10649  *
10650  * @brief Function to extract RB info received from CU
10651  *
10652  * @details
10653  *
10654  *    Function : extractMacRbCfg
10655  *
10656  *    Functionality: Function to extract RB info received from CU
10657  *
10658  * @params[in] F1AP message
10659  * @return ROK/RFAILED
10660  *
10661  * ****************************************************************/
10662
10663 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10664 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10665 {
10666    if(drbCfg != NULLP)
10667    {
10668       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10669       {
10670          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10671          return RFAILED;
10672       }
10673    }
10674    else if(drbSetupModCfg != NULLP)
10675    { 
10676       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10677       {
10678          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10679          return RFAILED;
10680       }
10681    }
10682    else if(drbModCfg != NULLP)
10683    { 
10684       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10685       {
10686          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10687          return RFAILED;
10688       }
10689    }
10690    else
10691    {
10692       lcCfg->lcConfig.drbQos = NULLP;
10693       lcCfg->lcConfig.snssai = NULLP;
10694       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10695          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10696       else
10697          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10698
10699    }
10700    if(ulLcCfg)
10701    {
10702       lcCfg->lcConfig.ulLcCfgPres = true;
10703       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10704    }
10705    else
10706       lcCfg->lcConfig.ulLcCfgPres = false;
10707    return ROK;
10708 }
10709
10710 /*******************************************************************
10711  *
10712  * @brief Function processing LC config info received from CU
10713  *
10714  * @details
10715  *
10716  *    Function : procMacLcCfg
10717  *
10718  *    Functionality: Function processing LC config info received from CU
10719  *
10720  * @params[in] F1AP message
10721  * @return ROK/RFAILED
10722  *
10723  * ****************************************************************/
10724
10725 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10726 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10727 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10728 {
10729    uint8_t ret = ROK;
10730
10731    lcCfg->lcConfig.lcId = lcId;
10732    lcCfg->configType = configType;
10733    if(rbType == RB_TYPE_SRB)
10734    {
10735       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10736    }
10737    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10738    {
10739       if(drbItem != NULL)
10740         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10741       else if(drbSetupModItem != NULL)
10742         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10743       else if(drbModItem != NULL)
10744         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10745    }
10746    return ret;
10747 }
10748
10749 /*******************************************************************
10750  *
10751  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10752  *
10753  * @details
10754  *
10755  *    Function : extractRlcCfgToAddMod
10756  *
10757  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10758  *
10759  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10760  *             DuUeCfg Pointer
10761  * @return ROK/RFAILED
10762  *
10763  * ****************************************************************/
10764
10765 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10766 {
10767   uint8_t idx, rbId, lcId, rlcMode, rbType;
10768   RLC_Config_t *f1RlcCfg = NULLP;
10769   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10770
10771   for(idx = 0; idx < lcCfg->list.count; idx++)
10772   {
10773      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10774      if(lcCfg->list.array[idx]->servedRadioBearer)
10775      {
10776         /* RadioBearer for SRB/DRB */
10777         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10778         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10779         {
10780            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10781            rbType = RB_TYPE_SRB;
10782         }
10783         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10784         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10785         {
10786            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10787            rbType = RB_TYPE_DRB;
10788         }
10789         else
10790         {
10791            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10792            return RFAILED;
10793         }
10794         /* MAC UL LC Config */
10795         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10796         {
10797            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10798         }
10799      }
10800      else
10801      {
10802         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10803         return RFAILED;
10804      }
10805      /* RLC Mode Config */
10806      if(lcCfg->list.array[idx]->rlc_Config)
10807      {
10808         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10809         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10810      }
10811      
10812      /* Filling RLC/MAC Config*/
10813      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10814      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10815      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10816      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10817      {
10818         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10819         return RFAILED;
10820      }
10821      (ueCfgDb->numRlcLcs)++;
10822      (ueCfgDb->numMacLcs)++;
10823      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10824         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10825   }
10826   //TODO: To send the failure cause in UeContextSetupRsp 
10827   return ROK;
10828 }
10829
10830 /*******************************************************************
10831  *
10832  * @brief DeAlloc pdsch serv cell config info
10833  *
10834  * @details
10835  *
10836  *    Function : freeMacPdschServCellInfo
10837  *
10838  *    Functionality: DeAlloc pdsch serv cell config info
10839  *
10840  * @params[in] PdschServCellCfg pointer
10841  * @return void
10842  *
10843  * ****************************************************************/
10844
10845 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10846 {
10847    if(pdsch->xOverhead)
10848    {
10849       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10850    }
10851    if(pdsch->codeBlkGrpFlushInd)
10852    {
10853       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10854    }
10855    if(pdsch->maxCodeBlkGrpPerTb)
10856    {
10857       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10858    }
10859    if(pdsch->maxMimoLayers)
10860    {
10861       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10862    }
10863 }
10864
10865 /*******************************************************************
10866  *
10867  * @brief Free Serving cell Info
10868  *
10869  * @details
10870  *
10871  *    Function : freeMacServingCellInfo
10872  *
10873  *    Functionality: Free Serving cell Info
10874  *
10875  * @params[in] ServCellCfgInfo *srvCellCfg
10876  * @return void
10877  *
10878  * ****************************************************************/
10879 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10880 {
10881    uint8_t timeDomRsrcIdx;
10882
10883    if(srvCellCfg->initDlBwp.pdschPresent)
10884    {
10885       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10886       {
10887          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10888             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10889       }
10890    }
10891
10892    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10893    if(srvCellCfg->bwpInactivityTmr)
10894    {
10895       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10896    }
10897
10898    if(srvCellCfg->initUlBwp.pucchPresent)
10899    {
10900       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10901    }
10902 }
10903
10904 /*******************************************************************
10905  *
10906  * @brief Free cell Grp Cfg Info
10907  *
10908  * @details
10909  *
10910  *    Function : freeUeRecfgCellGrpInfo
10911  *
10912  *    Functionality: Free cell Grp Cfg Info
10913  *
10914  * @params[in] DuMacUeCfg*  duUeCfg
10915  * @return void
10916  *
10917  * ****************************************************************/
10918
10919 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10920 {
10921    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10922 }
10923
10924 /*******************************************************************
10925  *
10926  * @brief Fills Reconfig SchReqReConfig
10927  *
10928  * @details
10929  *
10930  *    Function : extractSchReqReConfig
10931  *
10932  *    Functionality: Fills Reconfig SchReqReConfig
10933  *
10934  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10935  *             SchedReqCfg*  macSchedReq
10936  * @return void
10937  *
10938  * ****************************************************************/
10939 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10940 {
10941    uint8_t schReqIdx = 0;
10942    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10943    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10944
10945    if(cuSchedReq->schedulingRequestToAddModList)
10946    {
10947       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10948       if(schReqListToAdd->list.count)
10949       {
10950          macSchedReq->addModListCount = schReqListToAdd->list.count;
10951          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10952          {
10953             macSchedReq->addModList[schReqIdx].schedReqId = \
10954                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10955             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10956                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10957             macSchedReq->addModList[schReqIdx].srTransMax    =\
10958                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10959          }
10960       }
10961    }
10962    /* Scheduling Req To release */
10963    if(cuSchedReq->schedulingRequestToReleaseList)
10964    {
10965       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10966       if(schReqListToRel->list.count)
10967       {
10968          macSchedReq->relListCount = schReqListToRel->list.count;
10969          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10970          {
10971             macSchedReq->relList[schReqIdx] = \
10972                *schReqListToRel->list.array[schReqIdx];
10973          }
10974       }
10975    }
10976 }
10977
10978 /*******************************************************************
10979  *
10980  * @brief Fills TagReconfig
10981  *
10982  * @details
10983  *
10984  *    Function : extractTagReconfig
10985  *
10986  *    Functionality: Fills extractTagReconfig
10987  *
10988  * @params[in] TAG_Config_t *cuTagCfg
10989  *             TagCfg *macTagCfg
10990  * @return void
10991  *
10992  * ****************************************************************/
10993
10994 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10995 {
10996   uint8_t tagIdx = 0;
10997   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10998   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10999
11000   /* Tag config to AddMod */
11001   if(cuTagCfg->tag_ToAddModList)
11002   {
11003      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11004      if(tagListToAddMod->list.count)
11005      {
11006         macTagCfg->addModListCount = tagListToAddMod->list.count;
11007         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11008         {
11009            macTagCfg->addModList[tagIdx].tagId =\
11010               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11011            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11012
11013               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11014         }
11015      }
11016   }
11017   /* Tag config to release */
11018   if(cuTagCfg->tag_ToReleaseList)
11019   {
11020      tagListToRel = cuTagCfg->tag_ToReleaseList;
11021      if(tagListToRel->list.count)
11022      {
11023         macTagCfg->relListCount = tagListToRel->list.count;
11024         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11025         {
11026            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11027         }
11028      }
11029   }
11030 }
11031
11032 /*******************************************************************
11033  *
11034  * @brief Fills PdcchCfg received by CU
11035  *
11036  * @details
11037  *
11038  *    Function : extractPdcchCfg
11039  *
11040  *    Functionality: Fills PdcchCfg received  by CU
11041  *
11042  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11043  *             PdcchConfig *duPdcchCfg
11044  * @return void
11045  *
11046  * ****************************************************************/
11047
11048 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11049 {
11050    uint8_t cRsetIdx = 0;
11051    uint8_t srchSpcIdx = 0;
11052
11053    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11054    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11055    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11056    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11057
11058
11059    /* Control Resource Set To Add/Mod List */
11060    if(cuPdcchCfg->controlResourceSetToAddModList)
11061    {
11062       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11063       if(cRsetToAddModList->list.count)
11064       {
11065          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11066          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11067          {
11068             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11069                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11070             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11071                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11072             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11073                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11074                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11075
11076             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11077                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11078
11079             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11080                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11081             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11082             {
11083                //TODO: handle the case for Interleaved
11084             }
11085             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11086                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11087             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11088             {
11089                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11090                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11091             }
11092          }
11093       }
11094    }
11095    /* Control Resource Set To Release List */
11096    if(cuPdcchCfg->controlResourceSetToReleaseList)
11097    {
11098       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11099       if(cRsetToRelList->list.count)
11100       {
11101          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11102          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11103          {
11104             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11105          }
11106       }
11107    }
11108
11109    /* Search space To Add/Mod List */
11110    if(cuPdcchCfg->searchSpacesToAddModList)
11111    {
11112       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11113       if(srchSpcToAddModList->list.count)
11114       {
11115          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11116          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11117          {
11118             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11119                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11120             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11121                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11122             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11123             {
11124                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11125                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11126             }
11127             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11128             {
11129                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11130                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11131             }
11132             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11133             {
11134                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11135                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11136                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11137                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11138                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11139                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11140
11141                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11142                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11143
11144                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11145                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11146             }
11147             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11148             {
11149                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11150                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11151                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11152                {
11153                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11154                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11155                }
11156
11157             }
11158          }
11159       }
11160    }
11161    /* Search space To Rel List */
11162    if(cuPdcchCfg->searchSpacesToReleaseList)
11163    {
11164       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11165       if(srchSpcToRelList->list.count)
11166       {
11167          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11168          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11169          {
11170             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11171                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11172          }
11173       }
11174    }
11175 }
11176
11177 /*******************************************************************
11178  *
11179  * @brief Fills PdschCfg received by CU
11180  *
11181  * @details
11182  *
11183  *    Function : extractPdschCfg
11184  *
11185  *    Functionality: Fills PdschCfg received  by CU
11186  *
11187  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11188  *                   which we have stored in F1UeContextSetupDb,
11189  *             PdschConfig *macPdschCfg = Used to Store the information which
11190  *                   needs to send in other layer, as well as this can be the variable
11191  *                   which stores the information in DuCb,
11192  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11193  *                   information to other layer else it will have stored pdsch 
11194  *                   configuration in copyOfmacUeCfg.
11195  * @return void
11196  *
11197  * ****************************************************************/
11198
11199 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11200 {
11201    uint8_t timeDomIdx;
11202    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11203
11204    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11205    {
11206       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11207             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11208       {
11209          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11210          {
11211             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11212                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11213          }
11214       }
11215    }
11216    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11217    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11218    {
11219       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11220       if(timeDomAlloc->present ==\
11221             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11222       {
11223          if(timeDomAlloc->choice.setup)
11224          {
11225             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11226             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11227             {
11228                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11229                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11230                {
11231                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11232                   {
11233                      if(storedPdschCfg)
11234                      {
11235                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11236                         {
11237                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11238                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11239                         }
11240                         else
11241                         {
11242                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11243                         }
11244                      }
11245                      else
11246                      {
11247                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11248                      }
11249                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11250                      {
11251                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11252                         return;
11253                      }
11254                   }
11255                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11256                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11257                }
11258                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11259                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11260                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11261                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11262             }
11263          }
11264       }
11265    }
11266    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11267    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11268       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11269    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11270    {
11271       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11272       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11273       {
11274          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11275          {
11276             macPdschCfg->bundlingInfo.StaticBundling.size = \
11277                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11278          }
11279       }
11280    }
11281    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11282    {
11283       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11284    }
11285
11286 }
11287
11288 /*******************************************************************
11289  *
11290  * @brief Fills PdschServingCellCfg received by CU
11291  *
11292  * @details
11293  *
11294  *    Function : extractPdschServingCellCfg
11295  *
11296  *    Functionality: Fills PdschCfg received  by CU
11297  *
11298  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11299  *             PdschServCellCfg *macUePdschSrvCellCfg
11300  * @return ROK/RFAILED
11301  *
11302  * ****************************************************************/
11303
11304 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11305 {
11306    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11307    {
11308       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11309       {
11310          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11311          {
11312             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11313                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11314          }
11315          else
11316          {
11317             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11318             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11319             {
11320                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11321                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11322             }
11323             else
11324             {
11325                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11326                return RFAILED;
11327             }
11328          }
11329          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11330          {
11331             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11332                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11333          }
11334          else
11335          {
11336             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11337             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11338             {
11339                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11340                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11341             }
11342             else
11343             {
11344                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11345                return RFAILED;
11346             }
11347          }
11348       }
11349    }
11350    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11351    {
11352       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11353    }
11354    if(cuPdschSrvCellCfg->ext1)
11355    {
11356       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11357       {
11358         if(macUePdschSrvCellCfg->maxMimoLayers)
11359         {
11360            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11361         }
11362         else
11363         {
11364            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11365            if(macUePdschSrvCellCfg->maxMimoLayers)
11366            {
11367               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11368            }
11369            else
11370            {
11371               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11372               return RFAILED;
11373            }
11374         }
11375       }
11376    }
11377    if(cuPdschSrvCellCfg->xOverhead)
11378    {
11379       if(macUePdschSrvCellCfg->xOverhead)
11380       {
11381          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11382       }
11383       else
11384       {
11385          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11386          if(macUePdschSrvCellCfg->xOverhead)
11387          {
11388             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11389          }
11390          else
11391          {
11392             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11393             return RFAILED;
11394          }
11395       }
11396    }
11397    return ROK;
11398 }
11399
11400 /*******************************************************************
11401  *
11402  * @brief Fills PuschCfg received by CU
11403  *
11404  * @details
11405  *
11406  *    Function : extractPuschCfg
11407  *
11408  *    Functionality: Fills PuschCfg received  by CU
11409  *
11410  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11411  *             PuschCfg *macPuschCfg
11412  * @return void
11413  *
11414  * ****************************************************************/
11415
11416 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11417 {
11418    uint8_t timeDomIdx = 0;
11419    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11420    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11421
11422    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11423    {
11424       if(cuPuschCfg->choice.setup)
11425       {
11426          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11427          {
11428              macPuschCfg->dataScramblingId = \
11429                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11430          }
11431          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11432          {
11433             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11434             {
11435                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11436                {
11437                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11438                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11439                   {
11440                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11441                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11442                   }
11443                   if(dmrsUlCfg->transformPrecodingDisabled)
11444                   {
11445                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11446                      {
11447                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11448                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11449                      }
11450                   }
11451                }
11452             }
11453          }
11454          /*Res Alloc Type for UL */
11455          if(cuPuschCfg->choice.setup->resourceAllocation)
11456          {
11457             macPuschCfg->resourceAllocType = \
11458                cuPuschCfg->choice.setup->resourceAllocation;
11459          }
11460          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11461          {
11462             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11463             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11464             {
11465                if(timeDomAllocList->choice.setup)
11466                {
11467                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11468                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11469                   {
11470                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11471                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11472                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11473                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11474                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11475                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11476                   }
11477                }
11478             }
11479          }
11480          if(cuPuschCfg->choice.setup->transformPrecoder)
11481             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11482       }
11483    }
11484 }
11485
11486 /*******************************************************************
11487  *
11488  * @brief Function to fill pucch Power Control
11489  *
11490  * @details
11491  *
11492  *    Function : extractPucchPowerControl
11493  *
11494  *    Functionality: Function to fill pucch Power Control
11495  *
11496  * @params[in] PucchPowerControl *pwrCtrl,
11497  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11498  * @return void
11499  *
11500  * ****************************************************************/
11501
11502 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11503 {
11504    uint8_t arrIdx;
11505
11506    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11507       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11508    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11509       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11510    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11511       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11512    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11513       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11514    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11515       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11516    if(cuPwrCtrlCfg->p0_Set)
11517    {
11518       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11519       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11520       {
11521          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11522             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11523          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11524             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11525       }
11526    }
11527    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11528    {
11529       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11530       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11531       {
11532          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11533             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11534       }
11535    }
11536 }
11537  
11538  /*******************************************************************
11539  *
11540  * @brief Function to extractResrcSetToAddModList sent by CU
11541  *
11542  * @details
11543  *
11544  *    Function : extractResrcSetToAddModList
11545  *
11546  *    Functionality: Fucntion to extractResrcSetToAddModList
11547  *
11548  * @params[in] PucchResrcSetCfg pointer,
11549  *             struct PUCCH_Config__resourceSetToAddModList pointer
11550  * @return void
11551  *
11552  * ****************************************************************/
11553
11554 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11555 {
11556    uint8_t arrIdx, rsrcListIdx;
11557
11558    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11559    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11560    {
11561       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11562          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11563       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11564          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11565       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11566       {
11567          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11568             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11569       }
11570
11571       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11572       {
11573          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11574             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11575       }
11576       else
11577       {
11578          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11579       }
11580    }
11581 }/* End of extractResrcSetToAddModList */
11582
11583 /*******************************************************************
11584  *
11585  * @brief Fills extractResrcToAddModList sent by CU
11586  *
11587  * @details
11588  *
11589  *    Function : extractResrcToAddModList
11590  *
11591  *    Functionality: Fills extractResrcToAddModList
11592  *
11593  * @params[in] PucchResrcCfg pointer,
11594  *             struct PUCCH_Config__resourceToAddModList pointer
11595  * @return ROk/RFAILED
11596  *
11597  * ****************************************************************/
11598
11599 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11600 {
11601    uint8_t arrIdx;
11602    
11603    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11604    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11605    {
11606       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11607         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11608       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11609         cuResrcList->list.array[arrIdx]->startingPRB;
11610       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11611       {
11612          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11613            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11614       }
11615       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11616       {
11617          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11618            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11619       }
11620       /* PUCCH RSRC FORMAT */
11621       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11622       {
11623          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11624          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11625          {
11626             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11627             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11628             {
11629                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11630                return RFAILED;
11631             }
11632             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11633                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11634             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11635                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11636             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11637                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11638          }
11639       }
11640       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11641       {
11642          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11643          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11644          {
11645             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11646             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11647             {
11648                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11649                return RFAILED;
11650             }
11651             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11652                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11653             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11654                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11655             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11656                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11657             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11658                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11659          }
11660       }
11661       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11662       {
11663          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11664          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11665          {
11666             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11667             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11668             {
11669                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11670                return RFAILED;
11671             }
11672             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11673                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11674             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11675                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11676             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11677                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11678          }
11679       }
11680       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11681       {
11682          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11683          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11684          {
11685             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11686             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11687             {
11688                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11689                return RFAILED;
11690             }
11691             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11692                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11693             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11694                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11695             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11696                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11697          }
11698       }
11699       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11700       {
11701          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11702          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11703          {
11704             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11705             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11706             {
11707                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11708                return RFAILED;
11709             }
11710             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11711                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11712             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11713                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11714             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11715                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11716             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11717                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11718          }
11719       }
11720    }
11721    return ROK;
11722
11723 }/* End of extractResrcToAddModList */
11724
11725 /*******************************************************************
11726  *
11727  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11728  *
11729  * @details
11730  *
11731  *    Function : fillPucchSchedReqPeriodAndOffset
11732  *
11733  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11734  *
11735  * @params[in] macPeriodicty,
11736  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11737  * @return void
11738  *
11739  * ****************************************************************/
11740
11741 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11742    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11743 {
11744    macPeriodicty = cuPeriodicty->present;
11745    switch(macPeriodicty)
11746    {
11747       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11748          {
11749             macOffset     = cuPeriodicty->choice.sym2;
11750             break;
11751          }
11752       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11753          {
11754             macOffset     = cuPeriodicty->choice.sym6or7;
11755             break;
11756          }
11757       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11758          {
11759             macOffset     = cuPeriodicty->choice.sl1;
11760             break;
11761          }
11762       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11763          {
11764             macOffset = cuPeriodicty->choice.sl2;
11765             break;
11766          }
11767       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11768          {
11769             macOffset = cuPeriodicty->choice.sl4;
11770             break;
11771          }
11772       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11773          {
11774             macOffset = cuPeriodicty->choice.sl5;
11775             break;
11776          }
11777       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11778          {
11779             macOffset = cuPeriodicty->choice.sl8;
11780             break;
11781          }
11782       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11783          {
11784             macOffset = cuPeriodicty->choice.sl10;
11785             break;
11786          }
11787       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11788          {
11789             macOffset = cuPeriodicty->choice.sl16;
11790             break;
11791          }
11792       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11793          {
11794             macOffset = cuPeriodicty->choice.sl20;
11795             break;
11796          }
11797       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11798          {
11799             macOffset = cuPeriodicty->choice.sl40;
11800             break;
11801          }
11802       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11803          {
11804             macOffset = cuPeriodicty->choice.sl80;
11805             break;
11806          }
11807       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11808          {
11809             macOffset = cuPeriodicty->choice.sl160;
11810             break;
11811          }
11812       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11813          {
11814             macOffset = cuPeriodicty->choice.sl320;
11815             break;
11816          }
11817       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11818          {
11819             macOffset = cuPeriodicty->choice.sl640;
11820             break;
11821          }
11822       default :
11823          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11824    }
11825 }
11826
11827 /*******************************************************************
11828  *
11829  * @brief Function to extractPucchFormatCfg sent by CU
11830  *
11831  * @details
11832  *
11833  *    Function : extractPucchFormatCfg
11834  *
11835  *    Functionality: Function to extractPucchFormatCfg
11836  *
11837  * @params[in] PucchFormatCfg pointer,
11838  *             PUCCH_FormatConfig_t pointer
11839  * @return void
11840  *
11841  * ****************************************************************/
11842
11843 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11844  {
11845     if(cuFormatCfg->interslotFrequencyHopping)
11846        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11847     if(cuFormatCfg->additionalDMRS)  
11848        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11849     if(cuFormatCfg->maxCodeRate)
11850        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11851     if(cuFormatCfg->nrofSlots)  
11852        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11853     if(cuFormatCfg->pi2BPSK)  
11854        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11855     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11856        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11857  }/* End of extractPucchFormatCfg */
11858
11859 /*******************************************************************
11860  *
11861  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11862  *
11863  * @details
11864  *
11865  *    Function : extractSchedReqCfgToAddMod
11866  *
11867  *    Functionality: Function to extractSchedReqCfgToAddMod
11868  *
11869  * @params[in] PucchSchedReqCfg pointer,
11870  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11871  * @return void
11872  *
11873  * ****************************************************************/
11874
11875 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11876 {
11877    uint8_t arrIdx;
11878
11879    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11880    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11881    {
11882       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11883          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11884       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11885          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11886       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11887       {
11888          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11889             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11890       }
11891       if(cuSchedReqList->list.array[arrIdx]->resource)
11892       {
11893          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11894             *cuSchedReqList->list.array[arrIdx]->resource;
11895       }
11896    }
11897
11898 }/* End of extractSchedReqCfgToAddMod */
11899
11900  /*******************************************************************
11901  *
11902  * @brief Fills PucchCfg received by CU
11903  *
11904  * @details
11905  *
11906  *    Function : extractPucchCfg
11907  *
11908  *    Functionality: Fills PucchCfg received  by CU
11909  *
11910  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11911  *                is send by CU, which we have stored in F1UeContextSetupDb,
11912  *             PucchCfg *macPucchCfg = Used to Store the information which
11913  *                needs to send in other layer, as well as this can be the variable
11914  *                which stores the information in DuCb,
11915  *             PucchCfg *storedPucchCfg = Null in case of sending the
11916  *                information to other layer else it will have Pucch Cfg which
11917  *                we have stored in copyOfmacUeCfg.
11918  * @return ROK/RFAILED
11919  *
11920  * ****************************************************************/
11921
11922 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11923 PucchCfg *storedPucchCfg)        
11924 {
11925    uint8_t arrIdx;
11926
11927    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11928    {
11929       if(cuPucchCfg->choice.setup)
11930       {
11931          /* Resource Set Cfg */ 
11932          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11933          {
11934             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11935             if(macPucchCfg->resrcSet == NULLP)
11936             {
11937                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11938                return RFAILED;
11939             }
11940             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11941             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11942          }
11943          
11944          /* Resource Cfg */ 
11945          if(cuPucchCfg->choice.setup->resourceToAddModList)
11946          {
11947             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11948             if(macPucchCfg->resrc == NULLP)
11949             {
11950                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11951                return RFAILED;
11952             }
11953             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11954             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11955          }
11956          
11957          /* Format 1 Cfg */ 
11958          if(cuPucchCfg->choice.setup->format1)
11959          {
11960             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11961             if(macPucchCfg->format1 == NULLP)
11962             {
11963                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11964                return RFAILED;
11965             }
11966             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11967             extractPucchFormatCfg(macPucchCfg->format1,\
11968                cuPucchCfg->choice.setup->format1->choice.setup);
11969          }
11970          
11971          /* Format 2 Cfg */
11972          if(cuPucchCfg->choice.setup->format2)
11973          {
11974             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11975             if(macPucchCfg->format2 == NULLP)
11976             {
11977                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11978                return RFAILED;
11979             }
11980             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11981             extractPucchFormatCfg(macPucchCfg->format2,\
11982                cuPucchCfg->choice.setup->format2->choice.setup);
11983          }
11984          
11985          /* Format 3 Cfg */
11986          if(cuPucchCfg->choice.setup->format3)
11987          {
11988             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11989             if(macPucchCfg->format3 == NULLP)
11990             {
11991                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11992                return RFAILED;
11993             }
11994             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11995             extractPucchFormatCfg(macPucchCfg->format3,\
11996                cuPucchCfg->choice.setup->format3->choice.setup);
11997          }
11998
11999          /* Format 4 Cfg */
12000          if(cuPucchCfg->choice.setup->format4)
12001          {
12002             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12003             if(macPucchCfg->format4 == NULLP)
12004             {
12005                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12006                return RFAILED;
12007             }
12008             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12009             extractPucchFormatCfg(macPucchCfg->format4,\
12010                cuPucchCfg->choice.setup->format4->choice.setup);
12011          }
12012
12013          /* Sched Req List */
12014          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12015          {
12016             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12017             if(macPucchCfg->schedReq == NULLP)
12018             {
12019                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12020                return RFAILED;
12021             }
12022             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12023             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12024             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12025          }
12026
12027          /*TODO: Add support for  Spatial Info */
12028
12029          /* MultiCsiCfg */
12030          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12031          {
12032             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12033             if(macPucchCfg->multiCsiCfg == NULLP)
12034             {
12035                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12036                return RFAILED;
12037             }
12038             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12039             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12040             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12041             {
12042                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12043                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12044             }
12045          }
12046
12047          /* Dl_DataToUL_ACK */ 
12048          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12049     {
12050        if(storedPucchCfg)
12051        {
12052           if(storedPucchCfg->dlDataToUlAck)
12053           {
12054              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12055           }
12056           else
12057           {
12058             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12059           }
12060        }
12061        else
12062        {
12063           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12064        }
12065        if(macPucchCfg->dlDataToUlAck == NULLP)
12066        {
12067           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12068           return RFAILED;
12069        }
12070        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12071        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12072        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12073        {
12074           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12075           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12076        }
12077          }
12078
12079          /* Power Control */
12080          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12081          {
12082             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12083             if(macPucchCfg->powerControl == NULLP)
12084             {
12085                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12086                return RFAILED;
12087             }
12088             extractPucchPowerControl(macPucchCfg->powerControl,\
12089                cuPucchCfg->choice.setup->pucch_PowerControl);
12090          }
12091       }
12092    }
12093    return ROK;
12094 }
12095
12096 /*******************************************************************
12097  *
12098  * @brief Fills ServingCellReconfig received by CU
12099  *
12100  * @details
12101  *
12102  *    Function : extractSpCellDedicatedCfg
12103  *
12104  *    Functionality: Fills ServingCellReconfig received  by CU
12105  *
12106  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12107  *                  CU, which we have stored in F1UeContextSetupDb,
12108  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12109  *                  which  needs to send in other layer, as well as this can be the
12110  *                  variable which stores the information in DuCb, 
12111  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12112  *                  information to other layer else it will have ServCellCfgInfo which
12113  *                  we have stored in copyOfmacUeCfg.
12114  * @return ROK/RFAILD
12115  *
12116  * ****************************************************************/
12117 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12118 ServCellRecfgInfo *storedSrvCellCfg)
12119 {
12120    uint8_t ret = ROK;
12121    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12122    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12123
12124    if(cuSrvCellCfg->initialDownlinkBWP)
12125    {
12126       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12127       if(dlBwp->pdcch_Config)
12128       {
12129          if(dlBwp->pdcch_Config->choice.setup)
12130          {
12131             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12132             if(storedSrvCellCfg)
12133             {
12134                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12135                {
12136                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12137                }
12138                else
12139                {
12140                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12141                }
12142             }
12143             else
12144             {
12145                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12146             }
12147          }
12148       }
12149       if(dlBwp->pdsch_Config)
12150       {
12151          if(dlBwp->pdsch_Config->choice.setup)
12152          {
12153             macSrvCellCfg->initDlBwp.pdschPresent = true;
12154             
12155             if(storedSrvCellCfg)
12156             {
12157                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12158                {
12159                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12160                }
12161                else
12162                {
12163                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12164                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12165                }
12166             }
12167             else
12168             {
12169                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12170             }
12171          }
12172       }
12173    }
12174    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12175       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12176    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12177       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12178    if(cuSrvCellCfg->bwp_InactivityTimer)
12179    {
12180       if(macSrvCellCfg->bwpInactivityTmr)
12181       {
12182          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12183       }
12184       else
12185       {
12186          macSrvCellCfg->bwpInactivityTmr = NULLP;
12187          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12188          if(macSrvCellCfg->bwpInactivityTmr)
12189          {
12190             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12191          }
12192          else
12193          {
12194             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12195             return RFAILED;
12196          }
12197       }
12198    }
12199    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12200    {
12201       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12202       {
12203          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12204          if(ret == RFAILED)
12205          {
12206             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12207             return RFAILED;
12208          }
12209       }
12210    }
12211    if(cuSrvCellCfg->uplinkConfig)
12212    {
12213       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12214       {
12215          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12216          if(ulBwp->pusch_Config)
12217          {
12218             macSrvCellCfg->initUlBwp.puschPresent = true;
12219             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12220          }
12221          if(ulBwp->pucch_Config)
12222          {
12223             macSrvCellCfg->initUlBwp.pucchPresent = true;
12224             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12225             if(storedSrvCellCfg)
12226             {
12227                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12228                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12229                else
12230                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12231                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12232             }
12233             else
12234             {
12235                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12236             }
12237          }
12238       }
12239       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12240          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12241    }
12242    return ret;
12243 }
12244
12245 #ifdef NR_DRX
12246
12247 /*******************************************************************
12248  *
12249  * @brief fill long cycle offset value of drx in UE structure
12250  *
12251  * @details
12252  *
12253  *    Function : fillLongCycleOffsetValueInUeDb
12254  *
12255  *    Functionality: fill long cycle offset value of drx in UE structure
12256  *
12257  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12258  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12259  *
12260  * @return ROK     - success
12261  *         RFAILED - failure
12262  *
12263  * ****************************************************************/
12264 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12265 {
12266
12267    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12268    switch(drx_LongCycleStartOffset->present)
12269    {
12270       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12271          {
12272             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12273             break;
12274          }
12275       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12276          {
12277             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12278             break;
12279          }
12280       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12281          {
12282             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12283             break;
12284          }
12285       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12286         {
12287             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12288             break;
12289          }
12290       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12291          {
12292             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12293             break;
12294          }
12295       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12296          {
12297             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12298             break;
12299          }
12300       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12301          {
12302             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12303             break;
12304          }
12305       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12306          {
12307             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12308             break;
12309          }
12310       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12311          {
12312             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12313             break;
12314          }
12315       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12316          {
12317             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12318             break;
12319          }
12320       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12321          {
12322             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12323             break;
12324          }
12325       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12326          {
12327             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12328             break;
12329          }
12330       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12331          {
12332             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12333             break;
12334          }
12335       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12336          {
12337             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12338             break;
12339          }
12340       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12341          {
12342             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12343             break;
12344          }
12345       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12346          {
12347             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12348             break;
12349          }
12350       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12351          {
12352             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12353             break;
12354          }
12355       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12356          {
12357             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12358             break;
12359          }
12360        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12361          {
12362             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12363             break;
12364          }
12365       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12366          {
12367             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12368             break;
12369          }
12370       default :
12371          break;
12372    }
12373 }
12374
12375 /*******************************************************************
12376  *
12377  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12378  *which recive from CU or storedDrxCfg which is already stored
12379  *
12380  * @details
12381  *
12382  *    Function : extractDrxConfiguration 
12383  *
12384  *    Functionality: Fills Reconfig Cell group Info received by CU
12385  *   
12386  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12387  *                       is send by CU, which we have stored in F1UeContextSetupDb
12388  *             DrxCfg * drxCfg  = Used to Store the information,
12389  *                      which needs to send in other layer, as well as this can be
12390  *                      the variable which stores the information in DuCb,
12391  *             DrxCfg *storedDrxCfg = Null in case of sending the
12392  *                      information to other layer else it will have the drx information 
12393  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12394  *
12395  * @return void
12396  *
12397  * ****************************************************************/
12398 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12399 {
12400    struct DRX_ConfigRrc *cuDrxConfig;
12401
12402    if(storedDrxCfg)
12403    {
12404       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12405    }
12406    else
12407    {
12408       if(cuMacCellGrpDrxConfig)
12409       {
12410          switch(cuMacCellGrpDrxConfig->present)
12411          {
12412             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12413                break;
12414
12415             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12416                {
12417                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12418                   if(cuDrxConfig)
12419                   {
12420                      switch(cuDrxConfig->drx_onDurationTimer.present)
12421                      {
12422                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12423                            break;
12424                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12425                            {
12426                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12427                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12428                               drx_onDurationTimer.choice.milliSeconds);
12429                               break;
12430                            }
12431                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12432                            {
12433                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12434                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12435                               break;
12436                            }
12437                      }
12438                   }
12439                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12440                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12441                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12442                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12443                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12444                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12445                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12446                   if(cuDrxConfig->shortDRX)
12447                   {
12448                      drxCfg->shortDrxPres=true;
12449                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12450                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12451                   }
12452                   else
12453                      drxCfg->shortDrxPres=false;
12454
12455                   break;
12456                }
12457
12458             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12459                break;
12460          }
12461       }
12462    }
12463 }
12464 #endif
12465
12466 /*******************************************************************
12467  *
12468  * @brief Fills Reconfig Cell group Info received by CU
12469  *
12470  * @details
12471  *
12472  *    Function : extractUeRecfgCellInfo
12473  *
12474  *    Functionality: Fills Reconfig Cell group Info received by CU
12475  *   
12476  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12477  *                       is send by CU, which we have stored in F1UeContextSetupDb
12478  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12479  *                      which needs to send in other layer, as well as this can be
12480  *                      the variable which stores the information in DuCb,
12481  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12482  *                      information to other layer else it will have copyOfmacUeCfg
12483  *                      which we have stored in F1UeContextSetupDb.
12484  *
12485  * @return ROK/RFAILED
12486  *
12487  * ****************************************************************/
12488 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12489 {
12490    uint8_t ret = ROK;
12491    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12492    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12493    SpCellConfig_t            *spcellCfg = NULLP;
12494    ServingCellConfig_t       *servCellCfg = NULLP;
12495
12496    if(cellGrp)
12497    {
12498       /* Fill MacCell Group Reconfig  */
12499       if(cellGrp->mac_CellGroupConfig)
12500       {
12501          macUeCfg->macCellGrpCfgPres = true;
12502          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12503
12504 #ifdef NR_DRX         
12505          if(macCellGroup->drx_ConfigRrc)
12506          {
12507             if(storedMacUeCfg)
12508             {
12509                if(!storedMacUeCfg->macCellGrpCfgPres) 
12510                {
12511                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12512                }
12513                else
12514                {
12515                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12516                }
12517             }
12518             else
12519             {
12520                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12521             }
12522          }
12523 #endif
12524
12525          if(macCellGroup->schedulingRequestConfig)
12526          {
12527             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12528          }
12529          if(macCellGroup->tag_Config)
12530          {
12531             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12532          }
12533          if(macCellGroup->bsr_Config)
12534          {
12535             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12536             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12537             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12538             {
12539                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12540                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12541             }
12542          }
12543          if(macCellGroup->phr_Config)
12544          {
12545             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12546             {
12547                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12548                if(macCellGroup->phr_Config->choice.setup)
12549                {
12550                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12551                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12552                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12553                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12554                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12555                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12556                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12557                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12558                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12559                   macCellGroup->phr_Config->choice.setup->dummy;
12560                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12561                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12562                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12563                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12564                }
12565             }
12566          }
12567       }
12568       /* Fill Physical Cell Group Reconfig */
12569       if(cellGrp->physicalCellGroupConfig)
12570       {
12571          macUeCfg->phyCellGrpCfgPres = true;
12572          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12573          if(phyCellGrpCfg->p_NR_FR1)
12574          {
12575             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12576                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12577          }
12578          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12579       }
12580       /* Fill SpCell Reconfig */
12581       if(cellGrp->spCellConfig)
12582       {
12583          macUeCfg->spCellCfgPres = true;
12584          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12585          if(spcellCfg->servCellIndex)
12586          {
12587             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12588          }
12589          /* Fill Serving cell Reconfig info */
12590          if(cellGrp->spCellConfig->spCellConfigDedicated)
12591          {
12592             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12593             if(storedMacUeCfg)
12594             {
12595                if(!storedMacUeCfg->spCellCfgPres)
12596                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12597                else
12598                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12599                         &storedMacUeCfg->spCellCfg.servCellCfg);
12600             }
12601             else
12602             {
12603                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12604             }
12605             if(ret == RFAILED)
12606             {
12607                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12608             }
12609          }
12610       }
12611    }
12612    return ret;
12613 }
12614 /*******************************************************************
12615 *
12616 * @brief free the memory allocated by decoder
12617 *
12618 * @details
12619 *
12620 *    Function : freeAperDecodeNrcgi 
12621 *
12622 *    Functionality: Free Nrcgi values
12623 *
12624 * @params[in] NRCGI_t *nrcgi
12625 * @return void
12626 *
12627 * ****************************************************************/
12628
12629
12630 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12631 {
12632     if(nrcgi->pLMN_Identity.buf != NULLP)
12633     {
12634        free(nrcgi->pLMN_Identity.buf);
12635     }
12636     if(nrcgi->nRCellIdentity.buf != NULLP)
12637     {
12638        free(nrcgi->nRCellIdentity.buf);
12639     }
12640 }
12641 /*******************************************************************
12642 *
12643 * @brief free the memory allocated by decoder
12644 *
12645 * @details
12646 *
12647 *    Function : freeAperDecodeCuToDuInfo 
12648 *
12649 *    Functionality:  Free Cu To Du Information
12650 *
12651 * @params[in] CUtoDURRCInformation_t *rrcMsg
12652 * @return void
12653 *
12654 * ****************************************************************/
12655
12656
12657 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12658 {
12659    uint8_t ieIdx =0;
12660    uint8_t arrIdx =0;
12661
12662    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12663    {
12664       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12665          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12666       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12667    }
12668
12669    if(rrcMsg->iE_Extensions)
12670    {
12671       if(rrcMsg->iE_Extensions->list.array)
12672       {
12673          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12674          {
12675             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12676             {
12677                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12678                {
12679                   case ProtocolIE_ID_id_CellGroupConfig:
12680                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12681                      {
12682                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12683                      }
12684                      break;
12685                   default:
12686                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12687                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12688                      break;
12689                }
12690             }
12691          }
12692          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12693          {
12694             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12695          }
12696          free(rrcMsg->iE_Extensions->list.array);
12697
12698       }
12699
12700       free(rrcMsg->iE_Extensions);
12701    }
12702 }
12703 /*******************************************************************
12704 *
12705 * @brief free the memory allocated by decoder
12706 *
12707 * @details 
12708 *
12709 *    Function : freeAperDecodeSplCellList
12710 *
12711 *    Functionality: Free Spl Cell List 
12712                     where memory allocated by aper_decoder
12713 *
12714 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12715 * @return void
12716 *
12717 * ****************************************************************/
12718
12719
12720 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12721 {
12722     uint8_t  cellIdx =0;
12723
12724     if(spCellLst->list.array != NULLP)
12725     {
12726        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12727        {
12728           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12729           {
12730              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12731           }
12732           if(spCellLst->list.array[cellIdx]!=NULLP)
12733           {
12734              free(spCellLst->list.array[cellIdx]);
12735           }
12736        }
12737        free(spCellLst->list.array);
12738     }
12739 }
12740 /*******************************************************************
12741 *
12742 * @brief free the memory allocated by decoder
12743 *
12744 * @details
12745 *
12746 *    Function : freeAperDecodeSRBSetup 
12747 *
12748 *    Functionality: added free part for the memory allocated by aper_decoder
12749 *
12750 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12751 * @return void
12752 *
12753 ****************************************************************/
12754
12755
12756 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12757 {
12758     uint8_t srbIdx =0;
12759     if(srbSet->list.array != NULLP)
12760     {
12761        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12762        {
12763           if(srbSet->list.array[srbIdx]!=NULLP)
12764           {
12765              free(srbSet->list.array[srbIdx]);
12766           }
12767        }
12768        free(srbSet->list.array);
12769     }
12770 }
12771
12772 /*******************************************************************
12773 *
12774 * @brief free the memory allocated by decoder
12775 *
12776 * @details
12777 *
12778 *    Function : freeAperDecodeULTnlInfo
12779 *
12780 *    Functionality: added free part for the memory allocated by aper_decoder
12781 *
12782 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12783 * @return void
12784 *
12785 * ****************************************************************/
12786
12787
12788 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12789 {
12790    uint8_t ulIdx=0;
12791    if(ulInfo->list.array != NULLP)
12792    {
12793       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12794       {
12795          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12796          {
12797             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12798             {
12799                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12800                      transportLayerAddress.buf != NULLP)
12801                {
12802                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12803                         !=NULLP)
12804                   {
12805                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12806                   }
12807                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12808                         transportLayerAddress.buf);
12809                }
12810                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12811             }
12812          }
12813          if(ulInfo->list.array[ulIdx]!=NULLP)
12814          {
12815             free(ulInfo->list.array[ulIdx]);
12816          }
12817       }
12818       free(ulInfo->list.array);
12819    }
12820 }
12821 /*******************************************************************
12822 *
12823 * @brief free the memory allocated by decoder
12824 *
12825 * @details
12826 *
12827 *    Function : freeAperDecodeDRBSetup  
12828 *
12829 *    Functionality: free DRBSetup which is allocated by decoder
12830 *
12831 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12832 * @return void
12833 *
12834 * ****************************************************************/
12835
12836 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12837 {
12838    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12839    uint8_t  flowIdx =0;
12840    uint8_t  drbIdx =0;
12841
12842    if(drbSet->list.array != NULLP)
12843    {
12844       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12845       {
12846          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12847          {
12848             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12849             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12850             {
12851                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12852                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12853                {
12854                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12855                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12856                   {
12857                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12858                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12859                      {
12860
12861                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12862                         {
12863
12864                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12865                            {
12866
12867                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12868                                     buf!=NULLP)
12869                               {
12870
12871                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12872                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12873                                  {
12874
12875                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12876                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12877                                     {
12878
12879                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12880                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12881                                        {
12882                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12883                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12884                                                 qoSFlowLevelQoSParameters.\
12885                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12886                                           {
12887                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12888                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12889                                                    qoSFlowLevelQoSParameters.\
12890                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12891                                              {
12892
12893                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12894                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12895                                                       qoSFlowLevelQoSParameters.\
12896                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12897                                                 {
12898
12899
12900                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12901                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12902                                                          qoSFlowLevelQoSParameters.\
12903                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12904                                                 }
12905
12906                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12907                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12908                                                       qoSFlowLevelQoSParameters.\
12909                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12910                                              }
12911
12912                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12913
12914                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12915                                                    qoSFlowLevelQoSParameters.\
12916                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12917                                           }
12918                                        }
12919                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12920                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12921                                        {
12922
12923                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12924                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12925                                        }
12926                                     }
12927
12928                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12929                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12930                                  }
12931
12932                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12933                                        DRB_Information.sNSSAI.sD->buf);
12934                               }
12935
12936                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12937                            }
12938
12939                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12940
12941                         }
12942
12943                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12944
12945                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12946                      }
12947
12948                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12949                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12950                   }
12951
12952                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12953                         qoS_Characteristics.choice.non_Dynamic_5QI);
12954                }
12955                free(drbSetItem->qoSInformation.choice.choice_extension);
12956             }
12957             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12958             if(drbSetItem->uLConfiguration)
12959             {
12960                free(drbSetItem->uLConfiguration);
12961             }
12962          }
12963          if(drbSet->list.array[drbIdx]!=NULLP)
12964          {
12965             free(drbSet->list.array[drbIdx]);
12966          }
12967       }
12968       free(drbSet->list.array);
12969    }
12970 }
12971
12972
12973 /*******************************************************************
12974  *
12975  * @brief builds Mac Cell Cfg
12976  *
12977  * @details
12978  *
12979  *    Function : procUeRecfgCellInfo
12980  *
12981  *    Functionality: builds Mac Cell Cfg
12982  *
12983  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12984  *                       needs to send in other layer, as well as this can be
12985  *                       the variable which stores the information in DuCb.
12986  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12987  *                       information to other layer else it will have copyOfmacUeCfg  
12988  *                       which we have stored in F1UeContextSetupDb
12989  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12990  *                        by CU, which we have stored in F1UeContextSetupDb 
12991  *
12992  * @return void 
12993  *
12994  * ****************************************************************/
12995 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12996 {
12997    uint8_t ret = ROK;
12998    CellGroupConfigRrc_t *cellGrp = NULLP;
12999
13000    if(cellInfo)
13001    {
13002       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13003       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13004       if(ret == RFAILED)
13005          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13006    }
13007    if(ret == RFAILED)
13008    {
13009       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13010    }
13011    return ret;
13012 }
13013
13014 /*******************************************************************
13015  *
13016  * @brief Filling modulation info in mac ue cfg
13017  *
13018  * @details
13019  *
13020  *    Function : duFillModulationDetails
13021  *
13022  *    Functionality: Filling modulation info in mac ue cfg
13023  *
13024  * @params[in] MAC UE Config to be updated
13025  *             Current UE configuration
13026  *             UE NR capability from CU
13027  * @return ROK     - success
13028  *         RFAILED - failure
13029  *
13030  * ****************************************************************/
13031 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13032 {
13033    UE_NR_Capability_t *ueNrCap=NULLP;
13034
13035    if(!ueCap && oldUeCfg)
13036    {
13037       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13038       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13039    }
13040    else
13041    {
13042       ueNrCap = (UE_NR_Capability_t *)ueCap;
13043
13044       /* Filling DL modulation info */
13045       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13046          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13047          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13048       {
13049          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13050          {
13051             case ModulationOrder_qpsk:
13052                {
13053                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13054                   break;
13055                }
13056             case ModulationOrder_qam16:
13057                {
13058                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13059                   break;
13060                }
13061             case ModulationOrder_qam64:
13062                {
13063                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13064                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13065                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13066                   break;
13067                }
13068             case ModulationOrder_qam256:
13069                {
13070                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13071                   break;
13072                }
13073             default:
13074                {
13075                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13076                   if(oldUeCfg)
13077                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13078                   break;
13079                }
13080          }
13081       }
13082       else
13083       {
13084          if(oldUeCfg)
13085             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13086       }
13087
13088       /* Filling UL modulation info */
13089       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13090          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13091          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13092       {
13093          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13094          {
13095             case ModulationOrder_qpsk:
13096                {
13097                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13098                   break;
13099                }
13100             case ModulationOrder_qam16:
13101                {
13102                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13103                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13104                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13105                   break;
13106                }
13107             case ModulationOrder_qam64:
13108                {
13109                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13110                   break;
13111                }
13112             case ModulationOrder_qam256:
13113                {
13114                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13115                   break;
13116                }
13117             default:
13118                {
13119                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13120                   if(oldUeCfg)
13121                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13122                   break;
13123                }
13124          }
13125       }
13126       else
13127       {
13128          if(oldUeCfg)
13129             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13130       }
13131    }
13132 }
13133
13134 /*******************************************************************
13135  *
13136  * @brief Function to extract info from CU to DU RRC container extension
13137  *
13138  * @details
13139  *
13140  *    Function : extractCuToDuRrcInfoExt
13141  *
13142  *    Functionality: Function to extract info from CU to DU RRC container
13143  *    extension
13144  *
13145  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13146  *
13147  * @return ROK
13148  *         RFAILED
13149  *
13150  * ****************************************************************/
13151 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13152 {
13153    uint8_t ieIdx =0;
13154    uint16_t recvBufLen =0;
13155    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13156    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13157    asn_dec_rval_t rval; /* Decoder return value */
13158    memset(&rval, 0, sizeof(asn_dec_rval_t));
13159
13160    if(protocolIeExtn)
13161    {
13162       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13163       {
13164          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13165          switch(extIeInfo->id)
13166          {
13167             case ProtocolIE_ID_id_CellGroupConfig:
13168                {
13169                   /* decoding the CellGroup Buf received */
13170                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13171                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13172                   if(cellGrpCfg)
13173                   {
13174                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13175                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13176                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13177                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13178                      {
13179                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13180                         return RFAILED;
13181                      }
13182                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13183
13184                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13185                         return NULLP;
13186                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13187                   }
13188                   break;
13189                }
13190
13191             case ProtocolIE_ID_id_HandoverPreparationInformation:
13192                {
13193                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13194                   break;
13195                }
13196
13197             default:
13198                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13199                break;
13200          }
13201       }
13202    }
13203    return ROK;
13204 }
13205
13206 /*******************************************************************
13207  *
13208  * @brief Fills Srb List received by CU
13209  *
13210  * @details
13211  *
13212  *    Function : procSrbListToSetup
13213  *
13214  *    Functionality: Fills Srb List received  by CU
13215  *
13216  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13217  *             DuLcCfg pointer
13218  *             RlcBearerCfg pointer
13219  * @return void
13220  *
13221  * ****************************************************************/
13222 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13223 {
13224
13225    /* Filling RLC INFO */
13226    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13227
13228    /* Filling MAC INFO */
13229    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13230    { 
13231       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13232       return RFAILED;
13233    }
13234
13235    return ROK;
13236 }
13237
13238
13239
13240 /*******************************************************************
13241  *
13242  * @brief extract Srb List received by CU
13243  *
13244  * @details
13245  *
13246  *    Function : extractSrbListToSetup
13247  *
13248  *    Functionality: extract Srb List received by CU
13249  *                   for both MAC and RLC
13250  *
13251  * @params[in] SRBs_ToBeSetup_Item_t pointer
13252  *             DuUeCfg pointer
13253  * @return ROK/RFAIED
13254  *
13255  * ****************************************************************/
13256
13257 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13258 {
13259    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13260    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13261    DuLcCfg *macLcCtxt = NULLP;
13262    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13263
13264    if(srbCfg)
13265    {
13266       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13267       {
13268          macLcCtxt = NULL;
13269          rlcLcCtxt = NULL;
13270
13271          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13272          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13273          { 
13274             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13275             ret = RFAILED;
13276             break;
13277          }
13278          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13279          {
13280             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13281             ret = RFAILED;
13282             break;
13283          }
13284
13285          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13286          {
13287             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13288             {
13289                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13290                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13291                break;
13292             }
13293          }
13294          if(!macLcCtxt)
13295          {
13296             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13297             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13298             ueCfgDb->numMacLcs++;
13299          }
13300          if(!rlcLcCtxt)
13301          {
13302             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13303             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13304             ueCfgDb->numRlcLcs++;
13305          }
13306
13307          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13308
13309          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13310                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13311          if(ret == RFAILED)
13312          {
13313             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13314             break;
13315          }
13316       }
13317    }
13318    else
13319       ret = RFAILED;
13320
13321    return ret;
13322 }
13323
13324 /*******************************************************************
13325  *
13326  * @brief Fills Drb List received by CU
13327  *
13328  * @details
13329  *
13330  *    Function : procDrbListToSetupMod
13331  *
13332  *    Functionality: Fills Drb List received by CU
13333  *                   for both MAC and RLC
13334  *
13335  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13336  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13337  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13338  * @return void
13339  *
13340  * ****************************************************************/
13341
13342 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13343 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13344 {
13345    uint8_t cfgIdx = 0;
13346    RlcMode rlcModeInfo;
13347
13348    if(drbItem != NULLP)
13349    {
13350       /* Filling RLC INFO */
13351       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13352       qoSInformation);
13353
13354       /* Filling MAC INFO */
13355       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13356       { 
13357          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13358          return RFAILED;
13359       }
13360    }
13361    else if(drbSetupModItem != NULLP)
13362    {
13363       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13364       &drbSetupModItem->qoSInformation);
13365
13366       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13367       {
13368          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13369          return RFAILED;
13370       }
13371    }
13372    else if(drbModItem != NULLP)
13373    {
13374       /* Drb to Mod IEs doesnot have rlcMode to be modified
13375        * in ASN. Hence no change in RLC configurations */
13376       if(storedRlcUeCfg != NULLP)
13377       {
13378          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13379          {
13380             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13381             {
13382                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13383                break;
13384             }
13385          }
13386       }
13387
13388       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13389       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13390       {
13391          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13392          return RFAILED;
13393       }
13394    }
13395    return ROK;
13396 }
13397
13398 /*******************************************************************
13399  *
13400  * @brief extract Drb List received by CU
13401  *
13402  * @details
13403  *
13404  *    Function : extractDrbListToSetupMod
13405  *
13406  *    Functionality: extract Drb List received by CU
13407  *                   for both MAC and RLC
13408  *
13409  * @params[in] DRBs_ToBeSetup_Item_t pointer
13410  *             DuUeCfg pointer
13411  * @return ROK/RFAIED
13412  *
13413  * ****************************************************************/
13414
13415 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13416  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13417 {
13418    uint8_t ret = ROK;
13419    uint8_t drbIdx = 0, rlcLcIdx = 0;
13420    uint8_t drbId = 0, lcId = 0;
13421    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13422    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13423    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13424    DuLcCfg *macLcCtxt = NULLP;
13425    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13426
13427    ret = ROK;
13428    if(drbCount > 0)
13429    {
13430       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13431       {
13432          macLcCtxt = NULL;
13433          rlcLcCtxt = NULL;
13434
13435          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13436          { 
13437             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13438             ret = RFAILED;
13439             break;
13440          }
13441          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13442          {
13443             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13444             ret = RFAILED;
13445             break;
13446          }
13447
13448          if(drbModCfg != NULLP)
13449          {
13450             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13451             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13452          }
13453          else if(drbCfg != NULLP)
13454             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13455          else if(drbSetupModCfg != NULL)
13456          {
13457             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13458             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13459          }
13460
13461          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13462          {
13463             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13464                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13465             {
13466                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13467                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13468                break;
13469             }
13470          }
13471          if(!macLcCtxt)
13472          {
13473             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13474             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13475             ueCfgDb->numMacLcs++;
13476          }
13477          if(!rlcLcCtxt)
13478          {
13479             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13480             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13481             ueCfgDb->numRlcLcs++;
13482          }
13483
13484          if(drbModCfg != NULLP)
13485          {
13486             lcId = fetchLcId(drbId);
13487             if(lcId < MIN_DRB_LCID)
13488             {
13489                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13490                break;
13491             } 
13492             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13493             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13494             if(ret == RFAILED)
13495             {
13496                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13497                break;
13498             }
13499             ueCfgDb->numDrbModified++;
13500          }
13501          else
13502          {
13503             lcId = getDrbLcId(drbBitMap);
13504             if(lcId == RFAILED)
13505             {
13506                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13507                ret = RFAILED;
13508                break;
13509             }
13510             if(drbCfg != NULL)
13511             {
13512                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13513                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13514                if(ret == RFAILED)
13515                {
13516                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13517                   break;
13518                }
13519             }
13520             else if(drbSetupModCfg != NULL)
13521             {
13522                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13523                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13524                if(ret == RFAILED)
13525                {
13526                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13527                   break;
13528                }
13529                ueCfgDb->numDrbSetupMod++;
13530             }
13531          }
13532          ueCfgDb->numDrb++;
13533  
13534          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13535                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13536          if(ret == RFAILED)
13537          {
13538             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13539             break;
13540          }
13541       }
13542    }
13543    else
13544       ret = RFAILED;
13545
13546    return ret;
13547 }
13548
13549 /*******************************************************************
13550  *
13551  * @brief extract Drb List received from CU
13552  *
13553  * @details
13554  *
13555  *    Function : extractDrbListToRelease
13556  *
13557  *    Functionality: extract Drb List received from CU
13558  *                   for both MAC and RLC
13559  *
13560  * @params[in] DRBs_ToBeReleased_Item_t pointer
13561  *             DuUeCfg pointer
13562  * @return ROK/RFAIED
13563  *
13564  * ****************************************************************/
13565
13566 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13567 {
13568    uint8_t ret = ROK, teIdx = 0;
13569    uint8_t drbIdx = 0, rlcLcIdx = 0;
13570    uint8_t drbId = 0, lcId = 0;
13571    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13572    DuLcCfg *macLcCtxt = NULLP;
13573    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13574
13575    ret = ROK;
13576    if(drbCount > 0)
13577    {
13578       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13579       {
13580          macLcCtxt = NULL;
13581          rlcLcCtxt = NULL;
13582
13583          if(drbToRel != NULLP)
13584          {
13585             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13586             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13587          }
13588          else
13589          {
13590             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13591             return RFAILED;
13592          }
13593
13594          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13595          {
13596             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13597             {
13598                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13599                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13600                break;
13601             }
13602          }
13603
13604          if(!macLcCtxt)
13605          {
13606             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13607             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13608             ueCfgDb->numMacLcs++;
13609          }
13610          if(!rlcLcCtxt)
13611          {
13612             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13613             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13614             ueCfgDb->numRlcLcs++;
13615          }
13616          lcId = fetchLcId(drbId);
13617          if(lcId < MIN_DRB_LCID)
13618          {
13619             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13620             break;
13621          } 
13622
13623          /* Filling RLC INFO */
13624          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13625          /* Filling MAC INFO */
13626          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13627          { 
13628             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13629             return RFAILED;
13630          }
13631          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13632          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13633          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13634
13635          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13636          {
13637             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13638                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13639             {
13640                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13641                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13642                break;
13643             }
13644          }
13645
13646          ueCfgDb->numDrb++;
13647          if(ret == RFAILED)
13648          {
13649             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13650             break;
13651          }
13652
13653          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13654                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13655       }
13656    }
13657    else
13658       ret = RFAILED;
13659
13660    return ret;
13661 }
13662
13663 /*******************************************************************
13664  *
13665  * @brief Function to extract Dl RRC Msg received from CU
13666  *
13667  * @details
13668  *
13669  *    Function : extractDlRrcMsg
13670  *
13671  *    Functionality: Function to extract Dl RRC Msg received from CU
13672  *
13673  * @params[in] F1AP message
13674  * @return ROK     - success
13675  *         RFAILED - failure
13676  *
13677  * ****************************************************************/
13678
13679 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13680    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13681 {
13682    uint8_t ret = ROK;
13683    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13684    if(dlRrcMsg->rrcMsgSize > 0)
13685    {
13686       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13687       if(!dlRrcMsg->rrcMsgPdu)
13688       {
13689          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13690          ret = RFAILED;
13691       }
13692       else
13693       {
13694          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13695          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13696          dlRrcMsg->srbId = SRB1_LCID;
13697          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13698       }
13699    }
13700    return ret;
13701 }
13702
13703 /*******************************************************************
13704  *
13705  * @brief Extract UE capability info 
13706  *
13707  * @details
13708  *
13709  *    Function : extractUeCapability
13710  *
13711  *    Functionality: Extract UE capability info and stores in ue Cb
13712  *
13713  * @params[in] Octet string of UE capability RAT container list
13714  * @return ROK     - success
13715  *         RFAILED - failure
13716  *
13717  * ****************************************************************/
13718 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13719 {
13720    uint8_t  idx;
13721    uint16_t recvBufLen;
13722    asn_dec_rval_t rval;
13723    UE_NR_Capability_t  *ueNrCap = NULLP;
13724    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13725
13726    /* Decoding UE Capability RAT Container List */
13727    recvBufLen = ueCapablityListBuf->size;
13728    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13729    if(!ueCapRatContList)
13730    {
13731       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13732       return NULLP;
13733    }
13734    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13735    memset(&rval, 0, sizeof(asn_dec_rval_t));
13736    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13737           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13738    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13739    {
13740       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13741       return NULLP;
13742    }
13743    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13744
13745    /* Free encoded buffer after decoding */
13746
13747    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13748    {
13749       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13750       {
13751          /* Decoding UE NR Capability */
13752           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13753           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13754           if(!ueNrCap)
13755           {
13756              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13757              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13758              return NULLP;
13759           } 
13760           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13761           memset(&rval, 0, sizeof(asn_dec_rval_t));
13762           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13763                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13764           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13765           {
13766              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13767              return NULLP;
13768           }
13769           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13770           
13771           /* Free encoded buffer after decoding */
13772           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13773       }
13774       free(ueCapRatContList->list.array[idx]);
13775    }
13776
13777    /* Free Memory*/
13778    free(ueCapRatContList->list.array);
13779    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13780    return ueNrCap;
13781 }
13782  
13783 /*******************************************************************
13784 *
13785 * @brief free UE context setup request from CU
13786 *
13787 * @details
13788 *
13789 *    Function : freeAperDecodeF1UeContextSetupReq
13790 *
13791 *    Functionality: freeing part for the memory allocated by aper_decoder
13792 *
13793 * @params[in] F1AP message
13794 * @return ROK     - success
13795 *         RFAILED - failure
13796 *
13797 * ****************************************************************/
13798 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13799 {
13800    uint8_t ieIdx = 0;
13801
13802    if(ueSetReq->protocolIEs.list.array != NULLP)
13803    {
13804       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13805       {
13806          if(ueSetReq->protocolIEs.list.array[ieIdx])
13807          {
13808             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13809             {
13810                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13811                   break;
13812                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13813                   break;
13814                case ProtocolIE_ID_id_SpCell_ID:
13815                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13816                   break;
13817                case ProtocolIE_ID_id_ServCellIndex:
13818                   break;
13819                case ProtocolIE_ID_id_SpCellULConfigured:
13820                   break;
13821                case ProtocolIE_ID_id_CUtoDURRCInformation:
13822
13823                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13824                   break;
13825                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13826
13827                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13828                   break;
13829                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13830
13831                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13832                   break;
13833                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13834
13835                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13836                   break;
13837                case ProtocolIE_ID_id_RRCContainer:
13838                   {
13839
13840                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13841                      {
13842
13843                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13844                      }
13845                      break;
13846                   }
13847                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13848                   break;
13849                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13850                   {
13851                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13852                      {
13853                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13854                      }
13855                      break;
13856                   }
13857 #ifdef NR_DRX
13858                case ProtocolIE_ID_id_DRXCycle:
13859                   {
13860                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13861                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13862                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13863                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13864                      break;
13865                   }
13866 #endif             
13867                 default:
13868                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13869             } 
13870             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13871          }
13872       }
13873       free(ueSetReq->protocolIEs.list.array);
13874    }
13875 }
13876 /*******************************************************************
13877  *
13878  * @brief Process UE context setup request from CU
13879  *
13880  * @details
13881  *
13882  *    Function : procF1UeContextSetupReq
13883  *
13884  *    Functionality: Process UE context setup request from CU
13885  *
13886  * @params[in] F1AP message
13887  * @return ROK     - success
13888  *         RFAILED - failure
13889  *
13890  * ****************************************************************/
13891 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13892 {
13893    int8_t ueIdx = -1;
13894    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13895    //uint8_t servCellIdx = 0;
13896    bool ueCbFound = false, hoInProgress = false;
13897    uint16_t cellIdx=0;
13898    uint64_t nrCellId = 0;
13899    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13900    DuUeCb   *duUeCb = NULL;
13901    UEContextSetupRequest_t   *ueSetReq = NULL;
13902    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13903    CUtoDURRCInformation_t *rrcInfo = NULL;
13904 #ifdef NR_DRX
13905    DRXCycle_t *drxCycle;
13906 #endif
13907    ret = ROK;
13908
13909    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13910    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13911    {
13912       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13913       {
13914          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13915             {
13916                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13917                break;
13918             }
13919
13920          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13921             {
13922                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13923                break;
13924             }
13925
13926          case ProtocolIE_ID_id_SpCell_ID:
13927             {
13928                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13929
13930                GET_CELL_IDX(nrCellId, cellIdx);
13931                if(!duCb.actvCellLst[cellIdx])
13932                {
13933                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13934                   ret = RFAILED;
13935                }
13936                break;
13937             }
13938
13939          case ProtocolIE_ID_id_ServCellIndex:
13940             {
13941                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13942                break;
13943             }
13944
13945          case ProtocolIE_ID_id_SpCellULConfigured:
13946             {
13947                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13948                   UL, SUL or UL+SUL for the indicated cell for the UE */
13949                break;
13950             }
13951
13952          case ProtocolIE_ID_id_CUtoDURRCInformation:
13953             {
13954                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13955
13956                /* Search if UE context is present */
13957                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13958                {
13959                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13960                   {
13961                      ueCbFound = true;
13962                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13963                      break;
13964                   }
13965                }
13966
13967                /* Check if UE Handover scenario */
13968                if(rrcInfo->iE_Extensions)
13969                {
13970                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13971                   {
13972                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13973                      {
13974                         hoInProgress = true;
13975                         break;
13976                      }
13977                   }
13978                }
13979                
13980                /* If UE context is not present, but UE is in handover */
13981                if(!ueCbFound && hoInProgress)
13982                {
13983                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13984                   if(ueIdx != -1)
13985                      gnbDuUeF1apId = ueIdx +1;
13986                   else
13987                   {
13988                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13989                      ret = RFAILED;
13990                      break;
13991                   }
13992                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13993                   duUeCb->f1UeDb = NULL;
13994                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13995                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13996                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13997                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13998                }
13999
14000                if(duUeCb)
14001                {
14002                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14003                   if(duUeCb->f1UeDb)
14004                   {
14005                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14006                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14007                      duUeCb->f1UeDb->cellIdx = cellIdx;
14008                   }
14009                   else
14010                   {
14011                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14012                      ret = RFAILED;
14013                      break;
14014                   }
14015                }
14016                else
14017                {
14018                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14019                   ret = RFAILED;
14020                   break;
14021                }
14022                  
14023                /* Extract UE capability info */
14024                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14025                {
14026                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14027                }
14028
14029                /* Extract IE extension */
14030                if(rrcInfo->iE_Extensions)
14031                {
14032                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14033                   {
14034                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14035                      //TODO: Update the failure cause in ue context Setup Response
14036                      ret = RFAILED;
14037                   }
14038                }
14039                break;
14040             } 
14041
14042 #ifdef NR_DRX
14043          case ProtocolIE_ID_id_DRXCycle:
14044             {
14045                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14046                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14047                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14048                if(drxCycle->shortDRXCycleLength)
14049                {
14050                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14051                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14052                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14053                }
14054                if(drxCycle->shortDRXCycleTimer)
14055                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14056
14057                break;
14058             }
14059
14060 #endif
14061          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14062             {
14063                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14064                         &duUeCb->f1UeDb->duUeCfg))
14065                {
14066                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14067                   //TODO: Update the failure cause in ue context Setup Response
14068                   ret = RFAILED;
14069                }
14070                break;
14071             }
14072
14073          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14074             {
14075                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14076
14077                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14078                {
14079                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14080                   //TODO: Update the failure cause in ue context Setup Response
14081                   ret = RFAILED;
14082                }
14083                break;
14084             }
14085          case ProtocolIE_ID_id_RRCContainer:
14086             {
14087                /* Filling Dl RRC Msg Info */
14088                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14089                if(!duUeCb->f1UeDb->dlRrcMsg)
14090                {
14091                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14092                   ret = RFAILED;
14093                }
14094                else
14095                {
14096                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14097                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14098                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14099                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14100                }          
14101                break;
14102             }
14103
14104          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14105             {
14106                if(duUeCb->f1UeDb->dlRrcMsg)
14107                {
14108                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14109                   {
14110                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14111                   }
14112                   else
14113                   {
14114                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14115                   }
14116                }
14117                break;
14118             }
14119
14120          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14121             {
14122                /* MaximumBitRate Uplink */
14123                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14124                if(bitRateSize > 0)
14125                {
14126                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14127                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14128                   {
14129                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14130                      ret = RFAILED;
14131                   }
14132                   else
14133                   {
14134                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14135                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14136                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14137                   }
14138                }
14139                else
14140                   ret = RFAILED;
14141                break;
14142             }
14143
14144          default:
14145             {
14146                break;
14147             }
14148       } /* End of switch */
14149
14150       /* In case of any failure in any IE */
14151       if(ret == RFAILED)
14152       {
14153          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14154          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14155          break;
14156       }
14157    } /* End of for loop of IEs */
14158
14159    if(ret == ROK)
14160       ret = duProcUeContextSetupRequest(duUeCb);
14161
14162    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14163    return ret;
14164
14165 }
14166 /*******************************************************************
14167  * @brief Free the memory allocated for Dl Tunnel Info
14168  *
14169  * @details
14170  *
14171  *    Function : freeDlTnlInfo
14172  *
14173  *    Functionality:
14174  *       Free the memory allocated for Dl Tunnel Info
14175  *
14176  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14177  * @return void
14178  *
14179  * ****************************************************************/
14180
14181 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14182 {
14183    uint8_t arrIdx = 0;
14184
14185    if(tnlInfo)
14186    {
14187       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14188       {
14189          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14190                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14191          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14192                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14193          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14194          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14195       }
14196       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14197    }
14198 }
14199
14200 /*******************************************************************
14201  * @brief Free the memory allocated for DRB setup List
14202  *
14203  * @details
14204  *
14205  *    Function : freeDrbSetupList
14206  *
14207  *    Functionality:
14208  *       Free the memory allocated for DRB setup list
14209  *
14210  * @params[in] DRBs_Setup_List_t *
14211  * @return void
14212  *
14213  * ****************************************************************/
14214 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14215 {
14216    uint8_t arrIdx = 0;
14217    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14218
14219    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14220    {
14221       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14222       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14223       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14224    }
14225    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14226 }
14227
14228 /*******************************************************************
14229  * @brief Free the memory allocated for UE Setup response
14230  *
14231  * @details
14232  *
14233  *    Function : FreeUeContextSetupRsp
14234  *
14235  *    Functionality:
14236  *       Free the memory allocated for UE Setup response
14237  *
14238  * @params[in] F1AP PDU for UE setup response
14239  * @return ROK     - success
14240  *         RFAILED - failure
14241  *
14242  * ****************************************************************/
14243 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14244 {
14245    uint8_t idx;
14246    UEContextSetupResponse_t *ueSetRsp = NULLP;
14247
14248    if(f1apMsg)
14249    {
14250       if(f1apMsg->choice.successfulOutcome)
14251       {
14252          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14253                     UEContextSetupResponse;
14254          if(ueSetRsp->protocolIEs.list.array)
14255          {
14256             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14257             {
14258                if(ueSetRsp->protocolIEs.list.array[idx])
14259                {
14260                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14261                   {
14262                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14263                         break;
14264                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14265                         break;
14266                      case ProtocolIE_ID_id_C_RNTI:
14267                         break;
14268                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14269                         {
14270                            CellGroupConfig_t *cellGrpCfg = NULLP;
14271                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14272                                          DUtoCURRCInformation.cellGroupConfig;
14273                            if(cellGrpCfg->buf != NULLP)
14274                            {
14275                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14276                               cellGrpCfg = NULLP;
14277                            }
14278                            break;
14279                         }
14280                      case ProtocolIE_ID_id_DRBs_Setup_List:
14281                         {
14282                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14283                            break;
14284                         }
14285                      default:
14286                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14287                               ueSetRsp->protocolIEs.list.array[idx]->id);
14288                         break;
14289                   }
14290                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14291                         sizeof(UEContextSetupResponseIEs_t));
14292                }
14293             }
14294             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14295                   ueSetRsp->protocolIEs.list.size);
14296          }
14297          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14298       }
14299       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14300    }
14301 }
14302
14303 /*******************************************************************
14304  *
14305  * @brief Builds Ue context Setup Rsp DU To CU Info
14306  *
14307  * @details
14308  *
14309  *    Function : EncodeUeCntxtDuToCuInfo
14310  *
14311  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14312  *
14313  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14314  *
14315  * @return ROK     - success
14316  *         RFAILED - failure
14317  *
14318  ******************************************************************/
14319
14320 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14321 {
14322    asn_enc_rval_t        encRetVal;
14323
14324    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14325    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14326    encBufSize = 0;
14327    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14328    /* Encode results */
14329    if(encRetVal.encoded == ENCODE_FAIL)
14330    {
14331       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14332             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14333       return RFAILED;
14334    }
14335    else
14336    {
14337       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14338 #ifdef DEBUG_ASN_PRINT
14339       for(int i=0; i< encBufSize; i++)
14340       {
14341          printf("%x",encBuf[i]);
14342       }
14343 #endif
14344    }
14345    duToCuCellGrp->size = encBufSize;
14346    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14347    if(!duToCuCellGrp->buf)
14348    {
14349       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14350    }
14351    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14352    return ROK;
14353 }
14354
14355 /*******************************************************************
14356  *
14357  * @brief Fills Dl Gtp tunnel Info
14358  *
14359  * @details
14360  *
14361  *    Function : fillGtpTunnelforDl
14362  *
14363  *    Functionality: Fills Dl Gtp tunnel Info
14364  *
14365  * @params[in] 
14366  *
14367  * @return ROK     - success
14368  *         RFAILED - failure
14369  *
14370  * ****************************************************************/
14371
14372 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14373 {
14374    uint8_t bufSize = 0;
14375
14376    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14377    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14378    if(gtpDl->transportLayerAddress.buf == NULLP)
14379    {
14380       return RFAILED;
14381    }
14382    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14383
14384    /*GTP TEID*/
14385    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14386    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14387    if(gtpDl->gTP_TEID.buf == NULLP)
14388    {
14389       return RFAILED;
14390    }
14391    bufSize = 3; /*forming an Octect String*/
14392    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14393
14394    return ROK;
14395 }
14396
14397 /*******************************************************************
14398  *
14399  * @brief Fills DL Tunnel Setup List
14400  *
14401  * @details
14402  *
14403  *    Function : fillDlTnlSetupList
14404  *
14405  *    Functionality: Fills the DL Tunnel Setup List
14406  *
14407  * @params[in] 
14408  *
14409  * @return ROK     - success
14410  *         RFAILED - failure
14411  *
14412  * ****************************************************************/
14413
14414 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14415 {
14416    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14417
14418    eleCount = 1;
14419    dlTnlInfo->list.count = eleCount; 
14420    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14421
14422    /* Initialize the DL Tnl Setup List Members */
14423    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14424    if(dlTnlInfo->list.array == NULLP)
14425    {
14426       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14427       ret = RFAILED;
14428    }
14429    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14430    {
14431       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14432       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14433       {
14434          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14435          return RFAILED;
14436       }
14437       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14438       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14439       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14440       {
14441          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14442          return RFAILED;
14443       }
14444       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14445                tnlCfg->tnlCfg1);
14446       if(ret != ROK)
14447          break;
14448    }
14449    return ret;
14450 }
14451
14452 /*******************************************************************
14453  *
14454  * @brief Fills the Drb Setup List for Ue Context Setup Response
14455  *
14456  * @details
14457  *
14458  *    Function : fillDrbSetupList
14459  *
14460  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14461  *
14462  * @params[in] 
14463  *
14464  * @return ROK     - success
14465  *         RFAILED - failure
14466  *
14467  * ****************************************************************/
14468 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14469 {
14470    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14471    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14472
14473    eleCount = ueCfg->numDrb;
14474    drbSetupList->list.count = eleCount;
14475    drbSetupList->list.size = \
14476         (eleCount * sizeof(DRBs_Setup_Item_t *));
14477
14478    /* Initialize the Drb Setup List Members */
14479    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14480    if(drbSetupList->list.array == NULLP)
14481    {
14482       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14483       ret = RFAILED;
14484    }
14485
14486    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14487    {
14488       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14489       if(drbSetupList->list.array[arrIdx] == NULLP)
14490       {
14491          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14492          return RFAILED;
14493       }
14494       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14495       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14496       drbItemIe->criticality = Criticality_reject;
14497       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14498       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14499       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14500           &ueCfg->upTnlInfo[arrIdx]);
14501       if(ret != ROK)
14502          break;
14503    }
14504    return ret;
14505 }
14506
14507 /*******************************************************************
14508  *
14509  * @brief Builds and sends the UE Setup Response
14510  *
14511  * @details
14512  *
14513  *    Function : BuildAndSendUeContextSetupRsp
14514  *
14515  *    Functionality: Constructs the UE Setup Response and sends
14516  *                   it to the DU through SCTP.
14517  *
14518  * @params[in] uint8_t cellId,uint8_t ueId
14519  *
14520  * @return ROK     - success
14521  *         RFAILED - failure
14522  *
14523  * ****************************************************************/
14524 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14525 {
14526    uint8_t   idx, ret, cellIdx, elementCnt;
14527    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14528    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14529    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14530    F1AP_PDU_t               *f1apMsg = NULLP;
14531    UEContextSetupResponse_t *ueSetRsp = NULLP;
14532    DuUeCb                   *ueCb = NULLP;
14533
14534    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14535
14536    while(true)
14537    {
14538       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14539       if(f1apMsg == NULLP)
14540       {
14541          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14542          ret = RFAILED;
14543          break;
14544       }
14545
14546       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14547       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14548             sizeof(SuccessfulOutcome_t));
14549       if(f1apMsg->choice.successfulOutcome == NULLP)
14550       {
14551          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14552          ret = RFAILED;
14553          break;
14554       }
14555
14556       f1apMsg->choice.successfulOutcome->procedureCode = \
14557                                                          ProcedureCode_id_UEContextSetup;
14558       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14559       f1apMsg->choice.successfulOutcome->value.present = \
14560                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14561
14562       ueSetRsp =
14563          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14564       elementCnt = 5;
14565       ueSetRsp->protocolIEs.list.count = elementCnt;
14566       ueSetRsp->protocolIEs.list.size = \
14567                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14568
14569       /* Initialize the UESetup members */
14570       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14571             ueSetRsp->protocolIEs.list.size);
14572       if(ueSetRsp->protocolIEs.list.array == NULLP)
14573       {
14574          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14575          ret = RFAILED;
14576          break;
14577       }
14578
14579       for(idx=0; idx<elementCnt; idx++)
14580       {
14581          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14582                sizeof(UEContextSetupResponseIEs_t));
14583          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14584          {
14585             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14586             ret = RFAILED;
14587             break;
14588          }
14589       }
14590       /* Fetching Ue Cb Info*/
14591       GET_CELL_IDX(cellId, cellIdx);
14592       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14593       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14594       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14595
14596       idx = 0;
14597       /*GNB CU UE F1AP ID*/
14598       ueSetRsp->protocolIEs.list.array[idx]->id = \
14599                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14600       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14601       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14602                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14603       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14604
14605       /*GNB DU UE F1AP ID*/
14606       idx++;
14607       ueSetRsp->protocolIEs.list.array[idx]->id = \
14608                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14609       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14610       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14611                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14612       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14613
14614
14615       /*DUtoCURRC Information */
14616       idx++;
14617       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14618                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14619       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14620       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14621                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14622       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14623
14624       /* CRNTI */
14625       idx++;
14626       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14627       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14628       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14629       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14630
14631
14632       /* Drb Setup List */
14633       idx++;
14634       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14635                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14636       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14637       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14638                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14639       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14640             &ueCb->f1UeDb->duUeCfg);
14641       if(ret == RFAILED)
14642       {
14643          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14644          freeF1UeDb(ueCb->f1UeDb);
14645          ueCb->f1UeDb = NULLP;
14646          break;
14647       }
14648
14649       /* Free UeContext Db created during Ue context Req */
14650       freeF1UeDb(ueCb->f1UeDb);
14651       ueCb->f1UeDb = NULLP;
14652
14653       /* TODO: To send Drb list */
14654       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14655
14656       /* Encode the UE context setup response type as APER */
14657       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14658       encBufSize = 0;
14659       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14660             encBuf);
14661       /* Encode results */
14662       if(encRetVal.encoded == ENCODE_FAIL)
14663       {
14664          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14665                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14666          ret = RFAILED;
14667          break;
14668       }
14669       else
14670       {
14671          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14672 #ifdef DEBUG_ASN_PRINT
14673          for(int i=0; i< encBufSize; i++)
14674          {
14675             printf("%x",encBuf[i]);
14676          }
14677 #endif
14678       }
14679
14680       /* Sending  msg  */
14681       if(sendF1APMsg()  != ROK)
14682       {
14683          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14684          ret = RFAILED;
14685          break;
14686       }
14687       break;
14688    }
14689    FreeUeContextSetupRsp(f1apMsg);
14690    return ret;
14691 }/* End of BuildAndSendUeContextSetupRsp */
14692
14693 /*******************************************************************
14694 *
14695 * @brief  Build And Send Ue Context Rsp 
14696 *
14697 * @details
14698 *
14699 *    Function : BuildAndSendUeCtxtRsp 
14700 *
14701 *    Functionality : Build And Send Ue Context Rsp
14702
14703 * @params[in]
14704 * @return sucess = ROK
14705 *         failure = RFAILED
14706 *
14707 * ****************************************************************/
14708 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14709 {
14710    uint8_t cellIdx = 0, actionType = 0; 
14711
14712    GET_CELL_IDX(cellId, cellIdx);
14713    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14714
14715    switch(actionType)
14716    {
14717       case UE_CTXT_SETUP:
14718          {
14719             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14720             {
14721                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14722                return RFAILED;
14723             }
14724             break;
14725          }
14726       case UE_CTXT_MOD:
14727          {
14728             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14729             {
14730                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14731                return RFAILED;
14732             }
14733             break;
14734          }
14735       default:
14736          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14737          break;
14738
14739    }
14740    return ROK;
14741 }
14742
14743 /*******************************************************************
14744  *
14745  * @brief deallocating the memory of  F1reset msg
14746  *
14747  * @details
14748  *
14749  *    Function : FreeF1ResetReq
14750  *
14751  *    Functionality :
14752  *         - freeing memory of F1reset request msg
14753  *
14754  * @params[in]
14755  * @return void
14756  *
14757  *
14758  * ****************************************************************/
14759 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14760 {
14761    uint8_t idx =0 ;
14762    Reset_t *f1ResetMsg;
14763
14764    if(f1apMsg)
14765    {
14766       if(f1apMsg->choice.initiatingMessage)
14767       {
14768          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14769
14770          if(f1ResetMsg->protocolIEs.list.array)
14771          {
14772             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14773             {
14774                if(f1ResetMsg->protocolIEs.list.array[idx])
14775                {
14776                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14777                }
14778             }
14779             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14780          }
14781          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14782       }
14783       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14784    }
14785 }
14786 /*******************************************************************
14787  *
14788  * @brief Build and Send F1reset request 
14789  *
14790  * @details
14791  *
14792  *    Function : BuildAndSendF1ResetReq
14793  *
14794  *    Functionality:
14795  *         - Build and Send F1reset request msg
14796  *
14797  * @params[in]
14798  * @return ROK     - success
14799  *         RFAILED - failure
14800  *
14801  * ****************************************************************/
14802 uint8_t BuildAndSendF1ResetReq()
14803 {
14804    uint8_t          elementCnt=0;
14805    uint8_t          idx=0;
14806    uint8_t          ret= RFAILED;
14807    Reset_t          *f1ResetMsg = NULLP;
14808    F1AP_PDU_t       *f1apMsg = NULLP;
14809    asn_enc_rval_t   encRetVal;
14810    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14811    do
14812    {
14813       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14814       if(f1apMsg == NULLP)
14815       {
14816          break;
14817       }
14818       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14819       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14820       if(f1apMsg->choice.initiatingMessage == NULLP)
14821       {
14822          break;
14823       }
14824       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14825       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14826       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14827
14828       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14829
14830       elementCnt = 3;
14831       f1ResetMsg->protocolIEs.list.count = elementCnt;
14832       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14833
14834       /* Initialize the F1Setup members */
14835       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14836       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14837       {
14838          break;
14839       }
14840       for(idx=0; idx<elementCnt; idx++)
14841       {
14842          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14843          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14844          {
14845             break;
14846          }
14847       }
14848
14849       /*TransactionID*/
14850       idx=0;
14851       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14852       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14853       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14854       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14855
14856       /*Cause*/
14857       idx++;
14858       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14859       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14860       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14861       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14862       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14863
14864       /*Reset Type*/
14865       idx++;
14866       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14867       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14868       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14869       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14870       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14871
14872       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14873
14874       /* Encode the F1SetupRequest type as APER */
14875       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14876       encBufSize = 0;
14877       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14878             encBuf);
14879
14880       /* Encode results */
14881       if(encRetVal.encoded == ENCODE_FAIL)
14882       {
14883          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14884                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14885          break;
14886       }
14887       else
14888       {
14889          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14890 #ifdef DEBUG_ASN_PRINT
14891          for(idx=0; idx< encBufSize; idx++)
14892          {
14893             printf("%x",encBuf[idx]);
14894          }
14895 #endif
14896       }
14897
14898       if(sendF1APMsg() != ROK)
14899       {
14900          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14901          break;
14902       }
14903
14904       ret = ROK;
14905       break;
14906    }while(true);
14907
14908    FreeF1ResetReq(f1apMsg);
14909    return ret;
14910 }
14911 /*******************************************************************
14912  *
14913  * @brief Build And Send F1ResetAck
14914  *
14915  * @details
14916  *
14917  *    Function : BuildAndSendF1ResetAck
14918  *
14919  *    Functionality:
14920  *         - Build And Send  F1ResetRSP
14921  *
14922  * @return ROK     - success
14923  *         RFAILED - failure
14924  *
14925  * ****************************************************************/
14926 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14927 {
14928    uint8_t idx;
14929    ResetAcknowledge_t *f1ResetAck;
14930
14931    if(f1apMsg)
14932    {
14933       if(f1apMsg->choice.successfulOutcome)
14934       {
14935          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14936
14937          if(f1ResetAck->protocolIEs.list.array)
14938          {
14939             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14940             {
14941                if(f1ResetAck->protocolIEs.list.array[idx])
14942                {
14943                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14944                }
14945             }
14946             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14947          }
14948          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14949       }
14950       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14951    }
14952 }
14953
14954 /*******************************************************************
14955  *
14956  * @brief Build And Send F1ResetAck
14957  *
14958  * @details
14959  *
14960  *    Function : BuildAndSendF1ResetAck
14961  *
14962  *    Functionality:
14963  *         - Build And Send  F1ResetRSP
14964  *
14965  *  @params[in]
14966  * @return ROK     - success
14967  *         RFAILED - failure
14968  *
14969  * ****************************************************************/
14970 uint8_t BuildAndSendF1ResetAck()
14971 {
14972    uint8_t                idx = 0;
14973    uint8_t                elementCnt = 0;
14974    uint8_t                ret = RFAILED;
14975    F1AP_PDU_t             *f1apMsg = NULL;
14976    ResetAcknowledge_t     *f1ResetAck = NULLP;
14977    asn_enc_rval_t         encRetVal;
14978    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14979
14980    do{
14981       /* Allocate the memory for F1ResetRequest_t */
14982       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14983       if(f1apMsg == NULLP)
14984       {
14985          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14986          break;
14987       }
14988
14989       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14990
14991       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14992       if(f1apMsg->choice.successfulOutcome == NULLP)
14993       {
14994          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14995          break;
14996       }
14997       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14998       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14999       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
15000
15001       elementCnt = 1;
15002
15003       f1ResetAck->protocolIEs.list.count = elementCnt;
15004       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15005
15006       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15007       if(f1ResetAck->protocolIEs.list.array == NULLP)
15008       {
15009          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15010          break;
15011       }
15012
15013       for(idx=0; idx<elementCnt; idx++)
15014       {
15015          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15016          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15017          {
15018             break;
15019          }
15020       }
15021       /*TransactionID*/
15022       idx = 0;
15023       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15024       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15025       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15026       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15027
15028       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15029
15030       /* Encode the F1SetupRequest type as UPER */
15031       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15032       encBufSize = 0;
15033       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15034
15035       /* Check encode results */
15036       if(encRetVal.encoded == ENCODE_FAIL)
15037       {
15038          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15039                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15040          break;
15041       }
15042       else
15043       {
15044          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15045 #ifdef DEBUG_ASN_PRINT
15046          for(int i=0; i< encBufSize; i++)
15047          {
15048             printf("%x",encBuf[i]);
15049          }
15050 #endif
15051       }
15052       /* Sending msg */
15053       if(sendF1APMsg() != ROK)
15054       {
15055          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15056          break;
15057       }
15058
15059       ret = ROK;
15060       break;
15061    }while(true);
15062
15063    FreeF1ResetAck(f1apMsg);
15064    return ret;
15065 }
15066 /******************************************************************
15067 *
15068 * @brief free F1 reset msg allocated by aper_decoder 
15069 *
15070 * @details
15071 *
15072 *    Function : freeAperDecodeF1ResetMsg 
15073 *
15074 *    Functionality: free F1 reset msg allocated by aper_decoder 
15075 *
15076 * @params[in] Reset_t *f1ResetMsg 
15077 * @return void 
15078 *
15079 * ****************************************************************/
15080
15081 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15082 {
15083    uint8_t ieIdx =0;
15084    if(f1ResetMsg->protocolIEs.list.array)
15085    {
15086       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15087       {
15088          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15089          {
15090             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15091          }
15092       }
15093       free(f1ResetMsg->protocolIEs.list.array);
15094    }
15095 }
15096
15097 /******************************************************************
15098  *
15099  * @brief Processes DL RRC Message Transfer  sent by CU
15100  *
15101  * @details
15102  *
15103  *    Function : procF1ResetReq
15104  *
15105  *    Functionality: Processes DL RRC Message Transfer sent by CU
15106  *
15107  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15108  * @return ROK     - success
15109  *         RFAILED - failure
15110  *
15111  * ****************************************************************/
15112 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15113 {
15114    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15115    uint8_t       ieIdx = 0;
15116    uint8_t        ret = ROK;
15117    Reset_t       *f1ResetMsg = NULLP;
15118
15119    DU_LOG("\nINFO   -->  Processing F1 reset request");
15120    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15121
15122    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15123    {
15124       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15125       {
15126          case ProtocolIE_ID_id_TransactionID:
15127             break;
15128
15129          case ProtocolIE_ID_id_Cause:
15130             break;
15131
15132          case ProtocolIE_ID_id_ResetType:
15133             {
15134                break;
15135             }
15136
15137          default:
15138             break;
15139       }
15140    }
15141    ret = BuildAndSendF1ResetAck();
15142    DU_LOG("\nINFO   -->  UE release is not supported for now");
15143
15144    freeAperDecodeF1ResetMsg(f1ResetMsg);
15145
15146    return ret;
15147 }
15148
15149 /*******************************************************************
15150  *
15151  * @brief free the RRC delivery report
15152  *
15153  * @details
15154  *
15155  *    Function : freeRrcDeliveryReport
15156  *
15157  *    Functionality: free the RRC delivery report
15158  *
15159  * @params[in]
15160  * @return ROK     - success
15161  *         RFAILED - failure
15162  *
15163  * ****************************************************************/
15164 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15165 {
15166    uint8_t idx=0;
15167    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15168
15169    if(f1apMsg)
15170    {
15171       if(f1apMsg->choice.initiatingMessage)
15172       {
15173          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15174          if(rrcDeliveryReport->protocolIEs.list.array)
15175          {
15176             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15177                   idx++)
15178             {
15179                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15180                {
15181                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15182                         sizeof(RRCDeliveryReportIEs_t));
15183                }   
15184             }
15185             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15186                   rrcDeliveryReport->protocolIEs.list.size);
15187          }
15188          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15189       }
15190       DU_FREE(f1apMsg,
15191             sizeof(F1AP_PDU_t));
15192    }
15193 }
15194
15195 /*******************************************************************
15196 *
15197 * @brief Builds and sends the RRC delivery report
15198 *
15199 * @details
15200 *
15201 *    Function : BuildAndSendRrcDeliveryReport
15202 *
15203 *    Functionality: Builds and sends the RRC delivery report
15204 *
15205 * @params[in]
15206 *
15207 * @return ROK     - success
15208 *         RFAILED - failure
15209 *
15210 * ****************************************************************/
15211 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15212    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15213 {
15214    uint8_t             ret = RFAILED;
15215    uint8_t             idx    = 0;
15216    uint8_t             idx1   = 0;
15217    uint8_t             elementCnt = 0;
15218    F1AP_PDU_t          *f1apMsg = NULLP;
15219    asn_enc_rval_t      encRetVal;  
15220    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15221
15222    do{
15223
15224       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15225       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15226       if(f1apMsg == NULLP)
15227       {
15228          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15229          break;
15230       }
15231       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15232       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15233       if(f1apMsg->choice.initiatingMessage == NULLP)
15234       {
15235          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15236          break;
15237       }
15238       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15239       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15240       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15241
15242       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15243       elementCnt = 4;
15244       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15245       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15246
15247       /* Initialize the F1Setup members */
15248       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15249       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15250       {
15251          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15252          break;
15253       }
15254       for(idx =0 ;idx <elementCnt; idx++)
15255       {
15256          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15257          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15258          {
15259             break;
15260          }
15261       }
15262
15263       idx1 = 0;
15264
15265       /*GNB CU UE F1AP ID*/
15266       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15267       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15268       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15269       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15270
15271       /*GNB DU UE F1AP ID*/
15272       idx1++;
15273       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15274       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15275       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15276       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15277
15278       /*RRC delivery status*/
15279       idx1++;
15280       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15281       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15282       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15283       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15284       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15285       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15286       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15287
15288       /* SRB ID */ 
15289       idx1++;
15290       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15291       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15292       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15293       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15294
15295       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15296
15297       /* Encode the RRC DELIVERY REPORT type as APER */
15298       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15299       encBufSize = 0;
15300       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15301             encBuf);
15302
15303       /* Encode results */
15304       if(encRetVal.encoded == ENCODE_FAIL)
15305       {
15306          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15307                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15308          break;
15309       }
15310       else
15311       {
15312          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15313 #ifdef DEBUG_ASN_PRINT
15314          for(idx=0; idx< encBufSize; idx++)
15315          {
15316             printf("%x",encBuf[idx]);
15317          }
15318 #endif
15319       }
15320
15321       /* Sending msg */
15322       if(sendF1APMsg() != ROK)
15323       {
15324          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15325          break;
15326       }
15327       ret = ROK;
15328       break;
15329
15330    }while(true);
15331
15332    freeRrcDeliveryReport(f1apMsg);
15333    return ret;
15334 }
15335
15336 /*******************************************************************
15337  *
15338  * @brief Processes cells to be activated
15339  *
15340  * @details
15341  *
15342  *    Function : extractCellsToBeActivated
15343  *
15344  *    Functionality:
15345  *      - Processes cells to be activated list received in F1SetupRsp
15346  *
15347  * @params[in] void
15348  * @return ROK     - success
15349  *         RFAILED - failure
15350  *
15351  * ****************************************************************/
15352
15353 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15354 {
15355    uint8_t  ret = ROK;
15356    uint16_t idx, pci = 0;
15357    uint64_t nci;
15358    Cells_to_be_Activated_List_Item_t cell;
15359
15360    for(idx=0; idx<cellsToActivate.list.count; idx++)
15361    {
15362       nci = 0;
15363       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15364       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15365
15366       if(cell.nRPCI)
15367       {
15368          pci = *cell.nRPCI;
15369       }
15370       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15371    }
15372    return ret;
15373 }
15374 /******************************************************************
15375 *
15376 * @brief Processes F1 Setup Response allocated by aper_decoder 
15377 *
15378 * @details
15379 *
15380 *    Function : freeF1SetupRsp 
15381 *
15382 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15383 *
15384 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15385 * @return void 
15386 *
15387 * ****************************************************************/
15388
15389 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15390 {
15391    uint8_t ieIdx =0;
15392    uint8_t arrIdx =0;
15393    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15394    RRC_Version_t      *rrcVer =NULLP;
15395
15396    if(f1SetRspMsg->protocolIEs.list.array)
15397    {
15398       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15399       {
15400          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15401          {
15402             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15403             {
15404                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15405                   {
15406                      cellToActivate =
15407                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15408                      if(cellToActivate->list.array)
15409                      {
15410                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15411                         {
15412                            if(cellToActivate->list.array[arrIdx])
15413                            {
15414
15415                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15416                               pLMN_Identity.buf)
15417                               {
15418                                  if(cellToActivate->list.array[0]->value.choice.\
15419                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15420                                  {
15421                                     free(cellToActivate->list.array[0]->value.choice.\
15422                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15423                                  }
15424
15425                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15426                                        nRCGI.pLMN_Identity.buf);
15427                               }
15428                               free(cellToActivate->list.array[arrIdx]);
15429                            }
15430                         }
15431                         free(cellToActivate->list.array);
15432                      }
15433                      break;
15434                   }
15435                case ProtocolIE_ID_id_TransactionID:
15436                   {
15437                      break;
15438                   }
15439                case ProtocolIE_ID_id_gNB_CU_Name:
15440                   {
15441                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15442                      break;
15443                   }
15444                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15445                   {
15446                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15447                      if(rrcVer->latest_RRC_Version.buf)
15448                      {
15449                         if(rrcVer->iE_Extensions)
15450                         {
15451                            if(rrcVer->iE_Extensions->list.array)
15452                            {
15453                               if(rrcVer->iE_Extensions->list.array[0])
15454                               {
15455                                  if(rrcVer->iE_Extensions->list.\
15456                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15457                                  {
15458                                     free(rrcVer->iE_Extensions->list.\
15459                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15460                                  }
15461                                  free(rrcVer->iE_Extensions->list.array[0]);
15462                               }
15463                               free(rrcVer->iE_Extensions->list.array);
15464                            }
15465                            free(rrcVer->iE_Extensions);
15466                         }
15467                         free(rrcVer->latest_RRC_Version.buf);
15468                      }
15469                      break;
15470
15471                   }
15472                default:
15473                   {
15474                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15475                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15476                   }
15477             }
15478             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15479          }
15480       }
15481       free(f1SetRspMsg->protocolIEs.list.array);
15482    }
15483 }
15484 /******************************************************************
15485  *
15486  * @brief Processes F1 Setup Response sent by CU
15487  *
15488  * @details
15489  *
15490  *    Function : procF1SetupRsp
15491  *
15492  *    Functionality: Processes F1 Setup Response sent by CU
15493  *
15494  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15495  * @return ROK     - success
15496  *         RFAILED - failure
15497  *
15498  * ****************************************************************/
15499 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15500 {
15501    uint8_t ret = ROK;
15502    uint16_t idx =0;
15503    F1SetupResponse_t *f1SetRspMsg = NULLP;
15504    GNB_CU_Name_t     *cuName = NULLP;
15505    F1SetupRsp  f1SetRspDb;
15506    RRC_Version_t      *rrcVer =NULLP;
15507    
15508    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15509
15510    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15511    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15512
15513    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15514    {
15515       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15516       {
15517          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15518             {
15519                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15520                      value.choice.Cells_to_be_Activated_List);
15521                break;
15522             }
15523          case ProtocolIE_ID_id_TransactionID:
15524             {
15525                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15526                                     value.choice.TransactionID;
15527                break;
15528             }
15529          case ProtocolIE_ID_id_gNB_CU_Name:
15530             {
15531                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15532                         value.choice.GNB_CU_Name;
15533                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15534                break;
15535             }
15536          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15537             {
15538                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15539                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15540                      (const char*)rrcVer->latest_RRC_Version.buf);
15541                break;
15542             }
15543          default:
15544             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15545                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15546       }
15547    }
15548    
15549    duProcF1SetupRsp();
15550    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15551
15552    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15553    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15554    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15555    {
15556       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15557       return RFAILED;
15558    }
15559    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15560
15561    if(BuildAndSendE2SetupReq() != ROK)
15562    {
15563       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15564       return RFAILED;
15565    }
15566    return ret;
15567 }
15568 /*******************************************************************
15569 *
15570 * @brief free GNB DU config update ack
15571 *
15572 * @details
15573 *
15574 *    Function : freeAperDecodeGnbDuAck 
15575 *
15576 *    Functionality: Processes GNB DU config update ack And
15577 *                     added free part for the memory allocated by aper_decoder
15578 *
15579 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15580 * @return ROK     - success
15581 *         RFAILED - failure
15582 *
15583 * ****************************************************************/
15584
15585 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15586 {
15587    uint8_t ieIdx = 0;
15588
15589    if(gnbDuAck->protocolIEs.list.array)
15590    {
15591       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15592       {
15593          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15594          {
15595             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15596          }
15597       }
15598       free(gnbDuAck->protocolIEs.list.array);
15599    }
15600 }
15601
15602 /*******************************************************************
15603 *
15604 * @brief Building  result of gnb-du config update ack output
15605 *
15606 * @details
15607 *
15608 *    Function : duProcGnbDuCfgUpdAckMsg 
15609 *
15610 *    Functionality: 
15611 *        Building output of gnb-du config update ack 
15612 *
15613 * @params[in] transId
15614 * @return void
15615 *
15616 * ****************************************************************/
15617
15618 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15619 {
15620    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15621    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15622    uint16_t cellIdx =0, crnti=0;
15623    uint64_t cellId =0;
15624    CmLList *f1apPduNode = NULLP;
15625    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15626    F1AP_PDU_t *f1apMsgPdu = NULLP;
15627    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15628    BIT_STRING_t *cellIdentity=NULLP;
15629    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15630    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15631    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15632
15633    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15634    f1apPduNode = searchFromReservedF1apPduList(transId);
15635    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15636    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15637
15638    if(f1apMsgPdu)
15639    {
15640       if(f1apMsgPdu->choice.initiatingMessage)
15641       {
15642          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15643          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15644          {
15645             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15646             {
15647                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15648                   {
15649                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15650                                      Served_Cells_To_Delete_List;
15651                      if(cellsToDelete->list.array)
15652                      {
15653                         if(cellsToDelete->list.array[arrIdx])
15654                         {
15655                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15656                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15657                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15658                            {
15659                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15660                               bitStringToInt(cellIdentity, &cellId);
15661
15662                               GET_CELL_IDX(cellId, cellIdx);
15663                               if(duCb.actvCellLst[cellIdx] != NULLP)
15664                               {
15665                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15666                               }
15667                            }
15668                         }
15669                      }
15670
15671                      if(duCb.actvCellLst[cellIdx] != NULLP)
15672                      {
15673                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15674                         {
15675                            ret = duSendCellDeletReq(cellId);
15676                            if(ret == RFAILED)
15677                            {
15678                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15679                               request for cellId[%lu]", cellId);
15680                            }
15681                         }
15682                         else
15683                         {
15684                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15685                            while(totalActiveUe)
15686                            {
15687                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15688                               {
15689                                  ueIdx++;
15690                                  continue;
15691                               }
15692
15693                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15694                               GET_UE_ID(crnti,ueId);
15695                               /* Sending Ue Context release request only for maximum supporting UEs */
15696                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15697                               if(ret == RFAILED)
15698                               {
15699                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15700                                  request for cellId[%lu]", cellId);
15701                               }
15702                               ueIdx++;
15703                               totalActiveUe--;
15704                            }
15705                         }
15706                      }
15707                      else
15708                      {
15709                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15710                         ret = RFAILED;
15711                      }
15712                      break;
15713                   }
15714
15715                default:
15716                   break;
15717             }
15718          }
15719       }
15720    }
15721    
15722    FreeDUConfigUpdate(f1apMsgPdu);
15723    deleteFromReservedF1apPduList(f1apPduNode);
15724    return ret;
15725 }
15726
15727 /*******************************************************************
15728 *
15729 * @brief Processes GNB DU config update ack
15730 *
15731 * @details
15732 *
15733 *    Function : procF1GNBDUCfgUpdAck
15734 *
15735 *    Functionality: added free part for the memory allocated by aper_decoder
15736 *
15737 * @params[in] F1AP_PDU_t *f1apMsg 
15738 * @return void 
15739 *
15740 * ****************************************************************/
15741 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15742 {
15743    uint8_t ieIdx=0,transId=0;
15744    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15745
15746    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15747    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15748
15749    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15750    {
15751       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15752       {
15753          case ProtocolIE_ID_id_TransactionID:
15754             {
15755                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15756                break;
15757             }
15758          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15759             {
15760                break;
15761             }
15762          default :
15763             {
15764                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15765                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15766                break;
15767             }
15768       }
15769    }
15770    
15771    duProcGnbDuCfgUpdAckMsg(transId);
15772     
15773 #if 0
15774    /* presently we are not supporting F1 Reset from DU to CU , we are only
15775     * supporting F1 Reset from CU to DU */
15776
15777    if(BuildAndSendF1ResetReq() != ROK)
15778    {
15779       return RFAILED;
15780    }
15781 #endif
15782
15783    freeAperDecodeGnbDuAck(gnbDuAck);
15784    return ROK;
15785 }
15786 /******************************************************************
15787 *
15788 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15789 *
15790 * @details
15791 *
15792 *    Function : freeAperDecodef1DlRrcMsg 
15793 *
15794 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15795 *
15796 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15797 * @return ROK     - success
15798 *         RFAILED - failure
15799 *
15800 * ****************************************************************/
15801
15802 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15803 {
15804    uint8_t ieIdx =0;
15805    RRCContainer_t *rrcContainer = NULLP;
15806
15807    if(f1DlRrcMsg->protocolIEs.list.array)
15808    {
15809       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15810       {
15811          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15812          {
15813             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15814             {
15815                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15816                   break;
15817                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15818                   break;
15819                case ProtocolIE_ID_id_SRBID:
15820                   break;
15821                case ProtocolIE_ID_id_RRCContainer:
15822                   {
15823                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15824                      free(rrcContainer->buf);
15825                   }
15826                case ProtocolIE_ID_id_ExecuteDuplication:
15827                   break;
15828                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15829                   break;
15830                   break;
15831             }
15832             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15833          }
15834       }
15835       free(f1DlRrcMsg->protocolIEs.list.array);
15836    }
15837 }
15838 /******************************************************************
15839  *
15840  * @brief Processes DL RRC Message Transfer  sent by CU
15841  *
15842  * @details
15843  *
15844  *    Function : procF1DlRrcMsgTrans
15845  *
15846  *    Functionality: Processes DL RRC Message Transfer sent by CU
15847  *
15848  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15849  * @return ROK     - success
15850  *         RFAILED - failure
15851  *
15852  * ****************************************************************/
15853 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15854 {
15855    uint8_t  idx, ret;
15856    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15857    F1DlRrcMsg dlMsg;
15858    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15859
15860    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15861    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15862
15863    ret = ROK;
15864
15865    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15866    {
15867       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15868       {
15869          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15870             {
15871                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15872                break;
15873             }
15874          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15875             {
15876                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15877                break;
15878             }
15879          case ProtocolIE_ID_id_SRBID:
15880             {
15881                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15882                break;
15883             }
15884          case ProtocolIE_ID_id_ExecuteDuplication:
15885             dlMsg.execDup = true;
15886             break;
15887
15888          case ProtocolIE_ID_id_RRCContainer:
15889             {
15890                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15891                {
15892              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15893              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15894              if(dlMsg.rrcMsgPdu)
15895              {
15896                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15897                       dlMsg.rrcMsgSize);
15898              }
15899              else
15900              {
15901                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15902                 return RFAILED;
15903              }
15904           }
15905           else
15906           {
15907              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15908                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15909              return RFAILED;
15910           }
15911           break;
15912        }
15913     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15914        {
15915           dlMsg.deliveryStatRpt = true;
15916           break;
15917        }
15918     default:
15919        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15920              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15921       }
15922    }
15923
15924    ret = duProcDlRrcMsg(&dlMsg);
15925
15926    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15927    return ret;
15928 }
15929 /*******************************************************************
15930  *
15931 * @brief Builds the DRB to be Setup Mod list
15932 *
15933 * @details
15934 *
15935 *    Function : 
15936 *
15937 *    Functionality: Constructs the DRB to be Setup Mod list
15938 *
15939 * @params[in] DRBs_SetupMod_List_t *drbSet
15940 *
15941 * @return ROK     - success
15942 *         RFAILED - failure
15943 *
15944 * ****************************************************************/
15945 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15946 {
15947    uint8_t srbIdx = 0;
15948    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15949
15950    srbList->list.count = ueCfg->numRlcLcs;
15951    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15952
15953    DU_ALLOC(srbList->list.array, srbList->list.size);
15954    if(srbList->list.array == NULLP)
15955    {
15956       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15957       return RFAILED;
15958    }
15959
15960    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15961    {
15962       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15963       if(srbList->list.array[srbIdx] == NULLP)
15964       {
15965          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15966          return RFAILED;
15967       }
15968    } 
15969
15970    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15971    {
15972       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15973       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15974       srbItemIe->criticality = Criticality_reject;
15975       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15976       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15977       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15978    }
15979    return ROK;
15980 }
15981
15982 /*******************************************************************
15983  *
15984 * @brief Builds the DRB to be Setup Mod list
15985 *
15986 * @details
15987 *
15988 *    Function : 
15989 *
15990 *    Functionality: Constructs the DRB to be Setup Mod list
15991 *
15992 * @params[in] DRBs_SetupMod_List_t *drbSet
15993 *
15994 * @return ROK     - success
15995 *         RFAILED - failure
15996 *
15997 * ****************************************************************/
15998
15999 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
16000 {
16001    uint8_t arrIdx =0;
16002    uint8_t drbCnt =0;
16003    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16004
16005    drbCnt = ueCfg->numDrbSetupMod;
16006
16007    drbSet->list.count = drbCnt;
16008    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16009    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16010    if(drbSet->list.array == NULLP)
16011    {
16012       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16013       return  RFAILED;
16014    }
16015    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16016    {
16017       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16018       if(drbSet->list.array[arrIdx] == NULLP)
16019       {
16020               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16021               return  RFAILED;
16022       }
16023
16024       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16025       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16026       drbItemIe->criticality = Criticality_reject;
16027       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16028       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16029       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16030       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16031       {
16032          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16033          return RFAILED;
16034       }
16035       
16036    }
16037
16038    return ROK;
16039 }
16040 /*******************************************************************
16041 * @brief Free the memory allocated for DRB setup List
16042 *
16043 * @details
16044 *
16045 *    Function : FreeDrbSetupModList 
16046 *
16047 *    Functionality:
16048 *       Free the memory allocated for DRB setup list
16049 *
16050 * @params[in] DRBs_Setup_List_t *
16051 * @return void
16052 *
16053 * ****************************************************************/
16054 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16055 {
16056    uint8_t arrIdx = 0;
16057    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16058
16059    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16060    {
16061       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16062       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16063       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16064    }
16065    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16066 }
16067
16068 /*******************************************************************
16069 *
16070 * @brief Builds the DRB to be Mod list
16071 *
16072 * @details
16073 *
16074 *    Function : 
16075 *
16076 *    Functionality: Constructs the DRB to be Mod list
16077 *
16078 * @params[in] DRBs_Modified_List_t *drbModList
16079 *
16080 * @return ROK     - success
16081 *         RFAILED - failure
16082 *
16083 * ****************************************************************/
16084
16085 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16086 {
16087    uint8_t arrIdx =0, drbIdx = 0;
16088    uint8_t drbCnt =0;
16089    struct DRBs_Modified_ItemIEs *drbItemIe;
16090
16091    drbCnt = ueCfg->numDrbModified;
16092
16093    drbModList->list.count = drbCnt;
16094    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16095    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16096    if(drbModList->list.array == NULLP)
16097    {
16098       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16099       return  RFAILED;
16100    }
16101
16102    drbIdx = 0;
16103    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16104    {
16105       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16106       {
16107          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16108          if(drbModList->list.array[drbIdx] == NULLP)
16109          {
16110             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16111             return  RFAILED;
16112          }
16113
16114          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16115          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16116          drbItemIe->criticality = Criticality_reject;
16117          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16118          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16119          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16120                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16121          {
16122             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16123             return RFAILED;
16124          }
16125          drbIdx++;
16126       } 
16127    }
16128
16129    return ROK;
16130 }
16131
16132 /*******************************************************************
16133 * @brief Free the memory allocated for DRB Mod List
16134 *
16135 * @details
16136 *
16137 *    Function : FreeDrbModList 
16138 *
16139 *    Functionality:
16140 *       Free the memory allocated for DRB modified list
16141 *
16142 * @params[in] DRBs_Modified_List_t *
16143 * @return void
16144 *
16145 * ****************************************************************/
16146 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16147 {
16148    uint8_t arrIdx = 0;
16149    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16150
16151    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16152    {
16153       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16154       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16155       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16156    }
16157    DU_FREE(drbModList->list.array, drbModList->list.size);
16158 }
16159
16160 /*******************************************************************
16161 * @brief Free the memory allocated for SRB setup List
16162 *
16163 * @details
16164 *
16165 *    Function : FreeSrbSetupModList 
16166 *
16167 *    Functionality:
16168 *       Free the memory allocated for SRB setup list
16169 *
16170 * @params[in] SRBs_Setup_List_t *
16171 * @return void
16172 *
16173 * ****************************************************************/
16174 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16175 {
16176    uint8_t srbIdx = 0;
16177    
16178    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16179       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16180    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16181 }
16182
16183 /*******************************************************************
16184 * @brief Free the memory allocated for UE Context Mod Response
16185 *
16186 * @details
16187 *
16188 *    Function : FreeUeContextModResp 
16189 *
16190 *    Functionality:
16191 *       Free the memory allocated for UE Context Mod Response
16192 *
16193 * @params[in] F1AP_PDU_t *f1apMsg
16194 * @return void
16195 *
16196 * ****************************************************************/
16197
16198 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16199 {
16200    uint8_t ieIdx;
16201    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16202    if(f1apMsg)
16203    {
16204       if(f1apMsg->choice.successfulOutcome)
16205       {
16206          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16207          if(ueContextModifyRes->protocolIEs.list.array)
16208          {
16209             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16210             {
16211                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16212                {
16213                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16214                   {
16215                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16216                         break;
16217                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16218                         break;
16219                      case ProtocolIE_ID_id_DUtoCURRCInformation:
16220                         {
16221                            DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.\
16222                               cellGroupConfig.buf, ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16223                               DUtoCURRCInformation.cellGroupConfig.size);
16224                            break;
16225                         }
16226                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16227                         {
16228                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16229                             value.choice.DRBs_SetupMod_List));
16230                             break;
16231                         }
16232                      case ProtocolIE_ID_id_DRBs_Modified_List:
16233                         {
16234                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16235                             value.choice.DRBs_Modified_List));
16236                             break;
16237                         }
16238                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16239                         {
16240                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16241                               SRBs_SetupMod_List));
16242                            break; 
16243                         }
16244                   }
16245                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16246                }
16247
16248             }
16249             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16250          }
16251          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16252       }
16253       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16254    }
16255 }
16256
16257 /*****************************************************************i
16258 *
16259 * @brief Creating the ue context modifcation response and sending
16260 *
16261 * @details
16262 *
16263 *    Function : BuildAndSendUeContextModRsp 
16264 *
16265 *    Functionality:
16266 *         - Creating the ue context modifcation response 
16267 *
16268 * @params[in] uint8_t cellId,uint8_t ueId
16269 * @return ROK     - success
16270 *         RFAILED - failure
16271 *
16272 * ****************************************************************/
16273 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16274 {
16275    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16276    uint8_t   elementCnt = 0;
16277    uint8_t   ret = RFAILED;
16278    F1AP_PDU_t *f1apMsg = NULLP;
16279    asn_enc_rval_t  encRetVal;
16280    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16281
16282    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16283
16284    while(true)
16285    {
16286       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16287       if(f1apMsg == NULLP)
16288       {
16289          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16290          break;
16291       }
16292
16293       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16294
16295       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16296       if(f1apMsg->choice.successfulOutcome == NULLP)
16297       {
16298          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16299          break;
16300       }
16301       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16302       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16303       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16304
16305       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16306   
16307       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16308       {
16309          elementCnt = 2;
16310          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16311             elementCnt++;
16312          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16313             elementCnt++; 
16314       }
16315       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16316       {
16317          elementCnt = 5;
16318       }
16319       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16320          elementCnt = 2;
16321       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16322       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16323
16324       /* Initialize the UE context modification members */
16325       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16326       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16327       {
16328          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16329          break;
16330       }
16331
16332       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16333       {
16334          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16335          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16336          {
16337             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16338             break;
16339          }
16340       }
16341
16342       ieIdx=0;
16343       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16344       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16345       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16346       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16347       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16348
16349       ieIdx++;
16350       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16351       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16352       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16353       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16354       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16355
16356       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16357       {
16358          ieIdx++;
16359          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16360          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16361          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16362          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16363          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16364       }
16365
16366       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16367            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16368       { 
16369          ieIdx++;
16370          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16371          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16372          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16373                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16374          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16375          {
16376             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16377             {
16378                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16379                {
16380                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16381                }
16382             }
16383          }
16384          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16385                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16386          if(ret != ROK)
16387          {
16388             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16389             break;
16390          }
16391       }
16392
16393       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16394       { 
16395          ieIdx++;
16396          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16397          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16398          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16399                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16400          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16401                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16402          if(ret != ROK)
16403          {
16404             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16405             break;
16406          }
16407       }
16408
16409       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16410       {
16411          ieIdx++;
16412          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16413          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16414          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16415                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16416          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16417          {
16418             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16419             {
16420                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16421                      sizeof(DuRlcBearerCfg));
16422             }
16423          }
16424          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16425                &ueCb->f1UeDb->duUeCfg);
16426          if(ret != ROK)
16427          {
16428             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16429             break;
16430          }
16431       }
16432
16433       freeF1UeDb(ueCb->f1UeDb);
16434       ueCb->f1UeDb = NULLP;
16435
16436       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16437
16438       /* Encode the F1SetupRequest type as APER */
16439       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16440       encBufSize = 0;
16441       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16442
16443       /* Encode results */
16444       if(encRetVal.encoded == ENCODE_FAIL)
16445       {
16446          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16447                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16448          ret = RFAILED;
16449          break;
16450       }
16451       else
16452       {
16453          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16454 #ifdef DEBUG_ASN_PRINT
16455          for(int i=0; i< encBufSize; i++)
16456          {
16457             printf("%x",encBuf[i]);
16458          }
16459 #endif
16460       }
16461
16462       /* Sending  msg  */
16463       if(sendF1APMsg() != ROK && (ret == ROK))
16464       {
16465          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16466          ret = RFAILED;
16467          break;
16468       }
16469
16470       ret = ROK;
16471       break;
16472    }
16473
16474    FreeUeContextModResp(f1apMsg);
16475    return ret;
16476 }
16477
16478 /*******************************************************************
16479  *
16480  * @brief Deallocating the memory allocated by the aper decoder
16481  *          for QOSInfo
16482  *
16483  * @details
16484  *
16485  *    Function : freeAperDecodeQosInfo
16486  *
16487  *    Functionality:  Deallocating the memory allocated for QOSInfo
16488  *
16489  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16490  *
16491  * @return void
16492  *
16493  * ****************************************************************/
16494
16495 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16496 {
16497    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16498    {
16499       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16500       {
16501          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16502          {
16503             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16504          }
16505          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16506       }
16507       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16508    }
16509 }
16510 /*******************************************************************
16511  *
16512  * @brief Deallocating the memory allocated by the aper decoder
16513  *          for UlTnlInfoforDrb
16514  *
16515  * @details
16516  *
16517  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16518  *
16519  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16520  *
16521  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16522  *
16523  * @return void
16524  *
16525  * ****************************************************************/
16526 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16527 {
16528    uint8_t arrIdx =0;
16529
16530    if(ulInfo->list.array)
16531    {
16532       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16533       {
16534          if(ulInfo->list.array[arrIdx])
16535          {
16536             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16537             {
16538                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16539                {
16540                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16541                   {
16542                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16543                            gTP_TEID.buf);
16544                   }
16545                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16546                         transportLayerAddress.buf);
16547                }
16548                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16549             }
16550             free(ulInfo->list.array[arrIdx]);
16551          }
16552       }
16553       free(ulInfo->list.array);
16554    }
16555 }
16556
16557 /*******************************************************************
16558  *
16559  * @brief Deallocating the memory allocated by the aper decoder
16560  *          for DrbSetupModItem  
16561  *
16562  * @details
16563  *
16564  *    Function : freeAperDecodeDrbSetupModItem 
16565  *
16566  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16567  *
16568  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16569  *
16570  * @return void
16571  *
16572  * ****************************************************************/
16573
16574 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16575 {
16576    uint8_t arrIdx =0;
16577    SNSSAI_t *snssai =NULLP;
16578    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16579
16580    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16581    switch(drbItem->qoSInformation.present)
16582    {
16583       case QoSInformation_PR_NOTHING:
16584          break;
16585       case QoSInformation_PR_eUTRANQoS:
16586          {
16587             if(drbItem->qoSInformation.choice.eUTRANQoS)
16588             {
16589                free(drbItem->qoSInformation.choice.eUTRANQoS);
16590             }
16591             break;
16592          }
16593       case QoSInformation_PR_choice_extension:
16594          {
16595             if(drbItem->qoSInformation.choice.choice_extension)
16596             {
16597                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16598                      DRB_Information.dRB_QoS);
16599                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16600                if(snssai->sST.buf)
16601                {
16602                   free(snssai->sST.buf);
16603                }
16604                if(snssai->sD)
16605                {
16606                   if(snssai->sD->buf)
16607                   {
16608                      free(snssai->sD->buf);
16609                   }
16610                   free(snssai->sD);
16611                }
16612
16613                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16614                          DRB_Information.flows_Mapped_To_DRB_List;
16615                if(flowMap->list.array)
16616                {
16617                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16618                   {
16619                      if(flowMap->list.array[arrIdx] )
16620                      {
16621                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16622                         free(flowMap->list.array[arrIdx]);
16623                      }
16624                   }
16625                   free(flowMap->list.array);
16626                }
16627
16628                free(drbItem->qoSInformation.choice.choice_extension);
16629             }
16630             break;
16631          }
16632
16633    }
16634    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16635    if(drbItem->uLConfiguration)
16636    {
16637       free(drbItem->uLConfiguration);
16638    }
16639 }
16640
16641 /*******************************************************************
16642  *
16643  * @brief Deallocating the memory allocated by the aper decoder
16644  *          for DrbToBeSetupModList
16645  *
16646  * @details
16647  *
16648  *    Function : freeAperDecodeDrbToBeSetupModList
16649  *
16650  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16651  *
16652  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16653  *
16654  * @return void
16655  *
16656  * ****************************************************************/
16657
16658 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16659 {
16660    uint8_t arrIdx =0;
16661    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16662
16663    if(drbSet->list.array)
16664    {
16665       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16666       {
16667          if(drbSet->list.array[arrIdx] != NULLP)
16668          {
16669             if(arrIdx == 0)
16670             {
16671                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16672                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16673             }
16674             free(drbSet->list.array[arrIdx]);
16675          }
16676       }
16677       free(drbSet->list.array);
16678    }
16679
16680 }
16681
16682 /*******************************************************************
16683  *
16684  * @brief Deallocating the memory allocated by the aper decoder
16685  *          for DrbSetupModItem  
16686  *
16687  * @details
16688  *
16689  *    Function : freeAperDecodeDrbModifiedItem 
16690  *
16691  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16692  *
16693  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16694  *
16695  * @return void
16696  *
16697  * ****************************************************************/
16698
16699 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16700 {
16701    uint8_t arrIdx =0;
16702    SNSSAI_t *snssai =NULLP;
16703    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16704
16705    if(drbItem->qoSInformation != NULLP)
16706    {
16707       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16708       switch(drbItem->qoSInformation->present)
16709       {
16710          case QoSInformation_PR_NOTHING:
16711             break;
16712          case QoSInformation_PR_eUTRANQoS:
16713             {
16714                if(drbItem->qoSInformation->choice.eUTRANQoS)
16715                {
16716                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16717                }
16718                break;
16719             }
16720          case QoSInformation_PR_choice_extension:
16721             {
16722                if(drbItem->qoSInformation->choice.choice_extension)
16723                {
16724                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16725                         DRB_Information.dRB_QoS);
16726                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16727                   if(snssai->sST.buf)
16728                   {
16729                      free(snssai->sST.buf);
16730                   }
16731                   if(snssai->sD)
16732                   {
16733                      if(snssai->sD->buf)
16734                      {
16735                         free(snssai->sD->buf);
16736                      }
16737                      free(snssai->sD);
16738                   }
16739
16740                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16741                             DRB_Information.flows_Mapped_To_DRB_List;
16742                   if(flowMap->list.array)
16743                   {
16744                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16745                      {
16746                         if(flowMap->list.array[arrIdx] )
16747                         {
16748                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16749                            free(flowMap->list.array[arrIdx]);
16750                         }
16751                      }
16752                      free(flowMap->list.array);
16753                   }
16754
16755                   free(drbItem->qoSInformation->choice.choice_extension);
16756                }
16757                break;
16758             }
16759       }
16760       free(drbItem->qoSInformation);
16761    }
16762    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16763    if(drbItem->uLConfiguration)
16764    {
16765       free(drbItem->uLConfiguration);
16766    }
16767 }
16768
16769 /*******************************************************************
16770  *
16771  * @brief Deallocating the memory allocated by the aper decoder
16772  *          for DrbToBeSetupModList
16773  *
16774  * @details
16775  *
16776  *    Function : freeAperDecodeDrbToBeModifiedList
16777  *
16778  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16779  *
16780  * @params[in] DRBs_ToBeModified_List_t *drbSet
16781  *
16782  * @return void
16783  *
16784  * ****************************************************************/
16785
16786 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16787 {
16788    uint8_t arrIdx =0;
16789    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16790
16791    if(drbSet->list.array)
16792    {
16793       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16794       {
16795          if(drbSet->list.array[arrIdx] != NULLP)
16796          {
16797             if(arrIdx == 0)
16798             {
16799                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16800                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16801             }
16802             free(drbSet->list.array[arrIdx]);
16803          }
16804       }
16805       free(drbSet->list.array);
16806    }
16807
16808 }
16809
16810 /*******************************************************************
16811  *
16812  * @brief Deallocating the memory allocated by the aper decoder
16813  *          for DrbToBeSetupModList
16814  *
16815  * @details
16816  *
16817  *    Function : freeAperDecodeDrbToBeReleasedList
16818  *
16819  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16820  *
16821  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16822  *
16823  * @return void
16824  *
16825  * ****************************************************************/
16826
16827 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16828 {
16829    uint8_t arrIdx =0;
16830
16831    if(drbSet->list.array)
16832    {
16833       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16834       {
16835          if(drbSet->list.array[arrIdx] != NULLP)
16836          {
16837             free(drbSet->list.array[arrIdx]);
16838          }
16839       }
16840       free(drbSet->list.array);
16841    }
16842
16843 }
16844 /*******************************************************************
16845  *
16846  * @brief Deallocating the memory allocated by the aper decoder
16847  *          for UeContextModificationReqMsg
16848  *
16849  * @details
16850  *
16851  *    Function : freeAperDecodeUeContextModificationReqMsg
16852  *
16853  *    Functionality:  Deallocating memory allocated for
16854  *                  UeContextModificationReqMsg
16855  *
16856  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16857  *
16858  * @return void
16859  *
16860  * ****************************************************************/
16861 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16862 {
16863    uint8_t arrIdx, ieId;
16864
16865    if(ueContextModifyReq->protocolIEs.list.array)
16866    {
16867       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16868       {
16869          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16870          {
16871             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16872             switch(ieId)
16873             {
16874                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16875                   break;
16876                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16877                   break;
16878                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16879                   {
16880                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16881                            value.choice.DRBs_ToBeSetupMod_List);
16882                      break;
16883                   }
16884                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16885                   {
16886                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16887                            value.choice.DRBs_ToBeModified_List);
16888                      break;
16889                   }
16890                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16891                   {
16892                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16893                            value.choice.DRBs_ToBeReleased_List);
16894                      break;
16895                   }
16896                case ProtocolIE_ID_id_TransmissionActionIndicator:
16897                   break;
16898                case ProtocolIE_ID_id_RRCContainer:
16899                   {
16900                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16901                   }
16902             }
16903             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16904          }
16905       }
16906       free(ueContextModifyReq->protocolIEs.list.array);
16907    }
16908 }
16909 /*******************************************************************
16910  *
16911  * @brief processing the F1 UeContextModificationReq
16912  *
16913  * @details
16914  *
16915  *    Function : procF1UeContextModificationReq
16916  *
16917  *    Functionality:  processing the F1 UeContextModificationReq
16918  *
16919  * @params[in] F1AP_PDU_t *f1apMsg
16920  *
16921  * @return
16922  * ****************************************************************/
16923 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16924 {
16925    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16926    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16927    DuUeCb   *duUeCb = NULLP;
16928    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16929    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16930    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16931    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16932
16933    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16934    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16935    {
16936       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16937       {
16938          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16939             {
16940                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16941                break;
16942             }
16943          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16944             {
16945                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16946                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16947                {
16948                   if(duCb.actvCellLst[cellIdx])
16949                   {
16950                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16951                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16952                      {
16953                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16954                         if(duUeCb->f1UeDb == NULLP)
16955                         {
16956                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16957                            duUeCb->f1UeDb->cellIdx = cellIdx;
16958                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16959                         }
16960                         break;
16961                      }
16962                   }
16963                }
16964                if(duUeCb == NULLP)
16965                {
16966                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16967                   ret = RFAILED;
16968                }
16969                break;
16970             }
16971
16972          case ProtocolIE_ID_id_RRCContainer:
16973             {
16974                /* Filling Dl RRC Msg Info */
16975                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16976                if(!duUeCb->f1UeDb->dlRrcMsg)
16977                {
16978                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16979                         Memory allocation failed ");
16980                   ret = RFAILED;
16981                }
16982                else
16983                {
16984                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16985                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16986                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16987                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16988                         value.choice.RRCContainer);
16989                }
16990
16991                break;
16992             }
16993
16994          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16995          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16996          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16997             {
16998                if(duUeCb->f1UeDb)
16999                {
17000                   /*DRBs to be Added*/
17001                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
17002                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
17003                   {
17004                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17005                                       choice.DRBs_ToBeSetupMod_List;
17006
17007                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
17008                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
17009                      {
17010                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17011                         ret = RFAILED;
17012                      }
17013                   }
17014
17015                   /*DRBs to be Modified*/
17016                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17017                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17018
17019                   {
17020                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17021                                       choice.DRBs_ToBeModified_List;
17022                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17023                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17024                      {
17025                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17026                         ret = RFAILED;
17027                      }
17028                   }
17029                   /*DRBs to be Released*/
17030                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17031                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17032
17033                   {
17034                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17035                                       choice.DRBs_ToBeReleased_List;
17036                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17037                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17038                      {
17039                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17040                         ret = RFAILED;
17041                      }
17042                   }
17043                }
17044                break;
17045             }
17046
17047          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17048             {
17049                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17050                if(duUeCb->f1UeDb)
17051                {
17052                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17053                }
17054                break;
17055             }
17056
17057          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17058             {
17059                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17060                   RRCReconfigurationCompleteIndicator_true)
17061                {
17062                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17063                }
17064                break;
17065             }
17066          case ProtocolIE_ID_id_TransmissionActionIndicator:
17067             {
17068                if(duUeCb->f1UeDb)
17069                {
17070                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17071                   {
17072                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17073                   }
17074                   else 
17075                   {
17076                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17077                   }
17078                }
17079                break;
17080             }
17081
17082          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17083             {
17084                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17085                {
17086                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17087                }
17088                break;
17089             }
17090 #ifdef NR_DRX
17091          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17092             {
17093                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17094                break;
17095             }
17096 #endif
17097               
17098       }
17099    }
17100
17101    if(ret != RFAILED) 
17102    {
17103       ret = duProcUeContextModReq(duUeCb);
17104    }
17105    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17106    return ret; 
17107 }
17108
17109 /*****************************************************************i
17110 *
17111 * @brief Free memory allocated for UE Context Release Request
17112 *
17113 * @details
17114 *
17115 *    Function : FreeUeContextReleaseReq
17116 *
17117 *    Functionality:
17118 *         - Free memory allocated for UE Context Release Request
17119 *
17120 * @params[in] F1AP_PDU_t *f1apMsg
17121 * @return void 
17122 *
17123 * *************************************************************/
17124 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17125 {
17126    uint8_t ieIdx;
17127    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17128    
17129    if(f1apMsg)
17130    {
17131       if(f1apMsg->choice.initiatingMessage)
17132       {
17133          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17134          if(ueReleaseReq->protocolIEs.list.array)
17135          {
17136             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17137             {
17138                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17139             }
17140             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17141          }
17142          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17143       }
17144       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17145    }
17146
17147 }
17148 /*****************************************************************i
17149 *
17150 * @brief Build and Send UE Context Release Request  
17151 *
17152 * @details
17153 *
17154 *    Function : BuildAndSendUeContextReleaseReq
17155 *
17156 *    Functionality:
17157 *         - Build and Send UE Context Release Request 
17158 *
17159 * @params[in]
17160 * @return ROK     - success
17161 *         RFAILED - failure
17162 *
17163 * *************************************************************/
17164 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17165 {
17166    bool memAllocFail = false;
17167    uint8_t ieIdx =0;
17168    uint8_t ret = RFAILED;
17169    uint16_t cellIdx =0;
17170    uint16_t crnti = 0;
17171    uint8_t  elementCnt = 0;
17172    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17173    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17174    asn_enc_rval_t encRetVal; 
17175    F1AP_PDU_t *f1apMsg = NULLP;
17176    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17177
17178    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17179    do
17180    {
17181       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17182       if(f1apMsg == NULLP)
17183       {
17184          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17185          break;
17186       }
17187
17188       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17189       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17190       if(f1apMsg->choice.initiatingMessage == NULLP)
17191       {
17192          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17193          initiatingMessage");   
17194          break;
17195       }
17196       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17197       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17198       f1apMsg->choice.initiatingMessage->value.present = \
17199       InitiatingMessage__value_PR_UEContextReleaseRequest;
17200
17201       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17202
17203       elementCnt = 2;
17204
17205       ueReleaseReq->protocolIEs.list.count = elementCnt;
17206       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17207
17208       /* Initialize the F1Setup members */
17209       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17210       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17211       {
17212          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17213          break;
17214       }
17215       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17216       {
17217          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17218                sizeof(UEContextReleaseRequest_t));
17219          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17220          {
17221             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17222             memAllocFail = true;  
17223             break;
17224          }
17225       }
17226       if(memAllocFail == true)
17227          break;
17228
17229       /* Fetching Ue Cb Info*/
17230       GET_CELL_IDX(cellId, cellIdx);
17231       if(duCb.actvCellLst[cellIdx] == NULLP)
17232       {
17233          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17234          break;
17235       }
17236       else
17237       {
17238          GET_CRNTI(crnti, ueId);
17239          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17240          {
17241             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17242             break;
17243          }
17244          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17245          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17246       }
17247
17248       ieIdx=0; 
17249       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17250       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17251       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17252       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17253       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17254       
17255       ieIdx++;
17256       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17257       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17258       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17259       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17260       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17261       
17262       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17263
17264       /* Encode the F1SetupRequest type as APER */
17265       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17266       encBufSize = 0;
17267       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17268       /* Encode results */
17269       if(encRetVal.encoded == ENCODE_FAIL)
17270       {
17271          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17272                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17273          break;
17274       }
17275       else
17276       {
17277          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17278 #ifdef DEBUG_ASN_PRINT
17279          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17280          {
17281             printf("%x",encBuf[ieIdx]);
17282          }
17283 #endif
17284       }
17285
17286       /* Sending msg */
17287       if(sendF1APMsg() != ROK)
17288       {
17289          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17290          break;
17291       }
17292       ret = ROK;
17293       break;
17294    }while(true);
17295
17296    FreeUeContextReleaseReq(f1apMsg);
17297    return ret;
17298 }
17299 /*****************************************************************i
17300  *
17301  * @brief Free memory allocated for UE Context Release Complete
17302  *
17303  * @details
17304  *
17305  *    Function : FreeUeContextReleaseComplete
17306  *
17307  *    Functionality:
17308  *         - Free memory allocated for UE Context Release Complete
17309  *
17310  * @params[in] F1AP_PDU_t *f1apMsg
17311  * @return void
17312  *
17313  * *************************************************************/
17314 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17315 {
17316    uint8_t ieIdx;
17317    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17318
17319    if(f1apMsg)
17320    {
17321       if(f1apMsg->choice.successfulOutcome)
17322       {
17323          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17324          if(ueReleaseComplete->protocolIEs.list.array)
17325          {
17326             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17327             {
17328                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17329             }
17330             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17331          }
17332          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17333       }
17334       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17335    }
17336
17337 }
17338 /*****************************************************************i
17339  *
17340  * @brief Build and Send UE Context Release Complete
17341  *
17342  * @details
17343  *
17344  *    Function : BuildAndSendUeContextReleaseComplete
17345  *
17346  *    Functionality:
17347  *         - Build and Send UE Context Release Complete
17348  *
17349  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17350  * @return ROK     - success
17351  *         RFAILED - failure
17352  *
17353  * *************************************************************/
17354 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17355 {
17356    bool memAllocFail = false;
17357    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17358    asn_enc_rval_t encRetVal;
17359    F1AP_PDU_t *f1apMsg = NULLP;
17360    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17361
17362    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17363    do
17364    {
17365       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17366       if(f1apMsg == NULLP)
17367       {
17368          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17369          break;
17370       }
17371
17372       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17373       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17374       if(f1apMsg->choice.successfulOutcome == NULLP)
17375       {
17376          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17377                successfulOutcome");
17378          break;
17379       }
17380       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17381       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17382       f1apMsg->choice.successfulOutcome->value.present = \
17383       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17384
17385       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17386
17387       elementCnt = 2;
17388       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17389       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17390
17391       /* Initialize the UE Release Complete members */
17392       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17393       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17394       {
17395          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17396          break;
17397       }
17398       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17399       {
17400          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17401                sizeof(UEContextReleaseComplete_t));
17402          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17403          {
17404             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17405             elements");
17406             memAllocFail = true;
17407             break;
17408          }
17409       }
17410       if(memAllocFail == true)
17411          break;
17412
17413
17414       ieIdx=0;
17415       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17416       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17417       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17418       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17419       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17420
17421       ieIdx++;
17422       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17423       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17424       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17425       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17426       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17427
17428       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17429
17430       /* Encode the F1SetupComplete type as APER */
17431       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17432       encBufSize = 0;
17433       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17434       /* Encode results */
17435       if(encRetVal.encoded == ENCODE_FAIL)
17436       {
17437          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17438                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17439          break;
17440       }
17441       else
17442       {
17443          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17444 #ifdef DEBUG_ASN_PRINT
17445          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17446          {
17447             printf("%x",encBuf[ieIdx]);
17448          }
17449 #endif
17450       }
17451
17452       /* Sending msg */
17453       if(sendF1APMsg() != ROK)
17454       {
17455          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17456          break;
17457       }
17458       ret = ROK;
17459       break;
17460    }while(true);
17461    
17462    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17463          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17464    {
17465       ret = duSendCellDeletReq(cellId);
17466       if(ret != ROK)
17467       {
17468          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17469                Delete req for CellId");
17470       }
17471    }
17472    FreeUeContextReleaseComplete(f1apMsg);
17473    return ret;
17474
17475 }
17476
17477 /*******************************************************************
17478 *
17479 * @brief added free part for the memory allocated by aper_decoder 
17480 *
17481 * @details
17482 *
17483 *    Function : freeAperDecodeUeContextReleaseCommand 
17484 *
17485 *    Functionality: added free part for the memory allocated by aper_decoder
17486 *
17487 * @params[in] F1AP_PDU_t *f1apMsg
17488 * @return void
17489 *
17490 * ****************************************************************/
17491 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17492 {
17493    uint8_t ieIdx=0;
17494    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17495
17496    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17497    
17498    if(ueContextReleaseCommand->protocolIEs.list.array)
17499    {
17500       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17501       {
17502          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17503          {
17504             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17505             {
17506                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17507                   break;
17508                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17509                   break;
17510                case ProtocolIE_ID_id_Cause:
17511                   break;
17512                case ProtocolIE_ID_id_RRCContainer:
17513                {
17514                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17515                   {
17516                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17517                   }
17518                   break;
17519                }
17520                default :
17521                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17522                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17523                   break;
17524             }
17525          }
17526          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17527       }
17528       free(ueContextReleaseCommand->protocolIEs.list.array);
17529    }
17530 }
17531 /*******************************************************************
17532 *
17533 * @brief processing of UE Context Release Command
17534 *
17535 * @details
17536 *
17537 *    Function : procF1UeContextReleaseCommand 
17538 *
17539 *    Functionality: processing of UE Context Release Command
17540 *
17541 * @params[in] F1AP_PDU_t *f1apMsg
17542 * @return void
17543 *
17544 * ****************************************************************/
17545 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17546 {
17547    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17548    uint16_t cellIdx =0, cellId = 0;
17549    bool ueIdxFound = false;
17550    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17551    DuUeCb   *duUeCb = NULLP;
17552    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17553
17554    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17555
17556    if(ueContextReleaseCommand->protocolIEs.list.array)
17557    {
17558       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17559       {
17560          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17561          {
17562             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17563             {
17564                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17565                   {
17566                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17567                                     value.choice.GNB_CU_UE_F1AP_ID;
17568                      break;
17569                   }
17570
17571                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17572                   {
17573                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17574                                      value.choice.GNB_DU_UE_F1AP_ID;
17575                      break;
17576                   }
17577
17578                case ProtocolIE_ID_id_Cause:
17579                   {
17580                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17581                      {
17582                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17583                         {
17584                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17585                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17586                            {
17587                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17588                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17589                               ueIdxFound = true;
17590                               break;
17591                            }
17592                         }
17593                         if(ueIdxFound == true)
17594                         {
17595                            break;
17596                         }
17597                      }
17598                      
17599                      if(!ueIdxFound)
17600                      {
17601                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17602                         ret = RFAILED;
17603                      }
17604                      break;
17605                   }
17606
17607                case ProtocolIE_ID_id_RRCContainer:
17608                   {
17609                      if(ueIdxFound == true)  
17610                      {
17611                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17612                         if(duUeCb->f1UeDb)
17613                         {
17614                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17615                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17616                            duUeCb->f1UeDb->cellIdx = cellIdx;
17617                            /* Filling Dl RRC Msg Info */
17618                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17619                            if(!duUeCb->f1UeDb->dlRrcMsg)
17620                            {
17621                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17622                                     Memory allocation failed ");
17623                               ret = RFAILED;
17624                            }
17625                            else
17626                            {
17627                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17628                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17629                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17630                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17631                                     value.choice.RRCContainer);
17632                            }
17633
17634                         }
17635                         else
17636                         {
17637                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17638                                  Memory allocation failed ");
17639                            ret = RFAILED;
17640
17641                         }
17642                      }
17643                      break;
17644                   }
17645                default :
17646                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17647                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17648                   break;
17649             }
17650          }
17651       }
17652    }
17653    if(ret != RFAILED)
17654    {
17655       duProcUeContextReleaseCommand(cellId, duUeCb);
17656    }
17657    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17658    return ret;
17659 }
17660
17661 /**************************************************************
17662  *
17663  * @brief free the memory allocated by aper decoder for paging
17664  *
17665  * @details
17666  *
17667  *    Function : freeAperDecodePagingMsg
17668  *
17669  *    Functionality:
17670  *         - free the memory allocated by aper decoder for
17671  *         the paging f1ap msg
17672  *
17673  * @params[in] Paging_t   *paging
17674  * @return ROK     - success
17675  *         RFAILED - failure
17676  *
17677  ****************************************************************/
17678 void freeAperDecodePagingMsg(Paging_t   *paging)
17679 {
17680    uint8_t ieIdx, cellIdx;
17681    PagingCell_ItemIEs_t *pagingCellItemIes;
17682    PagingCell_Item_t *pagingCellItem;
17683    PagingCell_list_t  *pagingCelllist;
17684
17685    if(paging)
17686    {
17687       if(paging->protocolIEs.list.array)
17688       {
17689          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17690          {
17691             if(paging->protocolIEs.list.array[ieIdx])
17692             {
17693                switch(paging->protocolIEs.list.array[ieIdx]->id)
17694                {
17695                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17696                      {
17697                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17698                         break;
17699                      }
17700                   case ProtocolIE_ID_id_PagingIdentity:
17701                      {
17702                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17703                         {
17704                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17705                            {
17706                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17707                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17708                               {
17709                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17710                               }
17711                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17712                            }
17713                         }
17714                         break;
17715                      }
17716                   case ProtocolIE_ID_id_PagingCell_List:
17717                      {
17718                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17719                         if(pagingCelllist->list.array)
17720                         {
17721                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17722                            {
17723                               if(pagingCelllist->list.array[cellIdx])
17724                               {
17725                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17726                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17727                                  {
17728                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17729                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17730                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17731                                  }
17732                                  free(pagingCelllist->list.array[cellIdx]);
17733                               }
17734                            }
17735                            free(pagingCelllist->list.array);
17736                         }
17737                         break;
17738                      }
17739                }
17740                free(paging->protocolIEs.list.array[ieIdx]);
17741             }
17742          }
17743          free(paging->protocolIEs.list.array);
17744
17745       }
17746    }
17747 }
17748
17749 /**************************************************************
17750  *
17751  * @brief processing the paging f1ap msg received from CU 
17752  *
17753  * @details
17754  *
17755  *    Function : procPagingMsg
17756  *
17757  *    Functionality:
17758  *         - processing the paging f1ap msg received from CU
17759  *
17760  * @params[in] F1AP_PDU_t *f1apMsg
17761  * @return ROK     - success
17762  *         RFAILED - failure
17763  *
17764  *
17765  ****************************************************************/
17766 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17767 {
17768    uint8_t ieIdx = 0, cellListIdx = 0;
17769    uint64_t cellId = 0;
17770    Paging_t   *paging = NULLP;
17771    PagingCell_list_t  *pagingCelllist = NULLP;
17772    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17773    PagingCell_Item_t *pagingCellItem = NULLP;
17774    DuPagingMsg *tmpPagingParam = NULLP;
17775
17776    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17777    if(paging)
17778    {
17779       if(paging->protocolIEs.list.array)
17780       {
17781          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17782          if(tmpPagingParam == NULLP)
17783          {
17784             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17785             freeAperDecodePagingMsg(paging);
17786             return RFAILED;
17787          }
17788          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17789          {
17790             if(paging->protocolIEs.list.array[ieIdx])
17791             {
17792                switch(paging->protocolIEs.list.array[ieIdx]->id)
17793                {
17794                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17795                      {
17796                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17797                                          &tmpPagingParam->pagUeId);
17798                         break;
17799                      }
17800
17801                   case ProtocolIE_ID_id_PagingIdentity:
17802                      {
17803                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17804                         {
17805                            case PagingIdentity_PR_cNUEPagingIdentity: 
17806                               {
17807                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17808                                  {
17809                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17810                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17811
17812                                  }
17813                                  break;
17814                               }
17815                             case PagingIdentity_PR_rANUEPagingIdentity:
17816                                {
17817                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17818                                   break;
17819                                }
17820                             default:
17821                                {
17822                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17823                                   continue;
17824                                }
17825                         }
17826                      }
17827
17828                   case ProtocolIE_ID_id_PagingDRX:
17829                      {
17830                         tmpPagingParam->pagingDrxPres = TRUE;
17831                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17832                         break;
17833                      }
17834
17835                   case ProtocolIE_ID_id_PagingPriority:
17836                      {
17837                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17838                         break;
17839                      }
17840
17841                   case ProtocolIE_ID_id_PagingCell_List:
17842                      {
17843                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17844                         if(pagingCelllist->list.array)
17845                         {
17846                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17847                            {
17848                               if(pagingCelllist->list.array[cellListIdx])
17849                               {
17850                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17851                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17852                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17853                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17854                                  {
17855                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17856                                     continue;
17857                                  }
17858                               }
17859                            }
17860                         }
17861                         break;
17862                      }
17863                    default:
17864                      {
17865                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17866                          break;
17867                      }
17868                }
17869             }
17870          }
17871       }
17872    }
17873    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17874    freeAperDecodePagingMsg(paging);
17875   
17876    return ROK;
17877 }
17878
17879 /**************************************************************
17880  *
17881  * @brief Handles received F1AP message and sends back response  
17882  *
17883  * @details
17884  *
17885  *    Function : F1APMsgHdlr
17886  *
17887  *    Functionality:
17888  *         - Decodes received F1AP control message
17889  *         - Prepares response message, encodes and sends to SCTP
17890  *
17891  * @params[in] 
17892  * @return ROK     - success
17893  *         RFAILED - failure
17894  *
17895  * ****************************************************************/
17896 void F1APMsgHdlr(Buffer *mBuf)
17897 {
17898    int i =0;
17899    char *recvBuf =NULLP;
17900    MsgLen copyCnt =0;
17901    MsgLen recvBufLen =0;
17902    F1AP_PDU_t *f1apMsg =NULLP;
17903    asn_dec_rval_t rval; /* Decoder return value */
17904    F1AP_PDU_t f1apasnmsg ;
17905    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17906    ODU_PRINT_MSG(mBuf, 0,0);
17907
17908    /* Copy mBuf into char array to decode it */
17909    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17910    DU_ALLOC(recvBuf, (Size)recvBufLen);
17911
17912    if(recvBuf == NULLP)
17913    {
17914       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17915       return;
17916    }
17917    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17918    {
17919       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17920       return;
17921    }
17922
17923 #ifdef DEBUG_ASN_PRINT
17924    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17925    for(i=0; i< recvBufLen; i++)
17926    {
17927       printf("%x",recvBuf[i]);
17928    }
17929 #endif
17930
17931    /* Decoding flat buffer into F1AP messsage */
17932    f1apMsg = &f1apasnmsg;
17933    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17934
17935    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17936
17937    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17938    {
17939       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17940       return;
17941    }
17942    printf("\n");
17943    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17944
17945    switch(f1apMsg->present)
17946    {
17947       case F1AP_PDU_PR_successfulOutcome:
17948          {
17949             switch(f1apMsg->choice.successfulOutcome->value.present)
17950             {
17951                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17952                   {
17953                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17954                      break;
17955                   }
17956                case SuccessfulOutcome__value_PR_F1SetupResponse:
17957                   {                             
17958 #ifndef ODU_TEST_STUB
17959                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17960 #endif
17961                      break;
17962                   }
17963
17964                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17965                   {
17966                      procF1GNBDUCfgUpdAck(f1apMsg);
17967                      break;
17968                   }
17969
17970                default:
17971                   {
17972                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17973                            f1apMsg->choice.successfulOutcome->value.present);
17974                      return;
17975                   }
17976             }/* End of switch(successfulOutcome) */
17977             free(f1apMsg->choice.successfulOutcome);
17978             break;
17979          }
17980       case F1AP_PDU_PR_initiatingMessage:
17981          {
17982             switch(f1apMsg->choice.initiatingMessage->value.present)
17983             {
17984                case InitiatingMessage__value_PR_Reset:
17985                   {
17986                      procF1ResetReq(f1apMsg);
17987                      break;
17988                   }
17989                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17990                   {
17991                      procF1DlRrcMsgTrans(f1apMsg);
17992                      break;
17993                   }
17994                case InitiatingMessage__value_PR_UEContextSetupRequest:
17995                   {
17996                      procF1UeContextSetupReq(f1apMsg);
17997                      break;
17998                   }
17999                case InitiatingMessage__value_PR_UEContextModificationRequest:
18000                   {
18001                      procF1UeContextModificationReq(f1apMsg);
18002                      break;
18003                   }
18004                case InitiatingMessage__value_PR_UEContextReleaseCommand:
18005                   {
18006                       procF1UeContextReleaseCommand(f1apMsg);
18007                       break;
18008                   }
18009                case InitiatingMessage__value_PR_Paging:
18010                   {
18011                      procPagingMsg(f1apMsg);
18012                      break;
18013                   }
18014                default:
18015                   {
18016                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18017                            f1apMsg->choice.initiatingMessage->value.present);
18018                      return;
18019                   }
18020             }/* End of switch(initiatingMessage) */
18021             free(f1apMsg->choice.initiatingMessage);
18022             break;
18023          }
18024
18025       default:
18026          {
18027             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18028             return;
18029          }
18030          free(f1apMsg);
18031
18032    }/* End of switch(f1apMsg->present) */
18033    
18034    DU_FREE(recvBuf, (Size)recvBufLen);
18035 } /* End of F1APMsgHdlr */
18036
18037 /**********************************************************************
18038   End of file
18039  **********************************************************************/