[Epic-ID: ODUHIGH-463][Task-ID: ODUHIGH-509]Fix for memory leak and F1AP message...
[o-du/l2.git] / src / du_app / du_f1ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "ckw.h"
22 #include "ckw.x"
23 #include "kwu.h"
24 #include "kwu.x"
25 #include "lkw.h"
26 #include "lrg.h"
27 #include "legtp.h"
28 #include "lkw.x"
29 #include "lrg.x"
30 #include "F1AP-PDU.h"
31 #include "InitiatingMessage.h"
32 #include "SuccessfulOutcome.h"
33 #include "du_app_mac_inf.h"
34 #include "du_cfg.h"
35 #include "du_app_rlc_inf.h"
36 #include "du_mgr_main.h"
37 #include "du_mgr.h"
38 #include "du_utils.h"
39 #include "du_ue_mgr.h"
40 #include "RAT-Type.h"
41 #include "NRFreqInfo.h"
42 #include "NRCGI.h"
43 #include "TDD-Info.h"
44 #include "NR-Mode-Info.h"
45 #include "ServedPLMNs-List.h"
46 #include "GNB-DU-Served-Cells-List.h"
47 #include "Served-Cell-Information.h"
48 #include "ProtocolExtensionContainer.h"
49 #include "RRC-Version.h"
50 #include "FDD-Info.h"
51 #include "FreqBandNrItem.h"
52 #include "ServedPLMNs-Item.h"
53 #include "GNB-DU-Served-Cells-Item.h"
54 #include "SliceSupportItem.h"
55 #include "FeatureSetUplinkPerCC.h"
56 #include "SliceSupportItem.h"
57 #include "Served-Cells-To-Modify-Item.h"
58 #include "Served-Cells-To-Delete-List.h"
59 #include "Served-Cells-To-Delete-Item.h"
60 #include "QoSInformation.h"
61 #include "ULUPTNLInformation-ToBeSetup-List.h"
62 #include "DRB-Information.h"
63 #include "DRBs-ToBeSetup-Item.h"
64 #include "DRBs-ToBeSetupMod-Item.h"
65 #include "DRBs-ToBeModified-Item.h"
66 #include "CUtoDURRCInformation.h"
67 #include "SCell-ToBeSetup-List.h"
68 #include "SRBs-ToBeSetup-List.h"
69 #include "DRBs-ToBeSetup-List.h"
70 #include "SRBs-ToBeSetup-Item.h"
71 #include "DRBs-ToBeModified-List.h"
72 #include "RRCContainer.h"
73 #include "UE-CapabilityRAT-ContainerList.h"
74 #include "DRBs-Setup-List.h"
75 #include "CellGroupConfig.h"
76 #include "ResetAll.h"
77 #include "ResetType.h"
78 #include "Cells-to-be-Activated-List.h"
79 #include "GNB-CU-Name.h"
80 #include "SRBs-SetupMod-List.h"
81 #include "DRBs-SetupMod-List.h"
82 #include "DRBs-ToBeSetupMod-List.h"
83 #include "PagingCell-Item.h"
84 #include "PagingCell-list.h"
85 #include "QoS-Characteristics.h"
86 #include "ULUPTNLInformation-ToBeSetup-Item.h"
87 #include "Flows-Mapped-To-DRB-Item.h"
88 #include "NonDynamic5QIDescriptor.h"
89 #include "Dynamic5QIDescriptor.h"
90 #include "FeatureSetDownlinkPerCC.h"
91 #include "FeatureSets.h"
92 #include "UE-NR-Capability.h"
93 #include "UE-CapabilityRAT-Container.h"
94 #include "UE-CapabilityRAT-ContainerListRRC.h"
95 #include "GNB-DU-System-Information.h"
96 #include "CellGroupConfigRrc.h"
97 #include "MAC-CellGroupConfig.h"
98 #include "SchedulingRequestConfig.h"
99 #include "SchedulingRequestToAddMod.h"
100 #include "BSR-Config.h"
101 #include "TAG-Config.h"
102 #include "TAG.h"
103 #include "PHR-Config.h"
104 #include "RLC-Config.h"
105 #include "UL-AM-RLC.h"
106 #include "DL-AM-RLC.h"
107 #include "LogicalChannelConfig.h"
108 #include "RLC-BearerConfig.h"
109 #include "PhysicalCellGroupConfig.h"
110 #include "SpCellConfig.h"
111 #include "TDD-UL-DL-ConfigDedicated.h"
112 #include "ServingCellConfig.h"
113 #include "ControlResourceSet.h"
114 #include "SearchSpace.h"
115 #include "PDCCH-Config.h"
116 #include "PDSCH-TimeDomainResourceAllocation.h"
117 #include "PDSCH-TimeDomainResourceAllocationList.h"
118 #include "PDSCH-CodeBlockGroupTransmission.h"
119 #include "PDSCH-ServingCellConfig.h"
120 #include "DMRS-DownlinkConfig.h"
121 #include "PDSCH-Config.h"
122 #include "BWP-DownlinkDedicated.h"
123 #include "BWP-Downlink.h"
124 #include "PUSCH-TimeDomainResourceAllocation.h"
125 #include "PUSCH-TimeDomainResourceAllocationList.h"
126 #include "DMRS-UplinkConfig.h"
127 #include "PUSCH-Config.h"
128 #include "SRS-ResourceId.h"
129 #include "SRS-Resource.h"
130 #include "SRS-ResourceSet.h"
131 #include "SRS-Config.h"
132 #include "BWP-UplinkDedicated.h"
133 #include "PUSCH-ServingCellConfig.h"
134 #include "UplinkConfig.h"
135 #include "DUtoCURRCContainer.h"
136 #include "GBR-QoSFlowInformation.h"
137 #include "QoSFlowLevelQoSParameters.h"
138 #include "PUCCH-Config.h"
139 #include "PUCCH-ResourceSet.h"
140 #include "PUCCH-Resource.h"
141 #include "PUCCH-PowerControl.h"
142 #include "P0-PUCCH.h"
143 #include "PUCCH-PathlossReferenceRS.h"
144 #include "PUCCH-format0.h"
145 #include "PUCCH-format1.h"
146 #include "PUCCH-format2.h"
147 #include "PUCCH-format3.h"
148 #include "PUCCH-format4.h"
149 #include "PUCCH-FormatConfig.h"
150 #include "SchedulingRequestResourceConfig.h"
151 #include<ProtocolIE-Field.h>
152 #include "ProtocolExtensionField.h"
153 #include "odu_common_codec.h"
154 #include "du_mgr.h"
155 #include "du_cell_mgr.h"
156 #include "du_f1ap_msg_hdl.h"
157 #include "DRBs-Setup-Item.h"
158 #include "DLUPTNLInformation-ToBeSetup-List.h"
159 #include "DLUPTNLInformation-ToBeSetup-Item.h"
160 #include "UPTransportLayerInformation.h"
161 #include "GTPTunnel.h"
162 #include "SupportedSULFreqBandItem.h"
163 #include "du_e2ap_msg_hdl.h"
164 #include "du_f1ap_conversions.h"
165 #include "CNUEPagingIdentity.h"
166 #include "PCCH-Config.h"
167 #include "SCS-SpecificCarrier.h"
168 #include "FrequencyInfoDL.h"
169 #include "DownlinkConfigCommon.h"
170 #include "FrequencyInfoUL.h"
171 #include "UplinkConfigCommon.h"
172 #include "TDD-UL-DL-ConfigCommon.h"
173 #include "RACH-ConfigDedicated.h"
174 #include "CFRA-SSB-Resource.h"
175 #include "BWP-UplinkCommon.h"
176 #include "ReconfigurationWithSync.h"
177 #include "BCCH-DL-SCH-Message.h"
178 #include "du_sys_info_hdl.h"
179 #include "DRX-ConfigRrc.h"
180 #include "MeasurementTimingConfigurationRrc.h"
181 #include "MeasurementTimingConfigurationRrc-IEs.h"
182 #include "MeasTimingList.h"
183 #include "MeasTiming.h"
184 #include "Cells-Status-List.h"
185 #include "Cells-Status-Item.h"
186
187 #ifdef O1_ENABLE
188 #include "CmInterface.h"
189 extern StartupConfig g_cfg;
190 #endif
191
192 DuCfgParams duCfgParam;
193
194 /******************************************************************
195  *
196  * @brief Function to fetch lcId based on DRB Id
197  *
198  * @details
199  *
200  *    Function : fetchLcId
201  *
202  *    @params[in] drbId
203  *
204  *    Functionality: Function to fetch lcId based on DRB Id
205  *
206  * Returns: lcId - SUCCESS
207  *          RFAILED - FAILURE
208  *****************************************************************/
209
210 uint8_t fetchLcId(uint8_t drbId)
211 {
212    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
213
214    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
215    {
216       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
217       {
218          if(duCb.actvCellLst[cellIdx] != NULLP)
219          {
220             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
221             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
222             {
223                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
224                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
225                {
226                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
227                   return lcId;
228                }
229             }
230          }
231       }
232    }
233    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
234    return RFAILED;
235 }
236
237 /*******************************************************************
238 *
239 * @brief Adding F1AP pdu to reserved pdu list
240 *
241 * @details
242 *
243 *    Function : addToReservedF1apPduList 
244 *
245 *    Functionality: Adding F1AP pdu to reserved pdu list.
246 *     These pdu are awaiting aknowledgment from CU
247 *
248 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
249 *
250 * @return ROK - success
251 *         RFAILED - failure
252 *
253 * ****************************************************************/
254 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
255 {
256    CmLList         *node = NULLP;
257    ReservedF1apPduInfo *pduInfo = NULLP;
258    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
259    if(pduInfo)
260    {
261       DU_ALLOC(node, sizeof(CmLList));
262       if(node)
263       {
264          pduInfo->transId = transId;
265          pduInfo->f1apMsg = (void*) f1apPdu;
266
267          node->node = (PTR)pduInfo;
268          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
269       }
270    }
271 }
272
273 /*******************************************************************
274 *
275 * @brief searching for F1AP pdu from ReservedF1apPduList 
276 *
277 * @details
278 *
279 *    Function : searchFromReservedF1apPduList 
280 *
281 *    Functionality: searching for F1AP pdu information
282 *
283 * @params[in] uint8_t transId
284 *
285 * @return pointer to F1AP_PDU_t
286 *
287 * ****************************************************************/
288
289 CmLList *searchFromReservedF1apPduList(uint8_t transId)
290 {
291    CmLList         *node;
292    ReservedF1apPduInfo *f1apPdu;
293    if(duCb.reservedF1apPduList.count)
294    {
295       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
296       while(node)
297       {
298          f1apPdu = (ReservedF1apPduInfo*)node->node;
299          if(f1apPdu->transId == transId)
300          {
301             return node;
302          }
303          node = node->next;
304       }
305    }
306    return NULL;
307 }
308
309 /*******************************************************************
310 *
311 * @brief deleting F1AP pdu information from ReservedF1apPduList
312 *
313 * @details
314 *
315 *    Function : deleteFromReservedF1apPduList 
316 *
317 *    Functionality: deleting pdu information from ReservedF1apPduList
318 *
319 * @params[in] CmLList *node 
320 *
321 * @return void 
322 *
323 * ****************************************************************/
324
325 void deleteFromReservedF1apPduList(CmLList *node)
326 {
327    ReservedF1apPduInfo *f1apPdu;
328
329    if(node != NULL)
330    {
331       f1apPdu = (ReservedF1apPduInfo *)node->node;
332       cmLListDelFrm(&duCb.reservedF1apPduList, node);
333       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
334       DU_FREE(node, sizeof(CmLList));
335       node = NULL;
336    }
337 }
338
339 /*******************************************************************
340  *
341  * @brief Builds Uplink Info for NR 
342  *
343  * @details
344  *
345  *    Function : BuildULNRInfo
346  *
347  *    Functionality: Building NR Uplink Info
348  *
349  * @params[in] NRFreqInfo_t *ulnrfreq
350  * @return ROK     - success
351  *         RFAILED - failure
352  *
353  * ****************************************************************/
354 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
355 {
356    uint8_t idx=0;
357    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
358                        fdd.ulNrFreqInfo.nrArfcn;
359    ulnrfreq->freqBandListNr.list.count = 1;
360    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
361    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
362    if(ulnrfreq->freqBandListNr.list.array == NULLP)
363    {
364       return RFAILED;
365    }
366    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
367    {
368       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
369       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
370       {
371          return RFAILED;
372       }
373    }
374    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
375                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
376                                                                  freqBand[0].nrFreqBand;
377    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
378    return ROK;
379 }
380 /*******************************************************************
381  *
382  * @brief Builds Downlink NR Info 
383  *
384  * @details
385  *
386  *    Function : BuildDLNRInfo
387  *
388  *    Functionality: Building Downlink NR Info
389  *    
390  * @params[in] NRFreqInfo_t *dlnrfreq
391  * @return ROK     - success
392  *         RFAILED - failure
393  *
394  * ****************************************************************/
395 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
396 {
397    uint8_t idx=0;
398    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
399                        fdd.dlNrFreqInfo.nrArfcn;
400    dlnrfreq->freqBandListNr.list.count = 1;
401    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
402    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
403    if(dlnrfreq->freqBandListNr.list.array == NULLP)
404    {
405       return RFAILED;   
406    }
407    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
408    {
409       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
410       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
411       {
412          return RFAILED;
413       }
414    }   
415    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
416                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
417                                                                  freqBand[0].nrFreqBand;
418    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
419
420    return ROK;
421 }
422
423 /*******************************************************************
424  *
425  * @brief Builds Nrcgi 
426  *
427  * @details
428  *
429  *    Function : BuildNrcgi
430  *
431  *    Functionality: Building the PLMN ID and NR Cell id
432  *
433  * @params[in] NRCGI_t *nrcgi
434  * @return ROK     - success
435  *         RFAILED - failure
436  *
437  * ****************************************************************/
438 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
439 {
440    uint8_t ret;
441    uint8_t byteSize = 5;
442    /* Allocate Buffer Memory */
443    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
444    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
445    if(nrcgi->pLMN_Identity.buf == NULLP)
446    {
447       return RFAILED;
448    }
449    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
450          nrcgi->pLMN_Identity.buf); // Building PLMN function
451    if(ret != ROK)
452    {
453       return RFAILED;
454    }
455    /*nrCellIdentity*/
456    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
457    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
458    if(nrcgi->nRCellIdentity.buf == NULLP)
459    {
460       return RFAILED;
461    }
462    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
463
464    return ROK;
465 }
466 /*******************************************************************
467  *
468  * @brief Builds FiveGStac 
469  *
470  * @details
471  *
472  *    Function : BuildFiveGSTac
473  *
474  *    Functionality: Building the FiveGSTac
475  *
476  * @params[in] OCTET_STRING_t *fivegsTac
477  * @return ROK     - success
478  *         RFAILED - failure
479  *
480  * ****************************************************************/
481 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
482 {
483    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
484    if(servcell->fiveGS_TAC == NULLP)
485    {
486       return RFAILED;
487    }
488    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
489    DU_ALLOC(servcell->fiveGS_TAC->buf,\
490          sizeof(servcell->fiveGS_TAC->size));
491    if(servcell->fiveGS_TAC->buf == NULLP)
492    {
493       return RFAILED;
494    }
495    servcell->fiveGS_TAC->buf[0] = 0;
496    servcell->fiveGS_TAC->buf[1] = 0;
497    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
498    return ROK;  
499 }
500
501 /*******************************************************************
502  *
503  * @brief fill nr frequency information
504  *
505  * @details
506  *
507  *    Function : fillNrTddInfo 
508  *
509  *    Functionality: fill nr frequency information
510  *
511  * @params[in] NRFreqInfo_t freqInfo
512  * @return ROK     - success
513  *         RFAILED - failure
514  *
515  * ****************************************************************/
516 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
517 {
518    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
519    NRFreqInfo_t *freqInfo = NULLP;
520
521    if(tddInfo == NULLP)
522    {
523       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
524       return RFAILED;
525    }
526    
527    freqInfo = &tddInfo->nRFreqInfo;
528    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
529
530    freqInfo->freqBandListNr.list.count = elementCnt; 
531    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
532    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
533    if(!freqInfo->freqBandListNr.list.array)
534    {
535       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
536       return RFAILED;
537    }
538
539    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
540    {
541       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
542       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
543       {
544          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
545          return RFAILED;
546       }
547
548       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
549       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
550
551       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
552       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
553       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
554
555       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
556             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
557       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
558       {
559          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
560          return RFAILED;
561       }
562
563       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
564       {
565          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
566                sizeof(SupportedSULFreqBandItem_t));
567          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
568          {
569             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
570             return RFAILED;
571          }
572
573          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
574          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
575       }
576    }
577
578    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
579    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
580
581    return ROK;
582 }
583
584 /*******************************************************************
585  *
586  * @brief Builds NR Mode 
587  *
588  * @details
589  *
590  *    Function : BuildNrMode
591  *
592  *    Functionality: Building the NR Mode
593  *
594  * @params[in] NR_Mode_Info_t *fdd
595  * @return ROK     - success
596  *         RFAILED - failure
597  *
598  * ****************************************************************/
599 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
600 {
601    uint8_t BuildDLNRInforet=0;
602    uint8_t BuildULNRInforet=0; 
603    
604 #ifdef NR_TDD
605    mode->present = NR_Mode_Info_PR_tDD;
606 #else
607    mode->present = NR_Mode_Info_PR_fDD;
608 #endif   
609    
610    if(mode->present == NR_Mode_Info_PR_fDD)
611    {
612       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
613       if(mode->choice.fDD == NULLP)
614       {
615          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
616          return RFAILED;
617       }
618       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
619       if(BuildULNRInforet != ROK)
620       {
621          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
622          return RFAILED;    
623       }
624       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
625       if(BuildDLNRInforet != ROK)
626       {
627          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
628          return RFAILED;
629       }
630       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
631                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
632                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
633       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
634                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
635                                                           f1Mode.mode.fdd.ulTxBw.nrb;
636       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
637                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
638                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
639       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
640                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
641                                                           f1Mode.mode.fdd.dlTxBw.nrb;
642    }
643    else if(mode->present == NR_Mode_Info_PR_tDD) 
644    {
645       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
646       if(mode->choice.tDD == NULLP)
647       {
648          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
649          return RFAILED;
650       }
651
652       if(fillNrTddInfo(mode->choice.tDD) != ROK)
653       {
654          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
655          return RFAILED;
656       }
657
658    }
659
660    return ROK;
661 }
662 /*******************************************************************
663  *
664  * @brief Builds IE Extensions for Served PLMNs 
665  *
666  * @details
667  *
668  *    Function : BuildExtensions
669  *
670  *    Functionality: Building the IE Extensions
671  *
672  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
673  * @return ROK     - success
674  *         RFAILED - failure
675  *
676  * ****************************************************************/
677 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
678 {
679    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
680    uint8_t elementCnt=0, extensionCnt=0;
681
682    extensionCnt=IE_EXTENSION_LIST_COUNT;
683    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
684    if((*ieExtend) == NULLP)
685    {
686       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
687       return RFAILED;
688    }
689    (*ieExtend)->list.count = extensionCnt;
690    (*ieExtend)->list.size = \
691                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
692    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
693    if((*ieExtend)->list.array == NULLP)
694    {
695       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
696       return RFAILED;
697    }
698    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
699    {
700       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
701             sizeof(ServedPLMNs_ItemExtIEs_t));
702       if((*ieExtend)->list.array[plmnidx] == NULLP)
703       {
704          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
705          return RFAILED;
706       }
707    }
708    
709    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
710    idx = 0;
711    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
712    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
713    (*ieExtend)->list.array[idx]->extensionValue.present = \
714    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
715    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
716       list.count = elementCnt;
717    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
719       list.count * sizeof(SliceSupportItem_t *);
720
721    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
722          list.array, elementCnt * sizeof(SliceSupportItem_t *));
723    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
724          list.array == NULLP)
725    {
726       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
727       return RFAILED;
728    }
729
730    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
731    {
732       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
733             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
734       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
735             list.array[sliceLstIdx] == NULLP) 
736       {
737          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
738          return RFAILED;
739       }
740       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
741          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
742       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
743             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
744             extensionValue.choice.SliceSupportList.\
745             list.array[sliceLstIdx]->sNSSAI.sST.size);
746       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
747             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
748       {
749          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
750          return RFAILED;
751       }
752       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
753          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
754          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
755       
756       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
757             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
758       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
759             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
760       {
761          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
762          return RFAILED;
763       }
764       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
765          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
766       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
767             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
768             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
769       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
770             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
771       {
772          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
773          return RFAILED;
774       }
775       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
776       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
777       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
778       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
779    }
780    return ROK;
781 }
782 /*******************************************************************
783  *
784  * @brief Builds Served PLMN 
785  *
786  * @details
787  *
788  *    Function : BuildServedPlmn
789  *
790  *    Functionality: Building the Served PLMN
791  *
792  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
793  * @return ROK     - success
794  *         RFAILED - failure
795  *
796  * ****************************************************************/
797 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
798 {  
799    uint8_t  plmnidx;
800    uint8_t  servPlmnCnt=1;
801    uint8_t buildPlmnIdret=0;
802    uint8_t BuildExtensionsret=0;
803    srvplmn->list.count = servPlmnCnt;
804    srvplmn->list.size = \
805                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
806    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
807    if(srvplmn->list.array == NULLP)
808    {
809       return RFAILED;
810    }
811    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
812    {   
813       DU_ALLOC(srvplmn->list.array[plmnidx],\
814             sizeof(ServedPLMNs_Item_t));
815       if(srvplmn->list.array[plmnidx] == NULLP)
816       {
817          return RFAILED;
818       }  
819    }
820    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
821    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
822    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
823          srvplmn->list.array[0]->pLMN_Identity.buf);
824    if(buildPlmnIdret!= ROK)
825    {
826       return RFAILED;
827    }
828    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
829    if(BuildExtensionsret!= ROK)
830    {
831       return RFAILED;
832    }
833    return ROK;
834 }
835
836 /*******************************************************************
837  *
838  * @brief Frees Measurement Timing configuration 
839  *
840  * @details
841  *
842  *    Function : FreeMeasTimingConf
843  *
844  *    Functionality: Frees Timing Configuration
845  *
846  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
847  * @return ROK     - success
848  *         RFAILED - failure
849  *
850  * ****************************************************************/
851 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
852 {
853    uint8_t measIeIdx = 0;
854    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
855
856    if(measTimingConfRrc.criticalExtensions.choice.c1)
857    {
858       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
859       {
860          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
861          if(measTimingConfIEs->measTiming)
862          {
863             if(measTimingConfIEs->measTiming->list.array)
864             {
865                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
866                {
867                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
868                   {
869                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
870                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
871                   }
872                }
873                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
874             }
875             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
876          }
877          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
878       }
879       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
880    }
881 }
882
883 /*******************************************************************
884  *
885  * @brief Builds MEasuerment Timing Configuration
886  *
887  * @details
888  *
889  *    Function : BuildMeasTimingConf
890  *
891  *    Functionality: Building Measurement Timing Configuration
892  *
893  * @params[in] Pointer to octet string to store Measurement timing
894  *             Configuration
895  * @return ROK     - success
896  *         RFAILED - failure
897  *
898  * ****************************************************************/
899 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
900 {
901    uint8_t ret = RFAILED;
902    uint8_t elementCnt = 0;
903    uint8_t measIeIdx = 0;
904    asn_enc_rval_t encRetVal;
905    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
906    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
907    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
908
909    while(true)
910    {
911       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
912       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
913       if(!measTimingConfRrc.criticalExtensions.choice.c1)
914       {
915          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
916          break;
917       }
918       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
919
920       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
921       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
922       {
923          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
924          break;
925       }
926       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
927
928       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
929       if(!measTimingConfIEs->measTiming)
930       {
931          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
932          break;
933       }
934
935       elementCnt = 1;  
936       measTimingConfIEs->measTiming->list.count = elementCnt;
937       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
938       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
939       if(!measTimingConfIEs->measTiming->list.array)
940       {
941          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
942          break;
943       }
944
945       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
946       {
947          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
948          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
949          {
950             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
951             break;
952          }
953       }
954       if(measIeIdx < elementCnt)
955       {
956          break;
957       }
958
959       measIeIdx = 0;
960       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
961       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
962       {
963          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
964          break;
965       }
966       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
967       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
968       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
969       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
970       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
971       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
972
973       /* Encode the F1SetupRequest type as APER */
974       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
975
976       memset(encBuf, 0, ENC_BUF_MAX_LEN);
977       encBufSize = 0;
978       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
979
980       /* Encode results */
981       if(encRetVal.encoded == ENCODE_FAIL)
982       {     
983          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
984                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
985          break;
986       }     
987       else  
988       {     
989          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
990 #ifdef DEBUG_ASN_PRINT
991          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
992          {
993             printf("%x",encBuf[measIeIdx]);
994          }
995 #endif
996
997          measTimingConf->size = encBufSize;
998          DU_ALLOC(measTimingConf->buf, encBufSize);
999          if(measTimingConf->buf == NULLP)
1000          {
1001             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
1002             return RFAILED;
1003          }
1004          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1005
1006          FreeMeasTimingConf(measTimingConfRrc);
1007
1008          ret = ROK;
1009          break;
1010       }
1011    }
1012    return ret;
1013 }
1014
1015 /*******************************************************************
1016  *
1017  * @brief Builds Served Cell List
1018  *
1019  * @details
1020  *
1021  *    Function : BuildServedCellList
1022  *
1023  *    Functionality: Building Served Cell List
1024  *
1025  * @params[in] PLMNID plmn
1026  * @return ROK     - success
1027  *         RFAILED - failure
1028  *
1029  * ****************************************************************/
1030
1031 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1032 {
1033    uint8_t  BuildNrcgiret=0;
1034    uint8_t  BuildFiveGSTacret=0;
1035    uint8_t  BuildServedPlmnret=0;
1036    uint8_t  BuildNrModeret=0;
1037    uint8_t  idx;
1038    uint8_t  plmnidx;
1039    uint8_t  plmnCnt=1;
1040    GNB_DU_Served_Cells_Item_t *srvCellItem;
1041    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1042    duServedCell->list.count = plmnCnt;
1043
1044    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1045    if(duServedCell->list.array == NULLP)
1046    {
1047       return RFAILED;
1048    }
1049    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1050    {
1051       DU_ALLOC(duServedCell->list.array[plmnidx],\
1052             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1053       if(duServedCell->list.array[plmnidx] == NULLP)
1054       {
1055          return RFAILED;
1056       }
1057    }
1058    idx = 0;
1059    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1060    duServedCell->list.array[idx]->criticality = Criticality_reject;
1061    duServedCell->list.array[idx]->value.present = \
1062                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1063    srvCellItem = \
1064                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1065    /*nRCGI*/
1066    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1067    if(BuildNrcgiret != ROK)
1068    {
1069       return RFAILED;
1070    }
1071    /*nRPCI*/
1072    srvCellItem->served_Cell_Information.nRPCI = \
1073                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1074
1075    /* fiveGS_TAC */
1076    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1077    if(BuildFiveGSTacret != ROK)
1078    {
1079       return RFAILED;
1080    }
1081
1082    /* Served PLMNs */
1083    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1084    if(BuildServedPlmnret !=ROK)
1085    {
1086       return RFAILED;
1087    }
1088
1089    /* nR Mode Info with FDD/TDD */
1090    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1091    if(BuildNrModeret != ROK)
1092    {
1093       return RFAILED;
1094    }
1095
1096    /*Measurement timing Config*/
1097    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1098       return RFAILED;
1099
1100    /* GNB DU System Information */
1101    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1102          sizeof(GNB_DU_System_Information_t));
1103    if(!srvCellItem->gNB_DU_System_Information)
1104    {
1105       return RFAILED;
1106    }
1107    /* MIB */
1108    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1109    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1110          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1111    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1112    {
1113       return RFAILED;
1114    }
1115    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1116          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1117
1118    /* SIB1 */
1119    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1120                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1121
1122    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1123          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1124    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1125    {
1126       return RFAILED;
1127    }
1128    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1129    {
1130       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1131                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1132    }
1133    return ROK; 
1134 }                                                                                                                  
1135 /*******************************************************************
1136  *
1137  * @brief Builds RRC Version 
1138  *
1139  * @details
1140  *
1141  *    Function : BuildRrcVer
1142  *
1143  *    Functionality: Building RRC Version
1144  *
1145  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1146  * @return ROK     - success
1147  *         RFAILED - failure
1148  *
1149  * ****************************************************************/
1150 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1151 {
1152    uint8_t rrcExt;
1153    uint8_t rrcLatest;
1154    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1155    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1156    if(rrcVer->latest_RRC_Version.buf == NULLP)
1157    {
1158       return RFAILED;
1159    }
1160    rrcVer->latest_RRC_Version.buf[0] = 0;
1161    rrcVer->latest_RRC_Version.bits_unused = 5;
1162    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1163    if(rrcVer->iE_Extensions == NULLP)
1164    {  
1165       return RFAILED;
1166    }
1167    rrcVer->iE_Extensions->list.count = 1;
1168    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1169    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1170    if(rrcVer->iE_Extensions->list.array == NULLP)
1171    {
1172       return RFAILED;
1173    }
1174    rrcExt = 0;
1175    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1176          sizeof(RRC_Version_ExtIEs_t));
1177    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1178    {
1179       return RFAILED;
1180    }
1181    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1182                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1183    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1184    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1185                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1186    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1187       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1188    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1189          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1190          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1191    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1192          .Latest_RRC_Version_Enhanced.buf == NULLP)
1193    {
1194       return RFAILED;
1195    }
1196    rrcLatest = 0;
1197    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1198       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1199    rrcLatest++;
1200    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1201       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1202    rrcLatest++;
1203    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1204       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1205    return ROK;
1206 }
1207 /*******************************************************************
1208  *
1209  * @brief Sends F1 msg over SCTP
1210  *
1211  * @details
1212  *
1213  *    Function : sendF1APMsg
1214  *
1215  *    Functionality: Sends F1 msg over SCTP
1216  *
1217  * @params[in] Region region
1218  *             Pool pool
1219  * @return ROK     - success
1220  *         RFAILED - failure
1221  *
1222  * ****************************************************************/
1223 uint8_t sendF1APMsg()
1224 {
1225    Buffer *mBuf = NULLP;
1226   
1227    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1228    {
1229       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1230       {
1231             ODU_PRINT_MSG(mBuf, 0,0);
1232
1233             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1234             {
1235                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1236                ODU_PUT_MSG_BUF(mBuf);
1237                return RFAILED;
1238             }
1239       }
1240       else
1241       {
1242          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1243          ODU_PUT_MSG_BUF(mBuf);
1244          return RFAILED;
1245       }
1246       ODU_PUT_MSG_BUF(mBuf);
1247    }
1248    else
1249    {
1250       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1251       return RFAILED;
1252    }
1253    return ROK; 
1254 } /* sendF1APMsg */
1255
1256 /*******************************************************************
1257  *
1258  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1259  *
1260  * @details
1261  *
1262  *    Function :  FreeRrcVer
1263  *
1264  *    Functionality: deallocating the memory of function BuildRrcVer
1265  *
1266  * @params[in] RRC_Version_t *rrcVer
1267  * 
1268  * @return void
1269  *
1270  *****************************************************************/
1271 void FreeRrcVer(RRC_Version_t *rrcVer)
1272 {
1273    if(rrcVer->latest_RRC_Version.buf != NULLP)
1274    {
1275       if(rrcVer->iE_Extensions != NULLP)
1276       {
1277          if(rrcVer->iE_Extensions->list.array != NULLP)
1278          {
1279             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1280             {
1281                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1282                      != NULLP)
1283                {
1284                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1285                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1286                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1287                }
1288                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1289             }
1290             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1291          }
1292          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1293       }
1294       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1295    }
1296 }
1297
1298 /*******************************************************************
1299  *
1300  * @brief Deallocating memory of TDD NrFreqInfo 
1301  *
1302  * @details
1303  *
1304  *    Function : freeTddNrFreqInfo 
1305  *
1306  *    Functionality: freeTddNrFreqInfo 
1307  *
1308  * @params[in]  F1AP_PDU_t *f1apDuCfg
1309  *
1310  * @return ROK     - void
1311  *
1312  * ****************************************************************/
1313 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1314 {
1315    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1316
1317    if(freqInfo->freqBandListNr.list.array)
1318    {
1319       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1320       {
1321          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1322          {
1323             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1324             {
1325                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1326                {
1327                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1328                         sizeof(SupportedSULFreqBandItem_t));
1329                }
1330                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1331                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1332
1333             }
1334             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1335          }
1336       }
1337       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1338    }
1339 }
1340
1341 /*******************************************************************
1342  *
1343  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1344  *
1345  * @details
1346  *
1347  *    Function : freeFddNrFreqInfo 
1348  *
1349  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1350  *
1351  * @params[in]  
1352  *
1353  * @return ROK     - void
1354  *
1355  * ****************************************************************/
1356 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1357 {
1358    uint8_t arrIdx =0;
1359
1360    if(fDD != NULLP)
1361    {
1362       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1363       {
1364          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1365                array[arrIdx], sizeof(FreqBandNrItem_t));
1366          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1367                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1368       }
1369
1370       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1371       {
1372          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1373                array[arrIdx], sizeof(FreqBandNrItem_t));
1374          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1375                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1376       }
1377       DU_FREE(fDD,sizeof(FDD_Info_t));
1378    }
1379 }
1380
1381 /*******************************************************************
1382  *
1383  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1384  *
1385  * @details
1386  *
1387  *    Function :  FreeServedCellList
1388  *
1389  *    Functionality:  deallocating the memory of function BuildServedCellList
1390
1391  *
1392  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1393  *
1394  * @return void
1395  *
1396  * ****************************************************************/
1397 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1398 {
1399    uint8_t   plmnCnt= 1;
1400    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1401    uint8_t  plmnIdx=0, sliceIdx=0;
1402    GNB_DU_Served_Cells_Item_t *srvCellItem;
1403    ServedPLMNs_Item_t  *servedPlmnItem;
1404    SliceSupportItem_t  *sliceSupportItem;
1405
1406    if(duServedCell->list.array!=NULLP)
1407    {
1408       if(duServedCell->list.array[0]!=NULLP)
1409       {
1410          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1411
1412          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1413                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1414          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1415                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1416
1417          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1418          {
1419             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1420                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1421             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1422          }
1423
1424          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1425          {
1426             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1427             {
1428                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1429                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1430
1431                if(servedPlmnItem->iE_Extensions != NULLP)
1432                {
1433                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1434                   {
1435                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1436                      {
1437                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1438                               SliceSupportList.list.array != NULLP)
1439                         {
1440                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1441                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1442                            {
1443                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1444                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1445                               {
1446                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1447                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1448
1449                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1450
1451                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1452                                  {
1453                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1454                                           sliceSupportItem->sNSSAI.sD->size);
1455                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1456                                  }
1457
1458                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1459                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1460                               }
1461                            }
1462                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1463                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1464                                  extensionValue.choice.SliceSupportList.list.size);
1465                         }
1466                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1467                               sizeof(ServedPLMNs_ItemExtIEs_t));
1468                      }
1469                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1470                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1471                   }
1472                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1473                }
1474                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1475                      sizeof(ServedPLMNs_Item_t));
1476             }
1477             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1478                   sizeof(ServedPLMNs_Item_t *));
1479          }
1480
1481          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1482          {
1483             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1484          }
1485          else   
1486          {
1487             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1488             {
1489                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1490                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1491             }
1492          }
1493          
1494          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1495                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1496
1497          if(srvCellItem->gNB_DU_System_Information != NULLP)
1498          {
1499             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1500             {
1501                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1502                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1503             }
1504
1505             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1506             { 
1507                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1508                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1509             }
1510
1511             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1512          }
1513
1514          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1515       }
1516       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1517    }
1518 }
1519
1520 /*******************************************************************
1521  *
1522  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1523  *
1524  * @details
1525  *
1526  *    Function :  FreeF1SetupReq
1527  *
1528  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1529  *
1530  * @params[in] F1AP_PDU_t *f1apMsg
1531  *
1532  * @return void
1533  *
1534  * ****************************************************************/
1535 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1536 {
1537    uint8_t ieIdx, ieIdx2;
1538    F1SetupRequest_t *f1SetupReq=NULLP;
1539
1540    if(f1apMsg != NULLP)
1541    {
1542       if(f1apMsg->choice.initiatingMessage != NULLP)
1543       {
1544          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1545          if(f1SetupReq->protocolIEs.list.array != NULLP)
1546          {
1547             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1548             {
1549                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1550                {
1551                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1552                   {
1553                      case ProtocolIE_ID_id_TransactionID:
1554                         break;
1555                      case ProtocolIE_ID_id_gNB_DU_ID:
1556                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1557                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1558                         break;
1559                      case ProtocolIE_ID_id_gNB_DU_Name:
1560                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1561                               strlen((char *)duCfgParam.duName));
1562                         break;
1563                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1564                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1565                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1566                         break;
1567                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1568                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1569                         break;
1570                      default:
1571                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1572                         break;
1573                   }
1574                }
1575             }
1576             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1577             {
1578                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1579             }
1580             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1581                   f1SetupReq->protocolIEs.list.size);
1582          }
1583          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1584       }
1585       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1586    }
1587 }
1588
1589 /*******************************************************************
1590  *
1591  * @brief Builds and Send the F1SetupRequest
1592  *
1593  * @details
1594  *
1595  *    Function : BuildAndSendF1SetupReq
1596  *
1597  * Functionality:Fills the F1SetupRequest
1598  *
1599  * @return ROK     - success
1600  *         RFAILED - failure
1601  *
1602  ******************************************************************/
1603 uint8_t BuildAndSendF1SetupReq()
1604 {
1605    uint8_t   ret, ieIdx, elementCnt;
1606    F1AP_PDU_t                 *f1apMsg = NULLP;
1607    F1SetupRequest_t           *f1SetupReq=NULLP;
1608    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1609    RRC_Version_t              *rrcVer=NULLP;
1610    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1611    ret= RFAILED;
1612
1613    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1614    do
1615    {
1616       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1617       if(f1apMsg == NULLP)
1618       {
1619          break;
1620       }
1621       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1622       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1623       if(f1apMsg->choice.initiatingMessage == NULLP)
1624       {
1625          break;
1626       }
1627       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1628       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1629       f1apMsg->choice.initiatingMessage->value.present = \
1630                                                          InitiatingMessage__value_PR_F1SetupRequest;
1631
1632       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1633
1634       elementCnt = 5;
1635
1636       f1SetupReq->protocolIEs.list.count = elementCnt;
1637       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1638
1639       /* Initialize the F1Setup members */
1640       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1641       if(f1SetupReq->protocolIEs.list.array == NULLP)
1642       {
1643          break;
1644       }
1645       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1646       {
1647          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1648                sizeof(F1SetupRequestIEs_t));
1649          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1650          {
1651             break;
1652          }
1653       }
1654
1655       ieIdx = 0;
1656       /*TransactionID*/
1657       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1658       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1659       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1660                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1661       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1662                                                                               TRANS_ID;
1663
1664       /*DU ID*/
1665       ieIdx++;
1666       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1667       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1668       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1669                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1670       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1671                                                                               sizeof(uint8_t);
1672
1673       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1674             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1675       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1676             NULLP)
1677       {
1678          break;
1679       }
1680
1681       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1682                                                                                 duCfgParam.duId;
1683       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1684        * However this string is decoded successfully on online decoders.
1685        * Since this is an optional IE and the value received in it are not
1686        * used as of now, eliminating this IE for now to avoid wireshark error.
1687        */
1688       /*DU Name*/
1689       if(duCfgParam.duName != NULL)
1690       {
1691          ieIdx++;
1692          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1693          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1694          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1695          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1696          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1697                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1698          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1699          {
1700             break;
1701          }
1702          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1703                (char*)duCfgParam.duName);
1704       }
1705
1706       /*Served Cell list */
1707       ieIdx++;
1708       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1709                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1710       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1711       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1712                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1713       duServedCell = &f1SetupReq->protocolIEs.list.\
1714                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1715       if(BuildServedCellList(duServedCell))
1716       {
1717          break;
1718       }
1719
1720       /*RRC Version*/
1721       ieIdx++;
1722       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1723                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1724       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1725       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1726                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1727       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1728       if(BuildRrcVer(rrcVer))
1729       {
1730          break;
1731       }
1732
1733       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1734
1735       /* Encode the F1SetupRequest type as APER */
1736       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1737       encBufSize = 0;
1738       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1739             encBuf);
1740
1741       /* Encode results */
1742       if(encRetVal.encoded == ENCODE_FAIL)
1743       {
1744          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1745                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1746          break;
1747       }
1748       else
1749       {
1750          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1751 #ifdef DEBUG_ASN_PRINT
1752          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1753          {
1754             printf("%x",encBuf[ieIdx]);
1755          }
1756 #endif
1757
1758          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1759          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1760          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1761          {
1762             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1763             return RFAILED;
1764          }
1765          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1766       }
1767
1768       /* Sending msg */
1769       if(sendF1APMsg() != ROK)
1770       {
1771          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1772          break;
1773       }
1774
1775       ret=ROK;
1776       break;
1777    }while(true);
1778
1779    FreeF1SetupReq(f1apMsg);
1780
1781    return ret;
1782 }/* End of BuildAndSendF1SetupReq */
1783
1784 /*******************************************************************
1785  *
1786  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1787  *
1788  * @details
1789  *
1790  *    Function : freeCellsToModifyItem 
1791  *
1792  *    Functionality: Deallocating memory of variables allocated in
1793  *                    BuildAndSendDUConfigUpdate function
1794  *
1795  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1796  *
1797  * @return ROK     - void
1798  *
1799  * ****************************************************************/
1800
1801 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1802 {
1803    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1804    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1805    SliceSupportItem_t *sliceSupportItem = NULLP;
1806
1807    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1808    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1809
1810    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1811            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1812    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1813          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1814
1815    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1816    {
1817       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1818       {
1819          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1820
1821          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1822
1823          if(servedPlmnItem->iE_Extensions != NULLP)
1824          {
1825             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1826             {
1827                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1828                {
1829                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1830                         list.array != NULLP)
1831                   {
1832                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1833                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1834                      {
1835                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1836                               list.array[sliceLstIdx] != NULLP)
1837                         {
1838
1839                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1840                                               SliceSupportList.list.array[sliceLstIdx];
1841
1842                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1843                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1844                            {
1845                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1846                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1847                            }
1848                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1849                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1850                         }
1851                      }
1852                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1853                            choice.SliceSupportList.list.array,\
1854                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1855                            extensionValue.choice.SliceSupportList.list.size);
1856                   }
1857                }
1858                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1859                {
1860                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1861                }
1862                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1863             }
1864             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1865          }
1866       }
1867       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1868       {
1869          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1870       }
1871       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1872          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1873    }
1874    
1875    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1876    {
1877       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1878    }  
1879    else
1880    {
1881       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1882       {
1883          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1884          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1885       }
1886    }
1887    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1888          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1889 }
1890
1891 /*******************************************************************
1892  *
1893  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1894  *
1895  * @details
1896  *
1897  *    Function : FreeDUConfigUpdate
1898  *
1899  *    Functionality: Deallocating memory of variables allocated in
1900  *                    BuildAndSendDUConfigUpdate function
1901  *
1902  * @params[in]  F1AP_PDU_t *f1apDuCfg
1903  *
1904  * @return ROK     - void
1905  *
1906  * ****************************************************************/
1907 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1908 {
1909    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1910    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1911    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1912    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1913    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1914    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1915    Cells_Status_ItemIEs_t *cellStatusItemIE;
1916
1917    if(f1apDuCfg != NULLP)
1918    {
1919       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1920       {
1921          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1922                        value.choice.GNBDUConfigurationUpdate;
1923          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1924          {
1925             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1926             {
1927                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1928                {
1929                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1930                   {
1931                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1932                         {
1933                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1934                                            value.choice.Served_Cells_To_Modify_List;
1935                            if(cellsToModify->list.array != NULLP)
1936                            {
1937                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1938                               {
1939                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1940                                  {
1941                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1942                                           Served_Cells_To_Modify_Item);
1943                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1944                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1945                                  }
1946                               }
1947                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1948                            }
1949                            break;
1950                         }
1951                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1952                         {
1953                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1954                                            value.choice.Served_Cells_To_Delete_List;
1955                            if(cellsToDelete->list.array != NULLP)
1956                            {
1957                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1958                               {
1959                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1960                                  {
1961                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1962                                           cellsToDelete->list.array[cellDeleteIdx]);
1963                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1964                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1965                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1966                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1967                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1968                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1969                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1970                                  }
1971                               }
1972                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1973                            }
1974
1975                            break;
1976                         }
1977                      case ProtocolIE_ID_id_gNB_DU_ID:
1978                         {
1979                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1980                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1981                            break;
1982                         }
1983                      case ProtocolIE_ID_id_Cells_Status_List:
1984                         {
1985                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
1986                            {
1987                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
1988                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
1989                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
1990                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
1991                            }
1992                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
1993                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
1994                         }
1995                   }
1996                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1997                         sizeof(GNBDUConfigurationUpdateIEs_t));
1998                }
1999             }
2000             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2001          }
2002          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2003       }
2004       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2005    }
2006 }
2007
2008 /*******************************************************************
2009  *
2010  * @brief Fills Served Plmns required in ServCellInfo IE
2011  *
2012  * @details
2013  *
2014  *    Function : fillServedPlmns
2015  *
2016  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2017  *
2018  * @params[in] Pointer to ServedPLMNs_List_t *
2019  *
2020  * @return ROK     - success
2021  *         RFAILED - failure
2022  *
2023  *****************************************************************/
2024
2025 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2026 {
2027    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2028
2029    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2030    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2031          array[arrayIdx]->pLMN_Identity.size);
2032    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2033    {
2034       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2035       return RFAILED;
2036    }
2037    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2038          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2039    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2040    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2041    {
2042       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2043       return RFAILED;
2044    }
2045
2046    ieListCnt=1;
2047    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2048    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2049    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2050          iE_Extensions->list.size);
2051    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2052    {
2053       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2054       return RFAILED;
2055    }
2056    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2057    {
2058       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2059             sizeof(ServedPLMNs_ItemExtIEs_t));
2060       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2061       {
2062          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2063          return RFAILED;
2064       }
2065    }
2066    
2067    ieIdx = 0;
2068    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2069    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2070    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2071    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2072    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2073    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2074       list.count = elementCnt;
2075    servedPlmn->list.array[arrayIdx]->\
2076       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2077       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2078    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2079          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2080          list.array,servedPlmn->list.array[arrayIdx]->\
2081          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2082    if(servedPlmn->list.array[arrayIdx]->\
2083          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2084          list.array == NULLP)
2085    {
2086       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2087       return RFAILED;
2088    }
2089
2090    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2091    {
2092       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2093       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2094       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2095       if(servedPlmn->list.array[arrayIdx]->\
2096       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2097       list.array[sliceLstIdx] == NULLP)
2098       {   
2099          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2100          return RFAILED;
2101       }
2102       
2103       servedPlmn->list.array[arrayIdx]->\
2104       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2105       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2106       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2107       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2108       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2109       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2110       sNSSAI.sST.size);
2111       
2112       if(servedPlmn->list.array[arrayIdx]->\
2113       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2114       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2115       {
2116          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2117          return RFAILED;
2118       }
2119       servedPlmn->list.array[arrayIdx]->\
2120       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2121       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2122       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2123
2124       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2125       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2126       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2127       if(servedPlmn->list.array[arrayIdx]->\
2128       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2129       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2130       {
2131          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2132          return RFAILED;
2133       }
2134       servedPlmn->list.array[arrayIdx]->\
2135       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2136       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2137       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2138       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2139       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2140       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2141       list.array[sliceLstIdx]->sNSSAI.sD->size);
2142       if(servedPlmn->list.array[arrayIdx]->\
2143       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2144       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2145       {
2146          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2147          return RFAILED;
2148       }
2149       memcpy(servedPlmn->list.array[arrayIdx]->\
2150       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2151       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2152       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2153       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2154       list.array[sliceLstIdx]->sNSSAI.sD->size);
2155    }
2156    return ROK;
2157 }
2158
2159 /*******************************************************************
2160  *
2161  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2162  *
2163  * @details
2164  *
2165  *    Function : fillNrFddInfo
2166  *
2167  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2168  *
2169  * @params[in] FDD_Info_t *fDD
2170  *
2171  * @return ROK     - success
2172  *         RFAILED - failure
2173  *
2174  *****************************************************************/
2175
2176 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2177 {
2178    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2179       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2180    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2181    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2182    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2183          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2184    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2185    {
2186       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2187       return RFAILED;
2188    }
2189
2190    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2191       sizeof(FreqBandNrItem_t));
2192    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2193    {
2194       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2195       return RFAILED;
2196    }
2197    
2198    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2199       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2200       freqBand[0].nrFreqBand;
2201    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2202    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2203       dlNrFreqInfo.nrArfcn;
2204    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2205    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2206    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2207    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2208    {
2209       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2210       return RFAILED;
2211    }
2212    
2213    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2214    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2215    {
2216       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2217       return RFAILED;
2218    }
2219
2220    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2221       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2222       freqBand[0].nrFreqBand;
2223    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2224    
2225    /*Transmission Bandwidth*/
2226    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2227       f1Mode.mode.fdd.ulTxBw.nrScs;
2228    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2229       f1Mode.mode.fdd.ulTxBw.nrb;
2230    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2231       f1Mode.mode.fdd.dlTxBw.nrScs;
2232    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2233       f1Mode.mode.fdd.dlTxBw.nrb;
2234
2235    return ROK;
2236 }
2237
2238 /*******************************************************************
2239  *
2240  * @brief Fills ServCellInfo IE
2241  *
2242  * @details
2243  *
2244  *    Function : fillServedCellInfo
2245  *
2246  *    Functionality: Fills ServCellInfo
2247  *
2248  * @params[in] Pointer to Served_Cell_Information_t *
2249  *
2250  * @return ROK     - success
2251  *         RFAILED - failure
2252  *
2253  *****************************************************************/
2254
2255 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2256 {
2257    uint8_t ieIdx, ieListCnt;
2258
2259    /*nRCGI*/
2260    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2261    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2262          srvCellInfo->nRCGI.pLMN_Identity.size);
2263    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2264    {
2265       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2266       return RFAILED;
2267    }
2268    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2269          srvCellInfo->nRCGI.pLMN_Identity.buf);
2270    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2271    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2272          srvCellInfo->nRCGI.nRCellIdentity.size);
2273    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2274    {   
2275       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2276       return RFAILED;
2277    }
2278    
2279    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2280    /*nRPCI*/
2281    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2282
2283    /*servedPLMNs*/
2284    ieListCnt = 1;
2285    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2286    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2287    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2288    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2289    {
2290       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2291       return RFAILED;
2292    }
2293    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2294    {
2295       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2296       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2297       {
2298          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2299          return RFAILED;
2300       }
2301    }
2302    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2303    {
2304       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2305       return RFAILED;
2306    }
2307
2308 #ifndef NR_TDD
2309    /*nR Mode Info with FDD*/
2310    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2311    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2312    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2313    {
2314       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2315       return RFAILED;
2316    }
2317    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2318    {
2319        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2320       return RFAILED;
2321    }
2322 #else
2323    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2324    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2325    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2326    {
2327       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2328       return RFAILED;
2329    }
2330    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2331    {
2332       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2333       return RFAILED;
2334    }
2335 #endif
2336
2337    /*Measurement timing Config*/
2338    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2339       return RFAILED;
2340
2341    return ROK;
2342 }
2343
2344 /*******************************************************************
2345  *
2346  * @brief Fills ServCellToModItem IE
2347  *
2348  * @details
2349  *
2350  *    Function : fillServCellToModItem
2351  *
2352  *    Functionality: Fills ServCellToModItem IE
2353  *
2354  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2355  *
2356  * @return ROK     - success
2357  *         RFAILED - failure
2358  *
2359  *****************************************************************/
2360
2361 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2362 {
2363    /*pLMN_Identity*/
2364    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2365    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2366    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2367    {
2368       return RFAILED;
2369    }
2370    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2371          modifyItem->oldNRCGI.pLMN_Identity.buf);
2372
2373    /*nRCellIdentity*/
2374    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2375    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2376          modifyItem->oldNRCGI.nRCellIdentity.size);
2377    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2378    {
2379       return RFAILED;
2380    }
2381    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2382
2383    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2384       return RFAILED;
2385    else
2386       return ROK;
2387 }
2388
2389 /*******************************************************************
2390  *
2391  * @brief Builds ServCellToModList
2392  *
2393  * @details
2394  *
2395  *    Function : buildServCellToModList
2396  *
2397  *    Functionality: Builds the serv cell to Mod List
2398  *
2399  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2400  *
2401  * @return ROK     - success
2402  *         RFAILED - failure
2403  *
2404  *****************************************************************/
2405
2406 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2407 {
2408    uint8_t ieListCnt, ieIdx;
2409    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2410
2411    ieListCnt = 1;
2412    cellsToModify->list.count = ieListCnt;
2413    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2414    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2415    if(cellsToModify->list.array == NULLP)
2416    {
2417       return RFAILED;
2418    }
2419    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2420    {
2421       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2422       if(cellsToModify->list.array[ieIdx] == NULLP)
2423       {
2424          return RFAILED;
2425       }
2426    }
2427    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2428    cellsToModify->list.array[0]->criticality = Criticality_reject;
2429    cellsToModify->list.array[0]->value.present =\
2430       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2431    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2432
2433    if(fillServCellToModItem(modifyItem))
2434       return RFAILED;
2435    else
2436       return ROK;
2437 }
2438 /*******************************************************************
2439  *
2440  * @brief filling the DeleteItemList
2441  *
2442  * @details
2443  *
2444  *    Function : fillCellToDeleteItem 
2445  *
2446  *    Functionality: Filling the DeleteItemIe 
2447  *
2448  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2449  *
2450  * @return ROK     - success
2451  *         RFAILED - failure
2452  *
2453  *****************************************************************/
2454 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2455 {
2456    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2457    
2458    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2459    deleteItemIe->criticality = Criticality_reject;
2460    deleteItemIe->value.present =\
2461    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2462    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2463
2464    /*pLMN_Identity*/
2465    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2466    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2467    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2468    {
2469       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2470       return RFAILED;
2471    }
2472    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2473          deleteItem->oldNRCGI.pLMN_Identity.buf);
2474
2475    /*nRCellIdentity*/
2476    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2477    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2478          deleteItem->oldNRCGI.nRCellIdentity.size);
2479    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2480    {
2481       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2482       return RFAILED;
2483    }
2484    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2485    return ROK;
2486
2487
2488 /*******************************************************************
2489  *
2490  * @brief Builds ServCellToDeleteList
2491  *
2492  * @details
2493  *
2494  *    Function : buildServCellToDeleteList
2495  *
2496  *    Functionality: Builds the serv cell to delete List
2497  *
2498  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2499  *
2500  * @return ROK     - success
2501  *         RFAILED - failure
2502  *
2503  *****************************************************************/
2504  
2505 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2506 {
2507    uint8_t ieListCnt, arrIdx;
2508    
2509    ieListCnt = 1;
2510    cellsToDelete->list.count = ieListCnt;
2511    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2512    
2513    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2514    if(cellsToDelete->list.array == NULLP)
2515    {
2516       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2517       return RFAILED;
2518    }
2519    
2520    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2521    {
2522       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2523       if(cellsToDelete->list.array[arrIdx] == NULLP)
2524       {
2525          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2526          return RFAILED;
2527       }
2528    }
2529    
2530    arrIdx=0;
2531    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2532    {
2533       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2534       return RFAILED;
2535    }
2536    return ROK;
2537 }
2538
2539 /*******************************************************************
2540  *
2541  * @brief Builds CellsStatusList
2542  *
2543  * @details
2544  *
2545  *    Function : buildCellsStatusList
2546  *
2547  *    Functionality: Builds the Cell Status List
2548  *
2549  * @params[in] Pointer to Cells_Status_List_t *
2550  *
2551  * @return ROK     - success
2552  *         RFAILED - failure
2553  *
2554  *****************************************************************/
2555 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2556 {
2557    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2558    Cells_Status_ItemIEs_t *cellStatusItemIE;
2559
2560    elementCnt = 1;
2561    cellStatusList->list.count = elementCnt;
2562    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2563    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2564
2565    for(idx = 0; idx < elementCnt; idx++)
2566    {
2567       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2568       if(!cellStatusList->list.array[idx])
2569       {
2570          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2571          return RFAILED;
2572       }
2573    }
2574    idx = 0;
2575    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2576    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2577    cellStatusItemIE->criticality = Criticality_reject;
2578    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2579    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2580    if(ret == RFAILED)
2581    {
2582          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2583          return RFAILED;
2584    }
2585    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2586    return ROK;
2587 }
2588
2589 /*******************************************************************
2590  *
2591  * @brief Builds and sends the DUConfigUpdate
2592  *
2593  * @details
2594  *
2595  *    Function : BuildAndSendDUConfigUpdate
2596  *
2597  *    Functionality: Constructs the DU Update message and sends
2598  *                   it to the CU through SCTP.
2599  *
2600  * @params[in] void **buf,Buffer to which encoded pattern is written into
2601  * @params[in] int *size,size of buffer
2602  *
2603  * @return ROK     - success
2604  *         RFAILED - failure
2605  *
2606  * ****************************************************************/
2607 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2608 {
2609    uint8_t ret =0, ieIdx=0, elementCnt=0;
2610    bool memAlloctionFailure = false;
2611    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2612    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2613    asn_enc_rval_t encRetVal;     /* Encoder return value */
2614    
2615    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2616    ret= RFAILED;
2617
2618    while(true)
2619    {
2620       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2621       /* Allocate the memory for F1DuCfg */
2622       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2623       if(f1apDuCfg == NULLP)
2624       {
2625          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2626          break;
2627       }
2628
2629       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2630       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2631       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2632       {
2633          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2634          break;
2635       }
2636
2637       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2638                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2639       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2640       f1apDuCfg->choice.initiatingMessage->value.present = \
2641                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2642       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2643                     choice.GNBDUConfigurationUpdate;
2644       elementCnt = 4;
2645       duCfgUpdate->protocolIEs.list.count = elementCnt;
2646       duCfgUpdate->protocolIEs.list.size = \
2647                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2648
2649       /* Initialize the F1Setup members */
2650       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2651       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2652       {
2653          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2654          break;
2655       }
2656       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2657       {
2658          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2659          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2660          {
2661             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2662             memAlloctionFailure = true;
2663             break;
2664          }
2665       }
2666       
2667       if(memAlloctionFailure == true)
2668       {
2669          break;
2670       }
2671       /*TransactionID*/
2672       ieIdx = 0;
2673       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2674       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2675       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2676       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2677       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2678       
2679       ieIdx++;
2680       if(servCellAction == SERV_CELL_TO_MODIFY)
2681       {
2682          /*Served Cell to Modify */
2683          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2684          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2685          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2686          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2687          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2688          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2689                   Served_Cells_To_Modify_List))
2690          {
2691             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2692             break;
2693          }
2694       }
2695       else
2696       {
2697          /*Served Cell to Delete */ 
2698          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2699          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2700          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2701          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2702          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2703          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2704          Served_Cells_To_Delete_List)!=ROK)
2705          {
2706             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2707             break;
2708          }
2709          
2710       }
2711       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2712       
2713       /*Cell Status List*/
2714       ieIdx++;
2715       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2716       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2717       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2718            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2719       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2720       if(ret == RFAILED)
2721       {
2722          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2723          break;
2724       }
2725
2726       /*GNB DU ID */
2727       ieIdx++;
2728       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2729       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2730       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2731       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2732       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2733       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2734             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2735       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2736       {
2737          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2738          break;
2739       }
2740       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2741
2742       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2743
2744       /* Encode the DU Config Update type as APER */
2745       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2746       encBufSize = 0;
2747       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2748
2749       /* Checking encode results */
2750       if(encRetVal.encoded == ENCODE_FAIL)
2751       {
2752          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2753                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2754          break;
2755       }
2756       else
2757       {
2758          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2759 #ifdef DEBUG_ASN_PRINT
2760          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2761          {
2762             printf("%x",encBuf[ieIdx]);
2763          }
2764 #endif
2765       }
2766       /* Sending msg */
2767       if(sendF1APMsg() != ROK)
2768       {
2769          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2770          break;
2771       }
2772
2773       ret = ROK;
2774       break;
2775    }
2776   
2777    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2778    return ret;
2779 }
2780
2781
2782 /*******************************************************************
2783  *
2784  * @brief free the ULRRCMessageTransfer
2785  *
2786  * @details
2787  *
2788  *    Function : FreeULRRCMessageTransfer
2789  *
2790  *    Functionality: Deallocating the memory of variable allocated in
2791  *                      FreeULRRCMessageTransfer
2792  *
2793  * @params[in]
2794  *
2795  * @return ROK     - void
2796  *
2797  ******************************************************************/
2798 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2799 {
2800    uint8_t idx1;
2801    ULRRCMessageTransfer_t  *ulRRCMsg;
2802
2803    if(f1apMsg != NULLP)
2804    { 
2805       if(f1apMsg->choice.initiatingMessage != NULLP)
2806       {
2807          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2808          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2809          {
2810             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2811             {
2812                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2813                {
2814                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2815                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2816                   {
2817                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2818                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2819                   }
2820                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2821                }
2822             }
2823             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2824          }
2825          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2826       }
2827       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2828    }
2829 }
2830 /*******************************************************************
2831  *
2832  * @brief Builds and sends the ULRRCMessageTransfer 
2833  *
2834  * @details
2835  *
2836  *    Function : BuildAndSendULRRCMessageTransfer
2837  *
2838  *    Functionality: Constructs the UL RRC Message Transfer and sends
2839  *                   it to the CU through SCTP.
2840  *
2841  * @params[in] 
2842  *
2843  * @return ROK     - success
2844  *         RFAILED - failure
2845  *
2846  * ****************************************************************/
2847 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2848       uint16_t msgLen, uint8_t *rrcMsg)
2849 {
2850    uint8_t                 elementCnt=0, idx1=0, idx=0;
2851    uint8_t                 ret = RFAILED;
2852    F1AP_PDU_t              *f1apMsg = NULLP;
2853    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2854    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2855    
2856    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2857
2858    while(true)
2859    {
2860       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2861
2862       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2863       if(f1apMsg == NULLP)
2864       {
2865          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2866          break;
2867       }
2868       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2869       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2870       if(f1apMsg->choice.initiatingMessage == NULLP)
2871       {
2872          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2873          break;
2874       }
2875       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2876       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2877       f1apMsg->choice.initiatingMessage->value.present = \
2878                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2879       ulRRCMsg =
2880          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2881       elementCnt = 4;
2882       ulRRCMsg->protocolIEs.list.count = elementCnt;
2883       ulRRCMsg->protocolIEs.list.size = \
2884                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2885
2886       /* Initialize the F1Setup members */
2887       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2888       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2889       {
2890          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2891          break;
2892       }
2893       for(idx=0; idx<elementCnt; idx++)
2894       {
2895          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2896          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2897          {
2898             break;
2899          }
2900       }
2901
2902       idx1 = 0;
2903
2904       /*GNB CU UE F1AP ID*/
2905       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2906       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2907       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2908                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2909       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2910
2911       /*GNB DU UE F1AP ID*/
2912       idx1++;
2913       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2914       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2915       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2916                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2917       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2918
2919       /*SRBID*/
2920       idx1++;
2921       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2922       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2923       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2924                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2925       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2926
2927       /*RRCContainer*/
2928       idx1++;
2929       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2930       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2931       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2932                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2933       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2934       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2935             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2936       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2937       {
2938          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2939          break;
2940       }
2941       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2942       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2943             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2944
2945       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2946
2947       /* Encode the F1SetupRequest type as APER */
2948       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2949       encBufSize = 0;
2950       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2951             encBuf);
2952       /* Encode results */
2953       if(encRetVal.encoded == ENCODE_FAIL)
2954       {
2955          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2956                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2957          break;
2958       }
2959       else
2960       {
2961          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2962 #ifdef DEBUG_ASN_PRINT
2963          for(int i=0; i< encBufSize; i++)
2964          {
2965             printf("%x",encBuf[i]);
2966          }
2967 #endif
2968       }
2969
2970       /* Sending  msg  */
2971       if(sendF1APMsg()  !=      ROK)
2972       {
2973          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2974          break;
2975       }
2976       ret = ROK;
2977       break;
2978    }
2979    FreeULRRCMessageTransfer(f1apMsg);
2980
2981    return ret;
2982 }/* End of BuildAndSendULRRCMessageTransfer*/
2983
2984 /*******************************************************************
2985  *
2986  * @brief Builds tag config 
2987  *
2988  * @details
2989  *
2990  *    Function : BuildTagConfig 
2991  *
2992  *    Functionality: Builds tag config in MacCellGroupConfig
2993  *
2994  * @params[in] TAG_Config *tag_Config
2995  *
2996  * @return ROK     - success
2997  *         RFAILED - failure
2998  *
2999  * ****************************************************************/
3000 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3001 {
3002    struct TAG_Config__tag_ToAddModList *tagList;
3003    uint8_t                     idx, elementCnt;
3004
3005    tagConfig->tag_ToReleaseList = NULLP;
3006    tagConfig->tag_ToAddModList = NULLP;
3007    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3008    if(!tagConfig->tag_ToAddModList)
3009    {
3010       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3011       return RFAILED;
3012    }
3013
3014    if(ueCb == NULLP)
3015       elementCnt = ODU_VALUE_ONE;
3016    else
3017       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3018
3019    tagList = tagConfig->tag_ToAddModList;
3020    tagList->list.count = elementCnt;
3021    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3022
3023    tagList->list.array = NULLP;
3024    DU_ALLOC(tagList->list.array, tagList->list.size);
3025    if(!tagList->list.array)
3026    {
3027       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3028       return RFAILED;
3029    }
3030
3031    for(idx=0; idx<tagList->list.count; idx++)
3032    {
3033       tagList->list.array[idx] = NULLP;
3034       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3035       if(!tagList->list.array[idx])
3036       {
3037          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3038          return RFAILED;
3039       }
3040    }
3041
3042    if(ueCb == NULLP)
3043    {
3044       idx = 0;
3045       tagList->list.array[idx]->tag_Id = TAG_ID;
3046       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3047    }
3048    else
3049    {
3050       for(idx=0; idx<tagList->list.count; idx++)
3051       {
3052          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3053          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3054       }
3055    }
3056
3057    return ROK;
3058 }
3059
3060 /*******************************************************************
3061  *
3062  * @brief Builds PHR Config 
3063  *
3064  * @details
3065  *
3066  *    Function : BuildPhrConfig
3067  *
3068  *    Functionality: Builds phrConfig in MacCellGroupConfig
3069  *
3070  * @params[in] PHR Config *
3071  *
3072  * @return ROK     - success
3073  *         RFAILED - failure
3074  *
3075  * ****************************************************************/
3076 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3077 {
3078
3079    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3080    phrConfig->choice.setup = NULLP;
3081    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3082    if(!phrConfig->choice.setup)
3083    {
3084       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3085       return RFAILED;
3086    }
3087
3088    if(ueCb == NULLP)
3089    {
3090       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3091       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3092       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3093       phrConfig->choice.setup->multiplePHR              = false;
3094       phrConfig->choice.setup->dummy                    = false;
3095       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3096       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3097    }
3098    else
3099    {
3100       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3101       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3102       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3103       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3104       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3105       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3106       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3107    }
3108
3109    return ROK;
3110 }
3111
3112 /*******************************************************************
3113  *
3114  * @brief Builds BSR Config 
3115  *
3116  * @details
3117  *
3118  *    Function : BuildBsrConfig
3119  *
3120  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3121  *
3122  * @params[in] BSR_Config *bsrConfig
3123  *
3124  * @return ROK     - success
3125  *         RFAILED - failure
3126  *
3127  * ****************************************************************/
3128 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3129 {
3130    if(ueCb == NULLP)
3131    {
3132       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3133       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3134       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3135    }
3136    else
3137    {
3138       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3139       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3140
3141       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3142       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3143       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3144       {
3145          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3146          return RFAILED;
3147       }
3148       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3149    }
3150
3151    return ROK;
3152 }
3153
3154 /*******************************************************************
3155  *
3156  * @brief Builds scheduling request config 
3157  *
3158  * @details
3159  *
3160  *    Function : BuildSchedulingReqConfig 
3161  *
3162  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3163  *
3164  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3165  *
3166  * @return ROK     - success
3167  *         RFAILED - failure
3168  *
3169  * ****************************************************************/
3170 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3171 {
3172    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3173    uint8_t                     idx, elementCnt;
3174
3175    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3176    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3177          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3178    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3179    {
3180       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3181       return RFAILED;
3182    }
3183
3184    if(ueCb == NULLP)
3185       elementCnt = ODU_VALUE_ONE;
3186    else
3187       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3188
3189    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3190    schReqList->list.count = elementCnt;
3191    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3192
3193    schReqList->list.array = NULLP;
3194    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3195    if(!schReqList->list.array)
3196    {
3197       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3198       return RFAILED;
3199    }
3200
3201    for(idx=0; idx<schReqList->list.count; idx++)
3202    {
3203       schReqList->list.array[idx] = NULLP;
3204       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3205       if(!schReqList->list.array[idx])
3206       {
3207          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3208          return RFAILED;
3209       }
3210    }
3211
3212    if(ueCb == NULLP)
3213    {
3214       idx = 0;
3215       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3216
3217       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3218       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3219       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3220       {
3221          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3222          return RFAILED;
3223       }
3224       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3225       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3226    }
3227    else
3228    {
3229       for(idx=0; idx<schReqList->list.count; idx++)
3230       {
3231          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3232
3233          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3234          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3235          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3236          {
3237             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3238             return RFAILED;
3239          }
3240          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3241          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3242       }
3243    }
3244
3245    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3246
3247    return ROK;
3248 }
3249
3250 /*******************************************************************
3251  *
3252  * @brief Builds RLC Configuration for AM mode
3253  *
3254  * @details
3255  *
3256  *    Function : BuildRlcConfigAm
3257  *
3258  *    Functionality: 
3259  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3260  *
3261  * @params[in] AmBearerCfg *amCfg
3262  *             RLC_Config_t  *rlcConfig
3263  *
3264  * @return ROK     - success
3265  *         RFAILED - failure
3266  *
3267  * ****************************************************************/
3268 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3269 {
3270    rlcConfig->choice.am = NULLP;
3271    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3272    if(!rlcConfig->choice.am)
3273    {
3274       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3275       return RFAILED;
3276    }
3277
3278    /* Fill AM UL configuration */
3279    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3280    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3281    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3282    {
3283       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3284       return RFAILED;
3285    }
3286
3287    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3288    if(amCfg == NULLP)
3289    {
3290       
3291       *(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"*/
3292       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3293       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3294       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3295       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3296    }
3297    else
3298    {
3299       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3300       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3301       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3302       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3303       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3304    }
3305
3306    /* Fill AM DL configuraion */
3307    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3308    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3309    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3310    {
3311       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3312       return RFAILED;
3313    }
3314
3315    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3316    if(amCfg == NULLP)
3317    {
3318       *(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"*/
3319       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3320       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3321    }
3322    else /* Fill AM configuration from DU database */
3323    {
3324       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3325       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3326       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3327    }
3328    return ROK;
3329 }
3330
3331 /*******************************************************************
3332  *
3333  * @brief Builds RLC Config for UM Bidirection
3334  *
3335  * @details
3336  *
3337  *    Function : BuildRlcConfig UmBiDir
3338  *
3339  *    Functionality: 
3340  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3341  *
3342  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3343  *             RLC_Config_t *rlcConfig
3344  *
3345  * @return ROK     - success
3346  *         RFAILED - failure
3347  *
3348  * ****************************************************************/
3349 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3350 {
3351    rlcConfig->choice.um_Bi_Directional = NULLP;
3352    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3353    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3354    {
3355       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3356       return RFAILED;
3357    }
3358
3359    /* Fill UM Bidirectional UL configuration */
3360    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3361    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3362    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3363    {
3364       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3365       return RFAILED;
3366    }
3367
3368    if(umBiDirCfg != NULLP)
3369    {
3370       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3371    }
3372
3373    /* Fill UM Bidirectional DL configuration */
3374    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3375    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3376    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3377    {
3378       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3379       return RFAILED;
3380    }
3381
3382    if(umBiDirCfg != NULLP)
3383    {
3384       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3385       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3386    }
3387
3388    return ROK;
3389 }
3390
3391 /*******************************************************************
3392  *
3393  * @brief Builds RLC Config for UM Uni directional UL
3394  *
3395  * @details
3396  *
3397  *    Function : BuildRlcConfigUmUniDirUl
3398  *
3399  *    Functionality: 
3400  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3401  *
3402  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3403  *             RLC_Config_t *rlcConfig
3404  *
3405  * @return ROK     - success
3406  *         RFAILED - failure
3407  *
3408  * ****************************************************************/
3409 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3410 {
3411    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3412    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3413    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3414    {
3415       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3416       return RFAILED;
3417    }
3418
3419    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3420    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3421    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3422    {
3423       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3424       return RFAILED;
3425    }
3426
3427    if(umUniDirDlCfg != NULLP)
3428    {
3429       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3430    }
3431
3432    return ROK;
3433 }
3434
3435 /*******************************************************************
3436  *
3437  * @brief Builds RLC Config for UM Uni directional DL
3438  *
3439  * @details
3440  *
3441  *    Function : BuildRlcConfigUmUniDirDl
3442  *
3443  *    Functionality: 
3444  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3445  *
3446  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3447  *             RLC_Config_t *rlcConfig
3448  *
3449  * @return ROK     - success
3450  *         RFAILED - failure
3451  *
3452  * ****************************************************************/
3453 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3454 {
3455    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3456    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3457    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3458    {
3459       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3460       return RFAILED;
3461    }
3462
3463    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3464    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3465    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3466    {
3467       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3468       return RFAILED;
3469    }
3470
3471    if(umUniDirUlCfg != NULLP)
3472    {
3473       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3474       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3475    }
3476
3477    return ROK;
3478 }
3479
3480 /*******************************************************************
3481  *
3482  * @brief Builds RLC Config
3483  *
3484  * @details
3485  *
3486  *    Function : BuildRlcConfig
3487  *
3488  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3489  *
3490  * @params[in] RLC_Config_t *rlcConfig
3491  *
3492  * @return ROK     - success
3493  *         RFAILED - failure
3494  *
3495  * ****************************************************************/
3496 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3497 {
3498    
3499    /* Fill default values if rbCfg is NULL */
3500    if(rbCfg == NULLP)
3501    {
3502       rlcConfig->present = RLC_Config_PR_am;
3503       BuildRlcConfigAm(NULLP, rlcConfig);
3504    }
3505    /* If RbCfg is present, fill RLC configurations from DU Database */
3506    else
3507    {
3508       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3509       switch(rlcConfig->present)
3510       {
3511          case RLC_Config_PR_am:
3512             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3513             break;
3514          case RLC_Config_PR_um_Bi_Directional:
3515             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3516             break;
3517          case RLC_Config_PR_um_Uni_Directional_UL:
3518             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3519             break;
3520          case RLC_Config_PR_um_Uni_Directional_DL:
3521             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3522             break;
3523          case RLC_Config_PR_NOTHING:
3524          default:
3525             break;
3526       }
3527    }
3528
3529    return ROK;
3530 }
3531
3532 /*******************************************************************
3533  *
3534  * @brief Builds MAC LC Config
3535  *
3536  * @details
3537  *
3538  *    Function : BuildMacLCConfig 
3539  *
3540  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3541  *
3542  * @params[in] struct LogicalChannelConfig macLcConfig
3543  *
3544  * @return ROK     - success
3545  *         RFAILED - failure
3546  *
3547  * ****************************************************************/
3548 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3549 {
3550    macLcConfig->ul_SpecificParameters = NULLP;
3551    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3552    if(!macLcConfig->ul_SpecificParameters)
3553    {
3554       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3555       return RFAILED;
3556    }
3557
3558    if(lcCfgDb == NULLP)
3559    {
3560       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3561       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3562       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3563    }
3564    else
3565    {
3566       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3567       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3568       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3569    }
3570
3571    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3572    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3573    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3574    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3575
3576    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3577    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3578    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3579    {
3580       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3581       return RFAILED;
3582    }
3583
3584    if(lcCfgDb == NULLP)
3585       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3586    else
3587       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3588
3589    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3590    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3591    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3592    {
3593       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3594       return RFAILED;
3595    }
3596
3597    if(lcCfgDb == NULLP)
3598       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3599    else
3600       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3601
3602    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3603    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3604    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3605
3606    return ROK;
3607 }
3608
3609 /*******************************************************************
3610  *
3611  * @brief Builds RLC Bearer to Add/Mod list
3612  *
3613  * @details
3614  *
3615  *    Function :BuildRlcBearerToAddModList 
3616  *
3617  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3618  *
3619  * @params[in] rlc_BearerToAddModList
3620  *
3621  * @return ROK     - success
3622  *         RFAILED - failure
3623  *
3624  * ****************************************************************/
3625 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3626 {
3627    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3628
3629    if(ueCb == NULLP)
3630       elementCnt = 1;
3631    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3632       elementCnt = ueCb->duRlcUeCfg.numLcs;
3633    else
3634    {
3635       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3636       {
3637          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3638             elementCnt++;
3639       }
3640    }
3641    rlcBearerList->list.count = elementCnt;
3642    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3643
3644    rlcBearerList->list.array = NULLP;
3645    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3646    if(!rlcBearerList->list.array)
3647    {
3648       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3649       return RFAILED;
3650    }
3651
3652    for(idx=0; idx<rlcBearerList->list.count; idx++)
3653    {
3654       rlcBearerList->list.array[idx] = NULLP;
3655       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3656       if(!rlcBearerList->list.array[idx])
3657       {
3658          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3659          return RFAILED;
3660       }
3661    }
3662
3663    if(ueCb == NULLP)
3664    {
3665       idx=0;
3666       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3667       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3668       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3669       {     
3670          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3671          return RFAILED;
3672       }     
3673       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3674       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3675       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3676
3677       /* Fill RLC related Configurations for this Radio Bearer */
3678       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3679       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3680       if(!rlcBearerList->list.array[idx]->rlc_Config)
3681       {
3682          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3683          return RFAILED;
3684       }
3685       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3686       {
3687          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3688          return RFAILED;
3689       }
3690
3691       /* Fill MAC related configurations for this Radio Bearer */
3692       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3693       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3694       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3695       {
3696          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3697          return RFAILED;
3698       }
3699       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3700       {
3701          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3702          return RFAILED;
3703       }
3704    }
3705    else
3706    {
3707       idx=0;
3708       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3709       {
3710          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3711             continue;
3712
3713          /* Fill Logical channel identity */
3714          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3715
3716          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3717          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3718          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3719          {
3720             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3721             return RFAILED;
3722          }
3723          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3724                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3725          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3726          {
3727             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3728                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3729                break;
3730             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3731                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3732                break;
3733             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3734             default:
3735                break;
3736          }
3737          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3738
3739          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3740
3741          /* Fill RLC related Configurations for this Radio Bearer */
3742          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3743          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3744          if(!rlcBearerList->list.array[idx]->rlc_Config)
3745          {
3746             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3747             return RFAILED;
3748          }
3749          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3750          {
3751             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3752             return RFAILED;
3753          }
3754
3755          /* Fill MAC related configurations for this Radio Bearer */
3756          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3757          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3758          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3759          {
3760             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3761             return RFAILED;
3762          }
3763          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3764          {
3765             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3766             {
3767                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3768                {
3769                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3770                   return RFAILED;
3771                }
3772                break;
3773             }
3774          }
3775
3776          idx++;
3777       }
3778    }
3779    return ROK;
3780 }
3781
3782 /*******************************************************************
3783  *
3784  * @brief Build Control resource set to add/modify list 
3785  *
3786  * @details
3787  *
3788  *    Function : BuildControlRSetToAddModList
3789  *
3790  *    Functionality: Build Control resource set to add/modify list
3791  *
3792  * @params[in] 
3793  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3794  *
3795  * @return ROK     - success
3796  *         RFAILED - failure
3797  *
3798  * ****************************************************************/
3799 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3800 {
3801    uint8_t idx;
3802    uint8_t elementCnt;
3803    uint8_t numBytes, bitsUnused;
3804    struct ControlResourceSet *controlRSet;
3805    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3806    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3807
3808    if(pdcchCfg == NULLP)
3809       elementCnt = 1;
3810    else
3811       elementCnt = pdcchCfg->numCRsetToAddMod;
3812
3813    controlRSetList->list.count = elementCnt;
3814    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3815
3816    controlRSetList->list.array = NULLP;
3817    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3818    if(!controlRSetList->list.array)
3819    {
3820       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3821       return RFAILED;
3822    }
3823
3824    for(idx = 0; idx < elementCnt; idx++)
3825    {
3826       controlRSetList->list.array[idx] = NULLP;
3827       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3828       if(!controlRSetList->list.array[idx])
3829       {
3830          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3831          return RFAILED;
3832       }
3833    }
3834
3835    for(idx = 0; idx < elementCnt; idx++)
3836    {
3837       controlRSet = controlRSetList->list.array[idx];
3838
3839       if(pdcchCfg == NULLP)
3840          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3841       else
3842          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3843
3844       /* size 6 bytes
3845        * 3 LSBs unsued
3846        * Bit string stored ff0000000000
3847        */
3848       numBytes = 6;
3849       bitsUnused = 3;
3850       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3851
3852       controlRSet->frequencyDomainResources.buf = NULLP;
3853       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3854       if(!controlRSet->frequencyDomainResources.buf)
3855       {
3856          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3857          return RFAILED;
3858       }
3859
3860       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3861
3862       if(pdcchCfg == NULLP)
3863       {
3864          coreset0EndPrb = CORESET0_END_PRB;
3865          coreset1StartPrb = coreset0EndPrb + 6;
3866          coreset1NumPrb = CORESET1_NUM_PRB;
3867          /* calculate the PRBs */
3868          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3869          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3870          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3871
3872          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3873          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3874          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3875       }
3876       else
3877       {
3878          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3879          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3880          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3881          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3882          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3883       }
3884       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3885       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3886       controlRSet->tci_PresentInDCI = NULLP;
3887
3888 #if 0
3889       uint8_t tciStateIdx;
3890
3891       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3892             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3893       if(!controlRset->tci_StatesPDCCH_ToAddList)
3894       {
3895          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3896          return RFAILED;
3897       }
3898
3899       elementCnt = 1;
3900       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3901       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3902       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3903             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3904          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3905          {
3906             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3907             return RFAILED;
3908          }
3909
3910       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3911       {
3912          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3913          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3914          {
3915             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3916             return RFAILED;
3917          }
3918       }
3919
3920       tciStateIdx = 0;
3921       /* TODO */
3922       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3923
3924       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3925       if(!controlRset->tci_PresentInDCI)
3926       {
3927          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3928          return RFAILED;
3929       }
3930       /* TODO */
3931       *(controlRset->tci_PresentInDCI);
3932 #endif
3933
3934       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3935       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3936       if(!controlRSet->pdcch_DMRS_ScramblingID)
3937       {
3938          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3939          return RFAILED;
3940       }
3941       if(pdcchCfg == NULLP)
3942          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3943       else
3944          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3945    }
3946    return ROK;
3947 } /* End BuildControlRSetToAddModList */
3948
3949 /*******************************************************************
3950  *
3951  * @brief Build search space to add/modify list
3952  *
3953  * @details
3954  *
3955  *    Function : BuildSearchSpcToAddModList
3956  *
3957  *    Functionality: Build search space to add/modify list
3958  *
3959  * @params[in] 
3960  * @return ROK     - success
3961  *         RFAILED - failure
3962  *
3963  * ****************************************************************/
3964 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3965 {
3966    uint8_t idx;
3967    uint8_t numBytes;
3968    uint8_t byteIdx;
3969    uint8_t bitsUnused;
3970    uint8_t elementCnt;
3971    struct SearchSpace *searchSpc;
3972
3973    if(pdcchCfg == NULLP)
3974       elementCnt = 1;
3975    else
3976       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3977
3978    searchSpcList->list.count = elementCnt;
3979    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3980
3981    searchSpcList->list.array = NULLP;
3982    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3983    if(!searchSpcList->list.array)
3984    {
3985       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3986       return RFAILED;
3987    }
3988
3989    for(idx = 0; idx < elementCnt; idx++)
3990    {
3991       searchSpcList->list.array[idx] = NULLP;
3992       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3993       if(!searchSpcList->list.array[idx])
3994       {
3995          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3996          return RFAILED;
3997       }
3998    }
3999
4000    for(idx = 0; idx < elementCnt; idx++)
4001    {
4002       searchSpc = searchSpcList->list.array[idx];
4003
4004       if(pdcchCfg == NULLP)
4005          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4006       else
4007          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4008
4009       searchSpc->controlResourceSetId = NULLP;
4010       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4011       if(!searchSpc->controlResourceSetId)
4012       {
4013          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4014          return RFAILED;
4015       }
4016       if(pdcchCfg == NULLP)
4017          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4018       else
4019          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4020
4021       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4022       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4023       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4024       {
4025          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4026          return RFAILED;
4027       }
4028       if(pdcchCfg == NULLP)
4029          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4030       else
4031          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4032
4033       searchSpc->duration = NULLP;
4034       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4035       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4036       if(!searchSpc->monitoringSymbolsWithinSlot)
4037       {
4038          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4039          return RFAILED;
4040       }
4041
4042       /* Values taken from reference logs :
4043        * size 2 bytes
4044        * 2 LSBs unsued
4045        * Bit string stores 8000
4046        */
4047       numBytes = 2;
4048       bitsUnused = 2;
4049       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4050       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4051       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4052       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4053       {
4054          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4055          return RFAILED;
4056       }
4057       if(pdcchCfg == NULLP)
4058       {
4059          byteIdx = 0;
4060          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4061          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4062       }
4063       else
4064          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4065       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4066
4067       searchSpc->nrofCandidates = NULLP;
4068       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4069       if(!searchSpc->nrofCandidates)
4070       {
4071          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4072          return RFAILED;
4073       }
4074
4075       if(pdcchCfg == NULLP)
4076       {
4077          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4078          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4079          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4080          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4081          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4082       }
4083       else
4084       {
4085          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4086          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4087          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4088          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4089          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4090       }
4091
4092       searchSpc->searchSpaceType = NULLP;
4093       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4094       if(!searchSpc->searchSpaceType)
4095       {
4096          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4097          return RFAILED;
4098       }
4099       if(pdcchCfg == NULLP)
4100          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4101       else
4102          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4103
4104       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4105       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4106       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4107       {
4108          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4109          return RFAILED;
4110       }  
4111       if(pdcchCfg == NULLP)
4112          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4113       else
4114          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4115    }
4116    return ROK;
4117 }/* End BuildSearchSpcToAddModList */
4118
4119 /*******************************************************************
4120  *
4121  * @brief Builds BWP DL dedicated PDCCH config
4122  *
4123  * @details
4124  *
4125  *    Function : BuildBWPDlDedPdcchCfg
4126  *
4127  *    Functionality: Builds BWP DL dedicated PDCCH config
4128  *
4129  * @params[in] struct PDCCH_Config *pdcchCfg
4130  *
4131  * @return ROK     - success
4132  *         RFAILED - failure
4133  *
4134  * ****************************************************************/
4135 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4136 {
4137    pdcchCfg->controlResourceSetToAddModList = NULLP;
4138    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4139    if(!pdcchCfg->controlResourceSetToAddModList)
4140    {
4141       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4142       return RFAILED;
4143    }
4144
4145    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4146    {
4147       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4148       return RFAILED;
4149    }
4150
4151    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4152
4153    pdcchCfg->searchSpacesToAddModList = NULLP;
4154    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4155    if(!pdcchCfg->searchSpacesToAddModList)
4156    {
4157       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4158       return RFAILED;
4159    }
4160
4161    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4162    {
4163       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4164       return RFAILED;
4165    }
4166
4167    pdcchCfg->searchSpacesToReleaseList = NULLP;
4168    pdcchCfg->downlinkPreemption = NULLP;
4169    pdcchCfg->tpc_PUSCH = NULLP;
4170    pdcchCfg->tpc_PUCCH = NULLP;
4171    pdcchCfg->tpc_SRS = NULLP;
4172
4173    return ROK;
4174 }
4175
4176 /*******************************************************************
4177  *
4178  * @brief Builds DMRS DL PDSCH Mapping type A
4179  *
4180  * @details
4181  *
4182  *    Function : BuildDMRSDLPdschMapTypeA
4183  *
4184  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4185  *
4186  * @params[in]
4187  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4188  * @return ROK     - success
4189  *         RFAILED - failure
4190  *
4191  * ****************************************************************/
4192 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4193 {
4194    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4195    dmrsDlCfg->choice.setup = NULLP;
4196    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4197    if(!dmrsDlCfg->choice.setup)
4198    {
4199       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4200       return RFAILED;
4201    }
4202
4203    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4204    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4205    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4206    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4207    {
4208       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4209       return RFAILED;
4210    }
4211    if(pdschCfg == NULLP)
4212       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4213    else
4214       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4215
4216    dmrsDlCfg->choice.setup->maxLength = NULLP;
4217    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4218    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4219    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4220
4221    return ROK;
4222 }
4223
4224 /*******************************************************************
4225  *
4226  * @brief Builds TCI states to add/modify list
4227  *
4228  * @details
4229  *
4230  *    Function : BuildTCIStatesToAddModList
4231  *
4232  *    Functionality:Builds TCI states to add/modify list
4233  *
4234  * @params[in] 
4235  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4236  *
4237  * @return ROK     - success
4238  *         RFAILED - failure
4239  *
4240  * ****************************************************************/
4241 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4242 {
4243    return ROK;
4244 }
4245
4246 /*******************************************************************
4247  *
4248  * @brief Builds PDSCH time domain allocation list
4249  *
4250  * @details
4251  *
4252  *    Function : BuildPdschTimeDomAllocList
4253  *
4254  *    Functionality: Builds PDSCH time domain allocation list
4255  *
4256  * @params[in] 
4257  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4258  *
4259  * @return ROK     - success
4260  *         RFAILED - failure
4261  *
4262  * ****************************************************************/
4263 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4264 {
4265    uint8_t idx;
4266    uint8_t elementCnt;
4267    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4268
4269    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4270
4271    timeDomAllocList->choice.setup = NULLP;
4272    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4273    if(!timeDomAllocList->choice.setup)
4274    {
4275       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4276       return RFAILED;
4277    }
4278
4279 if(pdschCfg == NULLP)
4280    elementCnt = 2;
4281 else
4282 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4283    timeDomAllocList->choice.setup->list.count = elementCnt;
4284    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4285
4286    timeDomAllocList->choice.setup->list.array = NULLP;
4287    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4288    if(!timeDomAllocList->choice.setup->list.array)
4289    {
4290       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4291       return RFAILED;
4292    }
4293
4294    for(idx = 0; idx < elementCnt; idx++)
4295    {
4296       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4297       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4298             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4299       if(!timeDomAllocList->choice.setup->list.array[idx])
4300       {
4301          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4302          return RFAILED;
4303       }
4304    }
4305
4306    if(pdschCfg == NULLP)
4307    {
4308       idx = 0;
4309       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4310       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4311       if(!timeDomAlloc->k0)
4312       {
4313          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4314          return RFAILED;
4315       }
4316       *(timeDomAlloc->k0) = 0;
4317       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4318       timeDomAlloc->startSymbolAndLength = \
4319                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4320
4321       idx++;
4322       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4323       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4324       if(!timeDomAlloc->k0)
4325       {
4326          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4327          return RFAILED;
4328       }
4329       *(timeDomAlloc->k0) = 1;
4330       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4331       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4332    }
4333    else
4334    {
4335       for(idx = 0; idx < elementCnt; idx++)
4336       {
4337          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4338          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4339          {
4340             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4341             if(!timeDomAlloc->k0)
4342             {
4343                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4344                return RFAILED;
4345             }
4346             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4347          }
4348          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4349          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4350       }
4351    }
4352
4353    return ROK;
4354 }
4355
4356 /*******************************************************************
4357  *
4358  * @brief Builds PDSCH PRB Bundling type
4359  *
4360  * @details
4361  *
4362  *    Function : BuildPdschPrbBundlingType
4363  *
4364  *    Functionality: Builds PDSCH PRB Bundling type
4365  *
4366  * @params[in] 
4367  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4368  *
4369  * @return ROK     - success
4370  *         RFAILED - failure
4371  *
4372  * ****************************************************************/
4373 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4374 {
4375    if(pdschCfg == NULLP)
4376       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4377    else
4378       prbBndlType->present = pdschCfg->bundlingType;
4379
4380    prbBndlType->choice.staticBundling = NULLP;
4381    DU_ALLOC(prbBndlType->choice.staticBundling, \
4382          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4383    if(!prbBndlType->choice.staticBundling)
4384    {
4385       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4386       return RFAILED;
4387    }
4388    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4389
4390    return ROK;
4391 }
4392
4393 /*******************************************************************
4394  *
4395  * @brief Builds BWP DL dedicated PDSCH config 
4396  *
4397  * @details
4398  *
4399  *    Function : BuildBWPDlDedPdschCfg
4400  *
4401  *    Functionality: Builds BWP DL dedicated PDSCH config
4402  *
4403  * @params[in] struct PDSCH_Config *pdschCfg
4404  *
4405  * @return ROK     - success
4406  *         RFAILED - failure
4407  *
4408  * ****************************************************************/
4409 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4410 {
4411    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4412
4413    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4414    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4415    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4416    {
4417       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4418       return RFAILED;
4419    }
4420
4421    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4422    {
4423       return RFAILED;
4424    }
4425
4426    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4427    pdschCfg->tci_StatesToAddModList = NULLP;
4428    pdschCfg->tci_StatesToReleaseList = NULLP;
4429    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4430 #if 0
4431    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4432    if(!pdschCfg->tci_StatesToAddModList)
4433    {
4434       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4435       return RFAILED;
4436    }
4437    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4438    {
4439       return RFAILED;
4440    }
4441 #endif
4442
4443 if(pdschCfgDb == NULLP)
4444    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4445 else
4446 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4447
4448    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4449    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4450    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4451    {
4452       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4453       return RFAILED;
4454    }
4455    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4456    {
4457       return RFAILED;
4458    }
4459
4460    pdschCfg->pdsch_AggregationFactor = NULLP;
4461    pdschCfg->rateMatchPatternToAddModList = NULLP;
4462    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4463    pdschCfg->rateMatchPatternGroup1 = NULLP;
4464    pdschCfg->rateMatchPatternGroup2 = NULLP;
4465    if(pdschCfgDb == NULLP)
4466       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4467    else
4468       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4469    pdschCfg->mcs_Table = NULLP;
4470
4471    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4472    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4473    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4474    {
4475       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4476       return RFAILED;
4477    }
4478    if(pdschCfgDb == NULLP)
4479       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4480    else
4481       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4482
4483    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4484    {
4485       return RFAILED;
4486    }
4487
4488    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4489    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4490    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4491    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4492    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4493    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4494    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4495
4496    return ROK;
4497 }
4498
4499 /*******************************************************************
4500  *
4501  * @brief Builds intitial DL BWP
4502  * @details
4503  *
4504  *    Function : BuildInitialDlBWP 
4505  *
4506  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4507  *
4508  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4509  *
4510  * @return ROK     - success
4511  *         RFAILED - failure
4512  *
4513  * ****************************************************************/
4514 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4515 {
4516    PdcchConfig *pdcchCfg = NULLP;
4517    PdschConfig *pdschCfg = NULLP;
4518
4519    if(initiDlBwp)
4520    {
4521       if(initiDlBwp->pdcchPresent)
4522          pdcchCfg = &initiDlBwp->pdcchCfg;
4523       if(initiDlBwp->pdschPresent)
4524          pdschCfg = &initiDlBwp->pdschCfg;
4525    }
4526
4527    dlBwp->pdcch_Config = NULLP;
4528    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4529    if(!dlBwp->pdcch_Config)
4530    {
4531       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4532       return RFAILED;
4533    }
4534    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4535
4536    dlBwp->pdcch_Config->choice.setup = NULLP;
4537    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4538    if(!dlBwp->pdcch_Config->choice.setup)
4539    {
4540       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4541       return RFAILED;
4542    }
4543    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4544    {
4545       return RFAILED;
4546    }
4547
4548    dlBwp->pdsch_Config = NULLP;
4549    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4550    if(!dlBwp->pdsch_Config)
4551    {
4552       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4553       return RFAILED;
4554    }
4555    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4556
4557    dlBwp->pdsch_Config->choice.setup = NULLP;
4558    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4559    if(!dlBwp->pdsch_Config->choice.setup)
4560    {
4561       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4562       return RFAILED;
4563    }
4564
4565    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4566    {
4567       return RFAILED;
4568    }
4569
4570    dlBwp->sps_Config = NULLP;
4571    dlBwp->radioLinkMonitoringConfig = NULLP; 
4572    return ROK;
4573 }
4574
4575 /*******************************************************************
4576  *
4577  * @brief Builds DMRS UL Pusch Mapping type A
4578  *
4579  * @details
4580  *
4581  *    Function : BuildDMRSULPuschMapTypeA
4582  *
4583  *    Functionality: Builds DMRS UL Pusch Mapping type A
4584  *
4585  * @params[in] 
4586  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4587  * @return ROK     - success
4588  *         RFAILED - failure
4589  *
4590  * ****************************************************************/
4591 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4592 {
4593    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4594    dmrsUlCfg->choice.setup= NULLP;
4595    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4596    if(!dmrsUlCfg->choice.setup)
4597    {
4598       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4599       return RFAILED;
4600    }
4601
4602    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4603    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4604    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4605    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4606    {
4607       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4608       return RFAILED;
4609    }
4610    if(ulDmrsCfgDb == NULLP)
4611       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4612    else
4613       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4614
4615    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4616    dmrsUlCfg->choice.setup->maxLength = NULLP;
4617    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4618    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4619    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4620    {
4621       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4622       return RFAILED;
4623    }
4624
4625    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4626    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4627          sizeof(long));
4628    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4629    {
4630       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4631       return RFAILED;
4632    }
4633    if(ulDmrsCfgDb == NULLP)
4634       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4635    else
4636       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4637
4638    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4639    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4640    return ROK;
4641 }
4642
4643 /*******************************************************************
4644  *
4645  * @brief Build PUSCH time domain allocation list
4646  *
4647  * @details
4648  *
4649  *    Function : BuildPuschTimeDomAllocList
4650  *
4651  *    Functionality: Build PUSCH time domain allocation list
4652  *
4653  * @params[in] 
4654  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4655  *
4656  * @return ROK     - success
4657  *         RFAILED - failure
4658  *
4659  * ****************************************************************/
4660 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4661 {
4662    uint8_t idx;
4663    uint8_t elementCnt;
4664    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4665
4666    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4667    timeDomAllocList->choice.setup = NULLP;
4668    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4669    if(!timeDomAllocList->choice.setup)
4670    {
4671       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4672       return RFAILED;
4673    }
4674
4675    if(puschCfgDb == NULLP)
4676       elementCnt = 2;
4677    else
4678       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4679
4680    timeDomAllocList->choice.setup->list.count = elementCnt;
4681    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4682    timeDomAllocList->choice.setup->list.array = NULLP;
4683    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4684    if(!timeDomAllocList->choice.setup->list.array)
4685    {
4686       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4687       return RFAILED;
4688    }
4689
4690    for(idx = 0; idx < elementCnt; idx++)
4691    {
4692       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4693       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4694       if(!timeDomAllocList->choice.setup->list.array[idx])
4695       {
4696          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4697          return RFAILED;
4698       }
4699    }
4700
4701    for(idx = 0; idx < elementCnt; idx++)
4702    {
4703       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4704       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4705       if(!timeDomAlloc->k2)
4706       {
4707          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4708          return RFAILED;
4709       }
4710       if(puschCfgDb == NULLP)
4711       {
4712          if(idx == 0)
4713             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4714          else if(idx == 1)
4715             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4716
4717          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4718          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4719       }
4720       else
4721       {
4722          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4723          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4724          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4725       }
4726    }
4727
4728    return ROK;
4729 }
4730
4731 /*******************************************************************
4732  *
4733  * @brief Builds BWP UL dedicated PUSCH Config
4734  *
4735  * @details
4736  *
4737  *    Function : BuildBWPUlDedPuschCfg
4738  *
4739  *    Functionality:
4740  *      Builds BWP UL dedicated PUSCH Config
4741  *
4742  * @params[in] : PUSCH_Config_t *puschCfg
4743  *    
4744  * @return ROK     - success
4745  *         RFAILED - failure
4746  *
4747  * ****************************************************************/
4748 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4749 {
4750    DmrsUlCfg *ulDmrsCfg = NULLP;
4751    
4752    if(puschCfgDb)
4753       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4754
4755    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4756    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4757    if(!puschCfg->dataScramblingIdentityPUSCH)
4758    {
4759       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4760       return RFAILED;
4761    }
4762    if(puschCfgDb == NULLP)
4763       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4764    else
4765       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4766
4767    puschCfg->txConfig = NULLP;
4768    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4769    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4770    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4771    {
4772       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4773       return RFAILED;
4774    }
4775
4776    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4777    {
4778       return RFAILED;
4779    }
4780
4781    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4782    puschCfg->pusch_PowerControl = NULLP;
4783    puschCfg->frequencyHopping = NULLP;
4784    puschCfg->frequencyHoppingOffsetLists = NULLP;
4785
4786    if(puschCfgDb == NULLP)
4787       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4788    else
4789       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4790
4791    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4792    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4793    if(!puschCfg->pusch_TimeDomainAllocationList)
4794    {
4795       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4796       return RFAILED;
4797    }
4798
4799    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4800    {
4801       return RFAILED;
4802    }
4803
4804    puschCfg->pusch_AggregationFactor = NULLP;
4805    puschCfg->mcs_Table = NULLP;
4806    puschCfg->mcs_TableTransformPrecoder = NULLP;
4807    puschCfg->transformPrecoder = NULLP;
4808    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4809    if(!puschCfg->transformPrecoder)
4810    {
4811       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4812       return RFAILED;
4813    }
4814    if(puschCfgDb == NULLP)
4815       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4816    else
4817       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4818
4819    puschCfg->codebookSubset = NULLP;
4820    puschCfg->maxRank = NULLP;
4821    puschCfg->rbg_Size = NULLP;
4822    puschCfg->uci_OnPUSCH = NULLP;
4823    puschCfg->tp_pi2BPSK = NULLP;
4824
4825    return ROK;
4826 }
4827
4828 /*******************************************************************
4829  *
4830  * @brief Builds PUCCH resource set add/modify list
4831  *
4832  * @details
4833  *
4834  *    Function : BuildPucchRsrcSetAddModList
4835  *
4836  *    Functionality:
4837  *      Builds PUCCH resource set add/modify list
4838  *
4839  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4840  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4841  *
4842  * @return ROK     - success
4843  *         RFAILED - failure
4844  *
4845  * ****************************************************************/
4846 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4847    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4848 {
4849    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4850    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4851
4852    if(rsrcSetCfgDb == NULLP)
4853       elementCnt = 1;
4854    else
4855       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4856
4857    resourceSetToAddModList->list.count = elementCnt;
4858    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4859    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4860    if(resourceSetToAddModList->list.array == NULLP)
4861    {
4862       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4863       return RFAILED;
4864    }
4865    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4866    {
4867       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4868       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4869       {
4870          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4871          return RFAILED;
4872       }
4873    }
4874
4875    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4876    {
4877       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4878
4879       /* Resource set Id */
4880       if(rsrcSetCfgDb == NULLP)
4881          rsrcSet->pucch_ResourceSetId = 1;
4882       else
4883          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4884  
4885       /* Resource list of a resource set */
4886       if(rsrcSetCfgDb == NULLP)
4887          elementCnt = 1;
4888       else
4889          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4890       rsrcSet->resourceList.list.count = elementCnt;
4891       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4892       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4893       if(rsrcSet->resourceList.list.array == NULLP)
4894       {
4895          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4896          return RFAILED;
4897       }
4898
4899       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4900       {
4901          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4902          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4903          {
4904             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4905             return RFAILED;
4906          }
4907       }
4908       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4909       {
4910          if(rsrcSetCfgDb == NULLP)
4911             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4912          else
4913             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4914       }
4915
4916       /* Max payload size (minus 1) in a Resource set */
4917       rsrcSet->maxPayloadMinus1 = NULLP;
4918       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4919       {
4920          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4921          if(rsrcSet->maxPayloadMinus1 == NULLP)
4922          {
4923             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4924             return RFAILED;
4925          }
4926          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4927       }
4928    }
4929    return ROK;
4930 }
4931
4932 /*******************************************************************
4933  *
4934  * @brief Builds PUCCH resource add/modify list
4935  *
4936  * @details
4937  *
4938  *    Function : BuildPucchRsrcAdddModList
4939  *
4940  *    Functionality:
4941  *      Builds PUCCH resource add/modify list
4942  *
4943  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4944  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4945  *
4946  * @return ROK     - success
4947  *         RFAILED - failure
4948  *
4949  * ****************************************************************/
4950 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4951 {
4952    uint8_t elementCnt = 0, rsrcIdx = 0;
4953    PUCCH_Resource_t *rsrc = NULLP;
4954
4955    if(rsrcCfgDb == NULLP)
4956       elementCnt = 1;
4957    else
4958       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4959    resourceToAddModList->list.count = elementCnt;
4960    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4961    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4962    if(resourceToAddModList->list.array == NULLP)
4963    {
4964       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4965       return RFAILED;
4966    }
4967    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4968    {
4969       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4970       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4971       {
4972          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4973          return RFAILED;
4974       }
4975    }
4976
4977    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4978    {
4979       rsrc = resourceToAddModList->list.array[rsrcIdx];
4980
4981       if(rsrcCfgDb == NULLP)
4982       {
4983          rsrc->pucch_ResourceId = 1;
4984          rsrc->startingPRB = 0;
4985          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4986          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4987          if(rsrc->format.choice.format1 == NULLP)
4988          {
4989             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4990             return RFAILED;
4991          }  
4992          rsrc->format.choice.format1->initialCyclicShift = 0;
4993          rsrc->format.choice.format1->nrofSymbols = 4;
4994          rsrc->format.choice.format1->startingSymbolIndex = 0;
4995          rsrc->format.choice.format1->timeDomainOCC = 0;
4996       }
4997       else
4998       {
4999          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
5000          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5001          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5002          {
5003             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5004             if(rsrc->intraSlotFrequencyHopping == NULLP)
5005             {
5006                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5007                return RFAILED;
5008             }
5009             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5010          }
5011          else
5012             rsrc->intraSlotFrequencyHopping = NULLP;
5013
5014          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5015          {
5016             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5017             if(rsrc->secondHopPRB == NULLP)
5018             {
5019                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5020                return RFAILED;
5021             }
5022             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5023          }
5024          else
5025             rsrc->secondHopPRB = NULLP;
5026          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5027
5028          switch(rsrc->format.present)
5029          {
5030             case PUCCH_Resource__format_PR_NOTHING:
5031                break;
5032             case PUCCH_Resource__format_PR_format0:
5033                {
5034                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5035                   if(rsrc->format.choice.format0 == NULLP)
5036                   {
5037                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5038                      return RFAILED;
5039                   }
5040                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5041                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5042                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5043                   break;
5044                }
5045
5046             case PUCCH_Resource__format_PR_format1:
5047                {
5048                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5049                   if(rsrc->format.choice.format1 == NULLP)
5050                   {
5051                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5052                      return RFAILED;
5053                   }  
5054                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5055                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5056                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5057                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5058                   break;
5059                }
5060
5061             case PUCCH_Resource__format_PR_format2:
5062                {
5063                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5064                   if(rsrc->format.choice.format2 == NULLP)
5065                   {
5066                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5067                      return RFAILED;
5068                   } 
5069                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5070                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5071                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5072                   break;
5073                }
5074
5075             case PUCCH_Resource__format_PR_format3:
5076                {
5077                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5078                   if(rsrc->format.choice.format3 == NULLP)
5079                   {
5080                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5081                      return RFAILED;
5082                   }
5083                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5084                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5085                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5086                   break;
5087                }
5088
5089             case PUCCH_Resource__format_PR_format4:
5090                {
5091                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5092                   if(rsrc->format.choice.format4 == NULLP)
5093                   {
5094                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5095                      return RFAILED;
5096                   }
5097                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5098                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5099                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5100                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5101                   break;
5102                }
5103          }
5104       }
5105    }
5106    return ROK;
5107 }
5108
5109 /*******************************************************************
5110  *
5111  * @brief Builds PUCCH format  config
5112  *
5113  * @details
5114  *
5115  *    Function : BuildPucchFormat
5116  *
5117  *    Functionality: Builds PUCCH format  config
5118  *
5119  * @params[in] : PucchFormatCfg *formatDb
5120  *               PUCCH_FormatConfig_t *format
5121  *
5122  * @return ROK     - success
5123  *         RFAILED - failure
5124  *
5125  * ****************************************************************/
5126 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5127 {
5128    /* Inter Slot Fequency hopping */
5129    format->interslotFrequencyHopping = NULLP;
5130    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5131    {
5132       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5133       if(format->interslotFrequencyHopping)
5134       {
5135          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5136          return RFAILED;
5137       }
5138       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5139    }
5140
5141    /* Additional DMRS */
5142    format->additionalDMRS = NULLP;
5143    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5144    {
5145       DU_ALLOC(format->additionalDMRS, sizeof(long));
5146       if(format->additionalDMRS)
5147       {
5148          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5149          return RFAILED;
5150       }
5151       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5152    }
5153
5154     /* Maximum code rate */
5155    format->maxCodeRate = NULLP;
5156    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5157    {
5158       DU_ALLOC(format->maxCodeRate, sizeof(long));
5159       if(format->maxCodeRate)
5160       {
5161          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5162          return RFAILED;
5163       }  
5164       *(format->maxCodeRate) = formatDb->maxCodeRate;
5165    }
5166  
5167    /* Number of slots */
5168    format->nrofSlots = NULLP;
5169    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5170    {
5171       DU_ALLOC(format->nrofSlots, sizeof(long));
5172       if(format->nrofSlots == NULLP)
5173       {
5174          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5175          return RFAILED;
5176       }
5177       if(formatDb == NULLP)
5178          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5179       else
5180          *(format->nrofSlots) = formatDb->numSlots;
5181    }
5182
5183    /* Pi2BPSK*/
5184    format->pi2BPSK = NULLP;
5185    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5186    {
5187       DU_ALLOC(format->pi2BPSK, sizeof(long));
5188       if(format->pi2BPSK)
5189       {     
5190          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5191          return RFAILED;
5192       }     
5193       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5194    }
5195
5196    /* Simultaneous HARQ ACK and CSI */
5197    format->simultaneousHARQ_ACK_CSI = NULLP;
5198    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5199    {
5200       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5201       if(format->simultaneousHARQ_ACK_CSI)
5202       {     
5203          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5204          return RFAILED;
5205       }     
5206       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5207    }
5208
5209    return ROK;
5210 }
5211
5212
5213 /*******************************************************************
5214  *
5215  * @brief Builds PUCCH scheduling request list
5216  *
5217  * @details
5218  *
5219  *    Function : BuildPucchSchReqAddModList
5220  *
5221  *    Functionality:
5222  *      Builds PUCCH scheduling request list
5223  *
5224  * @params[in] : PucchSchedReqCfg *schReqDb
5225  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5226  *
5227  * @return ROK     - success
5228  *         RFAILED - failure
5229  *
5230  * ****************************************************************/
5231 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5232    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5233 {
5234    uint8_t elementCnt = 0, schReqIdx = 0;
5235    SchedulingRequestResourceConfig_t *schReqRsrc;
5236
5237    elementCnt = schReqDb->schedAddModListCount;
5238    schReqRsrcToAddModList->list.count = elementCnt;
5239    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5240
5241    schReqRsrcToAddModList->list.array = NULLP;
5242    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5243    if(schReqRsrcToAddModList->list.array == NULLP)
5244    {
5245       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5246       return RFAILED;
5247    }
5248
5249    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5250    {
5251       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5252       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5253       {
5254          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5255          return RFAILED;
5256       }
5257    }
5258
5259    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5260    {
5261       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5262       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5263       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5264
5265       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5266       {
5267          schReqRsrc->periodicityAndOffset = NULLP;
5268          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5269          if(schReqRsrc->periodicityAndOffset == NULLP)
5270          {
5271             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5272             return RFAILED;
5273          }
5274
5275          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5276          switch(schReqRsrc->periodicityAndOffset->present)
5277          {
5278             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5279                break;
5280             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5281                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5282                break;
5283             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5284                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5285                break;
5286             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5287                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5288                break;
5289             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5290                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5291                break;
5292             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5293                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5294                break;
5295             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5296                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5297                break;
5298             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5299                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5300                break;
5301             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5302                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5303                break;
5304             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5305                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5306                break;
5307             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5308                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5309                break;
5310             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5311                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5312                break;
5313             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5314                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5315                break;
5316             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5317                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5318                break;
5319             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5320                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5321                break;
5322             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5323                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5324                break;
5325          }
5326       }
5327
5328       if(schReqDb->schedAddModList[schReqIdx].resrc)
5329       {
5330          schReqRsrc->resource = NULLP;
5331          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5332          if(schReqRsrc->resource == NULLP)
5333          {
5334             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5335             return RFAILED;
5336          }
5337          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5338
5339       }
5340    }
5341    return ROK;
5342 }
5343
5344 /*******************************************************************
5345  *
5346  * @brief Builds PUCCH multi csi resource list
5347  *
5348  * @details
5349  *
5350  *    Function : BuildPucchMultiCsiRsrcList
5351  *
5352  *    Functionality:
5353  *      Builds PUCCH multi csi resource list
5354  *
5355  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5356  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5357  *
5358  * @return ROK     - success
5359  *         RFAILED - failure
5360  *
5361  * ****************************************************************/
5362 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5363 {
5364    uint8_t elementCnt = 0, rsrcIdx = 0;
5365
5366    elementCnt = multiCsiDb->multiCsiResrcListCount;
5367    multiCsiRsrcList->list.count = elementCnt;
5368    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5369    multiCsiRsrcList->list.array = NULLP;
5370    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5371    if(multiCsiRsrcList->list.array == NULLP)
5372    {
5373       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5374       return RFAILED;
5375    }
5376
5377    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5378    {
5379       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5380       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5381       {
5382          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5383          return RFAILED;
5384       }
5385    }
5386
5387    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5388    {
5389       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5390    }
5391    return ROK;
5392 }
5393
5394 /*******************************************************************
5395  *
5396  * @brief Builds DL data -to- Ul Ack list
5397  *
5398  * @details
5399  *
5400  *    Function : BuildDlDataToUlAckList
5401  *
5402  *    Functionality: Builds DL data -to- Ul Ack list
5403  *
5404  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5405  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5406  *
5407  * @return ROK     - success
5408  *         RFAILED - failure
5409  *
5410  * ****************************************************************/
5411 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5412 {
5413    uint8_t elementCnt = 0, arrIdx = 0;
5414
5415    if(dlDataToUlAckDb == NULLP)
5416       elementCnt = 2;
5417    else
5418       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5419
5420    dlDataToUlACKList->list.count = elementCnt;
5421    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5422    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5423    if(dlDataToUlACKList->list.array == NULLP)
5424    {
5425       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5426       return RFAILED;
5427    }   
5428
5429    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5430    {
5431       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5432       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5433       {
5434          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5435          return RFAILED;
5436       }   
5437    }
5438
5439    if(dlDataToUlAckDb == NULLP)
5440    {
5441       arrIdx = 0;
5442       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5443       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5444    }
5445    else
5446    {
5447       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5448       {
5449          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5450       }
5451    }
5452    return ROK;
5453 }
5454
5455 /*******************************************************************
5456  *
5457  * @brief Builds BWP UL dedicated PUCCH Config
5458  *
5459  * @details
5460  *
5461  *    Function : BuildBWPUlDedPucchCfg
5462  *
5463  *    Functionality:
5464  *      Builds BWP UL dedicated PUCCH Config
5465  *
5466  * @params[in] : PUCCH_Config_t *pucchCfg
5467  *
5468  * @return ROK     - success
5469  *         RFAILED - failure
5470  *
5471  * ****************************************************************/
5472 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5473 {
5474    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5475    PucchResrcCfg *rsrcCfgDb = NULLP;
5476    PucchFormatCfg *format1Db = NULLP;
5477    PucchFormatCfg *format2Db = NULLP;
5478    PucchFormatCfg *format3Db = NULLP;
5479    PucchFormatCfg *format4Db = NULLP;
5480    PucchSchedReqCfg *schReqDb = NULLP;   
5481    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5482    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5483
5484    if(pucchCfgDb)
5485    {
5486       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5487       rsrcCfgDb = pucchCfgDb->resrc;
5488       format1Db = pucchCfgDb->format1;
5489       format2Db = pucchCfgDb->format2;
5490       format3Db = pucchCfgDb->format3;
5491       format4Db = pucchCfgDb->format4;
5492       schReqDb = pucchCfgDb->schedReq;
5493       multiCsiDb = pucchCfgDb->multiCsiCfg;
5494       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5495    }
5496
5497    /* RESOURCE SET */
5498    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5499    if(pucchCfg->resourceSetToAddModList == NULL)
5500    {
5501       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5502       return RFAILED;
5503    }
5504
5505    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5506    {
5507       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5508       return RFAILED;
5509    }
5510
5511    /* PUCCH RESOURCE */
5512    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5513    if(pucchCfg->resourceToAddModList == NULLP)
5514    {
5515       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5516       return RFAILED;
5517    }
5518
5519    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5520    {
5521       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5522       return RFAILED;
5523    }
5524
5525    /* PUCCH Format 1 */
5526    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5527    if(pucchCfg->format1 == NULLP)
5528    {
5529       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5530       return RFAILED;
5531    }
5532    
5533    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5534    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5535    if(pucchCfg->format1->choice.setup == NULLP)
5536    {
5537       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5538       return RFAILED;
5539    }
5540
5541    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5542    {
5543       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5544       return RFAILED;
5545    }
5546
5547    /* PUCCH Format 2 */
5548    if(format2Db)
5549    {
5550       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5551       if(pucchCfg->format2 == NULLP)
5552       {
5553          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5554          return RFAILED;
5555       }
5556
5557       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5558       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5559       if(pucchCfg->format2->choice.setup == NULLP)
5560       {
5561          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5562          return RFAILED;
5563       }
5564
5565       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5566       {
5567          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5568          return RFAILED;
5569       }
5570    }
5571
5572    /* PUCCH Format 3 */
5573    if(format3Db)
5574    {
5575       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5576       if(pucchCfg->format3 == NULLP)
5577       {
5578          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5579          return RFAILED;
5580       }
5581
5582       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5583       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5584       if(pucchCfg->format3->choice.setup == NULLP)
5585       {
5586          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5587          return RFAILED;
5588       }
5589
5590       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5591       {
5592          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5593          return RFAILED;
5594       }
5595    }
5596
5597    /* PUCCH Format 4 */
5598    if(format4Db)
5599    {
5600       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5601       if(pucchCfg->format4 == NULLP)
5602       {
5603          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5604          return RFAILED;
5605       }
5606
5607       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5608       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5609       if(pucchCfg->format4->choice.setup == NULLP)
5610       {
5611          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5612          return RFAILED;
5613       }
5614
5615       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5616       {
5617          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5618          return RFAILED;
5619       }
5620    }
5621
5622    /* Scheduling Request */
5623    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5624    {
5625       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5626       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5627       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5628       {
5629          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5630          return RFAILED;
5631       }
5632
5633       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5634       {
5635          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5636          return RFAILED;
5637       }
5638    }
5639
5640    /* Multi CSI */
5641    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5642    {
5643       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5644       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5645       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5646       {
5647          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5648          return RFAILED;
5649       }
5650
5651       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5652       {
5653          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5654          return RFAILED;
5655       }
5656    }
5657
5658    /* DL DATA TO UL ACK */
5659    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5660    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5661    {
5662       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5663       return RFAILED;
5664    }
5665
5666    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5667    {
5668       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5669       return RFAILED;
5670    }
5671    
5672    /* TODO : spatial relation info add/mod list and power control*/
5673
5674    return ROK;
5675 }
5676
5677 /*******************************************************************
5678  *
5679  * @brief Fills SRS resource to add/modify list 
5680  *
5681  * @details
5682  *
5683  *    Function : BuildSrsRsrcAddModList
5684  *
5685  *    Functionality: Fills SRS resource to add/modify list
5686  *
5687  * @params[in] 
5688  * @return ROK     - success
5689  *         RFAILED - failure
5690  *
5691  * ****************************************************************/
5692 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5693 {
5694    uint8_t   elementCnt;
5695    uint8_t   rsrcIdx;
5696
5697    elementCnt = 1;
5698    resourceList->list.count = elementCnt;
5699    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5700    resourceList->list.array = NULLP;
5701    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5702    if(!resourceList->list.array)
5703    {
5704       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5705       return RFAILED;
5706    }
5707
5708    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5709    {
5710       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5711       if(!resourceList->list.array[rsrcIdx])
5712       {
5713          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5714          return RFAILED;
5715       }
5716    }
5717
5718    rsrcIdx = 0;
5719    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5720    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5721    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5722
5723    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5724    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5725          sizeof(struct SRS_Resource__transmissionComb__n2));
5726    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5727    {
5728       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5729       return RFAILED;
5730    }
5731    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5732       = SRS_COMB_OFFSET_N2;
5733    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5734       = SRS_CYCLIC_SHIFT_N2;
5735
5736    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5737                                                                       PUSCH_START_SYMBOL;
5738    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5739                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5740    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5741                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5742
5743    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5744    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5745    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5746    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5747    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5748    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5749                                                                SRS_Resource__groupOrSequenceHopping_neither;
5750
5751    /* Setting resource type to aperiodic for intergration purposes */
5752    resourceList->list.array[rsrcIdx]->resourceType.present = \
5753                                                              SRS_Resource__resourceType_PR_aperiodic;
5754    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5755    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5756          sizeof(struct SRS_Resource__resourceType__aperiodic));
5757    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5758    {
5759       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5760       return RFAILED;
5761    }
5762
5763    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5764
5765    return ROK;
5766 }
5767
5768 /*******************************************************************
5769  *
5770  * @brief Build SRS resource set Add/mod list
5771  *
5772  * @details
5773  *
5774  *    Function : BuildSrsRsrcSetAddModList
5775  *
5776  *    Functionality: Build SRS resource set Add/mod list
5777  *
5778  * @params[in] 
5779  * @return ROK     - success
5780  *         RFAILED - failure
5781  *
5782  * ****************************************************************/
5783    uint8_t BuildSrsRsrcSetAddModList
5784 (
5785  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5786  )
5787 {
5788    uint8_t  elementCnt;
5789    uint8_t  rSetIdx;
5790    uint8_t  rsrcIdx;
5791    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5792
5793    elementCnt = 1;
5794    rsrcSetList->list.count = elementCnt;
5795    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5796    rsrcSetList->list.array = NULLP;
5797    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5798    if(!rsrcSetList->list.array)
5799    {
5800       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5801       return RFAILED;
5802    }
5803
5804    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5805    {
5806       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5807       if(!rsrcSetList->list.array[rSetIdx])
5808       {
5809          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5810          return RFAILED;
5811       }
5812    }
5813
5814    rSetIdx = 0;
5815    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5816
5817    /* Fill Resource Id list in resource set */
5818    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5819    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5820          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5821    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5822    {
5823       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5824       return RFAILED;
5825    }
5826
5827    elementCnt = 1;
5828    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5829    rsrcIdList->list.count = elementCnt;
5830    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5831    rsrcIdList->list.array = NULLP;
5832    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5833    if(!rsrcIdList->list.array)
5834    {
5835       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5836       return RFAILED;
5837    }
5838
5839    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5840    {
5841       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5842       if(!rsrcIdList->list.array[rsrcIdx])
5843       {
5844          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5845          return RFAILED;
5846       }
5847    }
5848
5849    rsrcIdx = 0;
5850    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5851
5852    /* Fill resource type */
5853    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5854                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5855
5856    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5857    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5858          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5859    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5860    {
5861       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5862       return RFAILED;
5863    }
5864    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5865       = APERIODIC_SRS_RESRC_TRIGGER;
5866
5867    /* TODO : Fill values for below IEs as expected by Viavi */
5868    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5869    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5870
5871
5872    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5873    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5874    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5875    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5876    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5877
5878    return ROK;
5879 }
5880
5881 /*******************************************************************
5882  *
5883  * @brief Builds BWP UL dedicated SRS Config
5884  *
5885  * @details
5886  *
5887  *    Function : BuildBWPUlDedSrsCfg
5888  *
5889  *    Functionality: Builds BWP UL dedicated SRS Config
5890  *
5891  * @params[in] SRS Config 
5892  * @return ROK     - success
5893  *         RFAILED - failure
5894  *
5895  * ****************************************************************/
5896 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5897 {
5898    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5899    srsCfg->srs_ResourceSetToAddModList = NULLP;
5900    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5901          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5902    if(!srsCfg->srs_ResourceSetToAddModList)
5903    {
5904       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5905       return RFAILED;
5906    }
5907    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5908    {
5909       return RFAILED;
5910    }
5911
5912    srsCfg->srs_ResourceToReleaseList = NULLP;
5913
5914    /* Resource to Add/Modify list */
5915    srsCfg->srs_ResourceToAddModList = NULLP;
5916    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5917          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5918    if(!srsCfg->srs_ResourceToAddModList)
5919    {
5920       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5921       return RFAILED;
5922    }
5923
5924    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5925    {
5926       return RFAILED;
5927    }
5928    srsCfg->tpc_Accumulation = NULLP;
5929
5930    return ROK;
5931 }
5932
5933
5934
5935 /*******************************************************************
5936  *
5937  * @brief Builds Pusch Serving cell Config
5938  *
5939  * @details
5940  *
5941  *    Function : BuildPuschSrvCellCfg
5942  *
5943  *    Functionality: Builds Pusch Serving cell Config
5944  *
5945  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5946  *
5947  * @return ROK     - success
5948  *         RFAILED - failure
5949  *
5950  * ****************************************************************/
5951 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5952 {
5953    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5954    puschCfg->choice.setup = NULLP;
5955    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5956    if(!puschCfg->choice.setup)
5957    {
5958       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5959       return RFAILED;
5960    }
5961
5962    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5963    puschCfg->choice.setup->rateMatching = NULLP;
5964    puschCfg->choice.setup->xOverhead = NULLP;
5965    puschCfg->choice.setup->ext1 = NULLP;
5966
5967    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5968    if(!puschCfg->choice.setup->ext1)
5969    {
5970       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5971       return RFAILED;
5972    }
5973
5974    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5975    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5976    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5977    {
5978       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5979       return RFAILED;
5980    }
5981    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5982
5983    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5984    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5985    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5986    {
5987       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5988       return RFAILED;
5989    }
5990    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5991
5992    return ROK;
5993 }
5994
5995 /*******************************************************************
5996  *
5997  * @brief Builds inital UL BWP
5998  *
5999  * @details
6000  *
6001  *    Function : BuildInitialUlBWP
6002  *
6003  *    Functionality: Builds initial UL BWP
6004  *
6005  * @params[in] BWP_UplinkDedicated_t *ulBwp
6006  * @return ROK     - success
6007  *         RFAILED - failure
6008  *
6009  * ****************************************************************/
6010 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6011 {
6012    PucchCfg *pucchCfg = NULLP;
6013    PuschCfg *puschCfg = NULLP;
6014
6015    if(initUlBwp)
6016    {
6017       if(initUlBwp->pucchPresent)
6018          pucchCfg = &initUlBwp->pucchCfg;
6019       if(initUlBwp->puschPresent)
6020          puschCfg = &initUlBwp->puschCfg;
6021    }
6022
6023    ulBwp->pucch_Config = NULLP;
6024    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6025    if(!ulBwp->pucch_Config)
6026    {
6027       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6028       return RFAILED;
6029    }
6030
6031    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6032    ulBwp->pucch_Config->choice.setup = NULLP;
6033    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6034    if(!ulBwp->pucch_Config->choice.setup)
6035    {
6036       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6037       return RFAILED;
6038    }
6039
6040    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6041    {
6042       return RFAILED;
6043    }
6044
6045    /* Fill BWP UL dedicated PUSCH config */
6046    ulBwp->pusch_Config = NULLP;
6047    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6048    if(!ulBwp->pusch_Config)
6049    {
6050       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6051       return RFAILED;
6052    }
6053
6054    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6055    ulBwp->pusch_Config->choice.setup = NULLP;
6056    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6057    if(!ulBwp->pusch_Config->choice.setup)
6058    {
6059       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6060       return RFAILED;
6061    }
6062
6063    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6064    {
6065       return RFAILED;
6066    }
6067
6068    ulBwp->configuredGrantConfig = NULLP;
6069
6070    /* Fill BPW UL dedicated SRS config */
6071    ulBwp->srs_Config = NULLP;
6072    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6073    if(!ulBwp->srs_Config)
6074    {
6075       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6076       return RFAILED;
6077    }
6078
6079    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6080    ulBwp->srs_Config->choice.setup = NULLP;
6081    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6082    if(!ulBwp->srs_Config->choice.setup)
6083    {
6084       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6085       return RFAILED;
6086    }
6087
6088    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6089    {
6090       return RFAILED;   
6091    }
6092
6093    ulBwp->beamFailureRecoveryConfig = NULLP;
6094
6095    return ROK;
6096 }
6097
6098 /*******************************************************************
6099  *
6100  * @brief Builds UL config
6101  * @details
6102  *
6103  *    Function : BuildUlCfg 
6104  *
6105  *    Functionality: Builds UL config in spCellCfgDed
6106  *
6107  * @params[in] UplinkConfig_t *ulCfg
6108  *
6109  * @return ROK     - success
6110  *         RFAILED - failure
6111  *
6112  * ****************************************************************/
6113 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6114 {
6115    InitialUlBwp *initUlBwp = NULLP;
6116
6117    if(servCellRecfg)
6118    {
6119       initUlBwp = &servCellRecfg->initUlBwp;
6120    }
6121
6122    ulCfg->initialUplinkBWP = NULLP;
6123    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6124    if(!ulCfg->initialUplinkBWP)
6125    {
6126       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6127       return RFAILED;
6128    }
6129
6130    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6131    {
6132       return RFAILED;
6133    }
6134
6135    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6136    ulCfg->uplinkBWP_ToAddModList = NULLP;
6137    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6138    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6139    if(!ulCfg->firstActiveUplinkBWP_Id)
6140    {
6141       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6142       return RFAILED;
6143    }
6144    if(servCellRecfg == NULLP)
6145       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6146    else
6147       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6148
6149    ulCfg->pusch_ServingCellConfig = NULLP;
6150    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6151    if(!ulCfg->pusch_ServingCellConfig)
6152    {
6153       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6154       return RFAILED;
6155    }
6156
6157    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6158    {
6159       return RFAILED;
6160    }
6161
6162    ulCfg->carrierSwitching = NULLP;
6163    ulCfg->ext1 = NULLP;
6164    return ROK;
6165 }
6166
6167 /*******************************************************************
6168  *
6169  * @brief Builds PDSCH serving cell config
6170  * @details
6171  *
6172  *    Function : BuildPdschSrvCellCfg
6173  *
6174  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6175  *
6176  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6177  *
6178  * @return ROK     - success
6179  *         RFAILED - failure
6180  *
6181  * ****************************************************************/
6182 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6183 {
6184    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6185    pdschCfg->choice.setup = NULLP;
6186    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6187    if(!pdschCfg->choice.setup)
6188    {
6189       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6190       return RFAILED;
6191    }
6192
6193    /* Code Block Group Transmission */
6194    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6195    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6196    {
6197       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6198       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6199       {
6200          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6201          return RFAILED;
6202       }
6203
6204       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6205       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6206       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6207       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6208       {
6209          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6210          return RFAILED;
6211       }
6212
6213       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6214          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6215       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6216          *(pdschServCellDb->codeBlkGrpFlushInd);
6217    }
6218
6219    /* xOverhead */
6220    pdschCfg->choice.setup->xOverhead = NULLP;
6221    if(pdschServCellDb && pdschServCellDb->xOverhead)
6222    {
6223       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6224       if(pdschCfg->choice.setup->xOverhead == NULLP)
6225       {
6226          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6227          return RFAILED;
6228       }
6229       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6230    }
6231
6232    /* Number of HARQ processes */
6233    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6234    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6235    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6236    {
6237       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6238       return RFAILED;
6239    }
6240
6241    if(pdschServCellDb == NULLP)
6242    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6243    else
6244    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6245
6246    pdschCfg->choice.setup->pucch_Cell = NULLP;
6247
6248    /* Extension */
6249    pdschCfg->choice.setup->ext1 = NULLP;
6250    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6251    {
6252       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6253       if(pdschCfg->choice.setup->ext1 == NULLP)
6254       {
6255          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6256          return RFAILED;
6257       }
6258
6259       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6260       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6261       {
6262          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6263          return RFAILED;
6264       }
6265       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6266    }
6267
6268    return ROK;
6269 }
6270
6271 /*******************************************************************
6272  *
6273  * @brief Builds CSI Meas config
6274  * @details
6275  *
6276  *    Function : BuildCsiMeasCfg 
6277  *
6278  *    Functionality: Builds CSI Meas config in spCellCfgDed
6279  *
6280  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6281  *
6282  * @return ROK     - success
6283  *         RFAILED - failure
6284  *
6285  * ****************************************************************/
6286 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6287 {
6288
6289    return ROK;
6290 }
6291
6292 /*******************************************************************
6293  *
6294  * @brief Builds DL BWP to add/modify list
6295  * @details
6296  *
6297  *    Function : BuildDlBwpToAddModList
6298  *
6299  *    Functionality: Builds DL BWP to add/modify list
6300  *
6301  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6302  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6303  *
6304  * @return ROK     - success
6305  *         RFAILED - failure
6306  *
6307  * ****************************************************************/ 
6308 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6309 {
6310    uint8_t elementCnt, idx;
6311
6312    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6313    dlBwpAddModList->list.count = elementCnt;
6314    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6315    dlBwpAddModList->list.array = NULLP;
6316    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6317    if(dlBwpAddModList->list.array == NULLP)
6318    {
6319       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6320       return RFAILED;
6321    }
6322
6323    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6324    {
6325       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6326       if(dlBwpAddModList->list.array[idx] == NULLP)
6327       {
6328          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6329          return RFAILED;
6330       }
6331    }
6332
6333    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6334    {
6335       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6336       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6337       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6338    }
6339    return ROK;
6340 }
6341
6342 /*******************************************************************
6343  *
6344  * @brief Builds Spcell config dedicated
6345  * @details
6346  *
6347  *    Function : BuildSpCellCfgDed
6348  *
6349  *    Functionality: Builds sp cell config dedicated in spCellCfg
6350  *
6351  * @params[in] ServingCellConfig_t srvCellCfg
6352  *
6353  * @return ROK     - success
6354  *         RFAILED - failure
6355  *
6356  * ****************************************************************/
6357 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6358 {
6359    ServCellRecfgInfo *servCellRecfg = NULLP;
6360    InitialDlBwp *initDlBwp = NULLP;
6361    PdschServCellCfg *pdschServCellDb = NULLP;
6362
6363    if(ueCb)
6364    {
6365       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6366       initDlBwp = &servCellRecfg->initDlBwp;
6367       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6368    }
6369
6370    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6371
6372    srvCellCfg->initialDownlinkBWP = NULLP;
6373    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6374    if(!srvCellCfg->initialDownlinkBWP)
6375    {
6376       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6377       return RFAILED;
6378    }
6379
6380    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6381    {
6382       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6383       return RFAILED;
6384    }
6385
6386    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6387
6388    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6389    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6390    {
6391       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6392       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6393       {
6394          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6395          return RFAILED;
6396       }
6397
6398       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6399       {
6400          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6401          return RFAILED;
6402       }
6403    }
6404
6405    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6406    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6407    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6408    {
6409       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6410       return RFAILED;
6411    }
6412    if(ueCb == NULLP)
6413       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6414    else
6415       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6416
6417    srvCellCfg->bwp_InactivityTimer = NULLP;
6418
6419    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6420    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6421    if(!srvCellCfg->defaultDownlinkBWP_Id)
6422    {
6423       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6424       return RFAILED;
6425    }
6426    if(ueCb == NULLP)
6427       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6428    else
6429       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6430
6431    srvCellCfg->uplinkConfig = NULLP;
6432    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6433    if(!srvCellCfg->uplinkConfig)
6434    {
6435       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6436       return RFAILED;
6437    }
6438
6439    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6440    {
6441       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6442       return RFAILED;
6443    }
6444    srvCellCfg->supplementaryUplink = NULLP;
6445    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6446
6447    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6448    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6449    if(!srvCellCfg->pdsch_ServingCellConfig)
6450    {
6451       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6452       return RFAILED;
6453    }
6454
6455    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6456    {
6457       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6458       return RFAILED;
6459    }
6460
6461    srvCellCfg->csi_MeasConfig = NULLP;
6462 #if 0
6463    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6464       if(!srvCellCfg->csi_MeasConfig)
6465       {
6466          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6467          return RFAILED;
6468       }
6469
6470    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6471    {
6472       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6473       return RFAILED;
6474    }
6475 #endif
6476    srvCellCfg->sCellDeactivationTimer = NULLP;
6477    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6478    srvCellCfg->tag_Id = TAG_ID;
6479    srvCellCfg->dummy = NULLP;
6480    srvCellCfg->pathlossReferenceLinking = NULLP;
6481    srvCellCfg->servingCellMO = NULLP;
6482    srvCellCfg->ext1 = NULLP;
6483
6484    return ROK;
6485 }
6486
6487 /*******************************************************************
6488  *
6489  * @brief Fills SCS specific carrier list in DL frequency info
6490  *
6491  * @details
6492  *
6493  *    Function : BuildScsSpecificCarrierListDl
6494  *
6495  *    Functionality: Fills SCS specific carrier list in DL frequency info
6496  *
6497  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6498  *
6499  * @return ROK     - success
6500  *         RFAILED - failure
6501  *
6502  * ****************************************************************/
6503 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6504 {
6505    uint8_t elementCnt = 0, listIdx = 0;
6506    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6507
6508    elementCnt = ODU_VALUE_ONE;
6509    scsCarrierList->list.count = elementCnt;
6510    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6511
6512    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6513    if(!scsCarrierList->list.array)
6514    {
6515       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6516          in BuildScsSpecificCarrierListDl()");
6517       return RFAILED;
6518    }
6519
6520    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6521    {
6522       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6523       if(!scsCarrierList->list.array[listIdx])
6524       {    
6525          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6526             element in BuildScsSpecificCarrierListDl()");
6527          return RFAILED;
6528       }    
6529    }
6530
6531    listIdx = 0;
6532    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6533    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6534    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6535
6536    return ROK;
6537 }
6538
6539 /*******************************************************************
6540  *
6541  * @brief Fills DL frequency info in DL config common
6542  *
6543  * @details
6544  *
6545  *    Function : BuildFreqInfoDl
6546  *
6547  *    Functionality: Fills DL frequency info in DL config common
6548  *
6549  * @params[in] Pointer to DownlinkConfigCommon_t
6550  *
6551  * @return ROK     - success
6552  *         RFAILED - failure
6553  *
6554  * ****************************************************************/
6555 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6556 {
6557    uint8_t freqBandIdx = 0, elementCnt = 0;
6558    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6559
6560    /* TODO : Fill SSB Absolute Frequency */
6561    /*
6562       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6563       if(!frequencyInfoDL->absoluteFrequencySSB)
6564       {
6565       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6566       return RFAILED;
6567       }
6568       frequencyInfoDL->absoluteFrequencySSB = ?;
6569       */
6570
6571    /* NR Multi Frequency Band List */
6572    elementCnt = ODU_VALUE_ONE;
6573    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6574    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6575
6576    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6577    if(!frequencyInfoDL->frequencyBandList.list.array)
6578    {
6579       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6580       return RFAILED;
6581    }
6582
6583    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6584    {
6585       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6586       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6587       {
6588          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6589          return RFAILED;
6590       }
6591    }
6592
6593    freqBandIdx = 0;
6594    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6595
6596    /* TODO : Absolute Frequency to Point A */
6597    //frequencyInfoDL->absoluteFrequencyPointA
6598
6599    /* Subcarrier Spacing specifc carrier List */
6600    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6601    {
6602       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6603       return RFAILED;
6604    }
6605
6606    return ROK;
6607
6608 }
6609
6610 /*******************************************************************
6611  *
6612  * @brief Fills DL config common in Serving cell config common
6613  *
6614  * @details
6615  *
6616  *    Function : BuildDlConfigCommon
6617  *
6618  *    Functionality: Fills DL config common in Serving cell config common
6619  *
6620  * @params[in] Pointer to DownlinkConfigCommon_t
6621  *
6622  * @return ROK     - success
6623  *         RFAILED - failure
6624  *
6625  * ****************************************************************/
6626 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6627 {
6628    /* DL Frequency Info */
6629    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6630    if(!dlCfgCommon->frequencyInfoDL)
6631    {
6632       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6633       return RFAILED;
6634    }
6635    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6636    {
6637       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6638       return RFAILED;
6639    }
6640
6641    /* DL BWP config common */
6642    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6643    if(!dlCfgCommon->initialDownlinkBWP)
6644    {
6645       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6646       return RFAILED;
6647    }
6648    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6649    {
6650       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6651       return RFAILED;
6652    }
6653
6654    return ROK;
6655 }
6656
6657 /*******************************************************************
6658  *
6659  * @brief Fills SCS specific carrier list in UL frequency Info
6660  *
6661  * @details
6662  *
6663  *    Function : BuildScsSpecificCarrierListUl
6664  *
6665  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6666  *
6667  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6668  *
6669  * @return ROK     - success
6670  *         RFAILED - failure
6671  *
6672  * ****************************************************************/
6673 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6674 {
6675    uint8_t elementCnt = 0, listIdx = 0; 
6676    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6677
6678    elementCnt = ODU_VALUE_ONE;
6679    scsCarrierList->list.count = elementCnt;
6680    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6681
6682    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6683    if(!scsCarrierList->list.array)
6684    {
6685       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6686       return RFAILED;
6687    }
6688
6689    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6690    {
6691       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6692       if(!scsCarrierList->list.array[listIdx])
6693       {    
6694          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6695          return RFAILED;
6696       }    
6697    }
6698    listIdx = 0; 
6699    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6700    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6701    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6702
6703    return ROK;
6704 }
6705
6706 /*******************************************************************
6707  *
6708  * @brief Fills frequency info in UL config common
6709  *
6710  * @details
6711  *
6712  *    Function : BuildFreqInfoUl
6713  *
6714  *    Functionality: Fills frequency info in UL config common
6715  *
6716  * @params[in] Pointer to FrequencyInfoUL_t
6717  *
6718  * @return ROK     - success
6719  *         RFAILED - failure
6720  *
6721  * ****************************************************************/
6722 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6723 {
6724    uint8_t elementCnt = 0, listIdx= 0;
6725    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6726
6727    /* NR Multi Frequency Band List */
6728    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6729    if(!frequencyInfoUL->frequencyBandList)
6730    {
6731       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6732       return RFAILED;
6733    }
6734
6735    elementCnt = ODU_VALUE_ONE;
6736    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6737    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6738
6739    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6740    if(!frequencyInfoUL->frequencyBandList->list.array)
6741    {
6742       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6743       return RFAILED;
6744    }
6745
6746    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6747    {
6748       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6749       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6750       {
6751          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6752          return RFAILED;
6753       }
6754    }
6755
6756    listIdx = 0;
6757    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6758
6759    /* TODO : Fill Absolute frequency point A */
6760    /*
6761       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6762       if(!frequencyInfoUL->absoluteFrequencyPointA)
6763       {
6764       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6765       return RFAILED;
6766       }
6767     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6768     */
6769
6770    /* Subcarrier Spacing specifc carrier */
6771    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6772    {
6773       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6774       return RFAILED;
6775    }
6776
6777    /* P-MAX */
6778    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6779    if(!frequencyInfoUL->p_Max)
6780    {
6781       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6782       return RFAILED;
6783    }
6784    *frequencyInfoUL->p_Max = ulCfg.pMax;
6785
6786    return ROK;
6787 }
6788
6789 /*******************************************************************
6790  *
6791  * @brief Fills UL config common in Serving cell config common
6792  *
6793  * @details
6794  *
6795  *    Function : BuildUlConfigCommon
6796  *
6797  *    Functionality: Fills UL config common in Serving cell config common
6798  *
6799  * @params[in] Pointer to UplinkConfigCommon_t
6800  *
6801  * @return ROK     - success
6802  *         RFAILED - failure
6803  *
6804  * ****************************************************************/
6805 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6806 {
6807    /* UL Frequency Info */
6808    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6809    if(!ulCfgCommon->frequencyInfoUL)
6810    {
6811       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6812       return RFAILED;
6813    }
6814
6815    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6816    {
6817       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6818       return RFAILED;
6819    }
6820
6821    /* UL BWP common */
6822    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6823    if(!ulCfgCommon->initialUplinkBWP)
6824    {
6825       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6826       return RFAILED;
6827    }
6828
6829    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6830    {
6831       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6832       return RFAILED;
6833    }
6834
6835    /* Time Alignment timer */
6836    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6837
6838    return ROK;
6839 }
6840
6841 /*******************************************************************
6842  *
6843  * @brief Fills SSB position in burst in SP cell config common
6844  *
6845  * @details
6846  *
6847  *    Function : BuildSsbPosInBurst
6848  *
6849  *    Functionality: 
6850  *       Fills SSB position in burst in SP cell config common
6851  *
6852  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6853  *
6854  * @return ROK     - success
6855  *         RFAILED - failure
6856  *
6857  * ****************************************************************/
6858 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6859 {
6860    uint8_t bitStringSizeInBytes = 0;
6861
6862    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6863
6864    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6865    bitStringSizeInBytes = 1;
6866    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6867
6868    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6869    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6870    {
6871       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6872       return RFAILED;
6873    }
6874
6875    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6876                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6877    {
6878       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6879       return RFAILED;
6880    }
6881
6882    return ROK;
6883 }
6884
6885 /*******************************************************************
6886  *
6887  * @brief Fills SP cell config common in Reconfig with Sync
6888  *
6889  * @details
6890  *
6891  *    Function : BuildSpCellConfigCommon
6892  *
6893  *    Functionality: Fills SP cell config common in Reconfig with Sync
6894  *
6895  * @params[in] Pointer to ServingCellConfigCommon_t
6896  *
6897  * @return ROK     - success
6898  *         RFAILED - failure
6899  *
6900  * ****************************************************************/
6901 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6902 {
6903    /* Physical Cell Identity */
6904    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6905    if(!spCellConfigCommon->physCellId)
6906    {
6907       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6908       return RFAILED;
6909    } 
6910    *(spCellConfigCommon->physCellId) = NR_PCI;
6911
6912    /* Downlink Config Common */
6913    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6914    if(!spCellConfigCommon->downlinkConfigCommon)
6915    {
6916       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6917       return RFAILED;
6918    }
6919    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6920    {
6921       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6922       return RFAILED;
6923    }
6924
6925    /* Uplinlink Config Common */
6926    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6927    if(!spCellConfigCommon->uplinkConfigCommon)
6928    {
6929       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6930       return RFAILED;
6931    }
6932    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6933    {
6934       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6935       return RFAILED;
6936    }
6937
6938    /* Timing Advance offset */
6939    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6940    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6941    {
6942       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6943       return RFAILED;
6944    }
6945    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6946
6947    /* SSB Position In Burst */
6948    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6949    if(!spCellConfigCommon->ssb_PositionsInBurst)
6950    {
6951       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6952       return RFAILED;
6953    }
6954    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6955    {
6956       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6957       return RFAILED;
6958    }
6959
6960    /* SSB Periodicity in Serving cell */
6961    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6962    if(!spCellConfigCommon->ssb_periodicityServingCell)
6963    {
6964       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6965          BuildSpCellConfigCommon()");
6966       return RFAILED;
6967    }
6968    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6969       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6970
6971    /* DMRS Type A position */
6972    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6973
6974    /* SSB subcarrier spacing */
6975    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6976    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6977    {
6978       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6979       return RFAILED;
6980    }
6981    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6982
6983    /* TDD UL-DL configuration common */
6984    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6985    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6986    {
6987       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6988       return RFAILED;
6989    }
6990    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6991    {
6992       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6993       return RFAILED;
6994    }
6995
6996    /* SS PBCH Block Power */
6997    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6998
6999    return ROK;
7000 }
7001
7002 /*******************************************************************
7003  *
7004  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7005  *
7006  * @details
7007  *
7008  *    Function : BuildRecfgWithSync
7009  *
7010  *    Functionality: 
7011  *       Fills dedicated RACH configuration in Reconfiguration with sync
7012  *
7013  * @params[in] DU UE CB
7014  *             Pointer to Rach config dedicated struct
7015  *
7016  * @return ROK     - success
7017  *         RFAILED - failure
7018  *
7019  * ****************************************************************/
7020 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7021 {
7022    uint8_t elementCnt = 0, listIdx = 0;
7023    CFRA_t *cfra = NULLP;
7024    struct CFRA__resources__ssb *ssbResource = NULLP;
7025    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7026
7027    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7028
7029    /* Uplink */
7030    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7031    if(!rachCfgDed->choice.uplink)
7032    {
7033       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7034       return RFAILED;
7035    }
7036
7037    /* CFRA : Contention free Random Access */
7038    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7039    if(!rachCfgDed->choice.uplink->cfra)
7040    {
7041       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7042       return RFAILED;
7043    }
7044    cfra = rachCfgDed->choice.uplink->cfra;
7045
7046    /* CFRA occassions */
7047    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7048    if(!cfra->occasions)
7049    {
7050       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7051       return RFAILED;
7052    }
7053
7054    /* CFRA occassions : RACH generic configuration */
7055    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7056    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7057    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7058    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7059    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7060    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7061    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7062    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7063
7064    /* CFRA occassions : SSB per RACH occasion */
7065    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7066    if(!cfra->occasions->ssb_perRACH_Occasion)
7067    {
7068       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7069       return RFAILED;
7070    }
7071    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7072
7073    /* CFRA resource */
7074    cfra->resources.present = CFRA__resources_PR_ssb;
7075
7076    /* CFRA resource : SSB */
7077    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7078    if(!cfra->resources.choice.ssb)
7079    {
7080       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7081       return RFAILED;
7082    }
7083    ssbResource = cfra->resources.choice.ssb;
7084
7085    /* CFRA SSB resource list */
7086    elementCnt = ueCb->cfraResource.numSsb;
7087    ssbResource->ssb_ResourceList.list.count = elementCnt;
7088    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7089
7090    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7091    if(!ssbResource->ssb_ResourceList.list.array)
7092    {
7093       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7094       return RFAILED;
7095    }
7096
7097    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7098    {
7099       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7100       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7101       {
7102          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7103          return RFAILED;
7104       }
7105       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7106       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7107    }
7108
7109    return ROK;
7110 }
7111
7112 /*******************************************************************
7113  *
7114  * @brief Fills reconfiguration with sync in SP cell config
7115  *
7116  * @details
7117  *
7118  *    Function : BuildRecfgWithSync
7119  *
7120  *    Functionality: Fills reconfiguration with sync in SP cell config
7121  *
7122  * @params[in] DU UE CB
7123  *             Pointer to ReconfigurationWithSync_t
7124  *
7125  * @return ROK     - success
7126  *         RFAILED - failure
7127  *
7128  * ****************************************************************/
7129 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7130 {
7131    /* SP Cell Config Common */  
7132    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7133    if(!recfgWithSync->spCellConfigCommon)
7134    {
7135       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7136       return RFAILED;
7137    }
7138
7139    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7140    {
7141       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7142       return RFAILED;
7143    }
7144
7145    /* New UE Identity */
7146    recfgWithSync->newUE_Identity = ueCb->crnti;
7147
7148    /* T304 timer */
7149    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7150
7151    /* RACH configuration dedicated */
7152    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7153    if(!recfgWithSync->rach_ConfigDedicated)
7154    {
7155       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7156       return RFAILED;
7157    }
7158
7159    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7160    {
7161       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7162       return RFAILED;
7163    }
7164
7165    return ROK;
7166 }
7167
7168 /*******************************************************************
7169  *
7170  * @brief Builds Spcell config 
7171  *
7172  * @details
7173  *
7174  *    Function : BuildSpCellCfg 
7175  *
7176  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7177  *
7178  * @params[in] SpCellConfig_t spCellCfg
7179  *
7180  * @return ROK     - success
7181  *         RFAILED - failure
7182  *
7183  * ****************************************************************/
7184 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7185 {
7186    spCellCfg->servCellIndex = NULLP;
7187    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7188    if(!spCellCfg->servCellIndex)
7189    {
7190       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7191       return RFAILED;
7192    }
7193
7194    if(ueCb == NULLP)
7195       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7196    else
7197       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7198
7199    spCellCfg->reconfigurationWithSync = NULLP;
7200    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7201    {
7202       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7203       if(!spCellCfg->reconfigurationWithSync)
7204       {
7205          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7206          return RFAILED;
7207       }
7208
7209       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7210       {
7211          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7212          return RFAILED;
7213       }
7214    }
7215
7216    spCellCfg->rlf_TimersAndConstants = NULLP;
7217    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7218
7219    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7220    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7221    {
7222       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7223       return RFAILED;
7224    }
7225    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7226
7227    spCellCfg->spCellConfigDedicated = NULLP;
7228    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7229    if(!spCellCfg->spCellConfigDedicated)
7230    {
7231       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7232       return RFAILED;
7233    }
7234    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7235    {
7236       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7237       return RFAILED;
7238    }
7239
7240    return ROK;
7241 }
7242
7243 /*******************************************************************
7244  *
7245  * @brief Builds Phy cell group config 
7246  *
7247  * @details
7248  *
7249  *    Function : BuildPhyCellGrpCfg 
7250  *
7251  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7252  *
7253  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7254  *
7255  * @return ROK     - success
7256  *         RFAILED - failure
7257  *
7258  * ****************************************************************/
7259 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7260 {
7261    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7262    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7263
7264    phyCellGrpCfg->p_NR_FR1 = NULLP;
7265    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7266    if(!phyCellGrpCfg->p_NR_FR1)
7267    {
7268       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7269       return RFAILED;
7270    }
7271
7272    if(ueCb == NULLP)
7273    {
7274       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7275       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7276    }
7277    else
7278    {
7279       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7280       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7281    }
7282
7283    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7284    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7285    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7286    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7287    phyCellGrpCfg->cs_RNTI = NULLP;
7288    phyCellGrpCfg->ext1 = NULLP;
7289    phyCellGrpCfg->ext2 = NULLP;
7290
7291    return ROK;
7292 }
7293 #ifdef NR_DRX
7294 /*******************************************************************
7295  *
7296  * @brief fill long cycle offset value of drx
7297  *
7298  * @details
7299  *
7300  *    Function : fillLongCycleOffsetValFromDuCb 
7301  *
7302  *    Functionality: fill long cycle offset value of drx
7303  *
7304  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7305  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7306  *
7307  * @return ROK     - success
7308  *         RFAILED - failure
7309  *
7310  * ****************************************************************/
7311 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7312 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7313 {
7314    
7315    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7316    switch(drx_LongCycleStartOffset->present)
7317    {
7318       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7319          {
7320             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7321             break;
7322          }
7323       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7324          {
7325             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7326             break;
7327          }
7328       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7329          {
7330             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7331             break;
7332          }
7333       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7334          {
7335             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7336             break;
7337          }
7338       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7339          {
7340             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7341             break;
7342          }
7343       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7344          {
7345             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7346             break;
7347          }
7348       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7349          {
7350             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7351             break;
7352          }
7353       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7354          {
7355             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7356             break;
7357          }
7358       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7359          {
7360             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7361             break;
7362          }
7363       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7364          {
7365             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7366             break;
7367          }
7368       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7369          {
7370             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7371             break;
7372          }
7373       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7374          {
7375             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7376             break;
7377          }
7378       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7379          {
7380             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7381             break;
7382          }
7383       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7384          {
7385             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7386             break;
7387          }
7388       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7389          {
7390             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7391             break;
7392          }
7393       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7394          {
7395             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7396             break;
7397          }
7398       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7399          {
7400             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7401             break;
7402          }
7403       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7404          {
7405             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7406             break;
7407          }
7408       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7409          {
7410             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7411             break;
7412          }
7413       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7414          {
7415             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7416             break;
7417          }
7418       default :
7419          break;
7420    }
7421 }
7422 /*******************************************************************
7423  *
7424  * @brief Builds drx config IE 
7425  *
7426  * @details
7427  *
7428  *    Function : BuildDrxConfigRrc 
7429  *
7430  *    Functionality: Build drx config in MacCellGrpCfg 
7431  *
7432  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7433  *
7434  * @return ROK     - success
7435  *         RFAILED - failure
7436  *
7437  * ****************************************************************/
7438 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7439 {
7440    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7441    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7442    if(!drxCfg->choice.setup)
7443    {
7444       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7445       return RFAILED;
7446    }
7447    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7448    {
7449       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7450       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7451       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7452    }
7453    else
7454    {
7455       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7456       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7457       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7458    }
7459    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7460    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7461    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7462    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7463    drxRetransmissionTimerDl);
7464    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7465    drxRetransmissionTimerUl);
7466    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7467    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7468    
7469    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7470    {
7471       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7472       if(drxCfg->choice.setup->shortDRX)
7473       {
7474          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7475          shortDrx.drxShortCycle);
7476          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7477       }
7478       else
7479       {
7480          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7481          return RFAILED;
7482       }
7483    }
7484    return ROK;
7485 }
7486 #endif
7487 /*******************************************************************
7488  *
7489  * @brief Builds Mac cell group config 
7490  *
7491  * @details
7492  *
7493  *    Function : BuildMacCellGrpCfg 
7494  *
7495  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7496  *
7497  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7498  *
7499  * @return ROK     - success
7500  *         RFAILED - failure
7501  *
7502  * ****************************************************************/
7503 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7504 {
7505    macCellGrpCfg->drx_ConfigRrc = NULLP;
7506 #ifdef NR_DRX   
7507    if(ueCb)
7508    {
7509       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7510       if(!macCellGrpCfg->drx_ConfigRrc)
7511       {
7512          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7513          return RFAILED;
7514       }
7515       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7516       {
7517          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7518          return RFAILED;
7519       }
7520    }
7521 #endif
7522    macCellGrpCfg->schedulingRequestConfig = NULLP;
7523    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7524    if(!macCellGrpCfg->schedulingRequestConfig)
7525    {
7526       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7527       return RFAILED;
7528    }
7529
7530    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7531    {
7532       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7533       return RFAILED;
7534    }
7535
7536    macCellGrpCfg->bsr_Config = NULLP;
7537    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7538    if(!macCellGrpCfg->bsr_Config)
7539    {
7540       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7541       return RFAILED;
7542    }
7543
7544    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7545    {
7546       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7547       return RFAILED;
7548    }
7549
7550    macCellGrpCfg->tag_Config = NULLP;
7551    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7552    if(!macCellGrpCfg->tag_Config)
7553    {
7554       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7555       return RFAILED;
7556    }
7557
7558    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7559    {
7560       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7561       return RFAILED;
7562    }
7563
7564    macCellGrpCfg->phr_Config = NULLP;
7565    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7566    if(!macCellGrpCfg->phr_Config)
7567    {
7568       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7569       return RFAILED;
7570    }
7571
7572    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7573    {
7574       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7575       return RFAILED;
7576    }
7577
7578    macCellGrpCfg->skipUplinkTxDynamic = false;
7579    macCellGrpCfg->ext1 = NULLP;
7580
7581    return ROK;
7582 }
7583 /*******************************************************************
7584  *
7585  * @brief Frees memeory allocated for SearchSpcToAddModList
7586  *
7587  * @details
7588  *
7589  *    Function : FreeSearchSpcToAddModList
7590  *
7591  *    Functionality: Deallocating memory of SearchSpcToAddModList
7592  *
7593  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7594  *
7595  * @return void
7596  *
7597  4221 * ****************************************************************/
7598 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7599 {
7600    uint8_t idx1=0;
7601    uint8_t idx2=0;
7602    struct  SearchSpace *searchSpc=NULLP;
7603
7604    if(searchSpcList->list.array)
7605    {
7606       if(searchSpcList->list.array[idx2])
7607       {
7608          searchSpc = searchSpcList->list.array[idx2];
7609          if(searchSpc->controlResourceSetId)
7610          {
7611             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7612             {
7613                if(searchSpc->monitoringSymbolsWithinSlot)
7614                {
7615                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7616                   {
7617                      if(searchSpc->nrofCandidates)
7618                      {
7619                         if(searchSpc->searchSpaceType)
7620                         {
7621                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7622                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7623                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7624                                     SearchSpace__searchSpaceType));
7625                         }
7626                         DU_FREE(searchSpc->nrofCandidates,
7627                               sizeof(struct SearchSpace__nrofCandidates));
7628                      }
7629                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7630                            searchSpc->monitoringSymbolsWithinSlot->size);
7631                   }
7632                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7633                         sizeof(BIT_STRING_t));
7634                }
7635                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7636                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7637             }
7638             DU_FREE(searchSpc->controlResourceSetId,
7639                   sizeof(ControlResourceSetId_t));
7640          }
7641       }
7642       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7643       {
7644          DU_FREE(searchSpcList->list.array[idx1],
7645                sizeof(struct SearchSpace));
7646       }
7647       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7648    }
7649 }
7650 /*******************************************************************
7651  *
7652  * @brief Frees memory allocated for PdschTimeDomAllocList
7653  *
7654  * @details
7655  *
7656  *    Function : FreePdschTimeDomAllocList
7657  *
7658  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7659  *
7660  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7661  *
7662  * @return void
7663  *
7664  * ****************************************************************/
7665 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7666 {
7667    uint8_t idx1=0;
7668
7669    if(timeDomAllocList->choice.setup)
7670    {
7671       if(timeDomAllocList->choice.setup->list.array)
7672       {
7673          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7674          {
7675             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7676             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7677                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7678          }
7679          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7680                timeDomAllocList->choice.setup->list.size);
7681       }
7682       DU_FREE(timeDomAllocList->choice.setup,\
7683             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7684    }
7685 }
7686 /*******************************************************************
7687  *
7688  * @brief Frees memory allocated for PuschTimeDomAllocList
7689  *
7690  *@details
7691  *
7692  *    Function : FreePuschTimeDomAllocList
7693  *
7694  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7695  *
7696  * @params[in] PUSCH_Config_t *puschCfg
7697  *
7698  * @return void
7699  *
7700  * ****************************************************************/
7701 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7702 {
7703    uint8_t rsrcListIdx=0;
7704    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7705
7706    if(puschCfg->pusch_TimeDomainAllocationList)
7707    {
7708       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7709       if(timeDomAllocList_t->choice.setup)
7710       {
7711          if(timeDomAllocList_t->choice.setup->list.array)
7712          {
7713             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7714             {
7715                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7716                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7717                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7718             }
7719             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7720                   timeDomAllocList_t->choice.setup->list.size);
7721          }
7722          DU_FREE(timeDomAllocList_t->choice.setup, \
7723                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7724       }
7725       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7726       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7727             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7728    }
7729
7730 }
7731
7732 /*******************************************************************
7733  *
7734  * @brief Frees memory allocated for Dedicated PUCCH config
7735  *
7736  * @details
7737  *
7738  *    Function : FreeBWPUlDedPucchCfg
7739  *
7740  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7741  *
7742  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7743  *
7744  * @return void
7745  *
7746  * ****************************************************************/
7747 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7748 {
7749    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7750    PUCCH_Config_t *pucchCfg = NULLP;
7751    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7752    PUCCH_Resource_t *rsrc = NULLP;
7753
7754    if(ulBwpPucchCfg)
7755    {
7756       if(ulBwpPucchCfg->choice.setup)
7757       {
7758          pucchCfg = ulBwpPucchCfg->choice.setup;
7759
7760          //Free resource set list
7761          if(pucchCfg->resourceSetToAddModList)
7762          {
7763             if(pucchCfg->resourceSetToAddModList->list.array)
7764             {
7765                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7766                {
7767                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7768                   if(rsrcSet->resourceList.list.array)
7769                   {
7770                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7771                      {
7772                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7773                      }
7774                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7775                   }
7776                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7777                }
7778                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7779             }
7780             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7781          }
7782
7783          //Free resource list
7784          if(pucchCfg->resourceToAddModList)
7785          {
7786             if(pucchCfg->resourceToAddModList->list.array)
7787             {
7788                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7789                {
7790                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7791                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7792                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7793                }
7794                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7795             }
7796             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7797          }
7798
7799          //PUCCH Format 1
7800          if(pucchCfg->format1)
7801          {
7802             if(pucchCfg->format1->choice.setup)
7803             {
7804                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7805                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7806             }
7807             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7808          }
7809          
7810          //DL DATA TO UL ACK
7811          if(pucchCfg->dl_DataToUL_ACK)
7812          {
7813             if(pucchCfg->dl_DataToUL_ACK->list.array)
7814             {
7815                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7816                {
7817                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7818                }
7819                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7820             }
7821             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7822          }
7823
7824          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7825       }
7826       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7827    }
7828 }
7829
7830 /*******************************************************************
7831  *
7832  * @brief Frees memory allocated for InitialUlBWP
7833  *
7834  * @details
7835  *
7836  *    Function : FreeInitialUlBWP
7837  *
7838  *    Functionality: Deallocating memory of InitialUlBWP
7839  *
7840  * @params[in] BWP_UplinkDedicated_t *ulBwp
7841  *
7842  * @return void
7843  *
7844  * ****************************************************************/
7845 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7846 {
7847    uint8_t  rSetIdx, rsrcIdx;
7848    SRS_Config_t   *srsCfg = NULLP;
7849    PUSCH_Config_t *puschCfg = NULLP;
7850    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7851    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7852    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7853    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7854
7855    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7856
7857    if(ulBwp->pusch_Config)
7858    {
7859       if(ulBwp->pusch_Config->choice.setup)
7860       {
7861          puschCfg=ulBwp->pusch_Config->choice.setup;
7862          if(puschCfg->dataScramblingIdentityPUSCH)
7863          {
7864             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7865             {
7866                FreePuschTimeDomAllocList(puschCfg);
7867                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7868                if(dmrsUlCfg->choice.setup)
7869                {
7870                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7871                   {
7872                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7873                      {
7874                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7875                               sizeof(long));
7876                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7877                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7878                      }
7879                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7880                            sizeof(long));
7881                   }
7882                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7883                }
7884                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7885                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7886             }
7887             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7888          }
7889          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7890       }
7891       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7892
7893       /* Free SRS-Config */
7894       if(ulBwp->srs_Config)
7895       {
7896          if(ulBwp->srs_Config->choice.setup)
7897          {
7898             srsCfg = ulBwp->srs_Config->choice.setup;
7899
7900             /* Free Resource Set to add/mod list */
7901             if(srsCfg->srs_ResourceSetToAddModList)
7902             {
7903                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7904                if(rsrcSetList->list.array)
7905                {
7906                   rSetIdx = 0;
7907
7908                   /* Free SRS resource Id list in this SRS resource set */
7909                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7910                   {
7911                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7912
7913                      if(rsrcIdList->list.array)
7914                      {
7915                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7916                         {
7917                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7918                         }
7919                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7920                      }
7921                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7922                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7923                   }
7924
7925                   /* Free resource type info for this SRS resource set */
7926                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7927                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7928
7929                   /* Free memory for each resource set */
7930                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7931                   {
7932                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7933                   }
7934                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7935                }
7936                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7937                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7938             }
7939
7940             /* Free resource to add/modd list */
7941             if(srsCfg->srs_ResourceToAddModList)
7942             {
7943                resourceList = srsCfg->srs_ResourceToAddModList;
7944                if(resourceList->list.array)
7945                {
7946                   rsrcIdx = 0;
7947                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7948                         sizeof(struct SRS_Resource__transmissionComb__n2));
7949                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7950                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7951
7952                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7953                   {
7954                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7955                   }
7956                   DU_FREE(resourceList->list.array, resourceList->list.size);
7957                }
7958                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7959                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7960             }
7961
7962             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7963          }
7964          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7965       }
7966    }
7967 }       
7968 /*******************************************************************
7969  *
7970  * @brief Frees memory allocated for initialUplinkBWP
7971  *
7972  * @details
7973  *
7974  *    Function : FreeinitialUplinkBWP
7975  *
7976  *    Functionality: Deallocating memory of initialUplinkBWP
7977  *
7978  * @params[in] UplinkConfig_t *ulCfg
7979  *
7980  * @return void
7981  *         
7982  *
7983  * ****************************************************************/
7984 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7985 {
7986    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7987    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7988
7989    if(ulCfg->initialUplinkBWP)
7990    {
7991       ulBwp=ulCfg->initialUplinkBWP;
7992       if(ulCfg->firstActiveUplinkBWP_Id)
7993       {
7994          if(ulCfg->pusch_ServingCellConfig)
7995          {
7996             puschCfg=ulCfg->pusch_ServingCellConfig;
7997             if(puschCfg->choice.setup)
7998             {
7999                if(puschCfg->choice.setup->ext1)
8000                {
8001                   DU_FREE(puschCfg->choice.setup->ext1->\
8002                         processingType2Enabled,sizeof(BOOLEAN_t));
8003                   DU_FREE(puschCfg->choice.setup->ext1->\
8004                         maxMIMO_Layers,sizeof(long));
8005                   DU_FREE(puschCfg->choice.setup->ext1, \
8006                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8007                }
8008                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8009             }
8010             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8011          }
8012          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8013       }
8014       FreeInitialUlBWP(ulBwp);
8015       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8016    }
8017 }
8018 /*******************************************************************
8019  *
8020  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8021  *
8022  * @details
8023  *
8024  *    Function : FreeBWPDlDedPdschCfg
8025  *
8026  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8027  *
8028  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8029  *
8030  * @return void
8031  *
8032  *
8033  * ****************************************************************/
8034 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8035 {
8036    struct PDSCH_Config *pdschCfg=NULLP;
8037    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8038    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8039    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8040
8041    if(dlBwp->pdsch_Config->choice.setup)
8042    {
8043       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8044       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8045       {
8046          if(pdschCfg->pdsch_TimeDomainAllocationList)
8047          {
8048             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8049             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8050             {
8051                prbBndlType=&pdschCfg->prb_BundlingType;
8052                DU_FREE(prbBndlType->choice.staticBundling,\
8053                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8054                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8055             }
8056             FreePdschTimeDomAllocList(timeDomAllocList);
8057             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8058                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8059          }
8060          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8061          if(dmrsDlCfg->choice.setup)
8062          {
8063             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8064                   sizeof(long));
8065             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8066          }
8067          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8068                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8069       }
8070       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8071    }
8072 }
8073 /*******************************************************************
8074  *
8075  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8076  *
8077  * @details
8078  *
8079  *    Function : FreeBWPDlDedPdcchCfg
8080  *
8081  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8082  *
8083  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8084  *
8085  * @return void
8086  *         
8087  *
8088  * ****************************************************************/
8089 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8090 {
8091    uint8_t idx1=0;
8092    uint8_t idx2=0;
8093    struct PDCCH_Config *pdcchCfg=NULLP;
8094    struct ControlResourceSet *controlRSet=NULLP;
8095    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8096
8097    if(dlBwp->pdcch_Config->choice.setup)
8098    {
8099       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8100       if(pdcchCfg->controlResourceSetToAddModList)
8101       {
8102          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8103          if(controlRSetList->list.array)
8104          {
8105             controlRSet = controlRSetList->list.array[idx2];
8106             if(controlRSet)
8107             {
8108                if(controlRSet->frequencyDomainResources.buf)
8109                {
8110                   if(controlRSet->pdcch_DMRS_ScramblingID)
8111                   {
8112                      if(pdcchCfg->searchSpacesToAddModList)
8113                      {
8114                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8115                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8116                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8117                      }
8118                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8119                   }
8120                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8121                         controlRSet->frequencyDomainResources.size);
8122                }
8123             }
8124             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8125             {
8126                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8127             }
8128             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8129          }
8130          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8131                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8132       }
8133       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8134    }
8135 }       
8136
8137 /*******************************************************************
8138  *
8139  * @brief Free SCS specific carrier list in DL frequency info
8140  *
8141  * @details
8142  *
8143  *    Function : FreeScsSpecificCarrierListDl
8144  *
8145  *    Functionality: Free SCS specific carrier list in DL frequency info
8146  *
8147  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8148  *
8149  * @return void
8150  *
8151  * ****************************************************************/
8152 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8153 {
8154    uint8_t listIdx = 0;
8155
8156    if(!scsCarrierList->list.array)
8157    {
8158       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8159       {
8160          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8161       }
8162       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8163    }
8164 }
8165
8166 /*******************************************************************
8167  *
8168  * @brief Free DL frequency info in DL config common
8169  *
8170  * @details
8171  *
8172  *    Function : FreeFreqInfoDl
8173  *
8174  *    Functionality: Free DL frequency info in DL config common
8175  *
8176  * @params[in] Pointer to DownlinkConfigCommon_t
8177  *
8178  * @return void
8179  *
8180  * ****************************************************************/
8181 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8182 {
8183    uint8_t freqBandIdx = 0;
8184
8185    /* SSB Absolute Frequency */
8186    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8187
8188    /* NR Multi Frequency Band List */
8189    if(frequencyInfoDL->frequencyBandList.list.array)
8190    {
8191       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8192       {
8193          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8194       }
8195       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8196    }
8197
8198    /* Subcarrier Spacing specifc carrier List */
8199    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8200 }
8201
8202 /*******************************************************************
8203  *
8204  * @brief Free DL config common in Serving cell config common
8205  *
8206  * @details
8207  *
8208  *    Function : FreeDlConfigCommon
8209  *
8210  *    Functionality: Free DL config common in Serving cell config common
8211  *
8212  * @params[in] Pointer to DownlinkConfigCommon_t
8213  *
8214  * @return void
8215  *
8216  * ****************************************************************/
8217 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8218 {
8219    /* DL Frequency Info */
8220    if(dlCfgCommon->frequencyInfoDL)
8221    {
8222       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8223       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8224    }
8225
8226    /* DL BWP config common */
8227    if(dlCfgCommon->initialDownlinkBWP)
8228    {
8229       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8230       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8231    }
8232 }
8233
8234 /*******************************************************************
8235  *
8236  * @brief Free SCS specific carrier list in UL frequency Info
8237  *
8238  * @details
8239  *
8240  *    Function : FreeScsSpecificCarrierListUl
8241  *
8242  *    Functionality: Free SCS specific carrier list in UL frequency Info
8243  *
8244  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8245  *
8246  * @return void
8247  *
8248  * ****************************************************************/
8249 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8250 {
8251    uint8_t listIdx = 0;
8252
8253    if(scsCarrierList->list.array)
8254    {
8255       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8256       {
8257          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8258       }
8259       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8260    }
8261 }
8262
8263 /*******************************************************************
8264  *
8265  * @brief Free frequency info in UL config common
8266  *
8267  * @details
8268  *
8269  *    Function : FreeFreqInfoUl
8270  *
8271  *    Functionality: Free frequency info in UL config common
8272  *
8273  * @params[in] Pointer to FrequencyInfoUL_t
8274  *
8275  * @return void
8276  *
8277  * ****************************************************************/
8278 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8279 {
8280    uint8_t listIdx= 0;
8281
8282    /* NR Multi Frequency Band List */
8283    if(!frequencyInfoUL->frequencyBandList)
8284    {
8285       if(frequencyInfoUL->frequencyBandList->list.array)
8286       {
8287          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8288          {
8289             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8290          }
8291          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8292       }
8293       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8294    }
8295
8296    /* Absolute frequency point A */
8297    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8298
8299    /* Subcarrier Spacing specifc carrier */
8300    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8301
8302    /* P-MAX */
8303    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8304 }
8305
8306 /*******************************************************************
8307  *
8308  * @brief Free UL config common in Serving cell config common
8309  *
8310  * @details
8311  *
8312  *    Function : FreeUlConfigCommon
8313  *
8314  *    Functionality: Free UL config common in Serving cell config common
8315  *
8316  * @params[in] Pointer to UplinkConfigCommon_t
8317  *
8318  * @return void
8319  *
8320  * ****************************************************************/
8321 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8322 {
8323    /* UL Frequency Info */
8324    if(ulCfgCommon->frequencyInfoUL)
8325    {
8326       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8327       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8328    }
8329
8330    /* UL BWP common */
8331    if(ulCfgCommon->initialUplinkBWP)
8332    {
8333       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8334       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8335    }
8336 }
8337
8338 /*******************************************************************
8339  *
8340  * @brief Free SP cell config common in Reconfig with Sync
8341  *
8342  * @details
8343  *
8344  *    Function : FreeSpCellConfigCommon
8345  *
8346  *    Functionality: Free SP cell config common in Reconfig with Sync
8347  *
8348  * @params[in] Pointer to ServingCellConfigCommon_t
8349  *
8350  * @return void
8351  *
8352  * ****************************************************************/
8353 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8354 {
8355    /* Free Physical cell identity */
8356    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8357
8358    /* Free Downlink Config common */
8359    if(spCellConfigCommon->downlinkConfigCommon)
8360    {
8361       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8362       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8363    }
8364
8365    /* Free Uplink Config common */
8366    if(spCellConfigCommon->uplinkConfigCommon)
8367    {
8368       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8369       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8370    }
8371
8372    /* Free Timing Advance offset */
8373    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8374
8375    /* Free SSB Position in Burst */
8376    if(spCellConfigCommon->ssb_PositionsInBurst)
8377    {
8378       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8379          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8380       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8381    }
8382
8383    /* Free SSB Periodicity in Serving cell */
8384    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8385
8386    /* Free SSB subcarrier spacing */
8387    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8388
8389    /* TDD UL-DL configuration common */
8390    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8391 }
8392
8393 /*******************************************************************
8394  *
8395  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8396  *
8397  * @details
8398  *
8399  *    Function : FreeRecfgWithSync
8400  *
8401  *    Functionality:
8402  *       Free dedicated RACH configuration in Reconfiguration with sync
8403  *
8404  * @params[in] Pinter to Rach config dedicated struct
8405  *
8406  * @return void
8407  *
8408  * ****************************************************************/
8409 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8410 {
8411    uint8_t listIdx = 0;
8412    CFRA_t *cfra = NULLP;
8413    struct CFRA__resources__ssb *ssbResource = NULLP;
8414
8415    /* Uplink */
8416    if(rachCfgDed->choice.uplink)
8417    {
8418       /* CFRA : Contention free Random Access */
8419       if(rachCfgDed->choice.uplink->cfra)
8420       {
8421          cfra = rachCfgDed->choice.uplink->cfra;
8422
8423          /* CFRA occassions */
8424          if(cfra->occasions)
8425          {
8426             /* CFRA occassions : SSB per RACH occasion */
8427             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8428             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8429          }
8430
8431          /* CFRA resource */
8432          cfra->resources.present = CFRA__resources_PR_ssb;
8433
8434          /* CFRA resource : SSB */
8435          if(cfra->resources.choice.ssb)
8436          {
8437             ssbResource = cfra->resources.choice.ssb;
8438
8439             /* CFRA SSB resource list */
8440             if(ssbResource->ssb_ResourceList.list.array)
8441             {
8442                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8443                {
8444                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8445                }
8446                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8447             }
8448             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8449          }
8450          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8451       }
8452       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8453    }
8454 }
8455
8456 /*******************************************************************
8457  *
8458  * @brief Frees reconfiguration with sync in SP cell config
8459  *
8460  * @details
8461  *
8462  *    Function : FreeRecfgWithSync
8463  *
8464  *    Functionality: Fress reconfiguration with sync in SP cell config
8465  *
8466  * @params[in] Pointer to ReconfigurationWithSync_t
8467  *
8468  * @return void
8469  *
8470  * ****************************************************************/
8471 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8472 {
8473    /* Free SP Cell config common */
8474    if(recfgWithSync->spCellConfigCommon)
8475    {
8476       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8477       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8478    }
8479
8480    /* Free Dedicated RACH configuration */
8481    if(recfgWithSync->rach_ConfigDedicated)
8482    {
8483       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8484       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8485    }
8486 }
8487
8488 /*******************************************************************
8489  *
8490  * @brief Frees emmory allocated for DUToCURRCContainer 
8491  *
8492  * @details
8493  *
8494  *    Function : FreeMemDuToCuRrcCont
8495  *
8496  *    Functionality: Deallocating memory of DuToCuRrcContainer
8497  *
8498  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8499  *
8500  * @return ROK     - success
8501  *         RFAILED - failure
8502  *
8503  * ****************************************************************/
8504 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8505 {
8506    uint8_t idx=0;
8507    SpCellConfig_t *spCellCfg=NULLP;
8508    ServingCellConfig_t *srvCellCfg=NULLP;
8509    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8510    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8511    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8512    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8513    struct RLC_Config *rlcConfig=NULLP;
8514    struct LogicalChannelConfig *macLcConfig=NULLP;
8515    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8516    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8517    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8518    struct TAG_Config *tagConfig=NULLP;
8519    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8520    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8521    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8522
8523    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8524    if(rlcBearerList)
8525    {
8526       if(rlcBearerList->list.array)
8527       {
8528          for(idx=0; idx<rlcBearerList->list.count; idx++)
8529          {
8530             if(rlcBearerList->list.array[idx])
8531             {  
8532                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8533                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8534                if(rlcConfig)
8535                {
8536                   switch(rlcConfig->present)
8537                   {
8538                      case RLC_Config_PR_NOTHING:
8539                         break;
8540
8541                      case RLC_Config_PR_am:
8542                         {
8543                            if(rlcConfig->choice.am)
8544                            {
8545                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8546                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8547                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8548                            }
8549                            break;
8550                         }
8551                      case RLC_Config_PR_um_Bi_Directional:
8552                         {
8553                            if(rlcConfig->choice.um_Bi_Directional)
8554                            {
8555                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8556                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8557                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8558                            }
8559                            break;
8560                         }
8561                      case RLC_Config_PR_um_Uni_Directional_UL:
8562                         {
8563                            if(rlcConfig->choice.um_Uni_Directional_UL)
8564                            {
8565                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8566                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8567                            }
8568                            break;
8569                         }
8570                      case RLC_Config_PR_um_Uni_Directional_DL:
8571                         {
8572                            if(rlcConfig->choice.um_Uni_Directional_DL )
8573                            {
8574                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8575                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8576                            }
8577                            break;
8578                         }
8579                   }     
8580                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8581                }
8582                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8583                if(macLcConfig)
8584                {
8585                   if(macLcConfig->ul_SpecificParameters)
8586                   {
8587                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8588                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8589                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8590                   }
8591                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8592                }
8593                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8594             }   
8595          }
8596          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8597       }
8598       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8599    }
8600
8601    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8602    if(macCellGrpCfg)
8603    {
8604       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8605
8606       if(drxCfg)
8607       {
8608           switch(drxCfg->present)
8609           {
8610             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8611                break;
8612             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8613             {
8614                if(drxCfg->choice.setup)
8615                {
8616                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8617                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8618                }
8619             }
8620             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8621                break;
8622           }
8623           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8624       }
8625       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8626       if(schedulingRequestConfig)
8627       {
8628          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8629          if(schReqList)
8630          {
8631             if(schReqList->list.array)
8632             {
8633                for(idx=0;idx<schReqList->list.count; idx++)
8634                {
8635                   if(schReqList->list.array[idx])
8636                   {
8637                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8638                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8639                   }
8640                }
8641                DU_FREE(schReqList->list.array, schReqList->list.size);
8642             }
8643             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8644                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8645             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8646       }
8647       if(macCellGrpCfg->bsr_Config)
8648       {
8649          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8650          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8651       }
8652       tagConfig = macCellGrpCfg->tag_Config;
8653       if(tagConfig)
8654       {
8655          tagList = tagConfig->tag_ToAddModList;
8656          if(tagList)
8657          {
8658             if(tagList->list.array)
8659             {
8660                for(idx=0; idx<tagList->list.count; idx++)
8661                {
8662                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8663                }
8664                DU_FREE(tagList->list.array, tagList->list.size);
8665             }
8666             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8667          }
8668          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8669       }
8670
8671       phrConfig = macCellGrpCfg->phr_Config;
8672       if(phrConfig)
8673       {
8674          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8675          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8676       }
8677
8678       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8679    }
8680
8681    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8682    if(phyCellGrpCfg)
8683    {
8684       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8685       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8686    }
8687
8688    spCellCfg = cellGrpCfg->spCellConfig;
8689    if(spCellCfg)
8690    {
8691       /* Free serving cell index */
8692       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8693
8694       /* Free Reconfiguration with sync */
8695       if(spCellCfg->reconfigurationWithSync)
8696       {
8697          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8698          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8699       }
8700
8701       /* Free rlmInSyncOutOfSyncThreshold */
8702       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8703
8704       /* Free SP Cell config dedicated */
8705       if(spCellCfg->spCellConfigDedicated)
8706       {
8707          srvCellCfg = spCellCfg->spCellConfigDedicated;
8708
8709          /* Free TDD UL-DL config dedicated */
8710          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8711
8712          /* Free Initial Downlink BWP */
8713          if(srvCellCfg->initialDownlinkBWP)
8714          {
8715             dlBwp = srvCellCfg->initialDownlinkBWP;
8716
8717             /* Free DL BWP PDCCH Config */
8718             if(dlBwp->pdcch_Config)
8719             {
8720                FreeBWPDlDedPdcchCfg(dlBwp);
8721                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8722             }
8723
8724             /* Free DL BWP PDSCH config */
8725             if(dlBwp->pdsch_Config)
8726             {
8727                FreeBWPDlDedPdschCfg(dlBwp);
8728                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8729             }
8730             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8731          }
8732
8733          /* Free First Active Downlink BWP */
8734          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8735
8736          /* Free Default downlink BWP */
8737          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8738
8739          /* Free Uplink config */
8740          if(srvCellCfg->uplinkConfig)
8741          {
8742             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8743             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8744          }
8745
8746          /* Free PDSCH serving cell config */
8747          if(srvCellCfg->pdsch_ServingCellConfig)
8748          {
8749             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8750             if(pdschCfg->choice.setup)
8751             {
8752                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8753                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8754             }
8755             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8756          }
8757
8758          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8759       }
8760       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8761    }
8762    return ROK;
8763 }
8764
8765 /*******************************************************************
8766  *
8767  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8768  *
8769  * @details
8770  *
8771  *    Function : BuildCellGroupConfigRrc
8772  *
8773  *    Functionality: Builds and copied Cell group config buffer into 
8774  *       DuToCuRrcContainer
8775  *
8776  * @params[in] idx, index in F1AP msg
8777  *             DuToCuRRCContainer, DuToCuRRCContainer
8778  *
8779  * @return ROK     - success
8780  *         RFAILED - failure
8781  *
8782  * ****************************************************************/
8783 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8784 {
8785    uint8_t  ret = ROK;
8786    CellGroupConfigRrc_t  cellGrpCfg;
8787    asn_enc_rval_t        encRetVal;
8788    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8789    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8790
8791    while(true)
8792    {
8793       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8794
8795       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8796       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8797       if(!cellGrpCfg.rlc_BearerToAddModList)
8798       {
8799          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8800          ret = RFAILED;
8801          break;
8802       }
8803       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8804       {
8805          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8806          ret = RFAILED;
8807          break;
8808       }
8809
8810       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8811       cellGrpCfg.mac_CellGroupConfig = NULLP;
8812       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8813       if(!cellGrpCfg.mac_CellGroupConfig)
8814       {
8815          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8816          ret = RFAILED;
8817          break;
8818       }
8819       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8820       {
8821          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8822          ret = RFAILED;
8823          break;
8824       }
8825
8826       cellGrpCfg.physicalCellGroupConfig = NULLP;
8827       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8828       if(!cellGrpCfg.physicalCellGroupConfig)
8829       {
8830          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8831          ret = RFAILED;
8832          break;
8833       }
8834       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8835       {
8836          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8837          ret = RFAILED;
8838          break;
8839       }
8840
8841       cellGrpCfg.spCellConfig = NULLP;
8842       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8843       if(!cellGrpCfg.spCellConfig)
8844       {
8845          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8846          ret = RFAILED;
8847          break;
8848       }
8849       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8850       {
8851          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8852          ret = RFAILED;
8853          break;
8854       }
8855
8856       cellGrpCfg.sCellToAddModList = NULLP;
8857       cellGrpCfg.sCellToReleaseList = NULLP;
8858       cellGrpCfg.ext1 = NULLP;
8859
8860       /* encode cellGrpCfg into duToCuRrcContainer */
8861       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8862       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8863       encBufSize = 0;
8864       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8865       /* Encode results */
8866       if(encRetVal.encoded == ENCODE_FAIL)
8867       {
8868          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8869                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8870          ret = RFAILED;
8871          break;
8872       }
8873       else
8874       {
8875          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8876 #ifdef DEBUG_ASN_PRINT
8877          for(int i=0; i< encBufSize; i++)
8878          {
8879             printf("%x",encBuf[i]);
8880          }
8881 #endif
8882       }
8883
8884       duToCuRrcContainer->size = encBufSize;
8885       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8886       if(!duToCuRrcContainer->buf)
8887       {
8888          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8889          ret = RFAILED;
8890          break;
8891       }
8892       if(ret == ROK)
8893       {
8894          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8895       }
8896       break;
8897    }
8898    FreeMemDuToCuRrcCont(&cellGrpCfg);
8899    return ret;
8900 }
8901
8902 /*******************************************************************
8903  *
8904  * @brief Free memory allocated in InitialULRRCMessage
8905  *
8906  * @details
8907  *
8908  *    Function : freeInitUlRrcMsgTransfer
8909  *
8910  *    Functionality: Free memory allocated in InitialULRRCMessage
8911  *
8912  * @params[in]F1AP_PDU_t  *f1apMsg)
8913  *
8914  * @return ROK     - success
8915  *         RFAILED - failure
8916  *
8917  * ****************************************************************/
8918
8919 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8920 {
8921    uint8_t ieIdx, arrIdx;
8922    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8923
8924    if(f1apMsg)
8925    {
8926       if(f1apMsg->choice.initiatingMessage)
8927       {
8928          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8929             choice.InitialULRRCMessageTransfer;
8930          if(initULRRCMsg->protocolIEs.list.array)
8931          {
8932             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8933             {
8934                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8935                {
8936                   case ProtocolIE_ID_id_NRCGI:
8937                   {
8938                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8939                      {
8940                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8941                         {
8942                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8943                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8944                         }
8945                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8946                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8947                      }
8948                      break;
8949                   }
8950                   case ProtocolIE_ID_id_RRCContainer:
8951                   {
8952                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8953                      {
8954                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8955                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8956                      }
8957                      break;
8958                   }
8959                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8960                   {
8961                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8962                      {
8963                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8964                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8965                      }
8966                      break;
8967                   }
8968                   default:
8969                      break;
8970                }
8971              }
8972              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8973              {
8974                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8975                 {
8976                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8977                       sizeof(InitialULRRCMessageTransferIEs_t));
8978                 }
8979              }
8980              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8981           }
8982          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8983       }
8984       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8985    }
8986    else
8987    {
8988       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8989       return RFAILED;
8990    }
8991    return ROK;
8992 }
8993
8994 /*******************************************************************
8995  *
8996  * @brief Builds and sends the InitialULRRCMessage 
8997  *
8998  * @details
8999  *
9000  *    Function : BuildAndSendInitialRrcMsgTransfer 
9001  *
9002  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9003  *                   it to the CU through SCTP.
9004  *
9005  * @params[in] 
9006  *
9007  * @return ROK     - success
9008  *         RFAILED - failure
9009  *
9010  * ****************************************************************/
9011 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9012       uint16_t rrcContSize, uint8_t *rrcContainer)
9013 {
9014    uint8_t   ret;
9015    uint8_t   elementCnt;
9016    uint8_t   ieIdx, cellIdx, ueIdx;
9017    DuUeCb    *duUeCb = NULLP;
9018    asn_enc_rval_t  encRetVal;
9019    F1AP_PDU_t  *f1apMsg = NULLP;
9020    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9021    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9022
9023    while(true)
9024    {
9025       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9026       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9027       if(f1apMsg == NULLP)
9028       {
9029          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9030          break;
9031       }
9032       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9033       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9034       if(f1apMsg->choice.initiatingMessage == NULLP)
9035       {
9036          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9037          break;
9038       }
9039       f1apMsg->choice.initiatingMessage->procedureCode =\
9040                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9041       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9042       f1apMsg->choice.initiatingMessage->value.present = \
9043                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9044       initULRRCMsg =\
9045                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9046       elementCnt = 5;
9047       initULRRCMsg->protocolIEs.list.count = elementCnt;
9048       initULRRCMsg->protocolIEs.list.size = \
9049                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9050       /* Initialize the F1Setup members */
9051       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9052       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9053       {
9054          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9055                RRCSetupRequestMessageTransferIEs failed");
9056          break;
9057       }
9058       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9059       {
9060          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9061                sizeof(InitialULRRCMessageTransferIEs_t));
9062          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9063          {
9064             break;
9065          }
9066       }
9067       ieIdx = 0;
9068       /*GNB DU UE F1AP ID*/
9069       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9070                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9071       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9072       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9073                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9074       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9075
9076
9077       /*NRCGI*/
9078       ieIdx++;
9079       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9080                                                         ProtocolIE_ID_id_NRCGI;
9081       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9082       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9083                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9084
9085       ret =\
9086            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9087       if(ret!=ROK)
9088       {
9089          break;
9090       }
9091
9092       /*CRNTI*/
9093       ieIdx++;
9094       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9095                                                         ProtocolIE_ID_id_C_RNTI;
9096       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9097       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9098                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9099       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9100
9101       /*RRCContainer*/
9102       ieIdx++;
9103       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9104                                                         ProtocolIE_ID_id_RRCContainer;
9105       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9106       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9107                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9108
9109       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9110       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9111             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9112       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9113       {
9114          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9115          break;
9116       
9117       }
9118       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9119             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9120
9121
9122       /*DUtoCURRCContainer*/
9123       ieIdx++;
9124       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9125       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9126       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9127                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9128
9129       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9130       {
9131          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9132          {
9133             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9134                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9135             {
9136                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9137             }
9138          }
9139       }
9140
9141       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9142       if(ret != ROK)
9143       {
9144          break;
9145       }
9146
9147       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9148
9149       /* Encode the Intial UL RRC Message transfer as APER */
9150       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9151       encBufSize = 0;
9152       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9153       /* Encode results */
9154       if(encRetVal.encoded == ENCODE_FAIL)
9155       {
9156          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9157                structure (at %s)\n",encRetVal.failed_type ? \
9158                encRetVal.failed_type->name : "unknown");
9159          ret = RFAILED;
9160          break;
9161       }
9162       else
9163       {
9164
9165          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9166                Message transfer\n");
9167 #ifdef DEBUG_ASN_PRINT
9168          for(int i=0; i< encBufSize; i++)
9169          {
9170             printf("%x",encBuf[i]);
9171          }
9172 #endif
9173       }
9174       /* Sending  msg  */
9175       if(sendF1APMsg() != ROK)
9176       {
9177          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9178          ret = RFAILED;
9179          break;
9180       }
9181       break;
9182    }
9183    freeInitUlRrcMsgTransfer(f1apMsg);
9184    return ret;
9185 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9186
9187 /*****  UE SETUP REQUEST *****/
9188
9189 /******************************************************************
9190 *
9191 * @brief Function to delete the RLC Lc cfg from UE APP DB
9192 *
9193 * @details
9194 *
9195 *  Function : freeRlcLcCfg
9196 *
9197 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9198 *
9199 *
9200  *****************************************************************/
9201
9202 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9203 {
9204    switch(lcCfg->rlcMode)
9205    {
9206       case RLC_AM :
9207          {
9208             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9209             break;
9210          }
9211       case RLC_UM_BI_DIRECTIONAL :
9212          {
9213             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9214             break;
9215          }
9216       case RLC_UM_UNI_DIRECTIONAL_UL :
9217          {
9218             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9219             break;
9220          }
9221       case RLC_UM_UNI_DIRECTIONAL_DL :
9222          {
9223             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9224             break;
9225          }
9226       default:
9227          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9228          break;
9229    }
9230    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9231 }
9232
9233 /*******************************************************************
9234  *
9235  * @brief Function to free MacLcCfg
9236  *
9237  * @details
9238  *
9239  *    Function : freeMacLcCfg
9240  *
9241  *    Functionality: Function to free MacLcCfg
9242  *
9243  * @params[in] LcCfg *lcCfg,
9244  * @return void
9245  *
9246  * ****************************************************************/
9247
9248 void freeMacLcCfg(LcCfg *lcCfg)
9249 {
9250     /* Deleting DRBQOS */
9251    if(lcCfg->drbQos)
9252    {
9253       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9254    }
9255    /* Deleting SNSSAI */
9256    if(lcCfg->snssai)
9257    {
9258       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9259    }
9260 }
9261 /*******************************************************************
9262  *
9263  * @brief Free UE NR Capability received in UE Context setup request
9264  *
9265  * @details
9266  *
9267  *    Function : freeAperDecodeUeNrCapability
9268  *
9269  *    Functionality:  
9270  *       Free UE NR Capability received in UE Context setup request
9271  *
9272  * @params[in] 
9273  * @return ROK     - success
9274  *         RFAILED - failure
9275  *
9276  * ****************************************************************/
9277 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9278 {
9279    uint8_t arrIdx =0;
9280    FeatureSets_t *featureSets =NULLP;
9281    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9282
9283    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9284    {
9285       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9286       {
9287          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9288             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9289       }
9290       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9291    }
9292
9293    if(ueNrCap->featureSets)
9294    {
9295       featureSets = ueNrCap->featureSets;
9296       if(featureSets->featureSetsDownlinkPerCC)
9297       {
9298          if(featureSets->featureSetsDownlinkPerCC->list.array)
9299          {
9300             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9301             {
9302                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9303                {
9304                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9305                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9306                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9307                }
9308             }
9309             free(featureSets->featureSetsDownlinkPerCC->list.array);
9310          }
9311          free(featureSets->featureSetsDownlinkPerCC);
9312       }
9313       if(featureSets->featureSetsUplinkPerCC)
9314       {
9315          if(featureSets->featureSetsUplinkPerCC->list.array)
9316          {
9317             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9318             {
9319                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9320                {
9321                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9322                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9323                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9324                }
9325             }
9326             free(featureSets->featureSetsUplinkPerCC->list.array);
9327          }
9328          free(featureSets->featureSetsUplinkPerCC);
9329       }
9330       free(ueNrCap->featureSets);
9331    }   
9332 }
9333
9334 /*******************************************************************
9335 *
9336 * @brief Function to free PdcchSearchSpcToAddModList
9337          where memory allocated by aper_decoder
9338 *
9339 * @details
9340 *
9341 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9342 *
9343 *    Functionality: Function to free PdcchSearchSpcToAddModList
9344 *
9345 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9346 * @return void
9347 *
9348 * ****************************************************************/
9349
9350 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9351 {
9352    uint8_t searchSpcArrIdx=0;
9353    uint8_t searchSpcArrIdx1=0;
9354    struct  SearchSpace *searchSpc=NULLP;
9355
9356
9357    if(searchSpcList->list.array)
9358    {
9359       if(searchSpcList->list.array[searchSpcArrIdx1])
9360       {
9361          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9362          if(searchSpc->controlResourceSetId)
9363          {
9364             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9365             {
9366                if(searchSpc->monitoringSymbolsWithinSlot)
9367                {
9368                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9369                   {
9370                      if(searchSpc->nrofCandidates)
9371                      {
9372                         if(searchSpc->searchSpaceType)
9373                         {
9374                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9375                            free(searchSpc->searchSpaceType);
9376                         }
9377                         free(searchSpc->nrofCandidates);
9378                      }
9379                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9380                   }
9381                   free(searchSpc->monitoringSymbolsWithinSlot);
9382                }
9383                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9384             }
9385             free(searchSpc->controlResourceSetId);
9386          }
9387       }
9388       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9389       {
9390          free(searchSpcList->list.array[searchSpcArrIdx]);
9391       }
9392       free(searchSpcList->list.array);
9393    }
9394 }
9395 /*******************************************************************
9396 *
9397 * @brief Function for free part for the memory allocated by aper_decoder
9398
9399 * @details
9400 *
9401 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9402 *
9403 *    Functionality: Function to free BWPDlDedPdcchConfig
9404 *
9405 * @params[in] 
9406 * @return void
9407 *
9408 * ****************************************************************/
9409
9410
9411 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9412 {
9413    uint8_t arrIdx1=0;
9414    uint8_t arrIdx2=0;
9415    struct PDCCH_Config *pdcchCfg=NULLP;
9416    struct ControlResourceSet *controlRSet=NULLP;
9417    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9418    
9419    if(dlBwp->pdcch_Config->choice.setup)
9420    {
9421       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9422       if(pdcchCfg->controlResourceSetToAddModList)
9423       {
9424          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9425          if(controlRSetList->list.array)
9426          {
9427             controlRSet = controlRSetList->list.array[arrIdx2];
9428             if(controlRSet)
9429             {
9430                if(controlRSet->frequencyDomainResources.buf)
9431                {
9432                   if(controlRSet->pdcch_DMRS_ScramblingID)
9433                   {
9434                      if(pdcchCfg->searchSpacesToAddModList)
9435                      {
9436                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9437                         free(pdcchCfg->searchSpacesToAddModList);
9438                      }
9439                      free(controlRSet->pdcch_DMRS_ScramblingID);
9440                   }
9441                   free(controlRSet->frequencyDomainResources.buf);
9442                }
9443             }
9444             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9445             {
9446                free(controlRSetList->list.array[arrIdx1]);
9447             }
9448             free(controlRSetList->list.array);
9449          }
9450          free(pdcchCfg->controlResourceSetToAddModList);
9451       }
9452       free(dlBwp->pdcch_Config->choice.setup);
9453    }
9454 }
9455 /*******************************************************************
9456 *
9457 * @brief Function to free PdschTimeDomAllocationList 
9458 *     where the memory allocated by aper_decoder
9459
9460 * @details
9461 *
9462 *    Function : freeAperDecodePdschTimeDomAllocationList
9463 *
9464 *    Functionality: Function to free PdschTimeDomAllocationList
9465 *
9466 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9467 * @return void
9468 *
9469 * ****************************************************************/
9470
9471
9472 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9473 {
9474    uint8_t arrIdx=0;
9475
9476    if(timeDomAllocList->choice.setup)
9477    {
9478       if(timeDomAllocList->choice.setup->list.array)
9479       {
9480          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9481          {
9482             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9483          }
9484          free(timeDomAllocList->choice.setup->list.array);
9485       }
9486       free(timeDomAllocList->choice.setup);
9487    }
9488 }
9489
9490 /*******************************************************************
9491 *
9492 * @brief Function to free BWPDlDedPdschConfig 
9493 *        where the memory allocated by aper_decoder
9494 *  
9495 * @details
9496 *
9497 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9498 *
9499 *    Functionality: Function to free BWPDlDedPdschConfig 
9500 *
9501 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9502 * @return void
9503 *
9504 * ****************************************************************/
9505
9506
9507 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9508 {
9509    struct PDSCH_Config *pdschCfg=NULLP;
9510    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9511    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9512    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9513
9514    if(dlBwp->pdsch_Config->choice.setup)
9515    {
9516       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9517       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9518       {
9519          if(pdschCfg->pdsch_TimeDomainAllocationList)
9520          {
9521             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9522             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9523             {
9524                prbBndlType=&pdschCfg->prb_BundlingType;
9525                free(prbBndlType->choice.staticBundling);
9526                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9527             }
9528             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9529             free(pdschCfg->pdsch_TimeDomainAllocationList);
9530          }
9531          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9532          if(dmrsDlCfg->choice.setup)
9533          {
9534             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9535             free(dmrsDlCfg->choice.setup);
9536          }
9537          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9538       }
9539       free(dlBwp->pdsch_Config->choice.setup);
9540    }
9541 }
9542 /*******************************************************************
9543 *
9544 * @brief Function to free PuschTimeDomAllocListCfg
9545                  where the memory allocated by aper_decoder
9546 *
9547 * @details
9548 *
9549 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9550 *
9551 *    Functionality: Function to free PuschTimeDomAllocListCfg
9552 *
9553 * @params[in] PUSCH_Config_t *puschCfg 
9554 * @return void
9555 *
9556 * ****************************************************************/
9557
9558
9559 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9560 {
9561    uint8_t arrIdx=0;
9562    uint8_t arrIdx1=0;
9563    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9564
9565    if(puschCfg->pusch_TimeDomainAllocationList)
9566    {
9567       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9568       if(timeDomAllocList_t->choice.setup)
9569       {
9570          if(timeDomAllocList_t->choice.setup->list.array)
9571          {
9572             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9573             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9574             {
9575                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9576             }
9577             free(timeDomAllocList_t->choice.setup->list.array);
9578          }
9579          free(timeDomAllocList_t->choice.setup);
9580       }
9581       free(puschCfg->transformPrecoder);
9582       free(puschCfg->pusch_TimeDomainAllocationList);
9583    }
9584 }
9585 /*******************************************************************
9586 *
9587 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9588 *
9589 * @details
9590 *
9591 *    Function : freeAperDecodeInitialUlBWPConfig 
9592 *
9593 *    Functionality: Function to free InitialUlBWPConfig
9594 *
9595 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9596 * @return void
9597 *
9598 * ****************************************************************/
9599
9600
9601 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9602 {
9603    uint8_t  rSetIdx =0;
9604    uint8_t  rsrcIdx =0;
9605    SRS_Config_t   *srsCfg = NULLP;
9606    PUSCH_Config_t *puschCfg = NULLP;
9607    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9608    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9609    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9610    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9611
9612    if(ulBwp->pusch_Config)
9613    {
9614       if(ulBwp->pusch_Config->choice.setup)
9615       {
9616          puschCfg=ulBwp->pusch_Config->choice.setup;
9617          if(puschCfg->dataScramblingIdentityPUSCH)
9618          {
9619             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9620             {
9621                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9622                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9623                if(dmrsUlCfg->choice.setup)
9624                {
9625                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9626                   {
9627                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9628                      {
9629                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9630                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9631                      }
9632                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9633                   }
9634                   free(dmrsUlCfg->choice.setup);
9635                }
9636                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9637             }
9638             free(puschCfg->dataScramblingIdentityPUSCH);
9639          }
9640          free(ulBwp->pusch_Config->choice.setup);
9641       }
9642       free(ulBwp->pusch_Config);
9643
9644       /* Free SRS-Config */
9645       if(ulBwp->srs_Config)
9646       {
9647          if(ulBwp->srs_Config->choice.setup)
9648          {
9649             srsCfg = ulBwp->srs_Config->choice.setup;
9650
9651             /* Free Resource Set to add/mod list */
9652             if(srsCfg->srs_ResourceSetToAddModList)
9653             {
9654                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9655                if(rsrcSetList->list.array)
9656                {
9657                   rSetIdx = 0;
9658
9659                   /* Free SRS resource Id list in this SRS resource set */
9660                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9661                   {
9662                      rsrcIdList =
9663                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9664
9665                      if(rsrcIdList->list.array)
9666                      {
9667                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9668                               rsrcIdx++)
9669                         {
9670                            free(rsrcIdList->list.array[rsrcIdx]);
9671                         }
9672                         free(rsrcIdList->list.array);
9673                      }
9674                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9675                   }
9676
9677                   /* Free resource type info for this SRS resource set */
9678
9679                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9680
9681                   /* Free memory for each resource set */
9682                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9683                   {
9684                      free(rsrcSetList->list.array[rSetIdx]);
9685                   }
9686                   free(rsrcSetList->list.array);
9687                }
9688                free(srsCfg->srs_ResourceSetToAddModList);
9689             }
9690
9691             /* Free resource to add/modd list */
9692             if(srsCfg->srs_ResourceToAddModList)
9693             {
9694                resourceList = srsCfg->srs_ResourceToAddModList;
9695                if(resourceList->list.array)
9696                {
9697                   rsrcIdx = 0;
9698
9699                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9700                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9701
9702                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9703                   {
9704                      free(resourceList->list.array[rsrcIdx]);
9705                   }
9706                   free(resourceList->list.array);
9707                }
9708                free(srsCfg->srs_ResourceToAddModList);
9709             }
9710
9711             free(ulBwp->srs_Config->choice.setup);
9712          }
9713          free(ulBwp->srs_Config);
9714       }
9715    }
9716 }
9717 /*******************************************************************
9718 *
9719 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9720 *
9721 * @details
9722 *
9723 *    Function : freeAperDecodeinitialUplinkBWPConfig
9724 *
9725 *    Functionality: Function to free initialUplinkBWPConfig
9726 *
9727 * @params[in] UplinkConfig_t *ulCfg 
9728 * @return void
9729 *
9730 * ****************************************************************/
9731
9732
9733 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9734 {
9735    BWP_UplinkDedicated_t *ulBwp=NULLP;
9736    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9737    
9738    if(ulCfg->initialUplinkBWP)
9739    {
9740       ulBwp=ulCfg->initialUplinkBWP;
9741       if(ulCfg->firstActiveUplinkBWP_Id)
9742       {
9743          if(ulCfg->pusch_ServingCellConfig)
9744          {
9745             puschCfg=ulCfg->pusch_ServingCellConfig;
9746             if(puschCfg->choice.setup)
9747             {
9748                if(puschCfg->choice.setup->ext1)
9749                {
9750                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9751                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9752                   free(puschCfg->choice.setup->ext1);
9753                }
9754                free(puschCfg->choice.setup);
9755             }
9756             free(ulCfg->pusch_ServingCellConfig);
9757          }
9758          free(ulCfg->firstActiveUplinkBWP_Id);
9759       }
9760       freeAperDecodeInitialUlBWPConfig(ulBwp);
9761       free(ulCfg->initialUplinkBWP);
9762    }
9763 }
9764
9765 /*******************************************************************
9766  *
9767  * @brief Function to free DuUeCfg
9768  *
9769  * @details
9770  *
9771  *    Function : freeDuUeCfg
9772  *
9773  *    Functionality: Function to free DuUeCfg
9774  *
9775  * @params[in] DuUeCfg *ueCfg
9776  * @return void
9777  *
9778  * ****************************************************************/
9779 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9780 {
9781    uint8_t lcIdx = 0;
9782    uint8_t arrIdx = 0;
9783    SpCellConfig_t *spCellCfg = NULLP;
9784    ServingCellConfig_t *srvCellCfg = NULLP;
9785    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9786    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9787    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9788    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9789    struct RLC_Config *rlcConfig = NULLP;
9790    struct LogicalChannelConfig *macLcConfig = NULLP;
9791    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9792    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9793    struct TAG_Config *tagConfig = NULLP;
9794    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9795    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9796    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9797    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9798   
9799    if(ueCfg->ueNrCapability)
9800    {
9801       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9802       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9803       ueCfg->ueNrCapability = NULLP;
9804    }
9805
9806    if(ueCfg->cellGrpCfg)
9807    {
9808       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9809       if(rlcBearerList)
9810       {
9811          if(rlcBearerList->list.array)
9812          {
9813             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9814             {
9815                if(rlcBearerList->list.array[arrIdx])
9816                {
9817                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9818                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9819
9820                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9821                   {
9822                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9823                   }
9824                   if(rlcConfig)
9825                   {
9826                      if(rlcConfig->choice.am)
9827                      {
9828                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9829                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9830                         free(rlcConfig->choice.am);
9831                      }
9832                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9833                   }
9834                   if(macLcConfig)
9835                   {
9836                      if(macLcConfig->ul_SpecificParameters)
9837                      {
9838                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9839                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9840                         free(macLcConfig->ul_SpecificParameters);
9841                      }
9842                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9843                   }
9844                   free(rlcBearerList->list.array[arrIdx]); 
9845                }
9846             }
9847             free(rlcBearerList->list.array);
9848          }
9849          free(cellGrpCfg->rlc_BearerToAddModList);
9850       }
9851
9852       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9853       if(macCellGrpCfg)
9854       {
9855          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9856          if(schedulingRequestConfig)
9857          {
9858             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9859             if(schReqList)
9860             {
9861                if(schReqList->list.array)
9862                {
9863                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9864                   {
9865                      if(schReqList->list.array[arrIdx])
9866                      {
9867                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9868                         free(schReqList->list.array[arrIdx]);
9869                      }
9870                   }
9871                   free(schReqList->list.array);
9872                }
9873                free(schedulingRequestConfig->schedulingRequestToAddModList);
9874             }
9875             free(macCellGrpCfg->schedulingRequestConfig);
9876          }
9877          if(macCellGrpCfg->bsr_Config)
9878          {
9879             free(macCellGrpCfg->bsr_Config);
9880          }
9881          tagConfig = macCellGrpCfg->tag_Config;
9882          if(tagConfig)
9883          {
9884             tagList = tagConfig->tag_ToAddModList;
9885             if(tagList)
9886             {
9887                if(tagList->list.array)
9888                {
9889                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9890                   {
9891                      free(tagList->list.array[arrIdx]);
9892                   }
9893                   free(tagList->list.array);
9894                }
9895                free(tagConfig->tag_ToAddModList);
9896             }
9897             free(tagConfig); 
9898          }
9899
9900          phrConfig = macCellGrpCfg->phr_Config;
9901          if(phrConfig)
9902          {
9903             free(phrConfig->choice.setup); 
9904             free(phrConfig); 
9905          }
9906
9907          free(macCellGrpCfg); 
9908       }
9909
9910       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9911       if(phyCellGrpCfg)
9912       {
9913          free(phyCellGrpCfg->p_NR_FR1);
9914          free(phyCellGrpCfg); 
9915       }
9916
9917       spCellCfg = cellGrpCfg->spCellConfig;
9918       if(spCellCfg)
9919       {
9920          if(spCellCfg->servCellIndex)
9921          {
9922             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9923             {
9924                if(spCellCfg->spCellConfigDedicated)
9925                {
9926                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9927                   if(srvCellCfg->initialDownlinkBWP)
9928                   {
9929                      dlBwp = srvCellCfg->initialDownlinkBWP;
9930                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9931                      {
9932                         if(srvCellCfg->defaultDownlinkBWP_Id)
9933                         {
9934                            if(srvCellCfg->uplinkConfig)
9935                            {
9936
9937                               if(srvCellCfg->pdsch_ServingCellConfig)
9938                               {
9939                                  pdschCfg=
9940                                     srvCellCfg->pdsch_ServingCellConfig;
9941                                  if(pdschCfg->choice.setup)
9942                                  {
9943
9944                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9945                                     free(pdschCfg->choice.setup);
9946                                  }
9947
9948                                  free(srvCellCfg->pdsch_ServingCellConfig);
9949                               }
9950
9951                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9952                               free(srvCellCfg->uplinkConfig);
9953                            }
9954                            free(srvCellCfg->defaultDownlinkBWP_Id);
9955                         }
9956
9957                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9958                      }
9959                      if(dlBwp->pdcch_Config)
9960                      {
9961                         if(dlBwp->pdsch_Config)
9962                         {
9963                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9964                            free(dlBwp->pdsch_Config);
9965                         }
9966                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9967                         free(dlBwp->pdcch_Config);
9968                      }
9969                      free(srvCellCfg->initialDownlinkBWP);
9970                   }
9971
9972                   free(spCellCfg->spCellConfigDedicated);
9973                }
9974                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9975             }
9976             free(spCellCfg->servCellIndex); 
9977          }
9978          free(spCellCfg);
9979       }
9980       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9981       ueCfg->cellGrpCfg = NULLP;
9982    }
9983
9984    if(ueCfg->ambrCfg)
9985    {
9986       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9987    }
9988
9989    if(actionType != UE_CTXT_CFG_QUERY)
9990    {
9991       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9992       {
9993          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9994       }
9995    }
9996
9997    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9998    {
9999       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
10000    }
10001
10002    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10003    {
10004       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10005    }
10006 }
10007
10008 /*******************************************************************
10009  *
10010  * @brief Function to free UecontextSetupDb
10011  *
10012  * @details
10013  *
10014  *    Function : freeF1UeDb
10015  *
10016  *    Functionality: Function to free UecontextSetupDb
10017  *
10018  * @params[in] UecontextSetupDb *
10019  * @return void
10020  *
10021  * ****************************************************************/
10022
10023 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10024 {
10025    
10026    if(f1UeDb->dlRrcMsg)
10027    {
10028       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10029       {
10030         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10031                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10032       }
10033       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10034    }
10035    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10036    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10037    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10038 }
10039
10040 /*******************************************************************
10041  *
10042  * @brief Function to build Am cfg Info
10043  *
10044  * @details
10045  *
10046  *    Function : extractRlcAmCfg
10047  *
10048  *    Functionality: Function to build Am cfg Info
10049  *
10050  * @params[in] AmBearerCfg *
10051  *             void *
10052  *
10053  * @return ROK/RFAILED
10054  *
10055  * ****************************************************************/
10056
10057 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10058 {
10059    if(rlcAmCfg)
10060    {
10061       /* UL AM */
10062       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10063       {
10064          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10065          /*TODO: Check the timer value when sent by real CU */
10066          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10067          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10068       }
10069
10070       /* DL AM */
10071       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10072       {
10073          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10074          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10075          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10076          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10077          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10078       }
10079    }
10080 }
10081
10082 /*******************************************************************
10083  *
10084  * @brief Function to build Um Bi Info
10085  *
10086  * @details
10087  *
10088  *    Function : extractRlcUmBiCfg
10089  *
10090  *    Functionality: Function to build Um Bi Info
10091  *
10092  * @params[in] UmBiDirBearerCfg *
10093  *             void *
10094  *
10095  * @return ROK/RFAILED
10096  *
10097  * ****************************************************************/
10098
10099 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10100 {
10101    if(rlcBiCfg)
10102    {
10103       /* UL UM BI DIR Cfg */
10104       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10105       {
10106          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10107          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10108       }
10109
10110       /* DL UM BI DIR Cfg */
10111       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10112          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10113    }
10114 }
10115
10116 /*******************************************************************
10117  *
10118  * @brief Function to build Um Ul Info
10119  *
10120  * @details
10121  *
10122  *    Function : extractRlcUmUlCfg
10123  *
10124  *    Functionality: Function to build Um Ul Info
10125  *
10126  * @params[in] UmUniDirUlBearerCfg *
10127  *             void *
10128  *
10129  * @return ROK/RFAILED
10130  *
10131  * ****************************************************************/
10132
10133 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10134 {
10135    if(umUlCfg)
10136    {
10137       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10138       {
10139          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10140          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10141       }
10142    }
10143 }
10144
10145 /*******************************************************************
10146  *
10147  * @brief Function to build Um Uni Dl Info
10148  *
10149  * @details
10150  *
10151  *    Function : extractRlcUmDlCfg
10152  *
10153  *    Functionality: Function to build Um Uni Dl Info
10154  *
10155  * @params[in] UmUniDirDlBearerCfg *
10156  *             void *
10157  *
10158  * @return ROK/RFAILED
10159  *
10160  * ****************************************************************/
10161 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10162 {
10163    if(umDlCfg)
10164    {
10165       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10166          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10167    }
10168 }
10169
10170 /*******************************************************************
10171  *
10172  * @brief Function to extractRlcModeCfg
10173  *
10174  * @details
10175  *
10176  *    Function : extractRlcModeCfg
10177  *
10178  *    Functionality: Function to extractRlcModeCfg
10179  *
10180  * @params[in] RLC_Config_t *
10181  *             RlcBearerCfg *
10182  *             void  *    
10183  * @return ROK/RFAILED
10184  *
10185  * ****************************************************************/
10186 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10187 {
10188    if(lcCfg)
10189    {
10190       switch(rlcMode)
10191       {
10192          case RLC_AM :
10193             {
10194                if(lcCfg->choice.am)
10195                {
10196                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10197                   if(rlcDbCfg->u.amCfg)
10198                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10199                }
10200                break;
10201             }
10202          case RLC_UM_BI_DIRECTIONAL :
10203             {
10204                if(lcCfg->choice.um_Bi_Directional)
10205                {
10206                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10207                   if(rlcDbCfg->u.umBiDirCfg)
10208                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10209                }
10210                break;
10211             }
10212          case RLC_UM_UNI_DIRECTIONAL_UL :
10213             {
10214                if(lcCfg->choice.um_Uni_Directional_DL)
10215                {
10216                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10217                   if(rlcDbCfg->u.umUniDirUlCfg)
10218                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10219                }
10220                break;
10221             }
10222          case RLC_UM_UNI_DIRECTIONAL_DL :
10223             {
10224                if(lcCfg->choice.um_Uni_Directional_UL)
10225                {
10226                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10227                   if(rlcDbCfg->u.umUniDirDlCfg)
10228                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10229                }
10230                break;
10231             }
10232          default:
10233             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10234             break;
10235       }
10236    }
10237 }
10238
10239 /*******************************************************************
10240  *
10241  * @brief Function to extract extractUlLcCfg
10242  *
10243  * @details
10244  *
10245  *    Function : extractUlLcCfg
10246  *
10247  *    Functionality: Function to extract extractUlLcCfg
10248  *
10249  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10250  * @return void
10251  *
10252  * ****************************************************************/
10253
10254 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10255 {
10256    if(ulLcCfg)
10257    {
10258       if(ulLcCfg->ul_SpecificParameters)
10259       {
10260          f1UlLcCfg->priority = \
10261             ulLcCfg->ul_SpecificParameters->priority;
10262       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10263       {
10264          f1UlLcCfg->lcGroup = \
10265            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10266       }
10267       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10268       {
10269          f1UlLcCfg->schReqId = \
10270            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10271       }
10272       f1UlLcCfg->pbr = \
10273          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10274       f1UlLcCfg->bsd = \
10275          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10276       }
10277    }
10278 }
10279
10280 /*******************************************************************
10281 *
10282 * @brief Function to extract Snssai Cfg Info from CU
10283 *
10284 * @details
10285 *
10286 *    Function : extractDrbSnssaiCfg
10287 *
10288 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10289 *
10290 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10291 * @return ROK/RFAILED
10292 *
10293 * ****************************************************************/
10294
10295 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10296 {
10297    if(!(*snssaiToBeShared))
10298    {
10299       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10300       if(snssaiToBeShared == NULLP)
10301       {
10302          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10303          return RFAILED;
10304       }
10305    }
10306    if(RecvSnssai)
10307    {
10308       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10309       if(RecvSnssai->sD)
10310       {
10311          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10312       }
10313       else
10314       {
10315          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10316          return RFAILED;
10317       }
10318    }
10319    return ROK;
10320 }
10321
10322 /*******************************************************************
10323  *
10324  * @brief Function to procRlcLcCfg
10325  *
10326  * @details
10327  *
10328  *    Function : procRlcLcCfg
10329  *
10330  *    Functionality: Function to procRlcLcCfg
10331  *
10332  * @params[in] rbId, lcId, rbType, rlcMod
10333  *             RLC_Config_t *, RlcBearerCfg * , 
10334  * @return void
10335  *
10336  * ****************************************************************/
10337
10338 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10339    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10340 {
10341    DRB_Information_t *drbInfo;
10342
10343    lcCfg->rlcBearerCfg.rbId   = rbId;
10344    lcCfg->configType = configType;
10345
10346    if(rbType == RB_TYPE_SRB)
10347    {
10348       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10349       lcCfg->rlcBearerCfg.lcId   = rbId;
10350       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10351       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10352    }
10353    else if(rbType == RB_TYPE_DRB)
10354    {
10355       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10356       lcCfg->rlcBearerCfg.lcId   = lcId;
10357       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10358       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10359    }
10360    if(f1RlcCfg) /* rlc mode config recived */
10361    {
10362       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10363    }
10364    if(qoSInformation != NULLP)
10365    {
10366       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10367       {
10368          if(qoSInformation->choice.choice_extension->value.present ==\
10369                QoSInformation_ExtIEs__value_PR_DRB_Information)
10370          {
10371             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10372             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10373             {
10374                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10375                return;
10376             }
10377          }
10378       }
10379    }
10380 }
10381
10382 /*******************************************************************
10383  *
10384  * @brief Fills DrbQos Info received by CU
10385  *
10386  * @details
10387  *
10388  *    Function : extractQosInfo
10389  *
10390  *    Functionality: Fills DrbQos Info received  by CU
10391  *
10392  * @params[in] DrbQosInfo *qosToAdd, 
10393  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10394  * @return void
10395  *
10396  * ****************************************************************/
10397
10398 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10399 {
10400    uint8_t qosCntIdx = 0;
10401    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10402
10403    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10404    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10405                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10406    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10407    {
10408       qosToAdd->u.nonDyn5Qi.avgWindow = \
10409                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10410    }
10411
10412    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10413    {
10414       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10415                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10416    }
10417
10418    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10419    {
10420       qosToAdd->u.nonDyn5Qi.priorLevel = \
10421                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10422    }
10423    qosToAdd->ngRanRetPri.priorityLevel = \
10424                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10425    qosToAdd->ngRanRetPri.preEmptionCap = \
10426                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10427    qosToAdd->ngRanRetPri.preEmptionVul = \
10428                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10429    if(qosFlowCfg->gBR_QoS_Flow_Information)
10430    {
10431       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10432             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10433             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10434       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10435             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10436             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10437       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10438             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10439             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10440       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10441             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10442             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10443    }
10444    /*Extracting PDU_SESSION_ID*/
10445    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10446    if(qosIeExt)
10447    {
10448       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10449       {
10450          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10451                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10452          {
10453             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10454             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10455          }
10456       }  
10457    }
10458    qosToAdd->ulPduSessAggMaxBitRate = 0;
10459 }
10460
10461 /*******************************************************************
10462  *
10463  * @brief Function to extract GTP Tunnel Info from CU
10464  *
10465  * @details
10466  *
10467  *    Function : extractUpTnlInfo
10468  *
10469  *    Functionality: Function to extract GTP Tunnel Info from CU
10470  *
10471  * @params[in] F1AP message
10472  * @return ROK/RFAILED
10473  *
10474  * ****************************************************************/
10475
10476 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10477    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10478 {
10479    uint8_t tnlIdx;
10480    uint32_t ipv4_du = 0;
10481    GTPTunnel_t *gtpTunnel = NULLP;
10482
10483    upTnlInfo->drbId = drbId; 
10484    upTnlInfo->configType = configType;
10485 #ifdef O1_ENABLE
10486    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10487 #else
10488    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10489 #endif
10490
10491    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10492    {
10493       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10494       {
10495          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10496          {
10497             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10498             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10499             if(upTnlInfo->tnlCfg1 == NULLP)
10500             {
10501                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10502                return RFAILED;
10503             }
10504             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10505             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10506             if(gtpTunnel->gTP_TEID.size > 0)
10507             {
10508                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10509             }
10510          }
10511          break;
10512       }
10513    }
10514    return ROK;
10515 }
10516
10517 /*******************************************************************
10518 *
10519 * @brief Function to extract Drb Qos Cfg Info from CU
10520 *
10521 * @details
10522 *
10523 *    Function : extractDrbQosCfg 
10524 *
10525 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10526 *
10527 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10528 * @return ROK/RFAILED
10529 *
10530 * ****************************************************************/
10531
10532 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10533 {
10534    if(!macLcToAdd->drbQos)
10535    {
10536       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10537       if(macLcToAdd->drbQos == NULLP)
10538       {
10539          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10540          return RFAILED;
10541       }
10542
10543    }
10544    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10545    {
10546       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10547       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10548    }
10549    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10550    {
10551       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10552       return RFAILED;
10553    }
10554    return ROK;
10555 }
10556 /*******************************************************************
10557  *
10558  * @brief Function to extract DRB info received from CU
10559  *
10560  * @details
10561  *
10562  *    Function : extractDrbCfg
10563  *
10564  *    Functionality: Function to extract DRB info received from CU
10565  *
10566  * @params[in] F1AP message
10567  * @return void
10568  *
10569  * ****************************************************************/
10570 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10571 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10572 {
10573    DRB_Information_t *drbInfo = NULLP;
10574
10575    if(drbItem != NULLP)
10576    {
10577       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10578       {
10579          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10580          return RFAILED;
10581       }
10582       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10583       {
10584          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10585          {
10586             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10587             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10588             {
10589                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10590                return RFAILED;
10591             }
10592          }
10593       }
10594    }
10595    else if(drbSetupModItem != NULLP)
10596    {
10597       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10598       upTnlInfo) != ROK)
10599       {
10600          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10601          return RFAILED;
10602       }
10603       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10604       {
10605          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10606          QoSInformation_ExtIEs__value_PR_DRB_Information)
10607          {
10608             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10609             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10610             {
10611                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10612                return RFAILED;
10613             }
10614
10615          }
10616       }
10617    }
10618    else if(drbModItem != NULLP)
10619    {
10620       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10621       upTnlInfo) != ROK)
10622       {
10623          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10624          return RFAILED;
10625       }
10626       if(drbModItem->qoSInformation != NULLP)
10627       {
10628          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10629          {
10630             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10631                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10632             {
10633                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10634                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10635                {
10636                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10637                   return RFAILED;
10638                }
10639
10640             }
10641          }
10642       }
10643    }
10644    return ROK;
10645 }
10646
10647 /*******************************************************************
10648  *
10649  * @brief Function to extract RB info received from CU
10650  *
10651  * @details
10652  *
10653  *    Function : extractMacRbCfg
10654  *
10655  *    Functionality: Function to extract RB info received from CU
10656  *
10657  * @params[in] F1AP message
10658  * @return ROK/RFAILED
10659  *
10660  * ****************************************************************/
10661
10662 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10663 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10664 {
10665    if(drbCfg != NULLP)
10666    {
10667       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10668       {
10669          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10670          return RFAILED;
10671       }
10672    }
10673    else if(drbSetupModCfg != NULLP)
10674    { 
10675       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10676       {
10677          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10678          return RFAILED;
10679       }
10680    }
10681    else if(drbModCfg != NULLP)
10682    { 
10683       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10684       {
10685          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10686          return RFAILED;
10687       }
10688    }
10689    else
10690    {
10691       lcCfg->lcConfig.drbQos = NULLP;
10692       lcCfg->lcConfig.snssai = NULLP;
10693       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10694          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10695       else
10696          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10697
10698    }
10699    if(ulLcCfg)
10700    {
10701       lcCfg->lcConfig.ulLcCfgPres = true;
10702       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10703    }
10704    else
10705       lcCfg->lcConfig.ulLcCfgPres = false;
10706    return ROK;
10707 }
10708
10709 /*******************************************************************
10710  *
10711  * @brief Function processing LC config info received from CU
10712  *
10713  * @details
10714  *
10715  *    Function : procMacLcCfg
10716  *
10717  *    Functionality: Function processing LC config info received from CU
10718  *
10719  * @params[in] F1AP message
10720  * @return ROK/RFAILED
10721  *
10722  * ****************************************************************/
10723
10724 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10725 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10726 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10727 {
10728    uint8_t ret = ROK;
10729
10730    lcCfg->lcConfig.lcId = lcId;
10731    lcCfg->configType = configType;
10732    if(rbType == RB_TYPE_SRB)
10733    {
10734       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10735    }
10736    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10737    {
10738       if(drbItem != NULL)
10739         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10740       else if(drbSetupModItem != NULL)
10741         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10742       else if(drbModItem != NULL)
10743         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10744    }
10745    return ret;
10746 }
10747
10748 /*******************************************************************
10749  *
10750  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10751  *
10752  * @details
10753  *
10754  *    Function : extractRlcCfgToAddMod
10755  *
10756  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10757  *
10758  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10759  *             DuUeCfg Pointer
10760  * @return ROK/RFAILED
10761  *
10762  * ****************************************************************/
10763
10764 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10765 {
10766   uint8_t idx, rbId, lcId, rlcMode, rbType;
10767   RLC_Config_t *f1RlcCfg = NULLP;
10768   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10769
10770   for(idx = 0; idx < lcCfg->list.count; idx++)
10771   {
10772      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10773      if(lcCfg->list.array[idx]->servedRadioBearer)
10774      {
10775         /* RadioBearer for SRB/DRB */
10776         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10777         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10778         {
10779            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10780            rbType = RB_TYPE_SRB;
10781         }
10782         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10783         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10784         {
10785            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10786            rbType = RB_TYPE_DRB;
10787         }
10788         else
10789         {
10790            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10791            return RFAILED;
10792         }
10793         /* MAC UL LC Config */
10794         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10795         {
10796            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10797         }
10798      }
10799      else
10800      {
10801         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10802         return RFAILED;
10803      }
10804      /* RLC Mode Config */
10805      if(lcCfg->list.array[idx]->rlc_Config)
10806      {
10807         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10808         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10809      }
10810      
10811      /* Filling RLC/MAC Config*/
10812      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10813      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10814      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10815      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10816      {
10817         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10818         return RFAILED;
10819      }
10820      (ueCfgDb->numRlcLcs)++;
10821      (ueCfgDb->numMacLcs)++;
10822      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10823         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10824   }
10825   //TODO: To send the failure cause in UeContextSetupRsp 
10826   return ROK;
10827 }
10828
10829 /*******************************************************************
10830  *
10831  * @brief DeAlloc pdsch serv cell config info
10832  *
10833  * @details
10834  *
10835  *    Function : freeMacPdschServCellInfo
10836  *
10837  *    Functionality: DeAlloc pdsch serv cell config info
10838  *
10839  * @params[in] PdschServCellCfg pointer
10840  * @return void
10841  *
10842  * ****************************************************************/
10843
10844 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10845 {
10846    if(pdsch->xOverhead)
10847    {
10848       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10849    }
10850    if(pdsch->codeBlkGrpFlushInd)
10851    {
10852       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10853    }
10854    if(pdsch->maxCodeBlkGrpPerTb)
10855    {
10856       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10857    }
10858    if(pdsch->maxMimoLayers)
10859    {
10860       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10861    }
10862 }
10863
10864 /*******************************************************************
10865  *
10866  * @brief Free Serving cell Info
10867  *
10868  * @details
10869  *
10870  *    Function : freeMacServingCellInfo
10871  *
10872  *    Functionality: Free Serving cell Info
10873  *
10874  * @params[in] ServCellCfgInfo *srvCellCfg
10875  * @return void
10876  *
10877  * ****************************************************************/
10878 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10879 {
10880    uint8_t timeDomRsrcIdx;
10881
10882    if(srvCellCfg->initDlBwp.pdschPresent)
10883    {
10884       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10885       {
10886          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10887             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10888       }
10889    }
10890
10891    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10892    if(srvCellCfg->bwpInactivityTmr)
10893    {
10894       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10895    }
10896
10897    if(srvCellCfg->initUlBwp.pucchPresent)
10898    {
10899       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10900    }
10901 }
10902
10903 /*******************************************************************
10904  *
10905  * @brief Free cell Grp Cfg Info
10906  *
10907  * @details
10908  *
10909  *    Function : freeUeRecfgCellGrpInfo
10910  *
10911  *    Functionality: Free cell Grp Cfg Info
10912  *
10913  * @params[in] DuMacUeCfg*  duUeCfg
10914  * @return void
10915  *
10916  * ****************************************************************/
10917
10918 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10919 {
10920    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10921 }
10922
10923 /*******************************************************************
10924  *
10925  * @brief Fills Reconfig SchReqReConfig
10926  *
10927  * @details
10928  *
10929  *    Function : extractSchReqReConfig
10930  *
10931  *    Functionality: Fills Reconfig SchReqReConfig
10932  *
10933  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10934  *             SchedReqCfg*  macSchedReq
10935  * @return void
10936  *
10937  * ****************************************************************/
10938 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10939 {
10940    uint8_t schReqIdx = 0;
10941    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10942    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10943
10944    if(cuSchedReq->schedulingRequestToAddModList)
10945    {
10946       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10947       if(schReqListToAdd->list.count)
10948       {
10949          macSchedReq->addModListCount = schReqListToAdd->list.count;
10950          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10951          {
10952             macSchedReq->addModList[schReqIdx].schedReqId = \
10953                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10954             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10955                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10956             macSchedReq->addModList[schReqIdx].srTransMax    =\
10957                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10958          }
10959       }
10960    }
10961    /* Scheduling Req To release */
10962    if(cuSchedReq->schedulingRequestToReleaseList)
10963    {
10964       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10965       if(schReqListToRel->list.count)
10966       {
10967          macSchedReq->relListCount = schReqListToRel->list.count;
10968          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10969          {
10970             macSchedReq->relList[schReqIdx] = \
10971                *schReqListToRel->list.array[schReqIdx];
10972          }
10973       }
10974    }
10975 }
10976
10977 /*******************************************************************
10978  *
10979  * @brief Fills TagReconfig
10980  *
10981  * @details
10982  *
10983  *    Function : extractTagReconfig
10984  *
10985  *    Functionality: Fills extractTagReconfig
10986  *
10987  * @params[in] TAG_Config_t *cuTagCfg
10988  *             TagCfg *macTagCfg
10989  * @return void
10990  *
10991  * ****************************************************************/
10992
10993 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10994 {
10995   uint8_t tagIdx = 0;
10996   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10997   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10998
10999   /* Tag config to AddMod */
11000   if(cuTagCfg->tag_ToAddModList)
11001   {
11002      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11003      if(tagListToAddMod->list.count)
11004      {
11005         macTagCfg->addModListCount = tagListToAddMod->list.count;
11006         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11007         {
11008            macTagCfg->addModList[tagIdx].tagId =\
11009               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11010            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11011
11012               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11013         }
11014      }
11015   }
11016   /* Tag config to release */
11017   if(cuTagCfg->tag_ToReleaseList)
11018   {
11019      tagListToRel = cuTagCfg->tag_ToReleaseList;
11020      if(tagListToRel->list.count)
11021      {
11022         macTagCfg->relListCount = tagListToRel->list.count;
11023         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11024         {
11025            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11026         }
11027      }
11028   }
11029 }
11030
11031 /*******************************************************************
11032  *
11033  * @brief Fills PdcchCfg received by CU
11034  *
11035  * @details
11036  *
11037  *    Function : extractPdcchCfg
11038  *
11039  *    Functionality: Fills PdcchCfg received  by CU
11040  *
11041  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11042  *             PdcchConfig *duPdcchCfg
11043  * @return void
11044  *
11045  * ****************************************************************/
11046
11047 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11048 {
11049    uint8_t cRsetIdx = 0;
11050    uint8_t srchSpcIdx = 0;
11051
11052    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11053    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11054    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11055    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11056
11057
11058    /* Control Resource Set To Add/Mod List */
11059    if(cuPdcchCfg->controlResourceSetToAddModList)
11060    {
11061       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11062       if(cRsetToAddModList->list.count)
11063       {
11064          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11065          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11066          {
11067             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11068                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11069             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11070                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11071             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11072                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11073                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11074
11075             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11076                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11077
11078             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11079                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11080             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11081             {
11082                //TODO: handle the case for Interleaved
11083             }
11084             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11085                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11086             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11087             {
11088                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11089                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11090             }
11091          }
11092       }
11093    }
11094    /* Control Resource Set To Release List */
11095    if(cuPdcchCfg->controlResourceSetToReleaseList)
11096    {
11097       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11098       if(cRsetToRelList->list.count)
11099       {
11100          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11101          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11102          {
11103             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11104          }
11105       }
11106    }
11107
11108    /* Search space To Add/Mod List */
11109    if(cuPdcchCfg->searchSpacesToAddModList)
11110    {
11111       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11112       if(srchSpcToAddModList->list.count)
11113       {
11114          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11115          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11116          {
11117             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11118                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11119             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11120                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11121             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11122             {
11123                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11124                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11125             }
11126             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11127             {
11128                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11129                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11130             }
11131             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11132             {
11133                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11134                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11135                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11136                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11137                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11138                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11139
11140                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11141                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11142
11143                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11144                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11145             }
11146             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11147             {
11148                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11149                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11150                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11151                {
11152                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11153                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11154                }
11155
11156             }
11157          }
11158       }
11159    }
11160    /* Search space To Rel List */
11161    if(cuPdcchCfg->searchSpacesToReleaseList)
11162    {
11163       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11164       if(srchSpcToRelList->list.count)
11165       {
11166          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11167          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11168          {
11169             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11170                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11171          }
11172       }
11173    }
11174 }
11175
11176 /*******************************************************************
11177  *
11178  * @brief Fills PdschCfg received by CU
11179  *
11180  * @details
11181  *
11182  *    Function : extractPdschCfg
11183  *
11184  *    Functionality: Fills PdschCfg received  by CU
11185  *
11186  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11187  *                   which we have stored in F1UeContextSetupDb,
11188  *             PdschConfig *macPdschCfg = Used to Store the information which
11189  *                   needs to send in other layer, as well as this can be the variable
11190  *                   which stores the information in DuCb,
11191  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11192  *                   information to other layer else it will have stored pdsch 
11193  *                   configuration in copyOfmacUeCfg.
11194  * @return void
11195  *
11196  * ****************************************************************/
11197
11198 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11199 {
11200    uint8_t timeDomIdx;
11201    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11202
11203    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11204    {
11205       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11206             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11207       {
11208          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11209          {
11210             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11211                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11212          }
11213       }
11214    }
11215    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11216    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11217    {
11218       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11219       if(timeDomAlloc->present ==\
11220             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11221       {
11222          if(timeDomAlloc->choice.setup)
11223          {
11224             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11225             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11226             {
11227                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11228                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11229                {
11230                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11231                   {
11232                      if(storedPdschCfg)
11233                      {
11234                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11235                         {
11236                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11237                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11238                         }
11239                         else
11240                         {
11241                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11242                         }
11243                      }
11244                      else
11245                      {
11246                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11247                      }
11248                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11249                      {
11250                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11251                         return;
11252                      }
11253                   }
11254                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11255                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11256                }
11257                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11258                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11259                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11260                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11261             }
11262          }
11263       }
11264    }
11265    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11266    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11267       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11268    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11269    {
11270       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11271       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11272       {
11273          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11274          {
11275             macPdschCfg->bundlingInfo.StaticBundling.size = \
11276                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11277          }
11278       }
11279    }
11280    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11281    {
11282       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11283    }
11284
11285 }
11286
11287 /*******************************************************************
11288  *
11289  * @brief Fills PdschServingCellCfg received by CU
11290  *
11291  * @details
11292  *
11293  *    Function : extractPdschServingCellCfg
11294  *
11295  *    Functionality: Fills PdschCfg received  by CU
11296  *
11297  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11298  *             PdschServCellCfg *macUePdschSrvCellCfg
11299  * @return ROK/RFAILED
11300  *
11301  * ****************************************************************/
11302
11303 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11304 {
11305    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11306    {
11307       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11308       {
11309          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11310          {
11311             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11312                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11313          }
11314          else
11315          {
11316             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11317             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11318             {
11319                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11320                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11321             }
11322             else
11323             {
11324                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11325                return RFAILED;
11326             }
11327          }
11328          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11329          {
11330             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11331                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11332          }
11333          else
11334          {
11335             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11336             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11337             {
11338                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11339                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11340             }
11341             else
11342             {
11343                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11344                return RFAILED;
11345             }
11346          }
11347       }
11348    }
11349    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11350    {
11351       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11352    }
11353    if(cuPdschSrvCellCfg->ext1)
11354    {
11355       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11356       {
11357         if(macUePdschSrvCellCfg->maxMimoLayers)
11358         {
11359            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11360         }
11361         else
11362         {
11363            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11364            if(macUePdschSrvCellCfg->maxMimoLayers)
11365            {
11366               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11367            }
11368            else
11369            {
11370               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11371               return RFAILED;
11372            }
11373         }
11374       }
11375    }
11376    if(cuPdschSrvCellCfg->xOverhead)
11377    {
11378       if(macUePdschSrvCellCfg->xOverhead)
11379       {
11380          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11381       }
11382       else
11383       {
11384          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11385          if(macUePdschSrvCellCfg->xOverhead)
11386          {
11387             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11388          }
11389          else
11390          {
11391             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11392             return RFAILED;
11393          }
11394       }
11395    }
11396    return ROK;
11397 }
11398
11399 /*******************************************************************
11400  *
11401  * @brief Fills PuschCfg received by CU
11402  *
11403  * @details
11404  *
11405  *    Function : extractPuschCfg
11406  *
11407  *    Functionality: Fills PuschCfg received  by CU
11408  *
11409  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11410  *             PuschCfg *macPuschCfg
11411  * @return void
11412  *
11413  * ****************************************************************/
11414
11415 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11416 {
11417    uint8_t timeDomIdx = 0;
11418    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11419    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11420
11421    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11422    {
11423       if(cuPuschCfg->choice.setup)
11424       {
11425          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11426          {
11427              macPuschCfg->dataScramblingId = \
11428                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11429          }
11430          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11431          {
11432             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11433             {
11434                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11435                {
11436                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11437                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11438                   {
11439                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11440                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11441                   }
11442                   if(dmrsUlCfg->transformPrecodingDisabled)
11443                   {
11444                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11445                      {
11446                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11447                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11448                      }
11449                   }
11450                }
11451             }
11452          }
11453          /*Res Alloc Type for UL */
11454          if(cuPuschCfg->choice.setup->resourceAllocation)
11455          {
11456             macPuschCfg->resourceAllocType = \
11457                cuPuschCfg->choice.setup->resourceAllocation;
11458          }
11459          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11460          {
11461             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11462             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11463             {
11464                if(timeDomAllocList->choice.setup)
11465                {
11466                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11467                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11468                   {
11469                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11470                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11471                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11472                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11473                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11474                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11475                   }
11476                }
11477             }
11478          }
11479          if(cuPuschCfg->choice.setup->transformPrecoder)
11480             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11481       }
11482    }
11483 }
11484
11485 /*******************************************************************
11486  *
11487  * @brief Function to fill pucch Power Control
11488  *
11489  * @details
11490  *
11491  *    Function : extractPucchPowerControl
11492  *
11493  *    Functionality: Function to fill pucch Power Control
11494  *
11495  * @params[in] PucchPowerControl *pwrCtrl,
11496  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11497  * @return void
11498  *
11499  * ****************************************************************/
11500
11501 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11502 {
11503    uint8_t arrIdx;
11504
11505    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11506       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11507    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11508       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11509    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11510       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11511    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11512       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11513    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11514       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11515    if(cuPwrCtrlCfg->p0_Set)
11516    {
11517       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11518       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11519       {
11520          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11521             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11522          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11523             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11524       }
11525    }
11526    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11527    {
11528       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11529       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11530       {
11531          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11532             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11533       }
11534    }
11535 }
11536  
11537  /*******************************************************************
11538  *
11539  * @brief Function to extractResrcSetToAddModList sent by CU
11540  *
11541  * @details
11542  *
11543  *    Function : extractResrcSetToAddModList
11544  *
11545  *    Functionality: Fucntion to extractResrcSetToAddModList
11546  *
11547  * @params[in] PucchResrcSetCfg pointer,
11548  *             struct PUCCH_Config__resourceSetToAddModList pointer
11549  * @return void
11550  *
11551  * ****************************************************************/
11552
11553 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11554 {
11555    uint8_t arrIdx, rsrcListIdx;
11556
11557    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11558    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11559    {
11560       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11561          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11562       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11563          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11564       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11565       {
11566          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11567             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11568       }
11569
11570       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11571       {
11572          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11573             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11574       }
11575       else
11576       {
11577          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11578       }
11579    }
11580 }/* End of extractResrcSetToAddModList */
11581
11582 /*******************************************************************
11583  *
11584  * @brief Fills extractResrcToAddModList sent by CU
11585  *
11586  * @details
11587  *
11588  *    Function : extractResrcToAddModList
11589  *
11590  *    Functionality: Fills extractResrcToAddModList
11591  *
11592  * @params[in] PucchResrcCfg pointer,
11593  *             struct PUCCH_Config__resourceToAddModList pointer
11594  * @return ROk/RFAILED
11595  *
11596  * ****************************************************************/
11597
11598 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11599 {
11600    uint8_t arrIdx;
11601    
11602    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11603    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11604    {
11605       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11606         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11607       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11608         cuResrcList->list.array[arrIdx]->startingPRB;
11609       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11610       {
11611          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11612            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11613       }
11614       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11615       {
11616          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11617            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11618       }
11619       /* PUCCH RSRC FORMAT */
11620       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11621       {
11622          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11623          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11624          {
11625             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11626             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11627             {
11628                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11629                return RFAILED;
11630             }
11631             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11632                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11633             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11634                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11635             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11636                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11637          }
11638       }
11639       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11640       {
11641          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11642          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11643          {
11644             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11645             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11646             {
11647                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11648                return RFAILED;
11649             }
11650             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11651                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11652             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11653                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11654             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11655                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11656             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11657                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11658          }
11659       }
11660       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11661       {
11662          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11663          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11664          {
11665             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11666             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11667             {
11668                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11669                return RFAILED;
11670             }
11671             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11672                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11673             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11674                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11675             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11676                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11677          }
11678       }
11679       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11680       {
11681          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11682          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11683          {
11684             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11685             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11686             {
11687                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11688                return RFAILED;
11689             }
11690             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11691                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11692             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11693                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11694             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11695                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11696          }
11697       }
11698       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11699       {
11700          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11701          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11702          {
11703             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11704             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11705             {
11706                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11707                return RFAILED;
11708             }
11709             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11710                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11711             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11712                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11713             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11714                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11715             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11716                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11717          }
11718       }
11719    }
11720    return ROK;
11721
11722 }/* End of extractResrcToAddModList */
11723
11724 /*******************************************************************
11725  *
11726  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11727  *
11728  * @details
11729  *
11730  *    Function : fillPucchSchedReqPeriodAndOffset
11731  *
11732  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11733  *
11734  * @params[in] macPeriodicty,
11735  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11736  * @return void
11737  *
11738  * ****************************************************************/
11739
11740 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11741    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11742 {
11743    macPeriodicty = cuPeriodicty->present;
11744    switch(macPeriodicty)
11745    {
11746       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11747          {
11748             macOffset     = cuPeriodicty->choice.sym2;
11749             break;
11750          }
11751       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11752          {
11753             macOffset     = cuPeriodicty->choice.sym6or7;
11754             break;
11755          }
11756       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11757          {
11758             macOffset     = cuPeriodicty->choice.sl1;
11759             break;
11760          }
11761       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11762          {
11763             macOffset = cuPeriodicty->choice.sl2;
11764             break;
11765          }
11766       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11767          {
11768             macOffset = cuPeriodicty->choice.sl4;
11769             break;
11770          }
11771       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11772          {
11773             macOffset = cuPeriodicty->choice.sl5;
11774             break;
11775          }
11776       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11777          {
11778             macOffset = cuPeriodicty->choice.sl8;
11779             break;
11780          }
11781       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11782          {
11783             macOffset = cuPeriodicty->choice.sl10;
11784             break;
11785          }
11786       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11787          {
11788             macOffset = cuPeriodicty->choice.sl16;
11789             break;
11790          }
11791       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11792          {
11793             macOffset = cuPeriodicty->choice.sl20;
11794             break;
11795          }
11796       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11797          {
11798             macOffset = cuPeriodicty->choice.sl40;
11799             break;
11800          }
11801       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11802          {
11803             macOffset = cuPeriodicty->choice.sl80;
11804             break;
11805          }
11806       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11807          {
11808             macOffset = cuPeriodicty->choice.sl160;
11809             break;
11810          }
11811       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11812          {
11813             macOffset = cuPeriodicty->choice.sl320;
11814             break;
11815          }
11816       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11817          {
11818             macOffset = cuPeriodicty->choice.sl640;
11819             break;
11820          }
11821       default :
11822          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11823    }
11824 }
11825
11826 /*******************************************************************
11827  *
11828  * @brief Function to extractPucchFormatCfg sent by CU
11829  *
11830  * @details
11831  *
11832  *    Function : extractPucchFormatCfg
11833  *
11834  *    Functionality: Function to extractPucchFormatCfg
11835  *
11836  * @params[in] PucchFormatCfg pointer,
11837  *             PUCCH_FormatConfig_t pointer
11838  * @return void
11839  *
11840  * ****************************************************************/
11841
11842 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11843  {
11844     if(cuFormatCfg->interslotFrequencyHopping)
11845        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11846     if(cuFormatCfg->additionalDMRS)  
11847        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11848     if(cuFormatCfg->maxCodeRate)
11849        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11850     if(cuFormatCfg->nrofSlots)  
11851        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11852     if(cuFormatCfg->pi2BPSK)  
11853        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11854     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11855        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11856  }/* End of extractPucchFormatCfg */
11857
11858 /*******************************************************************
11859  *
11860  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11861  *
11862  * @details
11863  *
11864  *    Function : extractSchedReqCfgToAddMod
11865  *
11866  *    Functionality: Function to extractSchedReqCfgToAddMod
11867  *
11868  * @params[in] PucchSchedReqCfg pointer,
11869  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11870  * @return void
11871  *
11872  * ****************************************************************/
11873
11874 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11875 {
11876    uint8_t arrIdx;
11877
11878    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11879    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11880    {
11881       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11882          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11883       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11884          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11885       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11886       {
11887          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11888             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11889       }
11890       if(cuSchedReqList->list.array[arrIdx]->resource)
11891       {
11892          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11893             *cuSchedReqList->list.array[arrIdx]->resource;
11894       }
11895    }
11896
11897 }/* End of extractSchedReqCfgToAddMod */
11898
11899  /*******************************************************************
11900  *
11901  * @brief Fills PucchCfg received by CU
11902  *
11903  * @details
11904  *
11905  *    Function : extractPucchCfg
11906  *
11907  *    Functionality: Fills PucchCfg received  by CU
11908  *
11909  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11910  *                is send by CU, which we have stored in F1UeContextSetupDb,
11911  *             PucchCfg *macPucchCfg = Used to Store the information which
11912  *                needs to send in other layer, as well as this can be the variable
11913  *                which stores the information in DuCb,
11914  *             PucchCfg *storedPucchCfg = Null in case of sending the
11915  *                information to other layer else it will have Pucch Cfg which
11916  *                we have stored in copyOfmacUeCfg.
11917  * @return ROK/RFAILED
11918  *
11919  * ****************************************************************/
11920
11921 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11922 PucchCfg *storedPucchCfg)        
11923 {
11924    uint8_t arrIdx;
11925
11926    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11927    {
11928       if(cuPucchCfg->choice.setup)
11929       {
11930          /* Resource Set Cfg */ 
11931          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11932          {
11933             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11934             if(macPucchCfg->resrcSet == NULLP)
11935             {
11936                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11937                return RFAILED;
11938             }
11939             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11940             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11941          }
11942          
11943          /* Resource Cfg */ 
11944          if(cuPucchCfg->choice.setup->resourceToAddModList)
11945          {
11946             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11947             if(macPucchCfg->resrc == NULLP)
11948             {
11949                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11950                return RFAILED;
11951             }
11952             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11953             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11954          }
11955          
11956          /* Format 1 Cfg */ 
11957          if(cuPucchCfg->choice.setup->format1)
11958          {
11959             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11960             if(macPucchCfg->format1 == NULLP)
11961             {
11962                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11963                return RFAILED;
11964             }
11965             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11966             extractPucchFormatCfg(macPucchCfg->format1,\
11967                cuPucchCfg->choice.setup->format1->choice.setup);
11968          }
11969          
11970          /* Format 2 Cfg */
11971          if(cuPucchCfg->choice.setup->format2)
11972          {
11973             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11974             if(macPucchCfg->format2 == NULLP)
11975             {
11976                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11977                return RFAILED;
11978             }
11979             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11980             extractPucchFormatCfg(macPucchCfg->format2,\
11981                cuPucchCfg->choice.setup->format2->choice.setup);
11982          }
11983          
11984          /* Format 3 Cfg */
11985          if(cuPucchCfg->choice.setup->format3)
11986          {
11987             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11988             if(macPucchCfg->format3 == NULLP)
11989             {
11990                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11991                return RFAILED;
11992             }
11993             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11994             extractPucchFormatCfg(macPucchCfg->format3,\
11995                cuPucchCfg->choice.setup->format3->choice.setup);
11996          }
11997
11998          /* Format 4 Cfg */
11999          if(cuPucchCfg->choice.setup->format4)
12000          {
12001             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12002             if(macPucchCfg->format4 == NULLP)
12003             {
12004                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12005                return RFAILED;
12006             }
12007             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12008             extractPucchFormatCfg(macPucchCfg->format4,\
12009                cuPucchCfg->choice.setup->format4->choice.setup);
12010          }
12011
12012          /* Sched Req List */
12013          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12014          {
12015             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12016             if(macPucchCfg->schedReq == NULLP)
12017             {
12018                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12019                return RFAILED;
12020             }
12021             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12022             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12023             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12024          }
12025
12026          /*TODO: Add support for  Spatial Info */
12027
12028          /* MultiCsiCfg */
12029          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12030          {
12031             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12032             if(macPucchCfg->multiCsiCfg == NULLP)
12033             {
12034                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12035                return RFAILED;
12036             }
12037             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12038             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12039             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12040             {
12041                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12042                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12043             }
12044          }
12045
12046          /* Dl_DataToUL_ACK */ 
12047          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12048     {
12049        if(storedPucchCfg)
12050        {
12051           if(storedPucchCfg->dlDataToUlAck)
12052           {
12053              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12054           }
12055           else
12056           {
12057             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12058           }
12059        }
12060        else
12061        {
12062           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12063        }
12064        if(macPucchCfg->dlDataToUlAck == NULLP)
12065        {
12066           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12067           return RFAILED;
12068        }
12069        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12070        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12071        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12072        {
12073           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12074           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12075        }
12076          }
12077
12078          /* Power Control */
12079          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12080          {
12081             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12082             if(macPucchCfg->powerControl == NULLP)
12083             {
12084                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12085                return RFAILED;
12086             }
12087             extractPucchPowerControl(macPucchCfg->powerControl,\
12088                cuPucchCfg->choice.setup->pucch_PowerControl);
12089          }
12090       }
12091    }
12092    return ROK;
12093 }
12094
12095 /*******************************************************************
12096  *
12097  * @brief Fills ServingCellReconfig received by CU
12098  *
12099  * @details
12100  *
12101  *    Function : extractSpCellDedicatedCfg
12102  *
12103  *    Functionality: Fills ServingCellReconfig received  by CU
12104  *
12105  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12106  *                  CU, which we have stored in F1UeContextSetupDb,
12107  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12108  *                  which  needs to send in other layer, as well as this can be the
12109  *                  variable which stores the information in DuCb, 
12110  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12111  *                  information to other layer else it will have ServCellCfgInfo which
12112  *                  we have stored in copyOfmacUeCfg.
12113  * @return ROK/RFAILD
12114  *
12115  * ****************************************************************/
12116 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12117 ServCellRecfgInfo *storedSrvCellCfg)
12118 {
12119    uint8_t ret = ROK;
12120    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12121    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12122
12123    if(cuSrvCellCfg->initialDownlinkBWP)
12124    {
12125       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12126       if(dlBwp->pdcch_Config)
12127       {
12128          if(dlBwp->pdcch_Config->choice.setup)
12129          {
12130             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12131             if(storedSrvCellCfg)
12132             {
12133                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12134                {
12135                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12136                }
12137                else
12138                {
12139                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12140                }
12141             }
12142             else
12143             {
12144                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12145             }
12146          }
12147       }
12148       if(dlBwp->pdsch_Config)
12149       {
12150          if(dlBwp->pdsch_Config->choice.setup)
12151          {
12152             macSrvCellCfg->initDlBwp.pdschPresent = true;
12153             
12154             if(storedSrvCellCfg)
12155             {
12156                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12157                {
12158                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12159                }
12160                else
12161                {
12162                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12163                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12164                }
12165             }
12166             else
12167             {
12168                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12169             }
12170          }
12171       }
12172    }
12173    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12174       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12175    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12176       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12177    if(cuSrvCellCfg->bwp_InactivityTimer)
12178    {
12179       if(macSrvCellCfg->bwpInactivityTmr)
12180       {
12181          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12182       }
12183       else
12184       {
12185          macSrvCellCfg->bwpInactivityTmr = NULLP;
12186          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12187          if(macSrvCellCfg->bwpInactivityTmr)
12188          {
12189             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12190          }
12191          else
12192          {
12193             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12194             return RFAILED;
12195          }
12196       }
12197    }
12198    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12199    {
12200       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12201       {
12202          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12203          if(ret == RFAILED)
12204          {
12205             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12206             return RFAILED;
12207          }
12208       }
12209    }
12210    if(cuSrvCellCfg->uplinkConfig)
12211    {
12212       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12213       {
12214          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12215          if(ulBwp->pusch_Config)
12216          {
12217             macSrvCellCfg->initUlBwp.puschPresent = true;
12218             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12219          }
12220          if(ulBwp->pucch_Config)
12221          {
12222             macSrvCellCfg->initUlBwp.pucchPresent = true;
12223             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12224             if(storedSrvCellCfg)
12225             {
12226                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12227                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12228                else
12229                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12230                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12231             }
12232             else
12233             {
12234                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12235             }
12236          }
12237       }
12238       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12239          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12240    }
12241    return ret;
12242 }
12243
12244 #ifdef NR_DRX
12245
12246 /*******************************************************************
12247  *
12248  * @brief fill long cycle offset value of drx in UE structure
12249  *
12250  * @details
12251  *
12252  *    Function : fillLongCycleOffsetValueInUeDb
12253  *
12254  *    Functionality: fill long cycle offset value of drx in UE structure
12255  *
12256  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12257  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12258  *
12259  * @return ROK     - success
12260  *         RFAILED - failure
12261  *
12262  * ****************************************************************/
12263 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12264 {
12265
12266    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12267    switch(drx_LongCycleStartOffset->present)
12268    {
12269       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12270          {
12271             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12272             break;
12273          }
12274       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12275          {
12276             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12277             break;
12278          }
12279       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12280          {
12281             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12282             break;
12283          }
12284       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12285         {
12286             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12287             break;
12288          }
12289       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12290          {
12291             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12292             break;
12293          }
12294       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12295          {
12296             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12297             break;
12298          }
12299       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12300          {
12301             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12302             break;
12303          }
12304       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12305          {
12306             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12307             break;
12308          }
12309       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12310          {
12311             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12312             break;
12313          }
12314       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12315          {
12316             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12317             break;
12318          }
12319       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12320          {
12321             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12322             break;
12323          }
12324       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12325          {
12326             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12327             break;
12328          }
12329       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12330          {
12331             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12332             break;
12333          }
12334       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12335          {
12336             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12337             break;
12338          }
12339       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12340          {
12341             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12342             break;
12343          }
12344       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12345          {
12346             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12347             break;
12348          }
12349       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12350          {
12351             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12352             break;
12353          }
12354       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12355          {
12356             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12357             break;
12358          }
12359        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12360          {
12361             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12362             break;
12363          }
12364       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12365          {
12366             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12367             break;
12368          }
12369       default :
12370          break;
12371    }
12372 }
12373
12374 /*******************************************************************
12375  *
12376  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12377  *which recive from CU or storedDrxCfg which is already stored
12378  *
12379  * @details
12380  *
12381  *    Function : extractDrxConfiguration 
12382  *
12383  *    Functionality: Fills Reconfig Cell group Info received by CU
12384  *   
12385  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12386  *                       is send by CU, which we have stored in F1UeContextSetupDb
12387  *             DrxCfg * drxCfg  = Used to Store the information,
12388  *                      which needs to send in other layer, as well as this can be
12389  *                      the variable which stores the information in DuCb,
12390  *             DrxCfg *storedDrxCfg = Null in case of sending the
12391  *                      information to other layer else it will have the drx information 
12392  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12393  *
12394  * @return void
12395  *
12396  * ****************************************************************/
12397 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12398 {
12399    struct DRX_ConfigRrc *cuDrxConfig;
12400
12401    if(storedDrxCfg)
12402    {
12403       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12404    }
12405    else
12406    {
12407       if(cuMacCellGrpDrxConfig)
12408       {
12409          switch(cuMacCellGrpDrxConfig->present)
12410          {
12411             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12412                break;
12413
12414             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12415                {
12416                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12417                   if(cuDrxConfig)
12418                   {
12419                      switch(cuDrxConfig->drx_onDurationTimer.present)
12420                      {
12421                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12422                            break;
12423                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12424                            {
12425                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12426                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12427                               drx_onDurationTimer.choice.milliSeconds);
12428                               break;
12429                            }
12430                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12431                            {
12432                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12433                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12434                               break;
12435                            }
12436                      }
12437                   }
12438                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12439                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12440                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12441                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12442                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12443                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12444                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12445                   if(cuDrxConfig->shortDRX)
12446                   {
12447                      drxCfg->shortDrxPres=true;
12448                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12449                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12450                   }
12451                   else
12452                      drxCfg->shortDrxPres=false;
12453
12454                   break;
12455                }
12456
12457             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12458                break;
12459          }
12460       }
12461    }
12462 }
12463 #endif
12464
12465 /*******************************************************************
12466  *
12467  * @brief Fills Reconfig Cell group Info received by CU
12468  *
12469  * @details
12470  *
12471  *    Function : extractUeRecfgCellInfo
12472  *
12473  *    Functionality: Fills Reconfig Cell group Info received by CU
12474  *   
12475  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12476  *                       is send by CU, which we have stored in F1UeContextSetupDb
12477  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12478  *                      which needs to send in other layer, as well as this can be
12479  *                      the variable which stores the information in DuCb,
12480  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12481  *                      information to other layer else it will have copyOfmacUeCfg
12482  *                      which we have stored in F1UeContextSetupDb.
12483  *
12484  * @return ROK/RFAILED
12485  *
12486  * ****************************************************************/
12487 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12488 {
12489    uint8_t ret = ROK;
12490    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12491    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12492    SpCellConfig_t            *spcellCfg = NULLP;
12493    ServingCellConfig_t       *servCellCfg = NULLP;
12494
12495    if(cellGrp)
12496    {
12497       /* Fill MacCell Group Reconfig  */
12498       if(cellGrp->mac_CellGroupConfig)
12499       {
12500          macUeCfg->macCellGrpCfgPres = true;
12501          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12502
12503 #ifdef NR_DRX         
12504          if(macCellGroup->drx_ConfigRrc)
12505          {
12506             if(storedMacUeCfg)
12507             {
12508                if(!storedMacUeCfg->macCellGrpCfgPres) 
12509                {
12510                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12511                }
12512                else
12513                {
12514                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12515                }
12516             }
12517             else
12518             {
12519                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12520             }
12521          }
12522 #endif
12523
12524          if(macCellGroup->schedulingRequestConfig)
12525          {
12526             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12527          }
12528          if(macCellGroup->tag_Config)
12529          {
12530             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12531          }
12532          if(macCellGroup->bsr_Config)
12533          {
12534             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12535             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12536             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12537             {
12538                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12539                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12540             }
12541          }
12542          if(macCellGroup->phr_Config)
12543          {
12544             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12545             {
12546                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12547                if(macCellGroup->phr_Config->choice.setup)
12548                {
12549                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12550                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12551                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12552                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12553                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12554                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12555                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12556                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12557                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12558                   macCellGroup->phr_Config->choice.setup->dummy;
12559                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12560                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12561                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12562                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12563                }
12564             }
12565          }
12566       }
12567       /* Fill Physical Cell Group Reconfig */
12568       if(cellGrp->physicalCellGroupConfig)
12569       {
12570          macUeCfg->phyCellGrpCfgPres = true;
12571          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12572          if(phyCellGrpCfg->p_NR_FR1)
12573          {
12574             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12575                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12576          }
12577          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12578       }
12579       /* Fill SpCell Reconfig */
12580       if(cellGrp->spCellConfig)
12581       {
12582          macUeCfg->spCellCfgPres = true;
12583          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12584          if(spcellCfg->servCellIndex)
12585          {
12586             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12587          }
12588          /* Fill Serving cell Reconfig info */
12589          if(cellGrp->spCellConfig->spCellConfigDedicated)
12590          {
12591             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12592             if(storedMacUeCfg)
12593             {
12594                if(!storedMacUeCfg->spCellCfgPres)
12595                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12596                else
12597                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12598                         &storedMacUeCfg->spCellCfg.servCellCfg);
12599             }
12600             else
12601             {
12602                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12603             }
12604             if(ret == RFAILED)
12605             {
12606                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12607             }
12608          }
12609       }
12610    }
12611    return ret;
12612 }
12613 /*******************************************************************
12614 *
12615 * @brief free the memory allocated by decoder
12616 *
12617 * @details
12618 *
12619 *    Function : freeAperDecodeNrcgi 
12620 *
12621 *    Functionality: Free Nrcgi values
12622 *
12623 * @params[in] NRCGI_t *nrcgi
12624 * @return void
12625 *
12626 * ****************************************************************/
12627
12628
12629 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12630 {
12631     if(nrcgi->pLMN_Identity.buf != NULLP)
12632     {
12633        free(nrcgi->pLMN_Identity.buf);
12634     }
12635     if(nrcgi->nRCellIdentity.buf != NULLP)
12636     {
12637        free(nrcgi->nRCellIdentity.buf);
12638     }
12639 }
12640 /*******************************************************************
12641 *
12642 * @brief free the memory allocated by decoder
12643 *
12644 * @details
12645 *
12646 *    Function : freeAperDecodeCuToDuInfo 
12647 *
12648 *    Functionality:  Free Cu To Du Information
12649 *
12650 * @params[in] CUtoDURRCInformation_t *rrcMsg
12651 * @return void
12652 *
12653 * ****************************************************************/
12654
12655
12656 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12657 {
12658    uint8_t ieIdx =0;
12659    uint8_t arrIdx =0;
12660
12661    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12662    {
12663       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12664          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12665       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12666    }
12667
12668    if(rrcMsg->iE_Extensions)
12669    {
12670       if(rrcMsg->iE_Extensions->list.array)
12671       {
12672          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12673          {
12674             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12675             {
12676                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12677                {
12678                   case ProtocolIE_ID_id_CellGroupConfig:
12679                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12680                      {
12681                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12682                      }
12683                      break;
12684                   default:
12685                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12686                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12687                      break;
12688                }
12689             }
12690          }
12691          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12692          {
12693             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12694          }
12695          free(rrcMsg->iE_Extensions->list.array);
12696
12697       }
12698
12699       free(rrcMsg->iE_Extensions);
12700    }
12701 }
12702 /*******************************************************************
12703 *
12704 * @brief free the memory allocated by decoder
12705 *
12706 * @details 
12707 *
12708 *    Function : freeAperDecodeSplCellList
12709 *
12710 *    Functionality: Free Spl Cell List 
12711                     where memory allocated by aper_decoder
12712 *
12713 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12714 * @return void
12715 *
12716 * ****************************************************************/
12717
12718
12719 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12720 {
12721     uint8_t  cellIdx =0;
12722
12723     if(spCellLst->list.array != NULLP)
12724     {
12725        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12726        {
12727           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12728           {
12729              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12730           }
12731           if(spCellLst->list.array[cellIdx]!=NULLP)
12732           {
12733              free(spCellLst->list.array[cellIdx]);
12734           }
12735        }
12736        free(spCellLst->list.array);
12737     }
12738 }
12739 /*******************************************************************
12740 *
12741 * @brief free the memory allocated by decoder
12742 *
12743 * @details
12744 *
12745 *    Function : freeAperDecodeSRBSetup 
12746 *
12747 *    Functionality: added free part for the memory allocated by aper_decoder
12748 *
12749 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12750 * @return void
12751 *
12752 ****************************************************************/
12753
12754
12755 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12756 {
12757     uint8_t srbIdx =0;
12758     if(srbSet->list.array != NULLP)
12759     {
12760        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12761        {
12762           if(srbSet->list.array[srbIdx]!=NULLP)
12763           {
12764              free(srbSet->list.array[srbIdx]);
12765           }
12766        }
12767        free(srbSet->list.array);
12768     }
12769 }
12770
12771 /*******************************************************************
12772 *
12773 * @brief free the memory allocated by decoder
12774 *
12775 * @details
12776 *
12777 *    Function : freeAperDecodeULTnlInfo
12778 *
12779 *    Functionality: added free part for the memory allocated by aper_decoder
12780 *
12781 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12782 * @return void
12783 *
12784 * ****************************************************************/
12785
12786
12787 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12788 {
12789    uint8_t ulIdx=0;
12790    if(ulInfo->list.array != NULLP)
12791    {
12792       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12793       {
12794          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12795          {
12796             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12797             {
12798                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12799                      transportLayerAddress.buf != NULLP)
12800                {
12801                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12802                         !=NULLP)
12803                   {
12804                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12805                   }
12806                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12807                         transportLayerAddress.buf);
12808                }
12809                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12810             }
12811          }
12812          if(ulInfo->list.array[ulIdx]!=NULLP)
12813          {
12814             free(ulInfo->list.array[ulIdx]);
12815          }
12816       }
12817       free(ulInfo->list.array);
12818    }
12819 }
12820 /*******************************************************************
12821 *
12822 * @brief free the memory allocated by decoder
12823 *
12824 * @details
12825 *
12826 *    Function : freeAperDecodeDRBSetup  
12827 *
12828 *    Functionality: free DRBSetup which is allocated by decoder
12829 *
12830 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12831 * @return void
12832 *
12833 * ****************************************************************/
12834
12835 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12836 {
12837    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12838    uint8_t  flowIdx =0;
12839    uint8_t  drbIdx =0;
12840
12841    if(drbSet->list.array != NULLP)
12842    {
12843       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12844       {
12845          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12846          {
12847             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12848             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12849             {
12850                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12851                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12852                {
12853                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12854                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12855                   {
12856                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12857                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12858                      {
12859
12860                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12861                         {
12862
12863                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12864                            {
12865
12866                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12867                                     buf!=NULLP)
12868                               {
12869
12870                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12871                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12872                                  {
12873
12874                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12875                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12876                                     {
12877
12878                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12879                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12880                                        {
12881                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12882                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12883                                                 qoSFlowLevelQoSParameters.\
12884                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12885                                           {
12886                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12887                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12888                                                    qoSFlowLevelQoSParameters.\
12889                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12890                                              {
12891
12892                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12893                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12894                                                       qoSFlowLevelQoSParameters.\
12895                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12896                                                 {
12897
12898
12899                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12900                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12901                                                          qoSFlowLevelQoSParameters.\
12902                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12903                                                 }
12904
12905                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12906                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12907                                                       qoSFlowLevelQoSParameters.\
12908                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12909                                              }
12910
12911                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12912
12913                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12914                                                    qoSFlowLevelQoSParameters.\
12915                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12916                                           }
12917                                        }
12918                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12919                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12920                                        {
12921
12922                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12923                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12924                                        }
12925                                     }
12926
12927                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12928                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12929                                  }
12930
12931                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12932                                        DRB_Information.sNSSAI.sD->buf);
12933                               }
12934
12935                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12936                            }
12937
12938                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12939
12940                         }
12941
12942                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12943
12944                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12945                      }
12946
12947                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12948                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12949                   }
12950
12951                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12952                         qoS_Characteristics.choice.non_Dynamic_5QI);
12953                }
12954                free(drbSetItem->qoSInformation.choice.choice_extension);
12955             }
12956             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12957             if(drbSetItem->uLConfiguration)
12958             {
12959                free(drbSetItem->uLConfiguration);
12960             }
12961          }
12962          if(drbSet->list.array[drbIdx]!=NULLP)
12963          {
12964             free(drbSet->list.array[drbIdx]);
12965          }
12966       }
12967       free(drbSet->list.array);
12968    }
12969 }
12970
12971
12972 /*******************************************************************
12973  *
12974  * @brief builds Mac Cell Cfg
12975  *
12976  * @details
12977  *
12978  *    Function : procUeRecfgCellInfo
12979  *
12980  *    Functionality: builds Mac Cell Cfg
12981  *
12982  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12983  *                       needs to send in other layer, as well as this can be
12984  *                       the variable which stores the information in DuCb.
12985  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12986  *                       information to other layer else it will have copyOfmacUeCfg  
12987  *                       which we have stored in F1UeContextSetupDb
12988  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12989  *                        by CU, which we have stored in F1UeContextSetupDb 
12990  *
12991  * @return void 
12992  *
12993  * ****************************************************************/
12994 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12995 {
12996    uint8_t ret = ROK;
12997    CellGroupConfigRrc_t *cellGrp = NULLP;
12998
12999    if(cellInfo)
13000    {
13001       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13002       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13003       if(ret == RFAILED)
13004          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13005    }
13006    if(ret == RFAILED)
13007    {
13008       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13009    }
13010    return ret;
13011 }
13012
13013 /*******************************************************************
13014  *
13015  * @brief Filling modulation info in mac ue cfg
13016  *
13017  * @details
13018  *
13019  *    Function : duFillModulationDetails
13020  *
13021  *    Functionality: Filling modulation info in mac ue cfg
13022  *
13023  * @params[in] MAC UE Config to be updated
13024  *             Current UE configuration
13025  *             UE NR capability from CU
13026  * @return ROK     - success
13027  *         RFAILED - failure
13028  *
13029  * ****************************************************************/
13030 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13031 {
13032    UE_NR_Capability_t *ueNrCap=NULLP;
13033
13034    if(!ueCap && oldUeCfg)
13035    {
13036       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13037       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13038    }
13039    else
13040    {
13041       ueNrCap = (UE_NR_Capability_t *)ueCap;
13042
13043       /* Filling DL modulation info */
13044       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13045          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13046          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13047       {
13048          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13049          {
13050             case ModulationOrder_qpsk:
13051                {
13052                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13053                   break;
13054                }
13055             case ModulationOrder_qam16:
13056                {
13057                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13058                   break;
13059                }
13060             case ModulationOrder_qam64:
13061                {
13062                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13063                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13064                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13065                   break;
13066                }
13067             case ModulationOrder_qam256:
13068                {
13069                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13070                   break;
13071                }
13072             default:
13073                {
13074                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13075                   if(oldUeCfg)
13076                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13077                   break;
13078                }
13079          }
13080       }
13081       else
13082       {
13083          if(oldUeCfg)
13084             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13085       }
13086
13087       /* Filling UL modulation info */
13088       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13089          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13090          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13091       {
13092          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13093          {
13094             case ModulationOrder_qpsk:
13095                {
13096                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13097                   break;
13098                }
13099             case ModulationOrder_qam16:
13100                {
13101                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13102                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13103                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13104                   break;
13105                }
13106             case ModulationOrder_qam64:
13107                {
13108                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13109                   break;
13110                }
13111             case ModulationOrder_qam256:
13112                {
13113                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13114                   break;
13115                }
13116             default:
13117                {
13118                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13119                   if(oldUeCfg)
13120                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13121                   break;
13122                }
13123          }
13124       }
13125       else
13126       {
13127          if(oldUeCfg)
13128             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13129       }
13130    }
13131 }
13132
13133 /*******************************************************************
13134  *
13135  * @brief Function to extract info from CU to DU RRC container extension
13136  *
13137  * @details
13138  *
13139  *    Function : extractCuToDuRrcInfoExt
13140  *
13141  *    Functionality: Function to extract info from CU to DU RRC container
13142  *    extension
13143  *
13144  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13145  *
13146  * @return ROK
13147  *         RFAILED
13148  *
13149  * ****************************************************************/
13150 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13151 {
13152    uint8_t ieIdx =0;
13153    uint16_t recvBufLen =0;
13154    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13155    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13156    asn_dec_rval_t rval; /* Decoder return value */
13157    memset(&rval, 0, sizeof(asn_dec_rval_t));
13158
13159    if(protocolIeExtn)
13160    {
13161       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13162       {
13163          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13164          switch(extIeInfo->id)
13165          {
13166             case ProtocolIE_ID_id_CellGroupConfig:
13167                {
13168                   /* decoding the CellGroup Buf received */
13169                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13170                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13171                   if(cellGrpCfg)
13172                   {
13173                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13174                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13175                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13176                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13177                      {
13178                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13179                         return RFAILED;
13180                      }
13181                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13182
13183                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13184                         return NULLP;
13185                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13186                   }
13187                   break;
13188                }
13189
13190             case ProtocolIE_ID_id_HandoverPreparationInformation:
13191                {
13192                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13193                   break;
13194                }
13195
13196             default:
13197                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13198                break;
13199          }
13200       }
13201    }
13202    return ROK;
13203 }
13204
13205 /*******************************************************************
13206  *
13207  * @brief Fills Srb List received by CU
13208  *
13209  * @details
13210  *
13211  *    Function : procSrbListToSetup
13212  *
13213  *    Functionality: Fills Srb List received  by CU
13214  *
13215  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13216  *             DuLcCfg pointer
13217  *             RlcBearerCfg pointer
13218  * @return void
13219  *
13220  * ****************************************************************/
13221 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13222 {
13223
13224    /* Filling RLC INFO */
13225    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13226
13227    /* Filling MAC INFO */
13228    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13229    { 
13230       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13231       return RFAILED;
13232    }
13233
13234    return ROK;
13235 }
13236
13237
13238
13239 /*******************************************************************
13240  *
13241  * @brief extract Srb List received by CU
13242  *
13243  * @details
13244  *
13245  *    Function : extractSrbListToSetup
13246  *
13247  *    Functionality: extract Srb List received by CU
13248  *                   for both MAC and RLC
13249  *
13250  * @params[in] SRBs_ToBeSetup_Item_t pointer
13251  *             DuUeCfg pointer
13252  * @return ROK/RFAIED
13253  *
13254  * ****************************************************************/
13255
13256 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13257 {
13258    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13259    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13260    DuLcCfg *macLcCtxt = NULLP;
13261    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13262
13263    if(srbCfg)
13264    {
13265       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13266       {
13267          macLcCtxt = NULL;
13268          rlcLcCtxt = NULL;
13269
13270          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13271          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13272          { 
13273             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13274             ret = RFAILED;
13275             break;
13276          }
13277          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13278          {
13279             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13280             ret = RFAILED;
13281             break;
13282          }
13283
13284          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13285          {
13286             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13287             {
13288                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13289                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13290                break;
13291             }
13292          }
13293          if(!macLcCtxt)
13294          {
13295             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13296             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13297             ueCfgDb->numMacLcs++;
13298          }
13299          if(!rlcLcCtxt)
13300          {
13301             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13302             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13303             ueCfgDb->numRlcLcs++;
13304          }
13305
13306          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13307
13308          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13309                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13310          if(ret == RFAILED)
13311          {
13312             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13313             break;
13314          }
13315       }
13316    }
13317    else
13318       ret = RFAILED;
13319
13320    return ret;
13321 }
13322
13323 /*******************************************************************
13324  *
13325  * @brief Fills Drb List received by CU
13326  *
13327  * @details
13328  *
13329  *    Function : procDrbListToSetupMod
13330  *
13331  *    Functionality: Fills Drb List received by CU
13332  *                   for both MAC and RLC
13333  *
13334  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13335  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13336  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13337  * @return void
13338  *
13339  * ****************************************************************/
13340
13341 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13342 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13343 {
13344    uint8_t cfgIdx = 0;
13345    RlcMode rlcModeInfo;
13346
13347    if(drbItem != NULLP)
13348    {
13349       /* Filling RLC INFO */
13350       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13351       qoSInformation);
13352
13353       /* Filling MAC INFO */
13354       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13355       { 
13356          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13357          return RFAILED;
13358       }
13359    }
13360    else if(drbSetupModItem != NULLP)
13361    {
13362       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13363       &drbSetupModItem->qoSInformation);
13364
13365       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13366       {
13367          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13368          return RFAILED;
13369       }
13370    }
13371    else if(drbModItem != NULLP)
13372    {
13373       /* Drb to Mod IEs doesnot have rlcMode to be modified
13374        * in ASN. Hence no change in RLC configurations */
13375       if(storedRlcUeCfg != NULLP)
13376       {
13377          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13378          {
13379             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13380             {
13381                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13382                break;
13383             }
13384          }
13385       }
13386
13387       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13388       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13389       {
13390          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13391          return RFAILED;
13392       }
13393    }
13394    return ROK;
13395 }
13396
13397 /*******************************************************************
13398  *
13399  * @brief extract Drb List received by CU
13400  *
13401  * @details
13402  *
13403  *    Function : extractDrbListToSetupMod
13404  *
13405  *    Functionality: extract Drb List received by CU
13406  *                   for both MAC and RLC
13407  *
13408  * @params[in] DRBs_ToBeSetup_Item_t pointer
13409  *             DuUeCfg pointer
13410  * @return ROK/RFAIED
13411  *
13412  * ****************************************************************/
13413
13414 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13415  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13416 {
13417    uint8_t ret = ROK;
13418    uint8_t drbIdx = 0, rlcLcIdx = 0;
13419    uint8_t drbId = 0, lcId = 0;
13420    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13421    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13422    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13423    DuLcCfg *macLcCtxt = NULLP;
13424    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13425
13426    ret = ROK;
13427    if(drbCount > 0)
13428    {
13429       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13430       {
13431          macLcCtxt = NULL;
13432          rlcLcCtxt = NULL;
13433
13434          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13435          { 
13436             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13437             ret = RFAILED;
13438             break;
13439          }
13440          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13441          {
13442             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13443             ret = RFAILED;
13444             break;
13445          }
13446
13447          if(drbModCfg != NULLP)
13448          {
13449             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13450             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13451          }
13452          else if(drbCfg != NULLP)
13453             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13454          else if(drbSetupModCfg != NULL)
13455          {
13456             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13457             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13458          }
13459
13460          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13461          {
13462             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13463                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13464             {
13465                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13466                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13467                break;
13468             }
13469          }
13470          if(!macLcCtxt)
13471          {
13472             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13473             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13474             ueCfgDb->numMacLcs++;
13475          }
13476          if(!rlcLcCtxt)
13477          {
13478             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13479             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13480             ueCfgDb->numRlcLcs++;
13481          }
13482
13483          if(drbModCfg != NULLP)
13484          {
13485             lcId = fetchLcId(drbId);
13486             if(lcId < MIN_DRB_LCID)
13487             {
13488                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13489                break;
13490             } 
13491             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13492             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13493             if(ret == RFAILED)
13494             {
13495                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13496                break;
13497             }
13498             ueCfgDb->numDrbModified++;
13499          }
13500          else
13501          {
13502             lcId = getDrbLcId(drbBitMap);
13503             if(lcId == RFAILED)
13504             {
13505                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13506                ret = RFAILED;
13507                break;
13508             }
13509             if(drbCfg != NULL)
13510             {
13511                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13512                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13513                if(ret == RFAILED)
13514                {
13515                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13516                   break;
13517                }
13518             }
13519             else if(drbSetupModCfg != NULL)
13520             {
13521                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13522                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13523                if(ret == RFAILED)
13524                {
13525                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13526                   break;
13527                }
13528                ueCfgDb->numDrbSetupMod++;
13529             }
13530          }
13531          ueCfgDb->numDrb++;
13532  
13533          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13534                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13535          if(ret == RFAILED)
13536          {
13537             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13538             break;
13539          }
13540       }
13541    }
13542    else
13543       ret = RFAILED;
13544
13545    return ret;
13546 }
13547
13548 /*******************************************************************
13549  *
13550  * @brief extract Drb List received from CU
13551  *
13552  * @details
13553  *
13554  *    Function : extractDrbListToRelease
13555  *
13556  *    Functionality: extract Drb List received from CU
13557  *                   for both MAC and RLC
13558  *
13559  * @params[in] DRBs_ToBeReleased_Item_t pointer
13560  *             DuUeCfg pointer
13561  * @return ROK/RFAIED
13562  *
13563  * ****************************************************************/
13564
13565 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13566 {
13567    uint8_t ret = ROK, teIdx = 0;
13568    uint8_t drbIdx = 0, rlcLcIdx = 0;
13569    uint8_t drbId = 0, lcId = 0;
13570    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13571    DuLcCfg *macLcCtxt = NULLP;
13572    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13573
13574    ret = ROK;
13575    if(drbCount > 0)
13576    {
13577       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13578       {
13579          macLcCtxt = NULL;
13580          rlcLcCtxt = NULL;
13581
13582          if(drbToRel != NULLP)
13583          {
13584             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13585             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13586          }
13587          else
13588          {
13589             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13590             return RFAILED;
13591          }
13592
13593          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13594          {
13595             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13596             {
13597                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13598                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13599                break;
13600             }
13601          }
13602
13603          if(!macLcCtxt)
13604          {
13605             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13606             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13607             ueCfgDb->numMacLcs++;
13608          }
13609          if(!rlcLcCtxt)
13610          {
13611             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13612             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13613             ueCfgDb->numRlcLcs++;
13614          }
13615          lcId = fetchLcId(drbId);
13616          if(lcId < MIN_DRB_LCID)
13617          {
13618             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13619             break;
13620          } 
13621
13622          /* Filling RLC INFO */
13623          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13624          /* Filling MAC INFO */
13625          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13626          { 
13627             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13628             return RFAILED;
13629          }
13630          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13631          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13632          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13633
13634          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13635          {
13636             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13637                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13638             {
13639                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13640                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13641                break;
13642             }
13643          }
13644
13645          ueCfgDb->numDrb++;
13646          if(ret == RFAILED)
13647          {
13648             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13649             break;
13650          }
13651
13652          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13653                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13654       }
13655    }
13656    else
13657       ret = RFAILED;
13658
13659    return ret;
13660 }
13661
13662 /*******************************************************************
13663  *
13664  * @brief Function to extract Dl RRC Msg received from CU
13665  *
13666  * @details
13667  *
13668  *    Function : extractDlRrcMsg
13669  *
13670  *    Functionality: Function to extract Dl RRC Msg received from CU
13671  *
13672  * @params[in] F1AP message
13673  * @return ROK     - success
13674  *         RFAILED - failure
13675  *
13676  * ****************************************************************/
13677
13678 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13679    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13680 {
13681    uint8_t ret = ROK;
13682    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13683    if(dlRrcMsg->rrcMsgSize > 0)
13684    {
13685       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13686       if(!dlRrcMsg->rrcMsgPdu)
13687       {
13688          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13689          ret = RFAILED;
13690       }
13691       else
13692       {
13693          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13694          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13695          dlRrcMsg->srbId = SRB1_LCID;
13696          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13697       }
13698    }
13699    return ret;
13700 }
13701
13702 /*******************************************************************
13703  *
13704  * @brief Extract UE capability info 
13705  *
13706  * @details
13707  *
13708  *    Function : extractUeCapability
13709  *
13710  *    Functionality: Extract UE capability info and stores in ue Cb
13711  *
13712  * @params[in] Octet string of UE capability RAT container list
13713  * @return ROK     - success
13714  *         RFAILED - failure
13715  *
13716  * ****************************************************************/
13717 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13718 {
13719    uint8_t  idx;
13720    uint16_t recvBufLen;
13721    asn_dec_rval_t rval;
13722    UE_NR_Capability_t  *ueNrCap = NULLP;
13723    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13724
13725    /* Decoding UE Capability RAT Container List */
13726    recvBufLen = ueCapablityListBuf->size;
13727    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13728    if(!ueCapRatContList)
13729    {
13730       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13731       return NULLP;
13732    }
13733    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13734    memset(&rval, 0, sizeof(asn_dec_rval_t));
13735    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13736           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13737    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13738    {
13739       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13740       return NULLP;
13741    }
13742    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13743
13744    /* Free encoded buffer after decoding */
13745
13746    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13747    {
13748       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13749       {
13750          /* Decoding UE NR Capability */
13751           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13752           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13753           if(!ueNrCap)
13754           {
13755              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13756              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13757              return NULLP;
13758           } 
13759           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13760           memset(&rval, 0, sizeof(asn_dec_rval_t));
13761           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13762                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13763           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13764           {
13765              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13766              return NULLP;
13767           }
13768           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13769           
13770           /* Free encoded buffer after decoding */
13771           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13772       }
13773       free(ueCapRatContList->list.array[idx]);
13774    }
13775
13776    /* Free Memory*/
13777    free(ueCapRatContList->list.array);
13778    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13779    return ueNrCap;
13780 }
13781  
13782 /*******************************************************************
13783 *
13784 * @brief free UE context setup request from CU
13785 *
13786 * @details
13787 *
13788 *    Function : freeAperDecodeF1UeContextSetupReq
13789 *
13790 *    Functionality: freeing part for the memory allocated by aper_decoder
13791 *
13792 * @params[in] F1AP message
13793 * @return ROK     - success
13794 *         RFAILED - failure
13795 *
13796 * ****************************************************************/
13797 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13798 {
13799    uint8_t ieIdx = 0;
13800
13801    if(ueSetReq->protocolIEs.list.array != NULLP)
13802    {
13803       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13804       {
13805          if(ueSetReq->protocolIEs.list.array[ieIdx])
13806          {
13807             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13808             {
13809                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13810                   break;
13811                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13812                   break;
13813                case ProtocolIE_ID_id_SpCell_ID:
13814                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13815                   break;
13816                case ProtocolIE_ID_id_ServCellIndex:
13817                   break;
13818                case ProtocolIE_ID_id_SpCellULConfigured:
13819                   break;
13820                case ProtocolIE_ID_id_CUtoDURRCInformation:
13821
13822                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13823                   break;
13824                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13825
13826                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13827                   break;
13828                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13829
13830                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13831                   break;
13832                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13833
13834                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13835                   break;
13836                case ProtocolIE_ID_id_RRCContainer:
13837                   {
13838
13839                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13840                      {
13841
13842                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13843                      }
13844                      break;
13845                   }
13846                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13847                   break;
13848                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13849                   {
13850                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13851                      {
13852                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13853                      }
13854                      break;
13855                   }
13856 #ifdef NR_DRX
13857                case ProtocolIE_ID_id_DRXCycle:
13858                   {
13859                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13860                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13861                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13862                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13863                      break;
13864                   }
13865 #endif             
13866                 default:
13867                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13868             } 
13869             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13870          }
13871       }
13872       free(ueSetReq->protocolIEs.list.array);
13873    }
13874 }
13875 /*******************************************************************
13876  *
13877  * @brief Process UE context setup request from CU
13878  *
13879  * @details
13880  *
13881  *    Function : procF1UeContextSetupReq
13882  *
13883  *    Functionality: Process UE context setup request from CU
13884  *
13885  * @params[in] F1AP message
13886  * @return ROK     - success
13887  *         RFAILED - failure
13888  *
13889  * ****************************************************************/
13890 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13891 {
13892    int8_t ueIdx = -1;
13893    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13894    //uint8_t servCellIdx = 0;
13895    bool ueCbFound = false, hoInProgress = false;
13896    uint16_t cellIdx=0;
13897    uint64_t nrCellId = 0;
13898    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13899    DuUeCb   *duUeCb = NULL;
13900    UEContextSetupRequest_t   *ueSetReq = NULL;
13901    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13902    CUtoDURRCInformation_t *rrcInfo = NULL;
13903 #ifdef NR_DRX
13904    DRXCycle_t *drxCycle;
13905 #endif
13906    ret = ROK;
13907
13908    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13909    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13910    {
13911       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13912       {
13913          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13914             {
13915                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13916                break;
13917             }
13918
13919          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13920             {
13921                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13922                break;
13923             }
13924
13925          case ProtocolIE_ID_id_SpCell_ID:
13926             {
13927                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13928
13929                GET_CELL_IDX(nrCellId, cellIdx);
13930                if(!duCb.actvCellLst[cellIdx])
13931                {
13932                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13933                   ret = RFAILED;
13934                }
13935                break;
13936             }
13937
13938          case ProtocolIE_ID_id_ServCellIndex:
13939             {
13940                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13941                break;
13942             }
13943
13944          case ProtocolIE_ID_id_SpCellULConfigured:
13945             {
13946                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13947                   UL, SUL or UL+SUL for the indicated cell for the UE */
13948                break;
13949             }
13950
13951          case ProtocolIE_ID_id_CUtoDURRCInformation:
13952             {
13953                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13954
13955                /* Search if UE context is present */
13956                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13957                {
13958                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13959                   {
13960                      ueCbFound = true;
13961                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13962                      break;
13963                   }
13964                }
13965
13966                /* Check if UE Handover scenario */
13967                if(rrcInfo->iE_Extensions)
13968                {
13969                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13970                   {
13971                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13972                      {
13973                         hoInProgress = true;
13974                         break;
13975                      }
13976                   }
13977                }
13978                
13979                /* If UE context is not present, but UE is in handover */
13980                if(!ueCbFound && hoInProgress)
13981                {
13982                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13983                   if(ueIdx != -1)
13984                      gnbDuUeF1apId = ueIdx +1;
13985                   else
13986                   {
13987                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13988                      ret = RFAILED;
13989                      break;
13990                   }
13991                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13992                   duUeCb->f1UeDb = NULL;
13993                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13994                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13995                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13996                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13997                }
13998
13999                if(duUeCb)
14000                {
14001                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14002                   if(duUeCb->f1UeDb)
14003                   {
14004                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14005                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14006                      duUeCb->f1UeDb->cellIdx = cellIdx;
14007                   }
14008                   else
14009                   {
14010                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14011                      ret = RFAILED;
14012                      break;
14013                   }
14014                }
14015                else
14016                {
14017                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14018                   ret = RFAILED;
14019                   break;
14020                }
14021                  
14022                /* Extract UE capability info */
14023                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14024                {
14025                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14026                }
14027
14028                /* Extract IE extension */
14029                if(rrcInfo->iE_Extensions)
14030                {
14031                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14032                   {
14033                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14034                      //TODO: Update the failure cause in ue context Setup Response
14035                      ret = RFAILED;
14036                   }
14037                }
14038                break;
14039             } 
14040
14041 #ifdef NR_DRX
14042          case ProtocolIE_ID_id_DRXCycle:
14043             {
14044                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14045                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14046                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14047                if(drxCycle->shortDRXCycleLength)
14048                {
14049                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14050                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14051                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14052                }
14053                if(drxCycle->shortDRXCycleTimer)
14054                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14055
14056                break;
14057             }
14058
14059 #endif
14060          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14061             {
14062                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14063                         &duUeCb->f1UeDb->duUeCfg))
14064                {
14065                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14066                   //TODO: Update the failure cause in ue context Setup Response
14067                   ret = RFAILED;
14068                }
14069                break;
14070             }
14071
14072          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14073             {
14074                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14075
14076                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14077                {
14078                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14079                   //TODO: Update the failure cause in ue context Setup Response
14080                   ret = RFAILED;
14081                }
14082                break;
14083             }
14084          case ProtocolIE_ID_id_RRCContainer:
14085             {
14086                /* Filling Dl RRC Msg Info */
14087                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14088                if(!duUeCb->f1UeDb->dlRrcMsg)
14089                {
14090                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14091                   ret = RFAILED;
14092                }
14093                else
14094                {
14095                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14096                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14097                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14098                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14099                }          
14100                break;
14101             }
14102
14103          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14104             {
14105                if(duUeCb->f1UeDb->dlRrcMsg)
14106                {
14107                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14108                   {
14109                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14110                   }
14111                   else
14112                   {
14113                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14114                   }
14115                }
14116                break;
14117             }
14118
14119          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14120             {
14121                /* MaximumBitRate Uplink */
14122                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14123                if(bitRateSize > 0)
14124                {
14125                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14126                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14127                   {
14128                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14129                      ret = RFAILED;
14130                   }
14131                   else
14132                   {
14133                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14134                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14135                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14136                   }
14137                }
14138                else
14139                   ret = RFAILED;
14140                break;
14141             }
14142
14143          default:
14144             {
14145                break;
14146             }
14147       } /* End of switch */
14148
14149       /* In case of any failure in any IE */
14150       if(ret == RFAILED)
14151       {
14152          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14153          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14154          break;
14155       }
14156    } /* End of for loop of IEs */
14157
14158    if(ret == ROK)
14159       ret = duProcUeContextSetupRequest(duUeCb);
14160
14161    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14162    return ret;
14163
14164 }
14165 /*******************************************************************
14166  * @brief Free the memory allocated for Dl Tunnel Info
14167  *
14168  * @details
14169  *
14170  *    Function : freeDlTnlInfo
14171  *
14172  *    Functionality:
14173  *       Free the memory allocated for Dl Tunnel Info
14174  *
14175  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14176  * @return void
14177  *
14178  * ****************************************************************/
14179
14180 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14181 {
14182    uint8_t arrIdx = 0;
14183
14184    if(tnlInfo)
14185    {
14186       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14187       {
14188          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14189                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14190          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14191                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14192          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14193          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14194       }
14195       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14196    }
14197 }
14198
14199 /*******************************************************************
14200  * @brief Free the memory allocated for DRB setup List
14201  *
14202  * @details
14203  *
14204  *    Function : freeDrbSetupList
14205  *
14206  *    Functionality:
14207  *       Free the memory allocated for DRB setup list
14208  *
14209  * @params[in] DRBs_Setup_List_t *
14210  * @return void
14211  *
14212  * ****************************************************************/
14213 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14214 {
14215    uint8_t arrIdx = 0;
14216    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14217
14218    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14219    {
14220       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14221       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14222       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14223    }
14224    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14225 }
14226
14227 /*******************************************************************
14228  * @brief Free the memory allocated for UE Setup response
14229  *
14230  * @details
14231  *
14232  *    Function : FreeUeContextSetupRsp
14233  *
14234  *    Functionality:
14235  *       Free the memory allocated for UE Setup response
14236  *
14237  * @params[in] F1AP PDU for UE setup response
14238  * @return ROK     - success
14239  *         RFAILED - failure
14240  *
14241  * ****************************************************************/
14242 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14243 {
14244    uint8_t idx;
14245    UEContextSetupResponse_t *ueSetRsp = NULLP;
14246
14247    if(f1apMsg)
14248    {
14249       if(f1apMsg->choice.successfulOutcome)
14250       {
14251          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14252                     UEContextSetupResponse;
14253          if(ueSetRsp->protocolIEs.list.array)
14254          {
14255             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14256             {
14257                if(ueSetRsp->protocolIEs.list.array[idx])
14258                {
14259                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14260                   {
14261                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14262                         break;
14263                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14264                         break;
14265                      case ProtocolIE_ID_id_C_RNTI:
14266                         break;
14267                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14268                         {
14269                            CellGroupConfig_t *cellGrpCfg = NULLP;
14270                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14271                                          DUtoCURRCInformation.cellGroupConfig;
14272                            if(cellGrpCfg->buf != NULLP)
14273                            {
14274                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14275                               cellGrpCfg = NULLP;
14276                            }
14277                            break;
14278                         }
14279                      case ProtocolIE_ID_id_DRBs_Setup_List:
14280                         {
14281                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14282                            break;
14283                         }
14284                      default:
14285                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14286                               ueSetRsp->protocolIEs.list.array[idx]->id);
14287                         break;
14288                   }
14289                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14290                         sizeof(UEContextSetupResponseIEs_t));
14291                }
14292             }
14293             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14294                   ueSetRsp->protocolIEs.list.size);
14295          }
14296          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14297       }
14298       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14299    }
14300 }
14301
14302 /*******************************************************************
14303  *
14304  * @brief Builds Ue context Setup Rsp DU To CU Info
14305  *
14306  * @details
14307  *
14308  *    Function : EncodeUeCntxtDuToCuInfo
14309  *
14310  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14311  *
14312  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14313  *
14314  * @return ROK     - success
14315  *         RFAILED - failure
14316  *
14317  ******************************************************************/
14318
14319 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14320 {
14321    asn_enc_rval_t        encRetVal;
14322
14323    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14324    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14325    encBufSize = 0;
14326    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14327    /* Encode results */
14328    if(encRetVal.encoded == ENCODE_FAIL)
14329    {
14330       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14331             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14332       return RFAILED;
14333    }
14334    else
14335    {
14336       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14337 #ifdef DEBUG_ASN_PRINT
14338       for(int i=0; i< encBufSize; i++)
14339       {
14340          printf("%x",encBuf[i]);
14341       }
14342 #endif
14343    }
14344    duToCuCellGrp->size = encBufSize;
14345    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14346    if(!duToCuCellGrp->buf)
14347    {
14348       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14349    }
14350    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14351    return ROK;
14352 }
14353
14354 /*******************************************************************
14355  *
14356  * @brief Fills Dl Gtp tunnel Info
14357  *
14358  * @details
14359  *
14360  *    Function : fillGtpTunnelforDl
14361  *
14362  *    Functionality: Fills Dl Gtp tunnel Info
14363  *
14364  * @params[in] 
14365  *
14366  * @return ROK     - success
14367  *         RFAILED - failure
14368  *
14369  * ****************************************************************/
14370
14371 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14372 {
14373    uint8_t bufSize = 0;
14374
14375    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14376    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14377    if(gtpDl->transportLayerAddress.buf == NULLP)
14378    {
14379       return RFAILED;
14380    }
14381    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14382
14383    /*GTP TEID*/
14384    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14385    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14386    if(gtpDl->gTP_TEID.buf == NULLP)
14387    {
14388       return RFAILED;
14389    }
14390    bufSize = 3; /*forming an Octect String*/
14391    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14392
14393    return ROK;
14394 }
14395
14396 /*******************************************************************
14397  *
14398  * @brief Fills DL Tunnel Setup List
14399  *
14400  * @details
14401  *
14402  *    Function : fillDlTnlSetupList
14403  *
14404  *    Functionality: Fills the DL Tunnel Setup List
14405  *
14406  * @params[in] 
14407  *
14408  * @return ROK     - success
14409  *         RFAILED - failure
14410  *
14411  * ****************************************************************/
14412
14413 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14414 {
14415    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14416
14417    eleCount = 1;
14418    dlTnlInfo->list.count = eleCount; 
14419    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14420
14421    /* Initialize the DL Tnl Setup List Members */
14422    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14423    if(dlTnlInfo->list.array == NULLP)
14424    {
14425       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14426       ret = RFAILED;
14427    }
14428    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14429    {
14430       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14431       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14432       {
14433          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14434          return RFAILED;
14435       }
14436       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14437       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14438       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14439       {
14440          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14441          return RFAILED;
14442       }
14443       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14444                tnlCfg->tnlCfg1);
14445       if(ret != ROK)
14446          break;
14447    }
14448    return ret;
14449 }
14450
14451 /*******************************************************************
14452  *
14453  * @brief Fills the Drb Setup List for Ue Context Setup Response
14454  *
14455  * @details
14456  *
14457  *    Function : fillDrbSetupList
14458  *
14459  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14460  *
14461  * @params[in] 
14462  *
14463  * @return ROK     - success
14464  *         RFAILED - failure
14465  *
14466  * ****************************************************************/
14467 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14468 {
14469    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14470    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14471
14472    eleCount = ueCfg->numDrb;
14473    drbSetupList->list.count = eleCount;
14474    drbSetupList->list.size = \
14475         (eleCount * sizeof(DRBs_Setup_Item_t *));
14476
14477    /* Initialize the Drb Setup List Members */
14478    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14479    if(drbSetupList->list.array == NULLP)
14480    {
14481       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14482       ret = RFAILED;
14483    }
14484
14485    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14486    {
14487       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14488       if(drbSetupList->list.array[arrIdx] == NULLP)
14489       {
14490          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14491          return RFAILED;
14492       }
14493       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14494       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14495       drbItemIe->criticality = Criticality_reject;
14496       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14497       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14498       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14499           &ueCfg->upTnlInfo[arrIdx]);
14500       if(ret != ROK)
14501          break;
14502    }
14503    return ret;
14504 }
14505
14506 /*******************************************************************
14507  *
14508  * @brief Builds and sends the UE Setup Response
14509  *
14510  * @details
14511  *
14512  *    Function : BuildAndSendUeContextSetupRsp
14513  *
14514  *    Functionality: Constructs the UE Setup Response and sends
14515  *                   it to the DU through SCTP.
14516  *
14517  * @params[in] uint8_t cellId,uint8_t ueId
14518  *
14519  * @return ROK     - success
14520  *         RFAILED - failure
14521  *
14522  * ****************************************************************/
14523 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14524 {
14525    uint8_t   idx, ret, cellIdx, elementCnt;
14526    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14527    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14528    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14529    F1AP_PDU_t               *f1apMsg = NULLP;
14530    UEContextSetupResponse_t *ueSetRsp = NULLP;
14531    DuUeCb                   *ueCb = NULLP;
14532
14533    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14534
14535    while(true)
14536    {
14537       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14538       if(f1apMsg == NULLP)
14539       {
14540          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14541          ret = RFAILED;
14542          break;
14543       }
14544
14545       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14546       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14547             sizeof(SuccessfulOutcome_t));
14548       if(f1apMsg->choice.successfulOutcome == NULLP)
14549       {
14550          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14551          ret = RFAILED;
14552          break;
14553       }
14554
14555       f1apMsg->choice.successfulOutcome->procedureCode = \
14556                                                          ProcedureCode_id_UEContextSetup;
14557       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14558       f1apMsg->choice.successfulOutcome->value.present = \
14559                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14560
14561       ueSetRsp =
14562          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14563       elementCnt = 5;
14564       ueSetRsp->protocolIEs.list.count = elementCnt;
14565       ueSetRsp->protocolIEs.list.size = \
14566                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14567
14568       /* Initialize the UESetup members */
14569       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14570             ueSetRsp->protocolIEs.list.size);
14571       if(ueSetRsp->protocolIEs.list.array == NULLP)
14572       {
14573          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14574          ret = RFAILED;
14575          break;
14576       }
14577
14578       for(idx=0; idx<elementCnt; idx++)
14579       {
14580          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14581                sizeof(UEContextSetupResponseIEs_t));
14582          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14583          {
14584             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14585             ret = RFAILED;
14586             break;
14587          }
14588       }
14589       /* Fetching Ue Cb Info*/
14590       GET_CELL_IDX(cellId, cellIdx);
14591       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14592       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14593       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14594
14595       idx = 0;
14596       /*GNB CU UE F1AP ID*/
14597       ueSetRsp->protocolIEs.list.array[idx]->id = \
14598                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14599       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14600       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14601                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14602       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14603
14604       /*GNB DU UE F1AP ID*/
14605       idx++;
14606       ueSetRsp->protocolIEs.list.array[idx]->id = \
14607                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14608       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14609       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14610                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14611       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14612
14613
14614       /*DUtoCURRC Information */
14615       idx++;
14616       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14617                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14618       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14619       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14620                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14621       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14622
14623       /* CRNTI */
14624       idx++;
14625       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14626       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14627       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14628       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14629
14630
14631       /* Drb Setup List */
14632       idx++;
14633       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14634                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14635       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14636       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14637                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14638       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14639             &ueCb->f1UeDb->duUeCfg);
14640       if(ret == RFAILED)
14641       {
14642          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14643          freeF1UeDb(ueCb->f1UeDb);
14644          ueCb->f1UeDb = NULLP;
14645          break;
14646       }
14647
14648       /* Free UeContext Db created during Ue context Req */
14649       freeF1UeDb(ueCb->f1UeDb);
14650       ueCb->f1UeDb = NULLP;
14651
14652       /* TODO: To send Drb list */
14653       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14654
14655       /* Encode the UE context setup response type as APER */
14656       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14657       encBufSize = 0;
14658       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14659             encBuf);
14660       /* Encode results */
14661       if(encRetVal.encoded == ENCODE_FAIL)
14662       {
14663          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14664                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14665          ret = RFAILED;
14666          break;
14667       }
14668       else
14669       {
14670          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14671 #ifdef DEBUG_ASN_PRINT
14672          for(int i=0; i< encBufSize; i++)
14673          {
14674             printf("%x",encBuf[i]);
14675          }
14676 #endif
14677       }
14678
14679       /* Sending  msg  */
14680       if(sendF1APMsg()  != ROK)
14681       {
14682          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14683          ret = RFAILED;
14684          break;
14685       }
14686       break;
14687    }
14688    FreeUeContextSetupRsp(f1apMsg);
14689    return ret;
14690 }/* End of BuildAndSendUeContextSetupRsp */
14691
14692 /*******************************************************************
14693 *
14694 * @brief  Build And Send Ue Context Rsp 
14695 *
14696 * @details
14697 *
14698 *    Function : BuildAndSendUeCtxtRsp 
14699 *
14700 *    Functionality : Build And Send Ue Context Rsp
14701
14702 * @params[in]
14703 * @return sucess = ROK
14704 *         failure = RFAILED
14705 *
14706 * ****************************************************************/
14707 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14708 {
14709    uint8_t cellIdx = 0, actionType = 0; 
14710
14711    GET_CELL_IDX(cellId, cellIdx);
14712    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14713
14714    switch(actionType)
14715    {
14716       case UE_CTXT_SETUP:
14717          {
14718             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14719             {
14720                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14721                return RFAILED;
14722             }
14723             break;
14724          }
14725       case UE_CTXT_MOD:
14726          {
14727             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14728             {
14729                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14730                return RFAILED;
14731             }
14732             break;
14733          }
14734       default:
14735          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14736          break;
14737
14738    }
14739    return ROK;
14740 }
14741
14742 /*******************************************************************
14743  *
14744  * @brief deallocating the memory of  F1reset msg
14745  *
14746  * @details
14747  *
14748  *    Function : FreeF1ResetReq
14749  *
14750  *    Functionality :
14751  *         - freeing memory of F1reset request msg
14752  *
14753  * @params[in]
14754  * @return void
14755  *
14756  *
14757  * ****************************************************************/
14758 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14759 {
14760    uint8_t idx =0 ;
14761    Reset_t *f1ResetMsg;
14762
14763    if(f1apMsg)
14764    {
14765       if(f1apMsg->choice.initiatingMessage)
14766       {
14767          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14768
14769          if(f1ResetMsg->protocolIEs.list.array)
14770          {
14771             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14772             {
14773                if(f1ResetMsg->protocolIEs.list.array[idx])
14774                {
14775                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14776                }
14777             }
14778             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14779          }
14780          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14781       }
14782       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14783    }
14784 }
14785 /*******************************************************************
14786  *
14787  * @brief Build and Send F1reset request 
14788  *
14789  * @details
14790  *
14791  *    Function : BuildAndSendF1ResetReq
14792  *
14793  *    Functionality:
14794  *         - Build and Send F1reset request msg
14795  *
14796  * @params[in]
14797  * @return ROK     - success
14798  *         RFAILED - failure
14799  *
14800  * ****************************************************************/
14801 uint8_t BuildAndSendF1ResetReq()
14802 {
14803    uint8_t          elementCnt=0;
14804    uint8_t          idx=0;
14805    uint8_t          ret= RFAILED;
14806    Reset_t          *f1ResetMsg = NULLP;
14807    F1AP_PDU_t       *f1apMsg = NULLP;
14808    asn_enc_rval_t   encRetVal;
14809    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14810    do
14811    {
14812       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14813       if(f1apMsg == NULLP)
14814       {
14815          break;
14816       }
14817       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14818       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14819       if(f1apMsg->choice.initiatingMessage == NULLP)
14820       {
14821          break;
14822       }
14823       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14824       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14825       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14826
14827       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14828
14829       elementCnt = 3;
14830       f1ResetMsg->protocolIEs.list.count = elementCnt;
14831       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14832
14833       /* Initialize the F1Setup members */
14834       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14835       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14836       {
14837          break;
14838       }
14839       for(idx=0; idx<elementCnt; idx++)
14840       {
14841          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14842          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14843          {
14844             break;
14845          }
14846       }
14847
14848       /*TransactionID*/
14849       idx=0;
14850       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14851       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14852       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14853       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14854
14855       /*Cause*/
14856       idx++;
14857       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14858       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14859       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14860       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14861       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14862
14863       /*Reset Type*/
14864       idx++;
14865       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14866       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14867       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14868       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14869       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14870
14871       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14872
14873       /* Encode the F1SetupRequest type as APER */
14874       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14875       encBufSize = 0;
14876       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14877             encBuf);
14878
14879       /* Encode results */
14880       if(encRetVal.encoded == ENCODE_FAIL)
14881       {
14882          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14883                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14884          break;
14885       }
14886       else
14887       {
14888          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14889 #ifdef DEBUG_ASN_PRINT
14890          for(idx=0; idx< encBufSize; idx++)
14891          {
14892             printf("%x",encBuf[idx]);
14893          }
14894 #endif
14895       }
14896
14897       if(sendF1APMsg() != ROK)
14898       {
14899          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14900          break;
14901       }
14902
14903       ret = ROK;
14904       break;
14905    }while(true);
14906
14907    FreeF1ResetReq(f1apMsg);
14908    return ret;
14909 }
14910 /*******************************************************************
14911  *
14912  * @brief Build And Send F1ResetAck
14913  *
14914  * @details
14915  *
14916  *    Function : BuildAndSendF1ResetAck
14917  *
14918  *    Functionality:
14919  *         - Build And Send  F1ResetRSP
14920  *
14921  * @return ROK     - success
14922  *         RFAILED - failure
14923  *
14924  * ****************************************************************/
14925 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14926 {
14927    uint8_t idx;
14928    ResetAcknowledge_t *f1ResetAck;
14929
14930    if(f1apMsg)
14931    {
14932       if(f1apMsg->choice.successfulOutcome)
14933       {
14934          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14935
14936          if(f1ResetAck->protocolIEs.list.array)
14937          {
14938             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14939             {
14940                if(f1ResetAck->protocolIEs.list.array[idx])
14941                {
14942                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14943                }
14944             }
14945             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14946          }
14947          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14948       }
14949       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14950    }
14951 }
14952
14953 /*******************************************************************
14954  *
14955  * @brief Build And Send F1ResetAck
14956  *
14957  * @details
14958  *
14959  *    Function : BuildAndSendF1ResetAck
14960  *
14961  *    Functionality:
14962  *         - Build And Send  F1ResetRSP
14963  *
14964  *  @params[in]
14965  * @return ROK     - success
14966  *         RFAILED - failure
14967  *
14968  * ****************************************************************/
14969 uint8_t BuildAndSendF1ResetAck()
14970 {
14971    uint8_t                idx = 0;
14972    uint8_t                elementCnt = 0;
14973    uint8_t                ret = RFAILED;
14974    F1AP_PDU_t             *f1apMsg = NULL;
14975    ResetAcknowledge_t     *f1ResetAck = NULLP;
14976    asn_enc_rval_t         encRetVal;
14977    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14978
14979    do{
14980       /* Allocate the memory for F1ResetRequest_t */
14981       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14982       if(f1apMsg == NULLP)
14983       {
14984          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14985          break;
14986       }
14987
14988       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14989
14990       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14991       if(f1apMsg->choice.successfulOutcome == NULLP)
14992       {
14993          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14994          break;
14995       }
14996       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14997       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14998       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14999
15000       elementCnt = 1;
15001
15002       f1ResetAck->protocolIEs.list.count = elementCnt;
15003       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15004
15005       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15006       if(f1ResetAck->protocolIEs.list.array == NULLP)
15007       {
15008          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15009          break;
15010       }
15011
15012       for(idx=0; idx<elementCnt; idx++)
15013       {
15014          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15015          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15016          {
15017             break;
15018          }
15019       }
15020       /*TransactionID*/
15021       idx = 0;
15022       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15023       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15024       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15025       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15026
15027       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15028
15029       /* Encode the F1SetupRequest type as UPER */
15030       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15031       encBufSize = 0;
15032       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15033
15034       /* Check encode results */
15035       if(encRetVal.encoded == ENCODE_FAIL)
15036       {
15037          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15038                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15039          break;
15040       }
15041       else
15042       {
15043          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15044 #ifdef DEBUG_ASN_PRINT
15045          for(int i=0; i< encBufSize; i++)
15046          {
15047             printf("%x",encBuf[i]);
15048          }
15049 #endif
15050       }
15051       /* Sending msg */
15052       if(sendF1APMsg() != ROK)
15053       {
15054          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15055          break;
15056       }
15057
15058       ret = ROK;
15059       break;
15060    }while(true);
15061
15062    FreeF1ResetAck(f1apMsg);
15063    return ret;
15064 }
15065 /******************************************************************
15066 *
15067 * @brief free F1 reset msg allocated by aper_decoder 
15068 *
15069 * @details
15070 *
15071 *    Function : freeAperDecodeF1ResetMsg 
15072 *
15073 *    Functionality: free F1 reset msg allocated by aper_decoder 
15074 *
15075 * @params[in] Reset_t *f1ResetMsg 
15076 * @return void 
15077 *
15078 * ****************************************************************/
15079
15080 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15081 {
15082    uint8_t ieIdx =0;
15083    if(f1ResetMsg->protocolIEs.list.array)
15084    {
15085       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15086       {
15087          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15088          {
15089             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15090          }
15091       }
15092       free(f1ResetMsg->protocolIEs.list.array);
15093    }
15094 }
15095
15096 /******************************************************************
15097  *
15098  * @brief Processes DL RRC Message Transfer  sent by CU
15099  *
15100  * @details
15101  *
15102  *    Function : procF1ResetReq
15103  *
15104  *    Functionality: Processes DL RRC Message Transfer sent by CU
15105  *
15106  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15107  * @return ROK     - success
15108  *         RFAILED - failure
15109  *
15110  * ****************************************************************/
15111 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15112 {
15113    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15114    uint8_t       ieIdx = 0;
15115    uint8_t        ret = ROK;
15116    Reset_t       *f1ResetMsg = NULLP;
15117
15118    DU_LOG("\nINFO   -->  Processing F1 reset request");
15119    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15120
15121    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15122    {
15123       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15124       {
15125          case ProtocolIE_ID_id_TransactionID:
15126             break;
15127
15128          case ProtocolIE_ID_id_Cause:
15129             break;
15130
15131          case ProtocolIE_ID_id_ResetType:
15132             {
15133                break;
15134             }
15135
15136          default:
15137             break;
15138       }
15139    }
15140    ret = BuildAndSendF1ResetAck();
15141    DU_LOG("\nINFO   -->  UE release is not supported for now");
15142
15143    freeAperDecodeF1ResetMsg(f1ResetMsg);
15144
15145    return ret;
15146 }
15147
15148 /*******************************************************************
15149  *
15150  * @brief free the RRC delivery report
15151  *
15152  * @details
15153  *
15154  *    Function : freeRrcDeliveryReport
15155  *
15156  *    Functionality: free the RRC delivery report
15157  *
15158  * @params[in]
15159  * @return ROK     - success
15160  *         RFAILED - failure
15161  *
15162  * ****************************************************************/
15163 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15164 {
15165    uint8_t idx=0;
15166    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15167
15168    if(f1apMsg)
15169    {
15170       if(f1apMsg->choice.initiatingMessage)
15171       {
15172          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15173          if(rrcDeliveryReport->protocolIEs.list.array)
15174          {
15175             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15176                   idx++)
15177             {
15178                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15179                {
15180                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15181                         sizeof(RRCDeliveryReportIEs_t));
15182                }   
15183             }
15184             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15185                   rrcDeliveryReport->protocolIEs.list.size);
15186          }
15187          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15188       }
15189       DU_FREE(f1apMsg,
15190             sizeof(F1AP_PDU_t));
15191    }
15192 }
15193
15194 /*******************************************************************
15195 *
15196 * @brief Builds and sends the RRC delivery report
15197 *
15198 * @details
15199 *
15200 *    Function : BuildAndSendRrcDeliveryReport
15201 *
15202 *    Functionality: Builds and sends the RRC delivery report
15203 *
15204 * @params[in]
15205 *
15206 * @return ROK     - success
15207 *         RFAILED - failure
15208 *
15209 * ****************************************************************/
15210 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15211    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15212 {
15213    uint8_t             ret = RFAILED;
15214    uint8_t             idx    = 0;
15215    uint8_t             idx1   = 0;
15216    uint8_t             elementCnt = 0;
15217    F1AP_PDU_t          *f1apMsg = NULLP;
15218    asn_enc_rval_t      encRetVal;  
15219    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15220
15221    do{
15222
15223       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15224       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15225       if(f1apMsg == NULLP)
15226       {
15227          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15228          break;
15229       }
15230       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15231       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15232       if(f1apMsg->choice.initiatingMessage == NULLP)
15233       {
15234          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15235          break;
15236       }
15237       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15238       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15239       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15240
15241       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15242       elementCnt = 4;
15243       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15244       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15245
15246       /* Initialize the F1Setup members */
15247       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15248       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15249       {
15250          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15251          break;
15252       }
15253       for(idx =0 ;idx <elementCnt; idx++)
15254       {
15255          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15256          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15257          {
15258             break;
15259          }
15260       }
15261
15262       idx1 = 0;
15263
15264       /*GNB CU UE F1AP ID*/
15265       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15266       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15267       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15268       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15269
15270       /*GNB DU UE F1AP ID*/
15271       idx1++;
15272       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15273       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15274       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15275       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15276
15277       /*RRC delivery status*/
15278       idx1++;
15279       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15280       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15281       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15282       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15283       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15284       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15285       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15286
15287       /* SRB ID */ 
15288       idx1++;
15289       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15290       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15291       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15292       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15293
15294       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15295
15296       /* Encode the RRC DELIVERY REPORT type as APER */
15297       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15298       encBufSize = 0;
15299       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15300             encBuf);
15301
15302       /* Encode results */
15303       if(encRetVal.encoded == ENCODE_FAIL)
15304       {
15305          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15306                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15307          break;
15308       }
15309       else
15310       {
15311          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15312 #ifdef DEBUG_ASN_PRINT
15313          for(idx=0; idx< encBufSize; idx++)
15314          {
15315             printf("%x",encBuf[idx]);
15316          }
15317 #endif
15318       }
15319
15320       /* Sending msg */
15321       if(sendF1APMsg() != ROK)
15322       {
15323          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15324          break;
15325       }
15326       ret = ROK;
15327       break;
15328
15329    }while(true);
15330
15331    freeRrcDeliveryReport(f1apMsg);
15332    return ret;
15333 }
15334
15335 /*******************************************************************
15336  *
15337  * @brief Processes cells to be activated
15338  *
15339  * @details
15340  *
15341  *    Function : extractCellsToBeActivated
15342  *
15343  *    Functionality:
15344  *      - Processes cells to be activated list received in F1SetupRsp
15345  *
15346  * @params[in] void
15347  * @return ROK     - success
15348  *         RFAILED - failure
15349  *
15350  * ****************************************************************/
15351
15352 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15353 {
15354    uint8_t  ret = ROK;
15355    uint16_t idx, pci = 0;
15356    uint64_t nci;
15357    Cells_to_be_Activated_List_Item_t cell;
15358
15359    for(idx=0; idx<cellsToActivate.list.count; idx++)
15360    {
15361       nci = 0;
15362       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15363       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15364
15365       if(cell.nRPCI)
15366       {
15367          pci = *cell.nRPCI;
15368       }
15369       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15370    }
15371    return ret;
15372 }
15373 /******************************************************************
15374 *
15375 * @brief Processes F1 Setup Response allocated by aper_decoder 
15376 *
15377 * @details
15378 *
15379 *    Function : freeF1SetupRsp 
15380 *
15381 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15382 *
15383 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15384 * @return void 
15385 *
15386 * ****************************************************************/
15387
15388 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15389 {
15390    uint8_t ieIdx =0;
15391    uint8_t arrIdx =0;
15392    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15393    RRC_Version_t      *rrcVer =NULLP;
15394
15395    if(f1SetRspMsg->protocolIEs.list.array)
15396    {
15397       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15398       {
15399          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15400          {
15401             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15402             {
15403                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15404                   {
15405                      cellToActivate =
15406                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15407                      if(cellToActivate->list.array)
15408                      {
15409                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15410                         {
15411                            if(cellToActivate->list.array[arrIdx])
15412                            {
15413
15414                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15415                               pLMN_Identity.buf)
15416                               {
15417                                  if(cellToActivate->list.array[0]->value.choice.\
15418                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15419                                  {
15420                                     free(cellToActivate->list.array[0]->value.choice.\
15421                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15422                                  }
15423
15424                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15425                                        nRCGI.pLMN_Identity.buf);
15426                               }
15427                               free(cellToActivate->list.array[arrIdx]);
15428                            }
15429                         }
15430                         free(cellToActivate->list.array);
15431                      }
15432                      break;
15433                   }
15434                case ProtocolIE_ID_id_TransactionID:
15435                   {
15436                      break;
15437                   }
15438                case ProtocolIE_ID_id_gNB_CU_Name:
15439                   {
15440                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15441                      break;
15442                   }
15443                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15444                   {
15445                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15446                      if(rrcVer->latest_RRC_Version.buf)
15447                      {
15448                         if(rrcVer->iE_Extensions)
15449                         {
15450                            if(rrcVer->iE_Extensions->list.array)
15451                            {
15452                               if(rrcVer->iE_Extensions->list.array[0])
15453                               {
15454                                  if(rrcVer->iE_Extensions->list.\
15455                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15456                                  {
15457                                     free(rrcVer->iE_Extensions->list.\
15458                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15459                                  }
15460                                  free(rrcVer->iE_Extensions->list.array[0]);
15461                               }
15462                               free(rrcVer->iE_Extensions->list.array);
15463                            }
15464                            free(rrcVer->iE_Extensions);
15465                         }
15466                         free(rrcVer->latest_RRC_Version.buf);
15467                      }
15468                      break;
15469
15470                   }
15471                default:
15472                   {
15473                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15474                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15475                   }
15476             }
15477             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15478          }
15479       }
15480       free(f1SetRspMsg->protocolIEs.list.array);
15481    }
15482 }
15483 /******************************************************************
15484  *
15485  * @brief Processes F1 Setup Response sent by CU
15486  *
15487  * @details
15488  *
15489  *    Function : procF1SetupRsp
15490  *
15491  *    Functionality: Processes F1 Setup Response sent by CU
15492  *
15493  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15494  * @return ROK     - success
15495  *         RFAILED - failure
15496  *
15497  * ****************************************************************/
15498 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15499 {
15500    uint8_t ret = ROK;
15501    uint16_t idx =0;
15502    F1SetupResponse_t *f1SetRspMsg = NULLP;
15503    GNB_CU_Name_t     *cuName = NULLP;
15504    F1SetupRsp  f1SetRspDb;
15505    RRC_Version_t      *rrcVer =NULLP;
15506    
15507    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15508
15509    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15510    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15511
15512    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15513    {
15514       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15515       {
15516          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15517             {
15518                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15519                      value.choice.Cells_to_be_Activated_List);
15520                break;
15521             }
15522          case ProtocolIE_ID_id_TransactionID:
15523             {
15524                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15525                                     value.choice.TransactionID;
15526                break;
15527             }
15528          case ProtocolIE_ID_id_gNB_CU_Name:
15529             {
15530                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15531                         value.choice.GNB_CU_Name;
15532                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15533                break;
15534             }
15535          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15536             {
15537                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15538                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15539                      (const char*)rrcVer->latest_RRC_Version.buf);
15540                break;
15541             }
15542          default:
15543             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15544                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15545       }
15546    }
15547    
15548    duProcF1SetupRsp();
15549    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15550
15551    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15552    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15553    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15554    {
15555       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15556       return RFAILED;
15557    }
15558    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15559
15560    if(BuildAndSendE2SetupReq() != ROK)
15561    {
15562       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15563       return RFAILED;
15564    }
15565    return ret;
15566 }
15567 /*******************************************************************
15568 *
15569 * @brief free GNB DU config update ack
15570 *
15571 * @details
15572 *
15573 *    Function : freeAperDecodeGnbDuAck 
15574 *
15575 *    Functionality: Processes GNB DU config update ack And
15576 *                     added free part for the memory allocated by aper_decoder
15577 *
15578 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15579 * @return ROK     - success
15580 *         RFAILED - failure
15581 *
15582 * ****************************************************************/
15583
15584 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15585 {
15586    uint8_t ieIdx = 0;
15587
15588    if(gnbDuAck->protocolIEs.list.array)
15589    {
15590       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15591       {
15592          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15593          {
15594             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15595          }
15596       }
15597       free(gnbDuAck->protocolIEs.list.array);
15598    }
15599 }
15600
15601 /*******************************************************************
15602 *
15603 * @brief Building  result of gnb-du config update ack output
15604 *
15605 * @details
15606 *
15607 *    Function : duProcGnbDuCfgUpdAckMsg 
15608 *
15609 *    Functionality: 
15610 *        Building output of gnb-du config update ack 
15611 *
15612 * @params[in] transId
15613 * @return void
15614 *
15615 * ****************************************************************/
15616
15617 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15618 {
15619    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15620    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15621    uint16_t cellIdx =0, crnti=0;
15622    uint64_t cellId =0;
15623    CmLList *f1apPduNode = NULLP;
15624    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15625    F1AP_PDU_t *f1apMsgPdu = NULLP;
15626    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15627    BIT_STRING_t *cellIdentity=NULLP;
15628    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15629    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15630    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15631
15632    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15633    f1apPduNode = searchFromReservedF1apPduList(transId);
15634    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15635    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15636
15637    if(f1apMsgPdu)
15638    {
15639       if(f1apMsgPdu->choice.initiatingMessage)
15640       {
15641          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15642          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15643          {
15644             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15645             {
15646                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15647                   {
15648                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15649                                      Served_Cells_To_Delete_List;
15650                      if(cellsToDelete->list.array)
15651                      {
15652                         if(cellsToDelete->list.array[arrIdx])
15653                         {
15654                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15655                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15656                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15657                            {
15658                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15659                               bitStringToInt(cellIdentity, &cellId);
15660
15661                               GET_CELL_IDX(cellId, cellIdx);
15662                               if(duCb.actvCellLst[cellIdx] != NULLP)
15663                               {
15664                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15665                               }
15666                            }
15667                         }
15668                      }
15669
15670                      if(duCb.actvCellLst[cellIdx] != NULLP)
15671                      {
15672                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15673                         {
15674                            ret = duSendCellDeletReq(cellId);
15675                            if(ret == RFAILED)
15676                            {
15677                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15678                               request for cellId[%lu]", cellId);
15679                            }
15680                         }
15681                         else
15682                         {
15683                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15684                            while(totalActiveUe)
15685                            {
15686                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15687                               {
15688                                  ueIdx++;
15689                                  continue;
15690                               }
15691
15692                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15693                               GET_UE_ID(crnti,ueId);
15694                               /* Sending Ue Context release request only for maximum supporting UEs */
15695                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15696                               if(ret == RFAILED)
15697                               {
15698                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15699                                  request for cellId[%lu]", cellId);
15700                               }
15701                               ueIdx++;
15702                               totalActiveUe--;
15703                            }
15704                         }
15705                      }
15706                      else
15707                      {
15708                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15709                         ret = RFAILED;
15710                      }
15711                      break;
15712                   }
15713
15714                default:
15715                   break;
15716             }
15717          }
15718       }
15719    }
15720    
15721    FreeDUConfigUpdate(f1apMsgPdu);
15722    deleteFromReservedF1apPduList(f1apPduNode);
15723    return ret;
15724 }
15725
15726 /*******************************************************************
15727 *
15728 * @brief Processes GNB DU config update ack
15729 *
15730 * @details
15731 *
15732 *    Function : procF1GNBDUCfgUpdAck
15733 *
15734 *    Functionality: added free part for the memory allocated by aper_decoder
15735 *
15736 * @params[in] F1AP_PDU_t *f1apMsg 
15737 * @return void 
15738 *
15739 * ****************************************************************/
15740 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15741 {
15742    uint8_t ieIdx=0,transId=0;
15743    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15744
15745    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15746    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15747
15748    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15749    {
15750       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15751       {
15752          case ProtocolIE_ID_id_TransactionID:
15753             {
15754                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15755                break;
15756             }
15757          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15758             {
15759                break;
15760             }
15761          default :
15762             {
15763                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15764                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15765                break;
15766             }
15767       }
15768    }
15769    
15770    duProcGnbDuCfgUpdAckMsg(transId);
15771     
15772 #if 0
15773    /* presently we are not supporting F1 Reset from DU to CU , we are only
15774     * supporting F1 Reset from CU to DU */
15775
15776    if(BuildAndSendF1ResetReq() != ROK)
15777    {
15778       return RFAILED;
15779    }
15780 #endif
15781
15782    freeAperDecodeGnbDuAck(gnbDuAck);
15783    return ROK;
15784 }
15785 /******************************************************************
15786 *
15787 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15788 *
15789 * @details
15790 *
15791 *    Function : freeAperDecodef1DlRrcMsg 
15792 *
15793 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15794 *
15795 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15796 * @return ROK     - success
15797 *         RFAILED - failure
15798 *
15799 * ****************************************************************/
15800
15801 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15802 {
15803    uint8_t ieIdx =0;
15804    RRCContainer_t *rrcContainer = NULLP;
15805
15806    if(f1DlRrcMsg->protocolIEs.list.array)
15807    {
15808       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15809       {
15810          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15811          {
15812             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15813             {
15814                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15815                   break;
15816                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15817                   break;
15818                case ProtocolIE_ID_id_SRBID:
15819                   break;
15820                case ProtocolIE_ID_id_RRCContainer:
15821                   {
15822                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15823                      free(rrcContainer->buf);
15824                   }
15825                case ProtocolIE_ID_id_ExecuteDuplication:
15826                   break;
15827                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15828                   break;
15829                   break;
15830             }
15831             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15832          }
15833       }
15834       free(f1DlRrcMsg->protocolIEs.list.array);
15835    }
15836 }
15837 /******************************************************************
15838  *
15839  * @brief Processes DL RRC Message Transfer  sent by CU
15840  *
15841  * @details
15842  *
15843  *    Function : procF1DlRrcMsgTrans
15844  *
15845  *    Functionality: Processes DL RRC Message Transfer sent by CU
15846  *
15847  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15848  * @return ROK     - success
15849  *         RFAILED - failure
15850  *
15851  * ****************************************************************/
15852 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15853 {
15854    uint8_t  idx, ret;
15855    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15856    F1DlRrcMsg dlMsg;
15857    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15858
15859    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15860    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15861
15862    ret = ROK;
15863
15864    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15865    {
15866       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15867       {
15868          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15869             {
15870                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15871                break;
15872             }
15873          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15874             {
15875                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15876                break;
15877             }
15878          case ProtocolIE_ID_id_SRBID:
15879             {
15880                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15881                break;
15882             }
15883          case ProtocolIE_ID_id_ExecuteDuplication:
15884             dlMsg.execDup = true;
15885             break;
15886
15887          case ProtocolIE_ID_id_RRCContainer:
15888             {
15889                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15890                {
15891              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15892              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15893              if(dlMsg.rrcMsgPdu)
15894              {
15895                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15896                       dlMsg.rrcMsgSize);
15897              }
15898              else
15899              {
15900                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15901                 return RFAILED;
15902              }
15903           }
15904           else
15905           {
15906              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15907                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15908              return RFAILED;
15909           }
15910           break;
15911        }
15912     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15913        {
15914           dlMsg.deliveryStatRpt = true;
15915           break;
15916        }
15917     default:
15918        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15919              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15920       }
15921    }
15922
15923    ret = duProcDlRrcMsg(&dlMsg);
15924
15925    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15926    return ret;
15927 }
15928 /*******************************************************************
15929  *
15930 * @brief Builds the DRB to be Setup Mod list
15931 *
15932 * @details
15933 *
15934 *    Function : 
15935 *
15936 *    Functionality: Constructs the DRB to be Setup Mod list
15937 *
15938 * @params[in] DRBs_SetupMod_List_t *drbSet
15939 *
15940 * @return ROK     - success
15941 *         RFAILED - failure
15942 *
15943 * ****************************************************************/
15944 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15945 {
15946    uint8_t srbIdx = 0;
15947    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15948
15949    srbList->list.count = ueCfg->numRlcLcs;
15950    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15951
15952    DU_ALLOC(srbList->list.array, srbList->list.size);
15953    if(srbList->list.array == NULLP)
15954    {
15955       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15956       return RFAILED;
15957    }
15958
15959    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15960    {
15961       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15962       if(srbList->list.array[srbIdx] == NULLP)
15963       {
15964          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15965          return RFAILED;
15966       }
15967    } 
15968
15969    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15970    {
15971       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15972       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15973       srbItemIe->criticality = Criticality_reject;
15974       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15975       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15976       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15977    }
15978    return ROK;
15979 }
15980
15981 /*******************************************************************
15982  *
15983 * @brief Builds the DRB to be Setup Mod list
15984 *
15985 * @details
15986 *
15987 *    Function : 
15988 *
15989 *    Functionality: Constructs the DRB to be Setup Mod list
15990 *
15991 * @params[in] DRBs_SetupMod_List_t *drbSet
15992 *
15993 * @return ROK     - success
15994 *         RFAILED - failure
15995 *
15996 * ****************************************************************/
15997
15998 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15999 {
16000    uint8_t arrIdx =0;
16001    uint8_t drbCnt =0;
16002    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16003
16004    drbCnt = ueCfg->numDrbSetupMod;
16005
16006    drbSet->list.count = drbCnt;
16007    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16008    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16009    if(drbSet->list.array == NULLP)
16010    {
16011       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16012       return  RFAILED;
16013    }
16014    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16015    {
16016       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16017       if(drbSet->list.array[arrIdx] == NULLP)
16018       {
16019               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16020               return  RFAILED;
16021       }
16022
16023       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16024       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16025       drbItemIe->criticality = Criticality_reject;
16026       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16027       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16028       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16029       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16030       {
16031          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16032          return RFAILED;
16033       }
16034       
16035    }
16036
16037    return ROK;
16038 }
16039 /*******************************************************************
16040 * @brief Free the memory allocated for DRB setup List
16041 *
16042 * @details
16043 *
16044 *    Function : FreeDrbSetupModList 
16045 *
16046 *    Functionality:
16047 *       Free the memory allocated for DRB setup list
16048 *
16049 * @params[in] DRBs_Setup_List_t *
16050 * @return void
16051 *
16052 * ****************************************************************/
16053 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16054 {
16055    uint8_t arrIdx = 0;
16056    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16057
16058    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16059    {
16060       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16061       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16062       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16063    }
16064    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16065 }
16066
16067 /*******************************************************************
16068 *
16069 * @brief Builds the DRB to be Mod list
16070 *
16071 * @details
16072 *
16073 *    Function : 
16074 *
16075 *    Functionality: Constructs the DRB to be Mod list
16076 *
16077 * @params[in] DRBs_Modified_List_t *drbModList
16078 *
16079 * @return ROK     - success
16080 *         RFAILED - failure
16081 *
16082 * ****************************************************************/
16083
16084 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16085 {
16086    uint8_t arrIdx =0, drbIdx = 0;
16087    uint8_t drbCnt =0;
16088    struct DRBs_Modified_ItemIEs *drbItemIe;
16089
16090    drbCnt = ueCfg->numDrbModified;
16091
16092    drbModList->list.count = drbCnt;
16093    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16094    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16095    if(drbModList->list.array == NULLP)
16096    {
16097       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16098       return  RFAILED;
16099    }
16100
16101    drbIdx = 0;
16102    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16103    {
16104       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16105       {
16106          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16107          if(drbModList->list.array[drbIdx] == NULLP)
16108          {
16109             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16110             return  RFAILED;
16111          }
16112
16113          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16114          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16115          drbItemIe->criticality = Criticality_reject;
16116          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16117          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16118          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16119                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16120          {
16121             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16122             return RFAILED;
16123          }
16124          drbIdx++;
16125       } 
16126    }
16127
16128    return ROK;
16129 }
16130
16131 /*******************************************************************
16132 * @brief Free the memory allocated for DRB Mod List
16133 *
16134 * @details
16135 *
16136 *    Function : FreeDrbModList 
16137 *
16138 *    Functionality:
16139 *       Free the memory allocated for DRB modified list
16140 *
16141 * @params[in] DRBs_Modified_List_t *
16142 * @return void
16143 *
16144 * ****************************************************************/
16145 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16146 {
16147    uint8_t arrIdx = 0;
16148    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16149
16150    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16151    {
16152       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16153       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16154       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16155    }
16156    DU_FREE(drbModList->list.array, drbModList->list.size);
16157 }
16158
16159 /*******************************************************************
16160 * @brief Free the memory allocated for SRB setup List
16161 *
16162 * @details
16163 *
16164 *    Function : FreeSrbSetupModList 
16165 *
16166 *    Functionality:
16167 *       Free the memory allocated for SRB setup list
16168 *
16169 * @params[in] SRBs_Setup_List_t *
16170 * @return void
16171 *
16172 * ****************************************************************/
16173 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16174 {
16175    uint8_t srbIdx = 0;
16176    
16177    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16178       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16179    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16180 }
16181
16182 /*******************************************************************
16183 * @brief Free the memory allocated for UE Context Mod Response
16184 *
16185 * @details
16186 *
16187 *    Function : FreeUeContextModResp 
16188 *
16189 *    Functionality:
16190 *       Free the memory allocated for UE Context Mod Response
16191 *
16192 * @params[in] F1AP_PDU_t *f1apMsg
16193 * @return void
16194 *
16195 * ****************************************************************/
16196
16197 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16198 {
16199    uint8_t ieIdx;
16200    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16201    if(f1apMsg)
16202    {
16203       if(f1apMsg->choice.successfulOutcome)
16204       {
16205          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16206          if(ueContextModifyRes->protocolIEs.list.array)
16207          {
16208             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16209             {
16210                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16211                {
16212                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16213                   {
16214                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16215                         break;
16216                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16217                         break;
16218                      case ProtocolIE_ID_id_DUtoCURRCInformation:
16219                         {
16220                            DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.\
16221                               cellGroupConfig.buf, ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16222                               DUtoCURRCInformation.cellGroupConfig.size);
16223                            break;
16224                         }
16225                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16226                         {
16227                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16228                             value.choice.DRBs_SetupMod_List));
16229                             break;
16230                         }
16231                      case ProtocolIE_ID_id_DRBs_Modified_List:
16232                         {
16233                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16234                             value.choice.DRBs_Modified_List));
16235                             break;
16236                         }
16237                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16238                         {
16239                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16240                               SRBs_SetupMod_List));
16241                            break; 
16242                         }
16243                   }
16244                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16245                }
16246
16247             }
16248             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16249          }
16250          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16251       }
16252       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16253    }
16254 }
16255
16256 /*****************************************************************i
16257 *
16258 * @brief Creating the ue context modifcation response and sending
16259 *
16260 * @details
16261 *
16262 *    Function : BuildAndSendUeContextModRsp 
16263 *
16264 *    Functionality:
16265 *         - Creating the ue context modifcation response 
16266 *
16267 * @params[in] uint8_t cellId,uint8_t ueId
16268 * @return ROK     - success
16269 *         RFAILED - failure
16270 *
16271 * ****************************************************************/
16272 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16273 {
16274    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16275    uint8_t   elementCnt = 0;
16276    uint8_t   ret = RFAILED;
16277    F1AP_PDU_t *f1apMsg = NULLP;
16278    asn_enc_rval_t  encRetVal;
16279    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16280
16281    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16282
16283    while(true)
16284    {
16285       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16286       if(f1apMsg == NULLP)
16287       {
16288          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16289          break;
16290       }
16291
16292       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16293
16294       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16295       if(f1apMsg->choice.successfulOutcome == NULLP)
16296       {
16297          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16298          break;
16299       }
16300       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16301       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16302       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16303
16304       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16305   
16306       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16307       {
16308          elementCnt = 2;
16309          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16310             elementCnt++;
16311          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16312             elementCnt++; 
16313       }
16314       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16315       {
16316          elementCnt = 5;
16317       }
16318       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16319          elementCnt = 2;
16320       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16321       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16322
16323       /* Initialize the UE context modification members */
16324       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16325       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16326       {
16327          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16328          break;
16329       }
16330
16331       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16332       {
16333          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16334          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16335          {
16336             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16337             break;
16338          }
16339       }
16340
16341       ieIdx=0;
16342       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16343       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16344       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16345       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16346       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16347
16348       ieIdx++;
16349       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16350       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16351       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16352       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16353       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16354
16355       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16356       {
16357          ieIdx++;
16358          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16359          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16360          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16361          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16362          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16363       }
16364
16365       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16366            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16367       { 
16368          ieIdx++;
16369          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16370          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16371          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16372                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16373          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16374          {
16375             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16376             {
16377                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16378                {
16379                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16380                }
16381             }
16382          }
16383          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16384                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16385          if(ret != ROK)
16386          {
16387             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16388             break;
16389          }
16390       }
16391
16392       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16393       { 
16394          ieIdx++;
16395          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16396          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16397          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16398                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16399          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16400                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16401          if(ret != ROK)
16402          {
16403             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16404             break;
16405          }
16406       }
16407
16408       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16409       {
16410          ieIdx++;
16411          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16412          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16413          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16414                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16415          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16416          {
16417             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16418             {
16419                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16420                      sizeof(DuRlcBearerCfg));
16421             }
16422          }
16423          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16424                &ueCb->f1UeDb->duUeCfg);
16425          if(ret != ROK)
16426          {
16427             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16428             break;
16429          }
16430       }
16431
16432       freeF1UeDb(ueCb->f1UeDb);
16433       ueCb->f1UeDb = NULLP;
16434
16435       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16436
16437       /* Encode the F1SetupRequest type as APER */
16438       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16439       encBufSize = 0;
16440       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16441
16442       /* Encode results */
16443       if(encRetVal.encoded == ENCODE_FAIL)
16444       {
16445          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16446                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16447          ret = RFAILED;
16448          break;
16449       }
16450       else
16451       {
16452          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16453 #ifdef DEBUG_ASN_PRINT
16454          for(int i=0; i< encBufSize; i++)
16455          {
16456             printf("%x",encBuf[i]);
16457          }
16458 #endif
16459       }
16460
16461       /* Sending  msg  */
16462       if(sendF1APMsg() != ROK && (ret == ROK))
16463       {
16464          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16465          ret = RFAILED;
16466          break;
16467       }
16468
16469       ret = ROK;
16470       break;
16471    }
16472
16473    FreeUeContextModResp(f1apMsg);
16474    return ret;
16475 }
16476
16477 /*******************************************************************
16478  *
16479  * @brief Deallocating the memory allocated by the aper decoder
16480  *          for QOSInfo
16481  *
16482  * @details
16483  *
16484  *    Function : freeAperDecodeQosInfo
16485  *
16486  *    Functionality:  Deallocating the memory allocated for QOSInfo
16487  *
16488  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16489  *
16490  * @return void
16491  *
16492  * ****************************************************************/
16493
16494 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16495 {
16496    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16497    {
16498       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16499       {
16500          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16501          {
16502             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16503          }
16504          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16505       }
16506       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16507    }
16508 }
16509 /*******************************************************************
16510  *
16511  * @brief Deallocating the memory allocated by the aper decoder
16512  *          for UlTnlInfoforDrb
16513  *
16514  * @details
16515  *
16516  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16517  *
16518  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16519  *
16520  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16521  *
16522  * @return void
16523  *
16524  * ****************************************************************/
16525 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16526 {
16527    uint8_t arrIdx =0;
16528
16529    if(ulInfo->list.array)
16530    {
16531       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16532       {
16533          if(ulInfo->list.array[arrIdx])
16534          {
16535             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16536             {
16537                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16538                {
16539                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16540                   {
16541                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16542                            gTP_TEID.buf);
16543                   }
16544                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16545                         transportLayerAddress.buf);
16546                }
16547                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16548             }
16549             free(ulInfo->list.array[arrIdx]);
16550          }
16551       }
16552       free(ulInfo->list.array);
16553    }
16554 }
16555
16556 /*******************************************************************
16557  *
16558  * @brief Deallocating the memory allocated by the aper decoder
16559  *          for DrbSetupModItem  
16560  *
16561  * @details
16562  *
16563  *    Function : freeAperDecodeDrbSetupModItem 
16564  *
16565  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16566  *
16567  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16568  *
16569  * @return void
16570  *
16571  * ****************************************************************/
16572
16573 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16574 {
16575    uint8_t arrIdx =0;
16576    SNSSAI_t *snssai =NULLP;
16577    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16578
16579    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16580    switch(drbItem->qoSInformation.present)
16581    {
16582       case QoSInformation_PR_NOTHING:
16583          break;
16584       case QoSInformation_PR_eUTRANQoS:
16585          {
16586             if(drbItem->qoSInformation.choice.eUTRANQoS)
16587             {
16588                free(drbItem->qoSInformation.choice.eUTRANQoS);
16589             }
16590             break;
16591          }
16592       case QoSInformation_PR_choice_extension:
16593          {
16594             if(drbItem->qoSInformation.choice.choice_extension)
16595             {
16596                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16597                      DRB_Information.dRB_QoS);
16598                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16599                if(snssai->sST.buf)
16600                {
16601                   free(snssai->sST.buf);
16602                }
16603                if(snssai->sD)
16604                {
16605                   if(snssai->sD->buf)
16606                   {
16607                      free(snssai->sD->buf);
16608                   }
16609                   free(snssai->sD);
16610                }
16611
16612                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16613                          DRB_Information.flows_Mapped_To_DRB_List;
16614                if(flowMap->list.array)
16615                {
16616                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16617                   {
16618                      if(flowMap->list.array[arrIdx] )
16619                      {
16620                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16621                         free(flowMap->list.array[arrIdx]);
16622                      }
16623                   }
16624                   free(flowMap->list.array);
16625                }
16626
16627                free(drbItem->qoSInformation.choice.choice_extension);
16628             }
16629             break;
16630          }
16631
16632    }
16633    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16634    if(drbItem->uLConfiguration)
16635    {
16636       free(drbItem->uLConfiguration);
16637    }
16638 }
16639
16640 /*******************************************************************
16641  *
16642  * @brief Deallocating the memory allocated by the aper decoder
16643  *          for DrbToBeSetupModList
16644  *
16645  * @details
16646  *
16647  *    Function : freeAperDecodeDrbToBeSetupModList
16648  *
16649  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16650  *
16651  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16652  *
16653  * @return void
16654  *
16655  * ****************************************************************/
16656
16657 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16658 {
16659    uint8_t arrIdx =0;
16660    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16661
16662    if(drbSet->list.array)
16663    {
16664       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16665       {
16666          if(drbSet->list.array[arrIdx] != NULLP)
16667          {
16668             if(arrIdx == 0)
16669             {
16670                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16671                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16672             }
16673             free(drbSet->list.array[arrIdx]);
16674          }
16675       }
16676       free(drbSet->list.array);
16677    }
16678
16679 }
16680
16681 /*******************************************************************
16682  *
16683  * @brief Deallocating the memory allocated by the aper decoder
16684  *          for DrbSetupModItem  
16685  *
16686  * @details
16687  *
16688  *    Function : freeAperDecodeDrbModifiedItem 
16689  *
16690  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16691  *
16692  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16693  *
16694  * @return void
16695  *
16696  * ****************************************************************/
16697
16698 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16699 {
16700    uint8_t arrIdx =0;
16701    SNSSAI_t *snssai =NULLP;
16702    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16703
16704    if(drbItem->qoSInformation != NULLP)
16705    {
16706       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16707       switch(drbItem->qoSInformation->present)
16708       {
16709          case QoSInformation_PR_NOTHING:
16710             break;
16711          case QoSInformation_PR_eUTRANQoS:
16712             {
16713                if(drbItem->qoSInformation->choice.eUTRANQoS)
16714                {
16715                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16716                }
16717                break;
16718             }
16719          case QoSInformation_PR_choice_extension:
16720             {
16721                if(drbItem->qoSInformation->choice.choice_extension)
16722                {
16723                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16724                         DRB_Information.dRB_QoS);
16725                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16726                   if(snssai->sST.buf)
16727                   {
16728                      free(snssai->sST.buf);
16729                   }
16730                   if(snssai->sD)
16731                   {
16732                      if(snssai->sD->buf)
16733                      {
16734                         free(snssai->sD->buf);
16735                      }
16736                      free(snssai->sD);
16737                   }
16738
16739                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16740                             DRB_Information.flows_Mapped_To_DRB_List;
16741                   if(flowMap->list.array)
16742                   {
16743                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16744                      {
16745                         if(flowMap->list.array[arrIdx] )
16746                         {
16747                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16748                            free(flowMap->list.array[arrIdx]);
16749                         }
16750                      }
16751                      free(flowMap->list.array);
16752                   }
16753
16754                   free(drbItem->qoSInformation->choice.choice_extension);
16755                }
16756                break;
16757             }
16758       }
16759       free(drbItem->qoSInformation);
16760    }
16761    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16762    if(drbItem->uLConfiguration)
16763    {
16764       free(drbItem->uLConfiguration);
16765    }
16766 }
16767
16768 /*******************************************************************
16769  *
16770  * @brief Deallocating the memory allocated by the aper decoder
16771  *          for DrbToBeSetupModList
16772  *
16773  * @details
16774  *
16775  *    Function : freeAperDecodeDrbToBeModifiedList
16776  *
16777  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16778  *
16779  * @params[in] DRBs_ToBeModified_List_t *drbSet
16780  *
16781  * @return void
16782  *
16783  * ****************************************************************/
16784
16785 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16786 {
16787    uint8_t arrIdx =0;
16788    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16789
16790    if(drbSet->list.array)
16791    {
16792       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16793       {
16794          if(drbSet->list.array[arrIdx] != NULLP)
16795          {
16796             if(arrIdx == 0)
16797             {
16798                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16799                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16800             }
16801             free(drbSet->list.array[arrIdx]);
16802          }
16803       }
16804       free(drbSet->list.array);
16805    }
16806
16807 }
16808
16809 /*******************************************************************
16810  *
16811  * @brief Deallocating the memory allocated by the aper decoder
16812  *          for DrbToBeSetupModList
16813  *
16814  * @details
16815  *
16816  *    Function : freeAperDecodeDrbToBeReleasedList
16817  *
16818  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16819  *
16820  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16821  *
16822  * @return void
16823  *
16824  * ****************************************************************/
16825
16826 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16827 {
16828    uint8_t arrIdx =0;
16829
16830    if(drbSet->list.array)
16831    {
16832       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16833       {
16834          if(drbSet->list.array[arrIdx] != NULLP)
16835          {
16836             free(drbSet->list.array[arrIdx]);
16837          }
16838       }
16839       free(drbSet->list.array);
16840    }
16841
16842 }
16843 /*******************************************************************
16844  *
16845  * @brief Deallocating the memory allocated by the aper decoder
16846  *          for UeContextModificationReqMsg
16847  *
16848  * @details
16849  *
16850  *    Function : freeAperDecodeUeContextModificationReqMsg
16851  *
16852  *    Functionality:  Deallocating memory allocated for
16853  *                  UeContextModificationReqMsg
16854  *
16855  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16856  *
16857  * @return void
16858  *
16859  * ****************************************************************/
16860 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16861 {
16862    uint8_t arrIdx, ieId;
16863
16864    if(ueContextModifyReq->protocolIEs.list.array)
16865    {
16866       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16867       {
16868          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16869          {
16870             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16871             switch(ieId)
16872             {
16873                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16874                   break;
16875                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16876                   break;
16877                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16878                   {
16879                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16880                            value.choice.DRBs_ToBeSetupMod_List);
16881                      break;
16882                   }
16883                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16884                   {
16885                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16886                            value.choice.DRBs_ToBeModified_List);
16887                      break;
16888                   }
16889                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16890                   {
16891                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16892                            value.choice.DRBs_ToBeReleased_List);
16893                      break;
16894                   }
16895                case ProtocolIE_ID_id_TransmissionActionIndicator:
16896                   break;
16897                case ProtocolIE_ID_id_RRCContainer:
16898                   {
16899                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16900                   }
16901             }
16902             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16903          }
16904       }
16905       free(ueContextModifyReq->protocolIEs.list.array);
16906    }
16907 }
16908 /*******************************************************************
16909  *
16910  * @brief processing the F1 UeContextModificationReq
16911  *
16912  * @details
16913  *
16914  *    Function : procF1UeContextModificationReq
16915  *
16916  *    Functionality:  processing the F1 UeContextModificationReq
16917  *
16918  * @params[in] F1AP_PDU_t *f1apMsg
16919  *
16920  * @return
16921  * ****************************************************************/
16922 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16923 {
16924    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16925    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16926    DuUeCb   *duUeCb = NULLP;
16927    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16928    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16929    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16930    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16931
16932    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16933    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16934    {
16935       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16936       {
16937          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16938             {
16939                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16940                break;
16941             }
16942          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16943             {
16944                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16945                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16946                {
16947                   if(duCb.actvCellLst[cellIdx])
16948                   {
16949                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16950                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16951                      {
16952                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16953                         if(duUeCb->f1UeDb == NULLP)
16954                         {
16955                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16956                            duUeCb->f1UeDb->cellIdx = cellIdx;
16957                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16958                         }
16959                         break;
16960                      }
16961                   }
16962                }
16963                if(duUeCb == NULLP)
16964                {
16965                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16966                   ret = RFAILED;
16967                }
16968                break;
16969             }
16970
16971          case ProtocolIE_ID_id_RRCContainer:
16972             {
16973                /* Filling Dl RRC Msg Info */
16974                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16975                if(!duUeCb->f1UeDb->dlRrcMsg)
16976                {
16977                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16978                         Memory allocation failed ");
16979                   ret = RFAILED;
16980                }
16981                else
16982                {
16983                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16984                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16985                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16986                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16987                         value.choice.RRCContainer);
16988                }
16989
16990                break;
16991             }
16992
16993          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16994          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16995          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16996             {
16997                if(duUeCb->f1UeDb)
16998                {
16999                   /*DRBs to be Added*/
17000                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
17001                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
17002                   {
17003                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17004                                       choice.DRBs_ToBeSetupMod_List;
17005
17006                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
17007                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
17008                      {
17009                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17010                         ret = RFAILED;
17011                      }
17012                   }
17013
17014                   /*DRBs to be Modified*/
17015                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17016                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17017
17018                   {
17019                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17020                                       choice.DRBs_ToBeModified_List;
17021                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17022                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17023                      {
17024                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17025                         ret = RFAILED;
17026                      }
17027                   }
17028                   /*DRBs to be Released*/
17029                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17030                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17031
17032                   {
17033                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17034                                       choice.DRBs_ToBeReleased_List;
17035                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17036                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17037                      {
17038                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17039                         ret = RFAILED;
17040                      }
17041                   }
17042                }
17043                break;
17044             }
17045
17046          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17047             {
17048                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17049                if(duUeCb->f1UeDb)
17050                {
17051                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17052                }
17053                break;
17054             }
17055
17056          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17057             {
17058                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17059                   RRCReconfigurationCompleteIndicator_true)
17060                {
17061                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17062                }
17063                break;
17064             }
17065          case ProtocolIE_ID_id_TransmissionActionIndicator:
17066             {
17067                if(duUeCb->f1UeDb)
17068                {
17069                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17070                   {
17071                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17072                   }
17073                   else 
17074                   {
17075                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17076                   }
17077                }
17078                break;
17079             }
17080
17081          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17082             {
17083                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17084                {
17085                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17086                }
17087                break;
17088             }
17089 #ifdef NR_DRX
17090          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17091             {
17092                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17093                break;
17094             }
17095 #endif
17096               
17097       }
17098    }
17099
17100    if(ret != RFAILED) 
17101    {
17102       ret = duProcUeContextModReq(duUeCb);
17103    }
17104    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17105    return ret; 
17106 }
17107
17108 /*****************************************************************i
17109 *
17110 * @brief Free memory allocated for UE Context Release Request
17111 *
17112 * @details
17113 *
17114 *    Function : FreeUeContextReleaseReq
17115 *
17116 *    Functionality:
17117 *         - Free memory allocated for UE Context Release Request
17118 *
17119 * @params[in] F1AP_PDU_t *f1apMsg
17120 * @return void 
17121 *
17122 * *************************************************************/
17123 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17124 {
17125    uint8_t ieIdx;
17126    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17127    
17128    if(f1apMsg)
17129    {
17130       if(f1apMsg->choice.initiatingMessage)
17131       {
17132          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17133          if(ueReleaseReq->protocolIEs.list.array)
17134          {
17135             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17136             {
17137                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17138             }
17139             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17140          }
17141          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17142       }
17143       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17144    }
17145
17146 }
17147 /*****************************************************************i
17148 *
17149 * @brief Build and Send UE Context Release Request  
17150 *
17151 * @details
17152 *
17153 *    Function : BuildAndSendUeContextReleaseReq
17154 *
17155 *    Functionality:
17156 *         - Build and Send UE Context Release Request 
17157 *
17158 * @params[in]
17159 * @return ROK     - success
17160 *         RFAILED - failure
17161 *
17162 * *************************************************************/
17163 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17164 {
17165    bool memAllocFail = false;
17166    uint8_t ieIdx =0;
17167    uint8_t ret = RFAILED;
17168    uint16_t cellIdx =0;
17169    uint16_t crnti = 0;
17170    uint8_t  elementCnt = 0;
17171    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17172    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17173    asn_enc_rval_t encRetVal; 
17174    F1AP_PDU_t *f1apMsg = NULLP;
17175    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17176
17177    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17178    do
17179    {
17180       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17181       if(f1apMsg == NULLP)
17182       {
17183          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17184          break;
17185       }
17186
17187       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17188       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17189       if(f1apMsg->choice.initiatingMessage == NULLP)
17190       {
17191          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17192          initiatingMessage");   
17193          break;
17194       }
17195       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17196       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17197       f1apMsg->choice.initiatingMessage->value.present = \
17198       InitiatingMessage__value_PR_UEContextReleaseRequest;
17199
17200       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17201
17202       elementCnt = 2;
17203
17204       ueReleaseReq->protocolIEs.list.count = elementCnt;
17205       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17206
17207       /* Initialize the F1Setup members */
17208       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17209       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17210       {
17211          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17212          break;
17213       }
17214       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17215       {
17216          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17217                sizeof(UEContextReleaseRequest_t));
17218          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17219          {
17220             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17221             memAllocFail = true;  
17222             break;
17223          }
17224       }
17225       if(memAllocFail == true)
17226          break;
17227
17228       /* Fetching Ue Cb Info*/
17229       GET_CELL_IDX(cellId, cellIdx);
17230       if(duCb.actvCellLst[cellIdx] == NULLP)
17231       {
17232          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17233          break;
17234       }
17235       else
17236       {
17237          GET_CRNTI(crnti, ueId);
17238          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17239          {
17240             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17241             break;
17242          }
17243          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17244          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17245       }
17246
17247       ieIdx=0; 
17248       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17249       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17250       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17251       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17252       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17253       
17254       ieIdx++;
17255       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17256       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17257       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17258       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17259       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17260       
17261       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17262
17263       /* Encode the F1SetupRequest type as APER */
17264       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17265       encBufSize = 0;
17266       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17267       /* Encode results */
17268       if(encRetVal.encoded == ENCODE_FAIL)
17269       {
17270          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17271                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17272          break;
17273       }
17274       else
17275       {
17276          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17277 #ifdef DEBUG_ASN_PRINT
17278          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17279          {
17280             printf("%x",encBuf[ieIdx]);
17281          }
17282 #endif
17283       }
17284
17285       /* Sending msg */
17286       if(sendF1APMsg() != ROK)
17287       {
17288          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17289          break;
17290       }
17291       ret = ROK;
17292       break;
17293    }while(true);
17294
17295    FreeUeContextReleaseReq(f1apMsg);
17296    return ret;
17297 }
17298 /*****************************************************************i
17299  *
17300  * @brief Free memory allocated for UE Context Release Complete
17301  *
17302  * @details
17303  *
17304  *    Function : FreeUeContextReleaseComplete
17305  *
17306  *    Functionality:
17307  *         - Free memory allocated for UE Context Release Complete
17308  *
17309  * @params[in] F1AP_PDU_t *f1apMsg
17310  * @return void
17311  *
17312  * *************************************************************/
17313 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17314 {
17315    uint8_t ieIdx;
17316    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17317
17318    if(f1apMsg)
17319    {
17320       if(f1apMsg->choice.successfulOutcome)
17321       {
17322          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17323          if(ueReleaseComplete->protocolIEs.list.array)
17324          {
17325             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17326             {
17327                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17328             }
17329             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17330          }
17331          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17332       }
17333       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17334    }
17335
17336 }
17337 /*****************************************************************i
17338  *
17339  * @brief Build and Send UE Context Release Complete
17340  *
17341  * @details
17342  *
17343  *    Function : BuildAndSendUeContextReleaseComplete
17344  *
17345  *    Functionality:
17346  *         - Build and Send UE Context Release Complete
17347  *
17348  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17349  * @return ROK     - success
17350  *         RFAILED - failure
17351  *
17352  * *************************************************************/
17353 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17354 {
17355    bool memAllocFail = false;
17356    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17357    asn_enc_rval_t encRetVal;
17358    F1AP_PDU_t *f1apMsg = NULLP;
17359    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17360
17361    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17362    do
17363    {
17364       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17365       if(f1apMsg == NULLP)
17366       {
17367          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17368          break;
17369       }
17370
17371       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17372       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17373       if(f1apMsg->choice.successfulOutcome == NULLP)
17374       {
17375          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17376                successfulOutcome");
17377          break;
17378       }
17379       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17380       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17381       f1apMsg->choice.successfulOutcome->value.present = \
17382       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17383
17384       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17385
17386       elementCnt = 2;
17387       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17388       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17389
17390       /* Initialize the UE Release Complete members */
17391       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17392       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17393       {
17394          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17395          break;
17396       }
17397       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17398       {
17399          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17400                sizeof(UEContextReleaseComplete_t));
17401          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17402          {
17403             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17404             elements");
17405             memAllocFail = true;
17406             break;
17407          }
17408       }
17409       if(memAllocFail == true)
17410          break;
17411
17412
17413       ieIdx=0;
17414       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17415       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17416       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17417       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17418       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17419
17420       ieIdx++;
17421       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17422       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17423       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17424       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17425       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17426
17427       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17428
17429       /* Encode the F1SetupComplete type as APER */
17430       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17431       encBufSize = 0;
17432       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17433       /* Encode results */
17434       if(encRetVal.encoded == ENCODE_FAIL)
17435       {
17436          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17437                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17438          break;
17439       }
17440       else
17441       {
17442          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17443 #ifdef DEBUG_ASN_PRINT
17444          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17445          {
17446             printf("%x",encBuf[ieIdx]);
17447          }
17448 #endif
17449       }
17450
17451       /* Sending msg */
17452       if(sendF1APMsg() != ROK)
17453       {
17454          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17455          break;
17456       }
17457       ret = ROK;
17458       break;
17459    }while(true);
17460    
17461    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17462          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17463    {
17464       ret = duSendCellDeletReq(cellId);
17465       if(ret != ROK)
17466       {
17467          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17468                Delete req for CellId");
17469       }
17470    }
17471    FreeUeContextReleaseComplete(f1apMsg);
17472    return ret;
17473
17474 }
17475
17476 /*******************************************************************
17477 *
17478 * @brief added free part for the memory allocated by aper_decoder 
17479 *
17480 * @details
17481 *
17482 *    Function : freeAperDecodeUeContextReleaseCommand 
17483 *
17484 *    Functionality: added free part for the memory allocated by aper_decoder
17485 *
17486 * @params[in] F1AP_PDU_t *f1apMsg
17487 * @return void
17488 *
17489 * ****************************************************************/
17490 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17491 {
17492    uint8_t ieIdx=0;
17493    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17494
17495    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17496    
17497    if(ueContextReleaseCommand->protocolIEs.list.array)
17498    {
17499       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17500       {
17501          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17502          {
17503             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17504             {
17505                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17506                   break;
17507                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17508                   break;
17509                case ProtocolIE_ID_id_Cause:
17510                   break;
17511                case ProtocolIE_ID_id_RRCContainer:
17512                {
17513                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17514                   {
17515                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17516                   }
17517                   break;
17518                }
17519                default :
17520                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17521                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17522                   break;
17523             }
17524          }
17525          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17526       }
17527       free(ueContextReleaseCommand->protocolIEs.list.array);
17528    }
17529 }
17530 /*******************************************************************
17531 *
17532 * @brief processing of UE Context Release Command
17533 *
17534 * @details
17535 *
17536 *    Function : procF1UeContextReleaseCommand 
17537 *
17538 *    Functionality: processing of UE Context Release Command
17539 *
17540 * @params[in] F1AP_PDU_t *f1apMsg
17541 * @return void
17542 *
17543 * ****************************************************************/
17544 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17545 {
17546    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17547    uint16_t cellIdx =0, cellId = 0;
17548    bool ueIdxFound = false;
17549    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17550    DuUeCb   *duUeCb = NULLP;
17551    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17552
17553    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17554
17555    if(ueContextReleaseCommand->protocolIEs.list.array)
17556    {
17557       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17558       {
17559          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17560          {
17561             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17562             {
17563                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17564                   {
17565                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17566                                     value.choice.GNB_CU_UE_F1AP_ID;
17567                      break;
17568                   }
17569
17570                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17571                   {
17572                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17573                                      value.choice.GNB_DU_UE_F1AP_ID;
17574                      break;
17575                   }
17576
17577                case ProtocolIE_ID_id_Cause:
17578                   {
17579                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17580                      {
17581                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17582                         {
17583                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17584                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17585                            {
17586                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17587                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17588                               ueIdxFound = true;
17589                               break;
17590                            }
17591                         }
17592                         if(ueIdxFound == true)
17593                         {
17594                            break;
17595                         }
17596                      }
17597                      
17598                      if(!ueIdxFound)
17599                      {
17600                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17601                         ret = RFAILED;
17602                      }
17603                      break;
17604                   }
17605
17606                case ProtocolIE_ID_id_RRCContainer:
17607                   {
17608                      if(ueIdxFound == true)  
17609                      {
17610                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17611                         if(duUeCb->f1UeDb)
17612                         {
17613                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17614                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17615                            duUeCb->f1UeDb->cellIdx = cellIdx;
17616                            /* Filling Dl RRC Msg Info */
17617                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17618                            if(!duUeCb->f1UeDb->dlRrcMsg)
17619                            {
17620                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17621                                     Memory allocation failed ");
17622                               ret = RFAILED;
17623                            }
17624                            else
17625                            {
17626                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17627                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17628                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17629                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17630                                     value.choice.RRCContainer);
17631                            }
17632
17633                         }
17634                         else
17635                         {
17636                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17637                                  Memory allocation failed ");
17638                            ret = RFAILED;
17639
17640                         }
17641                      }
17642                      break;
17643                   }
17644                default :
17645                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17646                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17647                   break;
17648             }
17649          }
17650       }
17651    }
17652    if(ret != RFAILED)
17653    {
17654       duProcUeContextReleaseCommand(cellId, duUeCb);
17655    }
17656    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17657    return ret;
17658 }
17659
17660 /**************************************************************
17661  *
17662  * @brief free the memory allocated by aper decoder for paging
17663  *
17664  * @details
17665  *
17666  *    Function : freeAperDecodePagingMsg
17667  *
17668  *    Functionality:
17669  *         - free the memory allocated by aper decoder for
17670  *         the paging f1ap msg
17671  *
17672  * @params[in] Paging_t   *paging
17673  * @return ROK     - success
17674  *         RFAILED - failure
17675  *
17676  ****************************************************************/
17677 void freeAperDecodePagingMsg(Paging_t   *paging)
17678 {
17679    uint8_t ieIdx, cellIdx;
17680    PagingCell_ItemIEs_t *pagingCellItemIes;
17681    PagingCell_Item_t *pagingCellItem;
17682    PagingCell_list_t  *pagingCelllist;
17683
17684    if(paging)
17685    {
17686       if(paging->protocolIEs.list.array)
17687       {
17688          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17689          {
17690             if(paging->protocolIEs.list.array[ieIdx])
17691             {
17692                switch(paging->protocolIEs.list.array[ieIdx]->id)
17693                {
17694                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17695                      {
17696                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17697                         break;
17698                      }
17699                   case ProtocolIE_ID_id_PagingIdentity:
17700                      {
17701                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17702                         {
17703                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17704                            {
17705                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17706                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17707                               {
17708                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17709                               }
17710                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17711                            }
17712                         }
17713                         break;
17714                      }
17715                   case ProtocolIE_ID_id_PagingCell_List:
17716                      {
17717                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17718                         if(pagingCelllist->list.array)
17719                         {
17720                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17721                            {
17722                               if(pagingCelllist->list.array[cellIdx])
17723                               {
17724                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17725                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17726                                  {
17727                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17728                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17729                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17730                                  }
17731                                  free(pagingCelllist->list.array[cellIdx]);
17732                               }
17733                            }
17734                            free(pagingCelllist->list.array);
17735                         }
17736                         break;
17737                      }
17738                }
17739                free(paging->protocolIEs.list.array[ieIdx]);
17740             }
17741          }
17742          free(paging->protocolIEs.list.array);
17743
17744       }
17745    }
17746 }
17747
17748 /**************************************************************
17749  *
17750  * @brief processing the paging f1ap msg received from CU 
17751  *
17752  * @details
17753  *
17754  *    Function : procPagingMsg
17755  *
17756  *    Functionality:
17757  *         - processing the paging f1ap msg received from CU
17758  *
17759  * @params[in] F1AP_PDU_t *f1apMsg
17760  * @return ROK     - success
17761  *         RFAILED - failure
17762  *
17763  *
17764  ****************************************************************/
17765 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17766 {
17767    uint8_t ieIdx = 0, cellListIdx = 0;
17768    uint64_t cellId = 0;
17769    Paging_t   *paging = NULLP;
17770    PagingCell_list_t  *pagingCelllist = NULLP;
17771    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17772    PagingCell_Item_t *pagingCellItem = NULLP;
17773    DuPagingMsg *tmpPagingParam = NULLP;
17774
17775    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17776    if(paging)
17777    {
17778       if(paging->protocolIEs.list.array)
17779       {
17780          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17781          if(tmpPagingParam == NULLP)
17782          {
17783             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17784             freeAperDecodePagingMsg(paging);
17785             return RFAILED;
17786          }
17787          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17788          {
17789             if(paging->protocolIEs.list.array[ieIdx])
17790             {
17791                switch(paging->protocolIEs.list.array[ieIdx]->id)
17792                {
17793                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17794                      {
17795                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17796                                          &tmpPagingParam->pagUeId);
17797                         break;
17798                      }
17799
17800                   case ProtocolIE_ID_id_PagingIdentity:
17801                      {
17802                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17803                         {
17804                            case PagingIdentity_PR_cNUEPagingIdentity: 
17805                               {
17806                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17807                                  {
17808                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17809                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17810
17811                                  }
17812                                  break;
17813                               }
17814                             case PagingIdentity_PR_rANUEPagingIdentity:
17815                                {
17816                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17817                                   break;
17818                                }
17819                             default:
17820                                {
17821                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17822                                   continue;
17823                                }
17824                         }
17825                      }
17826
17827                   case ProtocolIE_ID_id_PagingDRX:
17828                      {
17829                         tmpPagingParam->pagingDrxPres = TRUE;
17830                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17831                         break;
17832                      }
17833
17834                   case ProtocolIE_ID_id_PagingPriority:
17835                      {
17836                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17837                         break;
17838                      }
17839
17840                   case ProtocolIE_ID_id_PagingCell_List:
17841                      {
17842                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17843                         if(pagingCelllist->list.array)
17844                         {
17845                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17846                            {
17847                               if(pagingCelllist->list.array[cellListIdx])
17848                               {
17849                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17850                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17851                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17852                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17853                                  {
17854                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17855                                     continue;
17856                                  }
17857                               }
17858                            }
17859                         }
17860                         break;
17861                      }
17862                    default:
17863                      {
17864                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17865                          break;
17866                      }
17867                }
17868             }
17869          }
17870       }
17871    }
17872    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17873    freeAperDecodePagingMsg(paging);
17874   
17875    return ROK;
17876 }
17877
17878 /**************************************************************
17879  *
17880  * @brief Handles received F1AP message and sends back response  
17881  *
17882  * @details
17883  *
17884  *    Function : F1APMsgHdlr
17885  *
17886  *    Functionality:
17887  *         - Decodes received F1AP control message
17888  *         - Prepares response message, encodes and sends to SCTP
17889  *
17890  * @params[in] 
17891  * @return ROK     - success
17892  *         RFAILED - failure
17893  *
17894  * ****************************************************************/
17895 void F1APMsgHdlr(Buffer *mBuf)
17896 {
17897    int i =0;
17898    char *recvBuf =NULLP;
17899    MsgLen copyCnt =0;
17900    MsgLen recvBufLen =0;
17901    F1AP_PDU_t *f1apMsg =NULLP;
17902    asn_dec_rval_t rval; /* Decoder return value */
17903    F1AP_PDU_t f1apasnmsg ;
17904    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17905    ODU_PRINT_MSG(mBuf, 0,0);
17906
17907    /* Copy mBuf into char array to decode it */
17908    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17909    DU_ALLOC(recvBuf, (Size)recvBufLen);
17910
17911    if(recvBuf == NULLP)
17912    {
17913       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17914       return;
17915    }
17916    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17917    {
17918       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17919       return;
17920    }
17921
17922 #ifdef DEBUG_ASN_PRINT
17923    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17924    for(i=0; i< recvBufLen; i++)
17925    {
17926       printf("%x",recvBuf[i]);
17927    }
17928 #endif
17929
17930    /* Decoding flat buffer into F1AP messsage */
17931    f1apMsg = &f1apasnmsg;
17932    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17933
17934    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17935
17936    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17937    {
17938       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17939       return;
17940    }
17941    printf("\n");
17942    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17943
17944    switch(f1apMsg->present)
17945    {
17946       case F1AP_PDU_PR_successfulOutcome:
17947          {
17948             switch(f1apMsg->choice.successfulOutcome->value.present)
17949             {
17950                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17951                   {
17952                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17953                      break;
17954                   }
17955                case SuccessfulOutcome__value_PR_F1SetupResponse:
17956                   {                             
17957 #ifndef ODU_TEST_STUB
17958                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17959 #endif
17960                      break;
17961                   }
17962
17963                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17964                   {
17965                      procF1GNBDUCfgUpdAck(f1apMsg);
17966                      break;
17967                   }
17968
17969                default:
17970                   {
17971                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17972                            f1apMsg->choice.successfulOutcome->value.present);
17973                      return;
17974                   }
17975             }/* End of switch(successfulOutcome) */
17976             free(f1apMsg->choice.successfulOutcome);
17977             break;
17978          }
17979       case F1AP_PDU_PR_initiatingMessage:
17980          {
17981             switch(f1apMsg->choice.initiatingMessage->value.present)
17982             {
17983                case InitiatingMessage__value_PR_Reset:
17984                   {
17985                      procF1ResetReq(f1apMsg);
17986                      break;
17987                   }
17988                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17989                   {
17990                      procF1DlRrcMsgTrans(f1apMsg);
17991                      break;
17992                   }
17993                case InitiatingMessage__value_PR_UEContextSetupRequest:
17994                   {
17995                      procF1UeContextSetupReq(f1apMsg);
17996                      break;
17997                   }
17998                case InitiatingMessage__value_PR_UEContextModificationRequest:
17999                   {
18000                      procF1UeContextModificationReq(f1apMsg);
18001                      break;
18002                   }
18003                case InitiatingMessage__value_PR_UEContextReleaseCommand:
18004                   {
18005                       procF1UeContextReleaseCommand(f1apMsg);
18006                       break;
18007                   }
18008                case InitiatingMessage__value_PR_Paging:
18009                   {
18010                      procPagingMsg(f1apMsg);
18011                      break;
18012                   }
18013                default:
18014                   {
18015                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18016                            f1apMsg->choice.initiatingMessage->value.present);
18017                      return;
18018                   }
18019             }/* End of switch(initiatingMessage) */
18020             free(f1apMsg->choice.initiatingMessage);
18021             break;
18022          }
18023
18024       default:
18025          {
18026             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18027             return;
18028          }
18029          free(f1apMsg);
18030
18031    }/* End of switch(f1apMsg->present) */
18032    
18033    DU_FREE(recvBuf, (Size)recvBufLen);
18034 } /* End of F1APMsgHdlr */
18035
18036 /**********************************************************************
18037   End of file
18038  **********************************************************************/